[GRASS5] $ETC/cleanup fails on directories in .tmp/

Glynn Clements glynn at gclements.plus.com
Tue Apr 4 05:29:37 EDT 2006

Markus Neteler wrote:

> a couple of GRASS modules generate subdirectories within the .tmp/
> directory of mapsets. I have discovered that etc/clean_temp fails
> on cleaning those as it is written to remove files only:
> strace /home/neteler/soft/61grass_cvsexp/dist.i686-pc-linux-gnu/etc/clean_temp
> ...
> unlink("31611.0")                       = -1 EISDIR (Is a directory)
> stat64("31944.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> kill(31944, SIG_0)                      = -1 ESRCH (No such process)
> unlink("31944.0")                       = -1 EISDIR (Is a directory)
> stat64("32038.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
> kill(32038, SIG_0)                      = -1 ESRCH (No such process)
> unlink("32038.0")                       = -1 EISDIR (Is a directory)
> ...
> The C file is lib/init/clean_temp.c
> I would appreciate if someone could add dir removal to this command
> to avoid that tons of files are left over. I am asking since this is
> probably sensible code which may carry some risk if badly implemented
> and which needs to be portable.

G_remove() does recursive removal of directories; changing the
unlink() to G_remove() should work.

[It was using a fixed 1K buffer with no overflow check. I've enlarged
the buffer to 4K and added an overflow check.]

Also, clean_temp should use opendir/readdir/closedir to enumerate the
directory contents rather than popen("ls").

If no-one else does it before, I'll look into it when I've had some
sleep (writing an "rm -rf" equivalent should probably be done when
fully awake).

Glynn Clements <glynn at gclements.plus.com>

More information about the grass-dev mailing list