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

Diff of /imapfilter/lock.c

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

revision 1.12.2.1 by lefcha, Fri Aug 8 00:28:03 2003 UTC revision 1.18 by lefcha, Sat Feb 14 19:14:43 2004 UTC
# Line 33  lockfile_create(void) Line 33  lockfile_create(void)
33    
34          fd = fopen(lockfile, "w");          fd = fopen(lockfile, "w");
35          if (fd == NULL)          if (fd == NULL)
36                  fatal(ERROR_FILE_OPEN, "opening lockfile; %s\n",                  fatal(ERROR_FILEOPEN, "opening lockfile; %s\n",
37                      strerror(errno));                      strerror(errno));
38          fprintf(fd, "%s\n", ultostr(getpid(), 10));          fprintf(fd, "%s\n", ultostr(getpid(), 10));
39          fclose(fd);          fclose(fd);
# Line 52  lockfile_check(void) Line 52  lockfile_check(void)
52                  errno = 0;                  errno = 0;
53                  kill(n, 0);                  kill(n, 0);
54                  if (errno == ESRCH) {   /* Process does not exist. */                  if (errno == ESRCH) {   /* Process does not exist. */
55                          fprintf(stderr, "imapfilter: removing stale lockfile\n");                          fprintf(stderr,
56                                "imapfilter: removing stale lockfile\n");
57                          lockfile_remove();                          lockfile_remove();
58                  } else {                  } else {
59                          fprintf(stderr,                          fprintf(stderr,
# Line 65  lockfile_check(void) Line 66  lockfile_check(void)
66    
67    
68  /*  /*
69   * Check if lockfile exists and if so, return the PID of the other   * Check if lockfile exists and if so, return the PID of the other imapfilter
70   * imapfilter running.   * running.
71   */   */
72  pid_t  pid_t
73  lockfile_pid(void)  lockfile_pid(void)
# Line 78  lockfile_pid(void) Line 79  lockfile_pid(void)
79    
80          n = 0;          n = 0;
81    
82          snprintf(lockf, PATH_MAX, "%s/%s", home, PATHNAME_LOCK_FILE);          snprintf(lockf, PATH_MAX, "%s/%s", home, PATHNAME_LOCK);
83          lockfile = xstrdup(lockf);          lockfile = xstrdup(lockf);
84    
85          if (exists_file(lockfile)) {          if (exists_file(lockfile)) {
86                  fd = fopen(lockfile, "r");                  fd = fopen(lockfile, "r");
87                  if (fd == NULL)                  if (fd == NULL)
88                          fatal(ERROR_FILE_OPEN, "opening lockfile; %s\n",                          fatal(ERROR_FILEOPEN, "opening lockfile; %s\n",
89                              strerror(errno));                              strerror(errno));
90                  if (fgets(line, LINE_MAX - 1, fd)) {                  if (fgets(line, LINE_MAX - 1, fd)) {
91                          errno = 0;                          errno = 0;
# Line 104  lockfile_pid(void) Line 105  lockfile_pid(void)
105  int  int
106  lockfile_remove(void)  lockfile_remove(void)
107  {  {
108    
109          if (lockfile == NULL)          if (lockfile == NULL)
110                  return 0;                  return 0;
111    
112          if (unlink(lockfile) && errno != ENOENT) {          if (unlink(lockfile) && errno != ENOENT) {
113                  error("removing lockfile; %s\n", strerror(errno));                  error("removing lockfile; %s\n", strerror(errno));
114                  return ERROR_FILE_OPEN;                  return ERROR_FILEOPEN;
115          }          }
116          return 0;          return 0;
117  }  }
# Line 127  kill_imapfilter(void) Line 129  kill_imapfilter(void)
129    
130          if (n > 0) {          if (n > 0) {
131                  if (kill(n, SIGTERM))                  if (kill(n, SIGTERM))
132                          fprintf(stderr, "imapfilter: killing process with "                          fprintf(stderr,
133                              "pid %d; %s\n", (int)(n), strerror(errno));                              "imapfilter: killing process with pid %d; %s\n",
134                                (int)(n), strerror(errno));
135                  lockfile_remove();                  lockfile_remove();
136                  exit(0);                  exit(0);
137          } else {          } else {

Legend:
Removed from v.1.12.2.1  
changed lines
  Added in v.1.18

webmaster@linux.gr
ViewVC Help
Powered by ViewVC 1.1.26