[dovecot-cvs] dovecot/src/lib unlink-lockfiles.c,1.3,1.4
unlink-lockfiles.h,1.1.1.1,1.2
cras at procontrol.fi
cras at procontrol.fi
Thu Jul 3 04:58:44 EEST 2003
Update of /home/cvs/dovecot/src/lib
In directory danu:/tmp/cvs-serv7736
Modified Files:
unlink-lockfiles.c unlink-lockfiles.h
Log Message:
Minor cleanups.
Index: unlink-lockfiles.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib/unlink-lockfiles.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- unlink-lockfiles.c 12 Feb 2003 12:07:51 -0000 1.3
+++ unlink-lockfiles.c 3 Jul 2003 00:58:42 -0000 1.4
@@ -32,19 +32,24 @@
#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 @@
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: unlink-lockfiles.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib/unlink-lockfiles.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- unlink-lockfiles.h 9 Aug 2002 09:15:46 -0000 1.1.1.1
+++ unlink-lockfiles.h 3 Jul 2003 00:58:42 -0000 1.2
@@ -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
More information about the dovecot-cvs
mailing list