29 #define BUF_MAX PATH_MAX
40 void clean_dir(
const char *pathname, uid_t uid, pid_t pid, time_t now,
45 struct dirent *cur_entry;
51 G_warning(
"Can't open directory %s: %s,skipping\n", pathname,
56 while ((cur_entry =
readdir(curdir))) {
65 (
"clean_temp: exceeded maximum pathname length %d, got %d, should'nt happen",
68 if (stat(buf, &info) != 0) {
69 G_warning(
"Can't stat file %s: %s,skipping\n", buf,
73 if (S_ISDIR(info.st_mode)) {
77 if (info.st_uid != uid)
80 if (rmdir(buf) != 0) {
81 if (
errno != ENOTEMPTY) {
83 (
"Can't remove empty directory %s: %s,skipping\n",
84 buf, strerror(
errno));
88 G_warning(
"Removing directory %s\n", buf);
92 if (info.st_uid == uid) {
93 if (sscanf(cur_entry->d_name,
"%d.%d", &pid, &n) == 2) {
97 G_warning(
"Can't remove file %s: %s,skipping\n",
98 buf, strerror(
errno));
104 if ((now - info.st_mtime) > max_age)
106 if (unlink(buf) != 0)
107 G_warning(
"Can't remove file %s: %s,skipping\n",
108 buf, strerror(
errno));
120 int main(
int argc,
char *argv[])
123 char element[GNAME_MAX];
135 sscanf(argv[1],
"%d", &ppid);
152 max_age = 4 * 24 * 60 * 60;
164 clean_dir(tmppath, uid, pid, now, max_age);
178 return (kill(pid, 0) == 0 ||
errno != ESRCH);