From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JCfi1-0002gy-Ln for qemu-devel@nongnu.org; Wed, 09 Jan 2008 13:31:25 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JCfhz-0002fX-M6 for qemu-devel@nongnu.org; Wed, 09 Jan 2008 13:31:24 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JCfhz-0002fS-Fe for qemu-devel@nongnu.org; Wed, 09 Jan 2008 13:31:23 -0500 Received: from kim.schedom-europe.net ([193.109.184.78]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1JCfhz-0003t4-BA for qemu-devel@nongnu.org; Wed, 09 Jan 2008 13:31:23 -0500 From: Mark Jonckheere Date: Wed, 9 Jan 2008 18:31:14 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200801091831.16449.mark.jonckheere@easynet.be> Subject: [Qemu-devel] [PATCH] Clean-up /tmp directory after -smb use Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org When using the -smb option with samba-3.0.28 qemu fails to completely remove the /tmp/qemu-smb.$pid directory at exit. Newer smbd versions also create subdirectories at this place. This patch removes recursively all files and subdirectories. diff -ur qemu/vl.c qemu-patched/vl.c --- qemu/vl.c 2008-01-08 20:32:16.000000000 +0100 +++ qemu-patched/vl.c 2008-01-09 18:01:33.000000000 +0100 @@ -3772,27 +3772,35 @@ char smb_dir[1024]; -static void smb_exit(void) +static void erase_dir(char *dir_name) { DIR *d; struct dirent *de; char filename[1024]; /* erase all the files in the directory */ - d = opendir(smb_dir); - for(;;) { - de = readdir(d); - if (!de) - break; - if (strcmp(de->d_name, ".") != 0 && - strcmp(de->d_name, "..") != 0) { - snprintf(filename, sizeof(filename), "%s/%s", - smb_dir, de->d_name); - unlink(filename); + if ((d = opendir(dir_name)) != 0) { + for(;;) { + de = readdir(d); + if (!de) + break; + if (strcmp(de->d_name, ".") != 0 && + strcmp(de->d_name, "..") != 0) { + snprintf(filename, sizeof(filename), "%s/%s", + smb_dir, de->d_name); + if (unlink(filename) != 0) /* is it a directory? */ + erase_dir(filename); + } } + closedir(d); + rmdir(dir_name); } - closedir(d); - rmdir(smb_dir); +} + +/* automatic user mode samba server configuration */ +static void smb_exit(void) +{ + erase_dir(smb_dir); } --