/[imapfilter]/imapfilter/lock.c
ViewVC logotype

Diff of /imapfilter/lock.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by lefcha, Mon Jul 29 01:31:20 2002 UTC revision 1.7 by lefcha, Tue Aug 20 14:30:34 2002 UTC
# Line 39  void lockfile_create(void) Line 39  void lockfile_create(void)
39  void lockfile_check(void)  void lockfile_check(void)
40  {  {
41      pid_t n;      pid_t n;
42        char lockf[PATH_MAX];
43    
44        snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock");
45        lockfile = xstrdup(lockf);
46    
47      if ((n = lockfile_pid())) {      if ((n = lockfile_pid())) {
48          fprintf(stderr,          errno = 0;
49                "imapfilter: another imapfilter is running with pid %d\n", n);          kill(n, 0);
50          exit(ERROR_LOCKFILE);          if (errno == ESRCH) {   /* Process does not exist. */
51                fprintf(stderr, "imapfilter: removing stale lockfile\n");
52                lockfile_remove();
53            } else {
54                fprintf(stderr,
55                        "imapfilter: another imapfilter"
56                        "is running with pid %d\n", n);
57                exit(ERROR_LOCKFILE);
58            }
59      }      }
60  }  }
61    
# Line 54  void lockfile_check(void) Line 66  void lockfile_check(void)
66   */   */
67  pid_t lockfile_pid(void)  pid_t lockfile_pid(void)
68  {  {
     char lockf[PATH_MAX];  
69      char line[LINE_MAX];      char line[LINE_MAX];
70      FILE *fd;      FILE *fd;
71      pid_t n = 0;      pid_t n = 0;
72    
     snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock");  
     lockfile = xstrdup(lockf);  
   
73      if (exists_file(lockfile)) {      if (exists_file(lockfile)) {
74          fd = fopen(lockfile, "r");          fd = fopen(lockfile, "r");
75          if (!fd)          if (!fd)
# Line 91  int lockfile_remove(void) Line 99  int lockfile_remove(void)
99          error("imapfilter: removing lockfile; %s\n", strerror(errno));          error("imapfilter: removing lockfile; %s\n", strerror(errno));
100          return ERROR_FILE_OPEN;          return ERROR_FILE_OPEN;
101      }      }
     xfree(lockfile);  
   
102      return 0;      return 0;
103  }  }
104    

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26