comparison src/dotlock.c @ 10:26e34ae9a3e3

changed indention and line wrapping to a more consistent style
author meillo@marmaro.de
date Mon, 27 Oct 2008 16:23:10 +0100
parents 08114f7dcc23
children 41958685480d
comparison
equal deleted inserted replaced
9:31cc8a89cb74 10:26e34ae9a3e3
27 #include <time.h> 27 #include <time.h>
28 28
29 #include "masqmail.h" 29 #include "masqmail.h"
30 #include "dotlock.h" 30 #include "dotlock.h"
31 31
32 gboolean dot_lock(gchar *lock_name, gchar *hitch_name) 32 gboolean
33 dot_lock(gchar * lock_name, gchar * hitch_name)
33 { 34 {
34 gboolean ok = FALSE; 35 gboolean ok = FALSE;
35 int fd; 36 int fd;
36 37
37 fd = open(hitch_name, O_WRONLY | O_CREAT | O_EXCL, 0); 38 fd = open(hitch_name, O_WRONLY | O_CREAT | O_EXCL, 0);
38 if(fd != -1){ 39 if (fd != -1) {
39 struct stat stat_buf; 40 struct stat stat_buf;
40 41
41 close(fd); 42 close(fd);
42 link(hitch_name, lock_name); 43 link(hitch_name, lock_name);
43 if(stat(hitch_name, &stat_buf) == 0){ 44 if (stat(hitch_name, &stat_buf) == 0) {
44 if(stat_buf.st_nlink == 2){ 45 if (stat_buf.st_nlink == 2) {
45 unlink(hitch_name); 46 unlink(hitch_name);
46 ok = TRUE; 47 ok = TRUE;
47 } 48 } else {
48 else{ 49 if (stat(lock_name, &stat_buf) == 0) {
49 if(stat(lock_name, &stat_buf) == 0){ 50 if ((time(NULL) - stat_buf.st_mtime) > MAX_LOCKAGE) {
50 if((time(NULL) - stat_buf.st_mtime) > MAX_LOCKAGE){ 51 /* remove lock if uncredibly old */
51 /* remove lock if uncredibly old */ 52 unlink(lock_name);
52 unlink(lock_name);
53 53
54 link(hitch_name, lock_name); 54 link(hitch_name, lock_name);
55 if(stat(hitch_name, &stat_buf) == 0){ 55 if (stat(hitch_name, &stat_buf) == 0) {
56 if(stat_buf.st_nlink == 2){ 56 if (stat_buf.st_nlink == 2) {
57 unlink(hitch_name); 57 unlink(hitch_name);
58 ok = TRUE; 58 ok = TRUE;
59 } 59 }
60 } 60 }
61 } 61 }
62 } 62 }
63 } 63 }
64 } 64 }
65 if(!ok){ 65 if (!ok) {
66 unlink(hitch_name); 66 unlink(hitch_name);
67 } 67 }
68 }else 68 } else
69 logwrite(LOG_WARNING, "could not create lock file %s: %s\n", 69 logwrite(LOG_WARNING, "could not create lock file %s: %s\n", lock_name, strerror(errno));
70 lock_name, strerror(errno));
71 70
72 return ok; 71 return ok;
73 } 72 }
74 73
75 gboolean dot_unlock(gchar *lock_name) 74 gboolean
75 dot_unlock(gchar * lock_name)
76 { 76 {
77 unlink(lock_name); 77 unlink(lock_name);
78 78
79 return TRUE; 79 return TRUE;
80 } 80 }