From cb8674c038e4d7a6e56490cb7c2ada08928bde0a Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 3 Jul 2003 04:01:10 +0300 Subject: [PATCH] some more cleanups --HG-- branch : HEAD --- src/lib/unlink-lockfiles.c | 14 ++++---------- src/lib/unlink-lockfiles.h | 5 ++++- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/lib/unlink-lockfiles.c b/src/lib/unlink-lockfiles.c index 71779eaf84..333c6842ab 100644 --- a/src/lib/unlink-lockfiles.c +++ b/src/lib/unlink-lockfiles.c @@ -44,12 +44,8 @@ int unlink_lockfiles(const char *dir, const char *pidprefix, /* check for any invalid access files */ dirp = opendir(dir); - if (dirp == NULL) { - if (errno == ENOENT) - return 0; - i_error("opendir(%s) failed: %m", dir); + if (dirp == NULL) return -1; - } pidlen = pidprefix == NULL ? 0 : strlen(pidprefix); otherlen = otherprefix == NULL ? 0 : strlen(otherprefix); @@ -69,7 +65,7 @@ int unlink_lockfiles(const char *dir, const char *pidprefix, if (str_path(path, sizeof(path), dir, fname) == 0) { if (unlink(path) < 0 && errno != ENOENT) { i_error("unlink(%s) failed: %m", path); - ret = -1; + ret = 0; } } } else if (otherprefix != NULL && @@ -80,15 +76,13 @@ int unlink_lockfiles(const char *dir, const char *pidprefix, st.st_ctime < other_min_time) if (unlink(path) < 0 && errno != ENOENT) { i_error("unlink(%s) failed: %m", path); - ret = -1; + ret = 0; } } } - if (closedir(dirp) < 0) { + if (closedir(dirp) < 0) i_error("closedir(%s) failed: %m", dir); - ret = -1; - } return ret; } diff --git a/src/lib/unlink-lockfiles.h b/src/lib/unlink-lockfiles.h index 05eebc2cfe..f8fdd6787c 100644 --- a/src/lib/unlink-lockfiles.h +++ b/src/lib/unlink-lockfiles.h @@ -4,7 +4,10 @@ /* Delete stale lock files. Filenames beginning with pidprefix 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. */ + other_min_time. + + Returns 1 if everything was successful, 0 if some of the files + couldn't be deleted, -1 if directory couldn't be opened at all. */ int unlink_lockfiles(const char *dir, const char *pidprefix, const char *otherprefix, time_t other_min_time); -- 2.47.3