]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Minor cleanups.
authorTimo Sirainen <tss@iki.fi>
Thu, 3 Jul 2003 00:58:42 +0000 (03:58 +0300)
committerTimo Sirainen <tss@iki.fi>
Thu, 3 Jul 2003 00:58:42 +0000 (03:58 +0300)
--HG--
branch : HEAD

src/lib/unlink-lockfiles.c
src/lib/unlink-lockfiles.h

index 3c76c9b1718f3094d857424e6c7249990642767a..71779eaf843f4000750770cc5144889bab3f8f7c 100644 (file)
 #include <dirent.h>
 #include <sys/stat.h>
 
-void unlink_lockfiles(const char *dir, const char *pidprefix,
-                     const char *otherprefix, time_t other_min_time)
+int unlink_lockfiles(const char *dir, const char *pidprefix,
+                    const char *otherprefix, time_t other_min_time)
 {
        DIR *dirp;
        struct dirent *d;
        struct stat st;
        char path[PATH_MAX];
        unsigned int pidlen, otherlen;
+       int ret = 0;
 
        /* check for any invalid access files */
        dirp = opendir(dir);
-       if (dirp == NULL)
-               return;
+       if (dirp == NULL) {
+               if (errno == ENOENT)
+                       return 0;
+               i_error("opendir(%s) failed: %m", dir);
+               return -1;
+       }
 
        pidlen = pidprefix == NULL ? 0 : strlen(pidprefix);
        otherlen = otherprefix == NULL ? 0 : strlen(otherprefix);
@@ -61,16 +66,29 @@ void unlink_lockfiles(const char *dir, const char *pidprefix,
                        if (kill(atol(fname+pidlen), 0) == 0 || errno != ESRCH)
                                continue; /* valid */
 
-                       if (str_path(path, sizeof(path), dir, fname) == 0)
-                               (void)unlink(path);
-               } else if (otherprefix != 0 &&
+                       if (str_path(path, sizeof(path), dir, fname) == 0) {
+                               if (unlink(path) < 0 && errno != ENOENT) {
+                                       i_error("unlink(%s) failed: %m", path);
+                                       ret = -1;
+                               }
+                       }
+               } else if (otherprefix != NULL &&
                           strncmp(fname, otherprefix, otherlen) == 0) {
                        if (str_path(path, sizeof(path), dir, fname) == 0 &&
                            stat(path, &st) == 0 &&
-                           st.st_mtime < other_min_time)
-                               (void)unlink(path);
+                           st.st_mtime < other_min_time &&
+                           st.st_ctime < other_min_time)
+                               if (unlink(path) < 0 && errno != ENOENT) {
+                                       i_error("unlink(%s) failed: %m", path);
+                                       ret = -1;
+                               }
                }
        }
 
-       (void)closedir(dirp);
+       if (closedir(dirp) < 0) {
+               i_error("closedir(%s) failed: %m", dir);
+               ret = -1;
+       }
+
+       return ret;
 }
index bd3a2ae568c2afc9bd8ca08bee82355085f6d7bc..05eebc2cfed8fcd2420363a42f7d2e13c54107af 100644 (file)
@@ -1,7 +1,11 @@
 #ifndef __UNLINK_LOCKFILES_H
 #define __UNLINK_LOCKFILES_H
 
-void unlink_lockfiles(const char *dir, const char *pidprefix,
-                     const char *otherprefix, time_t other_min_time);
+/* Delete stale lock files. Filenames beginning with pidprefix<PID> are
+   deleted immediately if PID doesn't exist. Filenames beginning with
+   otherprefix are deleted if their mtime and ctime is older than
+   other_min_time. */
+int unlink_lockfiles(const char *dir, const char *pidprefix,
+                    const char *otherprefix, time_t other_min_time);
 
 #endif