summaryrefslogtreecommitdiff
path: root/source4/smbd
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-10 08:06:28 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:19:31 -0500
commit9281b58398de76815c23361826615478a611bc60 (patch)
treef5f6543b99e30de486b2c83c7c31722a4274fee9 /source4/smbd
parent0871be3f351e80de8b97717f7975d98702112376 (diff)
downloadsamba-9281b58398de76815c23361826615478a611bc60.tar.gz
samba-9281b58398de76815c23361826615478a611bc60.tar.bz2
samba-9281b58398de76815c23361826615478a611bc60.zip
r8282: make the deletion of the smbd.tmp directory recursive. This cleans up the messaging
directory (This used to be commit 783679e0df6c059ebd26f78115445e81e304bc84)
Diffstat (limited to 'source4/smbd')
-rw-r--r--source4/smbd/server.c85
1 files changed, 40 insertions, 45 deletions
diff --git a/source4/smbd/server.c b/source4/smbd/server.c
index 717de0c523..f5f37a55cf 100644
--- a/source4/smbd/server.c
+++ b/source4/smbd/server.c
@@ -33,66 +33,61 @@
/*
- cleanup temporary files. This is the new alternative to
- TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
- efficient on unix systems due to the lack of scaling of the byte
- range locking system. So instead of putting the burden on tdb to
- cleanup tmp files, this function deletes them.
+ recursively delete a directory tree
*/
-static void cleanup_tmp_files(void)
+static void recursive_delete(const char *path)
{
- char *path;
DIR *dir;
struct dirent *de;
- TALLOC_CTX *mem_ctx = talloc_new(NULL);
-
- path = smbd_tmp_path(mem_ctx, NULL);
dir = opendir(path);
if (!dir) {
- talloc_free(mem_ctx);
return;
}
for (de=readdir(dir);de;de=readdir(dir)) {
- /*
- * Don't try to delete . and ..
- */
- if (strcmp(de->d_name, ".") != 0 &&
- strcmp(de->d_name, "..") != 0) {
- char *fname = talloc_asprintf(mem_ctx, "%s/%s", path, de->d_name);
- int ret = unlink(fname);
- if (ret == -1 &&
- errno != ENOENT &&
- errno != EPERM &&
- errno != EISDIR) {
- DEBUG(0,("Unabled to delete '%s' - %s\n",
- fname, strerror(errno)));
- smb_panic("unable to cleanup tmp files");
- }
- if (ret == -1 &&
- errno == EPERM) {
- /*
- * If it is a dir, don't complain
- * NOTE! The test will only happen if we have
- * sys/stat.h, otherwise we will always error out
- */
-#ifdef HAVE_SYS_STAT_H
- struct stat sb;
- if (stat(fname, &sb) != -1 &&
- !S_ISDIR(sb.st_mode))
-#endif
- {
- DEBUG(0,("Unable to delete '%s' - %s\n",
- fname, strerror(errno)));
- smb_panic("unable to cleanup tmp files");
- }
- }
- talloc_free(fname);
+ char *fname;
+ struct stat st;
+
+ if (strcmp(de->d_name, ".") == 0 ||
+ strcmp(de->d_name, "..") == 0) {
+ continue;
+ }
+
+ fname = talloc_asprintf(path, "%s/%s", path, de->d_name);
+ if (stat(fname, &st) != 0) {
+ continue;
+ }
+ if (S_ISDIR(st.st_mode)) {
+ recursive_delete(fname);
+ talloc_free(fname);
+ continue;
+ }
+ if (unlink(fname) != 0) {
+ DEBUG(0,("Unabled to delete '%s' - %s\n",
+ fname, strerror(errno)));
+ smb_panic("unable to cleanup tmp files");
}
+ talloc_free(fname);
}
closedir(dir);
+}
+
+/*
+ cleanup temporary files. This is the new alternative to
+ TDB_CLEAR_IF_FIRST. Unfortunately TDB_CLEAR_IF_FIRST is not
+ efficient on unix systems due to the lack of scaling of the byte
+ range locking system. So instead of putting the burden on tdb to
+ cleanup tmp files, this function deletes them.
+*/
+static void cleanup_tmp_files(void)
+{
+ char *path;
+ TALLOC_CTX *mem_ctx = talloc_new(NULL);
+
+ path = smbd_tmp_path(mem_ctx, NULL);
+ recursive_delete(path);
talloc_free(mem_ctx);
}