11 #include "local_proto.h"
31 #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;
49 curdir = opendir(pathname);
51 G_warning(
"Can't open directory %s: %s,skipping\n", pathname,
56 while ((cur_entry = readdir(curdir))) {
61 if ((pathlen = snprintf(buf,
BUF_MAX,
"%s/%s", pathname,
63 G_fatal_error(
"clean_temp: exceeded maximum pathname length %d, "
64 "got %d, shouldn't happen",
67 if (stat(buf, &info) != 0) {
68 G_warning(
"Can't stat file %s: %s,skipping\n", buf,
72 if (S_ISDIR(info.st_mode)) {
76 if (info.st_uid != uid)
79 if (rmdir(buf) != 0) {
80 if (errno != ENOTEMPTY) {
81 G_warning(
"Can't remove empty directory %s: %s,skipping\n",
82 buf, strerror(errno));
86 G_warning(
"Removing directory %s\n", buf);
92 if (sscanf(cur_entry->d_name,
"%d.%d", &pid, &n) == 2) {
96 G_warning(
"Can't remove file %s: %s,skipping\n",
97 buf, strerror(errno));
103 if ((now - info.st_mtime) >
107 if (unlink(buf) != 0)
108 G_warning(
"Can't remove file %s: %s,skipping\n",
109 buf, strerror(errno));
121 int main(
int argc,
char *argv[])
136 sscanf(argv[1],
"%d", &ppid);
153 max_age = 4 * 24 * 60 * 60;
165 clean_dir(tmppath, uid, pid, now, max_age);
179 return (kill(pid, 0) == 0 || errno != ESRCH);
int main(int argc, char *argv[])
int find_process(int pid)
void clean_dir(const char *pathname, uid_t uid, pid_t pid, time_t now, int max_age)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
void G_temp_element(char *)
Populates element with a path string.
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
const char * G_mapset(void)
Get current mapset name.
void G_sleep(unsigned int)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)