X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=src%2Flaunch.c;h=ca89b6383018e709ec152a77e55f97a0ab3a5782;hb=690ff694ca6db586c06ec484ea158261c156aa2f;hp=9add092a1993fef2e018637a1d38070fd229b021;hpb=486cafd4acf4945bbf3fea541eaa320f5c419406;p=libguestfs.git diff --git a/src/launch.c b/src/launch.c index 9add092..ca89b63 100644 --- a/src/launch.c +++ b/src/launch.c @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include #include @@ -1092,6 +1094,34 @@ guestfs___persistent_tmpdir (void) return tmpdir; } +/* Recursively remove a temporary directory. If removal fails, just + * return (it's a temporary directory so it'll eventually be cleaned + * up by a temp cleaner). This is done using "rm -rf" because that's + * simpler and safer, but we have to exec to ensure that paths don't + * need to be quoted. + */ +void +guestfs___remove_tmpdir (const char *dir) +{ + pid_t pid = fork (); + + if (pid == -1) { + perror ("remove tmpdir: fork"); + return; + } + if (pid == 0) { + execlp ("rm", "rm", "-rf", dir, NULL); + perror ("remove tmpdir: exec: rm"); + _exit (EXIT_FAILURE); + } + + /* Parent. */ + if (waitpid (pid, NULL, 0) == -1) { + perror ("remove tmpdir: waitpid"); + return; + } +} + /* Compute Y - X and return the result in milliseconds. * Approximately the same as this code: * http://www.mpp.mpg.de/~huber/util/timevaldiff.c