diff options
author | Andrew Tridgell <tridge@samba.org> | 2004-10-29 08:38:59 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:05:01 -0500 |
commit | 09d0b152b7bd85aa01898af81bd166a7673ab886 (patch) | |
tree | 6bebf9648412322c15b2b8a5777aa67c3a09d463 /source4 | |
parent | 98052096e3150c2b1a3d31fc6fcc1dbc0d7a3067 (diff) | |
download | samba-09d0b152b7bd85aa01898af81bd166a7673ab886.tar.gz samba-09d0b152b7bd85aa01898af81bd166a7673ab886.tar.bz2 samba-09d0b152b7bd85aa01898af81bd166a7673ab886.zip |
r3360: improved the deletion of tmp files. smbd now puts all tmp files in var/locks/smbd.tmp/
and deletes that dir on startup.
(This used to be commit 7e942e7f1bd2c293a0e6648df43a96f8b8a2a295)
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/messaging/messaging.c | 4 | ||||
-rw-r--r-- | source4/lib/util.c | 25 | ||||
-rw-r--r-- | source4/libcli/unexpected.c | 19 | ||||
-rw-r--r-- | source4/ntvfs/common/brlock.c | 5 | ||||
-rw-r--r-- | source4/ntvfs/common/opendb.c | 2 | ||||
-rw-r--r-- | source4/rpc_server/netlogon/schannel_state.c | 3 | ||||
-rw-r--r-- | source4/smbd/service.c | 43 |
7 files changed, 66 insertions, 35 deletions
diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 7f90bd4e40..125089ac62 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -85,7 +85,7 @@ static char *messaging_path(TALLOC_CTX *mem_ctx, servid_t server_id) { 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 @@ struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, servid_t server_id } /* 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); diff --git a/source4/lib/util.c b/source4/lib/util.c index 8b27bf070c..97d3d5dd1b 100644 --- a/source4/lib/util.c +++ b/source4/lib/util.c @@ -702,7 +702,6 @@ char *name_to_fqdn(TALLOC_CTX *mem_ctx, const char *name) /***************************************************************** 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 @@ char *lib_path(TALLOC_CTX* mem_ctx, const char *name) 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. * diff --git a/source4/libcli/unexpected.c b/source4/libcli/unexpected.c index 19a02bdeb8..264b9d7b33 100644 --- a/source4/libcli/unexpected.c +++ b/source4/libcli/unexpected.c @@ -44,15 +44,13 @@ void unexpected_packet(struct packet_struct *p) 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 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, 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 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, tdb_traverse(tdb2->tdb, traverse_match, NULL); - talloc_destroy(mem_ctx); + talloc_free(tdb2); return matched_packet; } diff --git a/source4/ntvfs/common/brlock.c b/source4/ntvfs/common/brlock.c index 0f6af3e971..a952cb1dc7 100644 --- a/source4/ntvfs/common/brlock.c +++ b/source4/ntvfs/common/brlock.c @@ -82,10 +82,9 @@ struct brl_context *brl_init(TALLOC_CTX *mem_ctx, servid_t server, uint16_t tid, 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); diff --git a/source4/ntvfs/common/opendb.c b/source4/ntvfs/common/opendb.c index a66549b764..c2c8075771 100644 --- a/source4/ntvfs/common/opendb.c +++ b/source4/ntvfs/common/opendb.c @@ -86,7 +86,7 @@ struct odb_context *odb_init(TALLOC_CTX *mem_ctx, servid_t server, uint16_t tid, 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); diff --git a/source4/rpc_server/netlogon/schannel_state.c b/source4/rpc_server/netlogon/schannel_state.c index 0900c05393..5657b1cd64 100644 --- a/source4/rpc_server/netlogon/schannel_state.c +++ b/source4/rpc_server/netlogon/schannel_state.c @@ -33,12 +33,13 @@ static struct ldb_wrap *schannel_db_connect(TALLOC_CTX *mem_ctx) 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; } diff --git a/source4/smbd/service.c b/source4/smbd/service.c index 33c0d5fcbd..d9841b63b2 100644 --- a/source4/smbd/service.c +++ b/source4/smbd/service.c @@ -356,26 +356,37 @@ void service_close_listening_sockets(struct server_context *srv_ctx) 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); } |