1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

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 commit is contained in:
Andrew Tridgell 2004-10-29 08:38:59 +00:00 committed by Gerald (Jerry) Carter
parent 415ba95927
commit 7e942e7f1b
7 changed files with 68 additions and 37 deletions

View File

@ -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);

View File

@ -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.
*

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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 &&
errno != ENOENT &&
errno != ENOTDIR) {
DEBUG(0,("Failed to cleanup '%s'\n", path));
smb_panic("unable to cleanup temporary files\n");
}
talloc_free(path);
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 != EISDIR &&
errno != EISDIR) {
DEBUG(0,("Unabled to delete '%s' - %s\n",
fname, strerror(errno)));
smb_panic("unable to cleanup tmp files");
}
talloc_free(fname);
}
closedir(dir);
talloc_free(mem_ctx);
}