svn commit: samba r3360 - in branches/SAMBA_4_0/source: lib
lib/messaging libcli ntvfs/common rpc_server/netlogon smbd
tridge at samba.org
tridge at samba.org
Fri Oct 29 08:38:59 GMT 2004
Author: tridge
Date: 2004-10-29 08:38:59 +0000 (Fri, 29 Oct 2004)
New Revision: 3360
WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=3360
Log:
improved the deletion of tmp files. smbd now puts all tmp files in var/locks/smbd.tmp/
and deletes that dir on startup.
Modified:
branches/SAMBA_4_0/source/lib/messaging/messaging.c
branches/SAMBA_4_0/source/lib/util.c
branches/SAMBA_4_0/source/libcli/unexpected.c
branches/SAMBA_4_0/source/ntvfs/common/brlock.c
branches/SAMBA_4_0/source/ntvfs/common/opendb.c
branches/SAMBA_4_0/source/rpc_server/netlogon/schannel_state.c
branches/SAMBA_4_0/source/smbd/service.c
Changeset:
Modified: branches/SAMBA_4_0/source/lib/messaging/messaging.c
===================================================================
--- branches/SAMBA_4_0/source/lib/messaging/messaging.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/lib/messaging/messaging.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -85,7 +85,7 @@
{
char *name = talloc_asprintf(mem_ctx, "messaging/msg.%u", (unsigned)server_id);
char *ret;
- ret = lock_path(mem_ctx, name);
+ ret = smbd_tmp_path(mem_ctx, name);
talloc_free(name);
return ret;
}
@@ -449,7 +449,7 @@
}
/* create the messaging directory if needed */
- msg->path = lock_path(msg, "messaging");
+ msg->path = smbd_tmp_path(msg, "messaging");
mkdir(msg->path, 0700);
talloc_free(msg->path);
Modified: branches/SAMBA_4_0/source/lib/util.c
===================================================================
--- branches/SAMBA_4_0/source/lib/util.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/lib/util.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -702,7 +702,6 @@
/*****************************************************************
A useful function for returning a path in the Samba lock directory.
*****************************************************************/
-
char *lock_path(TALLOC_CTX* mem_ctx, const char *name)
{
char *fname, *dname;
@@ -736,6 +735,30 @@
return fname;
}
+/*
+ return a path in the smbd.tmp directory, where all temporary file
+ for smbd go. If NULL is passed for name then return the directory
+ path itself
+*/
+char *smbd_tmp_path(TALLOC_CTX *mem_ctx, const char *name)
+{
+ char *fname, *dname;
+
+ dname = lock_path(mem_ctx, "smbd.tmp");
+ if (!directory_exist(dname,NULL)) {
+ mkdir(dname,0755);
+ }
+
+ if (name == NULL) {
+ return dname;
+ }
+
+ fname = talloc_asprintf(mem_ctx, "%s/%s", dname, name);
+ talloc_free(dname);
+
+ return fname;
+}
+
/**
* @brief Returns the platform specific shared library extension.
*
Modified: branches/SAMBA_4_0/source/libcli/unexpected.c
===================================================================
--- branches/SAMBA_4_0/source/libcli/unexpected.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/libcli/unexpected.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -44,15 +44,13 @@
struct unexpected_key key;
char buf[1024];
int len=0;
- TALLOC_CTX *mem_ctx;
if (!tdbd) {
- mem_ctx = talloc_init("receive_unexpected");
- if (!mem_ctx) return;
- tdbd = tdb_wrap_open(NULL, lock_path(mem_ctx, "unexpected.tdb"), 0,
+ char *path = smbd_tmp_path(NULL, "unexpected.tdb");
+ tdbd = tdb_wrap_open(NULL, path, 0,
TDB_DEFAULT,
O_RDWR | O_CREAT, 0644);
- talloc_destroy(mem_ctx);
+ talloc_free(path);
if (!tdbd) {
return;
}
@@ -150,13 +148,12 @@
const char *mailslot_name)
{
struct tdb_wrap *tdb2;
- TALLOC_CTX *mem_ctx;
+ char *path;
- mem_ctx = talloc_init("receive_unexpected");
- if (!mem_ctx) return NULL;
- tdb2 = tdb_wrap_open(mem_ctx, lock_path(mem_ctx, "unexpected.tdb"), 0, 0, O_RDONLY, 0);
+ path = smbd_tmp_path(NULL, "unexpected.tdb");
+ tdb2 = tdb_wrap_open(NULL, path, 0, 0, O_RDONLY, 0);
+ talloc_free(path);
if (!tdb2) {
- talloc_destroy(mem_ctx);
return NULL;
}
@@ -167,7 +164,7 @@
tdb_traverse(tdb2->tdb, traverse_match, NULL);
- talloc_destroy(mem_ctx);
+ talloc_free(tdb2);
return matched_packet;
}
Modified: branches/SAMBA_4_0/source/ntvfs/common/brlock.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/common/brlock.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/ntvfs/common/brlock.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -82,10 +82,9 @@
return NULL;
}
- path = lock_path(brl, "brlock.tdb");
+ path = smbd_tmp_path(brl, "brlock.tdb");
brl->w = tdb_wrap_open(brl, path, 0,
- TDB_DEFAULT,
- O_RDWR|O_CREAT, 0600);
+ TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
talloc_free(path);
if (brl->w == NULL) {
talloc_free(brl);
Modified: branches/SAMBA_4_0/source/ntvfs/common/opendb.c
===================================================================
--- branches/SAMBA_4_0/source/ntvfs/common/opendb.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/ntvfs/common/opendb.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -86,7 +86,7 @@
return NULL;
}
- path = lock_path(odb, "openfiles.tdb");
+ path = smbd_tmp_path(odb, "openfiles.tdb");
odb->w = tdb_wrap_open(odb, path, 0,
TDB_DEFAULT,
O_RDWR|O_CREAT, 0600);
Modified: branches/SAMBA_4_0/source/rpc_server/netlogon/schannel_state.c
===================================================================
--- branches/SAMBA_4_0/source/rpc_server/netlogon/schannel_state.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/rpc_server/netlogon/schannel_state.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -33,12 +33,13 @@
char *path;
struct ldb_wrap *ldb;
- path = lock_path(mem_ctx, "schannel.ldb");
+ path = smbd_tmp_path(mem_ctx, "schannel.ldb");
if (!path) {
return NULL;
}
ldb = ldb_wrap_connect(mem_ctx, path, 0, NULL);
+ talloc_free(path);
if (!ldb) {
return NULL;
}
Modified: branches/SAMBA_4_0/source/smbd/service.c
===================================================================
--- branches/SAMBA_4_0/source/smbd/service.c 2004-10-29 08:32:59 UTC (rev 3359)
+++ branches/SAMBA_4_0/source/smbd/service.c 2004-10-29 08:38:59 UTC (rev 3360)
@@ -356,26 +356,37 @@
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. You need to expand
- the list here as appropriate.
+ cleanup tmp files, this function deletes them.
*/
void service_cleanup_tmp_files(void)
{
- const char *list[] = {
- "openfiles.tdb",
- "brlock.tdb",
- "unexpected.tdb"};
- int i;
- for (i=0;i<ARRAY_SIZE(list);i++) {
- char *path = lock_path(NULL, list[i]);
- int ret;
- ret = unlink(path);
- if (ret == -1 &&
+ char *path;
+ DIR *dir;
+ struct dirent *de;
+ TALLOC_CTX *mem_ctx = talloc_init("service_cleanup_tmp_files");
+
+ 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)) {
+ char *fname = talloc_asprintf(mem_ctx, "%s/%s", path, de->d_name);
+ int ret = unlink(fname);
+ if (ret == -1 &&
errno != ENOENT &&
- errno != ENOTDIR) {
- DEBUG(0,("Failed to cleanup '%s'\n", path));
- smb_panic("unable to cleanup temporary files\n");
+ errno != EISDIR &&
+ errno != EISDIR) {
+ DEBUG(0,("Unabled to delete '%s' - %s\n",
+ fname, strerror(errno)));
+ smb_panic("unable to cleanup tmp files");
}
- talloc_free(path);
+ talloc_free(fname);
}
+ closedir(dir);
+
+ talloc_free(mem_ctx);
}
More information about the samba-cvs
mailing list