next up previous Back to Operating Systems Home Page
Next: A4 - Re: Conflicts Up: 1998 term messages Previous: A4: Return status of

A4 - Deleting application directory - second take

Replying to correct myself - I read your colleague's question
a tad too quickly.

> > My quick-n'dirty way of removing all the files is with a call to
> > system("\rm -r ./APPDIRNAME_HERE"); 
> > 
> rmdir(2)   (and mkdir(2) to create one)
> 

Oops, had missed the "removing all the files" bit. rmdir(2) will fail with 
EEXIST if the directory contains files. No, there is no ready-made
syscall to remove in one shot all the files in a directory. 
You can either loop calling unlink(2) on all the files (getting
their names via opendir(2) / readdir(2) ), or just plainly
execl(2) the rm(1) command. Please do not fork a shell, which
is what system(3) does, unless it's *absolutely* necessary.

Forking a shell in a daemon is always bad practice, since it's
a potential security hole exploitalble by rogue clients. If
you choose to execute rm(1), use execl(2) specifying the full
path to rm; do not rely on a path, or you introduce another
security hole (what if i run your daemon after changing
my path, so that rm points to a nice little program of
mine that something nasty with your user privileges?).

Ciao
Franco


\ Franco Callari