/* * ratWatchdog.c -- * * Provides a small forked copy of tkrat which cleans up * when the parent dies. * * * TkRat software and its included text is Copyright 1996-2002 by * Martin Forssén * * The full text of the legal notice is contained in the file called * COPYRIGHT, included with this distribution. */ #include "rat.h" #include static void RatWatchdogCleanup(const char *tmp); /* *---------------------------------------------------------------------- * * RatReleaseWatchdog -- * * Release the watchdog which eventually will cleanup the tmp- * directory. * * Results: * None. * * Side effects: * forks. * * *---------------------------------------------------------------------- */ void RatReleaseWatchdog(const char *tmpdir) { struct rlimit rlim; int i, leash[2]; char c; /* * The leash is used to release the watchdog (child) when the parent * dies. */ pipe(leash); if (0 == fork()) { /* * Install signal handlers */ signal(SIGHUP, SIG_IGN); signal(SIGINT, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGABRT, SIG_IGN); signal(SIGPIPE, SIG_IGN); /* * The watchdog starts by closing all decriptors except our * end of the leash. */ getrlimit(RLIMIT_NOFILE, &rlim); for (i=0; id_name) || !strcmp("..", d->d_name)) { continue; } snprintf(buf, sizeof(buf), "%s/%s", tmpdir, d->d_name); unlink(buf); } closedir(dir); rmdir(tmpdir); }