updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / bluemote / bluemote-lock.patch
bloba5803df2909e7cfc29e52ddd34d93fcda17ac6d2
1 diff -ur bluemote.orig/bluemote.c bluemote/bluemote.c
2 --- bluemote.orig/bluemote.c 2005-01-03 08:15:42.000000000 +0100
3 +++ bluemote/bluemote.c 2006-06-08 00:04:50.000000000 +0200
4 @@ -79,19 +79,17 @@
5 close_producer();
6 exit(0);
8 - else
10 + if(!get_lock())
12 - if(!get_lock())
13 - {
14 - printf("Another instance of Bluemote already running!\n");
15 - exit(1);
16 - }
17 + printf("Another instance of Bluemote already running!\n");
18 + exit(1);
19 + }
21 - if(!open_consumer())
22 - {
23 - printf("Unable to listen for messages!\n");
24 - exit(1);
25 - }
26 + if(!open_consumer())
27 + {
28 + printf("Unable to listen for messages!\n");
29 + exit(1);
32 strcpy(logfile, getenv("HOME"));
33 diff -ur bluemote.orig/ipc.c bluemote/ipc.c
34 --- bluemote.orig/ipc.c 2004-12-09 10:30:08.000000000 +0100
35 +++ bluemote/ipc.c 2006-06-08 00:05:22.000000000 +0200
36 @@ -32,24 +32,21 @@
37 struct sockaddr_un sockadr;
38 int sock;
40 -int get_lock()
41 +void remove_lock()
43 - struct flock fl;
44 + unlink(lockfile);
47 +int get_lock()
49 strcpy(lockfile, getenv("HOME"));
50 strcat(lockfile, BLUEMOTEDIR);
51 strcat(lockfile, LOCKFILE);
53 - fl.l_type = F_WRLCK;
54 - fl.l_whence = SEEK_SET;
55 - fl.l_start = 0;
56 - fl.l_len = 1;
58 - if((fdlock = open(lockfile, O_WRONLY|O_CREAT, 0600)) == -1)
59 + if((fdlock = open(lockfile, O_WRONLY|O_CREAT|O_EXCL, 0600)) == -1)
60 return 0;
62 - if(fcntl(fdlock, F_SETLK, &fl) == -1)
63 - return 0;
64 + atexit(remove_lock);
66 return 1;