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

Diff of /imapfilter/lock.c

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

revision 1.3 by lefcha, Tue Jun 18 21:18:31 2002 UTC revision 1.4 by lefcha, Sat Jul 13 21:19:23 2002 UTC
# Line 10  Line 10 
10    
11    
12  extern char *home;  extern char *home;
13        
14  static char *lockfile = NULL;   /* Lock file to stop new  static char *lockfile = NULL;   /* Lock file to stop new imapfilter
15                                     imapfilter processes. */                                     processes. */
16    
17    
18  /*  /*
# Line 28  void lockfile_create(void) Line 28  void lockfile_create(void)
28      if (!fd)      if (!fd)
29          fatal(ERROR_FILE_OPEN, "imapfilter: opening lockfile; %s\n",          fatal(ERROR_FILE_OPEN, "imapfilter: opening lockfile; %s\n",
30                strerror(errno));                strerror(errno));
31      fputs(ultostr(getpid(), 10), fd);      fprintf(fd, "%s\n", ultostr(getpid(), 10));
32      fclose(fd);      fclose(fd);
33  }  }
34    
# Line 42  void lockfile_check(void) Line 42  void lockfile_check(void)
42    
43      if ((n = lockfile_pid())) {      if ((n = lockfile_pid())) {
44          fprintf(stderr,          fprintf(stderr,
45                  "imapfilter: another imapfilter is running with pid %d\n", n);                "imapfilter: another imapfilter is running with pid %d\n", n);
46          exit(ERROR_LOCKFILE);          exit(ERROR_LOCKFILE);
47      }      }
48  }  }
# Line 58  pid_t lockfile_pid(void) Line 58  pid_t lockfile_pid(void)
58      char line[LINE_MAX];      char line[LINE_MAX];
59      FILE *fd;      FILE *fd;
60      pid_t n = 0;      pid_t n = 0;
61        
62      snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock");      snprintf(lockf, PATH_MAX, "%s/%s", home, ".imapfilter/lock");
63      lockfile = xstrdup(lockf);      lockfile = xstrdup(lockf);
64        
65      if (exists_file(lockfile)) {      if (exists_file(lockfile)) {
66          fd = fopen(lockfile, "r");          fd = fopen(lockfile, "r");
67          if (!fd)          if (!fd)
# Line 75  pid_t lockfile_pid(void) Line 75  pid_t lockfile_pid(void)
75          }          }
76          fclose(fd);          fclose(fd);
77      }      }
       
78      return n;      return n;
79  }  }
80    
# Line 87  int lockfile_remove(void) Line 86  int lockfile_remove(void)
86  {  {
87      if (!lockfile)      if (!lockfile)
88          return 0;          return 0;
89        
90      if (remove(lockfile)) {      if (remove(lockfile)) {
91          error("imapfilter: removing lockfile; %s\n", strerror(errno));          error("imapfilter: removing lockfile; %s\n", strerror(errno));
92          return ERROR_FILE_OPEN;          return ERROR_FILE_OPEN;
93      }      }
       
94      xfree(lockfile);      xfree(lockfile);
95        
96      return 0;      return 0;
97  }  }
98    
# Line 107  void kill_imapfilter(void) Line 105  void kill_imapfilter(void)
105      pid_t n;      pid_t n;
106    
107      n = lockfile_pid();      n = lockfile_pid();
108        
109      if (n > 0) {      if (n > 0) {
110          if (kill(n, SIGTERM))          if (kill(n, SIGTERM))
111              fprintf(stderr, "imapfilter: killing process with pid %d; %s\n",              fprintf(stderr, "imapfilter: killing process with pid %d; %s\n",

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26