[Libguestfs] [PATCH 3/2] lib: remove all temporary directories may remained last launching

Wanlong Gao wanlong.gao at gmail.com
Fri Dec 23 14:22:08 UTC 2011


On 12/23/2011 10:17 PM, Richard W.M. Jones wrote:

> On Fri, Dec 23, 2011 at 10:06:37PM +0800, Wanlong Gao wrote:
>> If guestfish or other progs which launching appliance was aborted or
>> killed last time, the temp dir will be remained, so delete it when
>> this time launching.
>> Prevent the possible waste of disk space.
>>
>> Signed-off-by: Wanlong Gao <gaowanlong at cn.fujitsu.com>
>> ---
>>  src/appliance.c |   10 ++++++++++
>>  1 files changed, 10 insertions(+), 0 deletions(-)
>>
>> diff --git a/src/appliance.c b/src/appliance.c
>> index 57ff38f..4ce8405 100644
>> --- a/src/appliance.c
>> +++ b/src/appliance.c
>> @@ -36,6 +36,8 @@
>>  #include <sys/types.h>
>>  #endif
>>  
>> +#include "ignore-value.h"
>> +
>>  #include "guestfs.h"
>>  #include "guestfs-internal.h"
>>  #include "guestfs-internal-actions.h"
>> @@ -437,6 +439,14 @@ build_supermin_appliance (guestfs_h *g,
>>     */
>>    size_t len = strlen (tmpdir) + 128;
>>  
>> +  /* If guestfish or other progs which launching appliance was aborted or
>> +   * killed last time, the temp dir will be remained, so delete it when
>> +   * this time launching.
>> +   */
>> +  char cmd[len];
>> +  snprintf (cmd, len, "rm -rf %s/guestfs.??????", tmpdir);
>> +  ignore_value (system (cmd));
>> +
>>    /* Build the appliance into a temporary directory. */
>>    char tmpcd[len];
>>    snprintf (tmpcd, len, "%s/guestfs.XXXXXX", tmpdir);
> 
> This isn't safe.  It'll remove unrelated guestfs.?????? directories
> that might be in use by other processes.


Yeah, you are right.

> 
> Almost every Linux system out there has a /tmp cleaner process which
> will clean up anything that the current system doesn't catch.


But I can just produce this by kill the guestfish when it's launching.

And, can we get the status of which tempdir is in use?

Thanks
-Wanlong Gao

> 
> Rich.
> 





More information about the Libguestfs mailing list