diff -ur bluemote.orig/bluemote.c bluemote/bluemote.c --- bluemote.orig/bluemote.c 2005-01-03 08:15:42.000000000 +0100 +++ bluemote/bluemote.c 2006-06-08 00:04:50.000000000 +0200 @@ -79,19 +79,17 @@ close_producer(); exit(0); } - else + + if(!get_lock()) { - if(!get_lock()) - { - printf("Another instance of Bluemote already running!\n"); - exit(1); - } + printf("Another instance of Bluemote already running!\n"); + exit(1); + } - if(!open_consumer()) - { - printf("Unable to listen for messages!\n"); - exit(1); - } + if(!open_consumer()) + { + printf("Unable to listen for messages!\n"); + exit(1); } strcpy(logfile, getenv("HOME")); diff -ur bluemote.orig/ipc.c bluemote/ipc.c --- bluemote.orig/ipc.c 2004-12-09 10:30:08.000000000 +0100 +++ bluemote/ipc.c 2006-06-08 00:05:22.000000000 +0200 @@ -32,24 +32,21 @@ struct sockaddr_un sockadr; int sock; -int get_lock() +void remove_lock() { - struct flock fl; + unlink(lockfile); +} +int get_lock() +{ strcpy(lockfile, getenv("HOME")); strcat(lockfile, BLUEMOTEDIR); strcat(lockfile, LOCKFILE); - fl.l_type = F_WRLCK; - fl.l_whence = SEEK_SET; - fl.l_start = 0; - fl.l_len = 1; - - if((fdlock = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1) + if((fdlock = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1) return 0; - if(fcntl(fdlock, F_SETLK, &fl) == -1) - return 0; + atexit(remove_lock); return 1; }