11 #include "local_proto.h"
31 #define BUF_MAX PATH_MAX
39 void clean_dir(
const char *pathname, uid_t uid, pid_t pid, time_t now,
50 G_warning(
"Can't open directory %s: %s,skipping\n", pathname,
55 while ((cur_entry =
readdir(curdir))) {
60 if ((pathlen = snprintf(buf,
BUF_MAX,
"%s/%s", pathname,
62 G_fatal_error(
"clean_temp: exceeded maximum pathname length %d, "
63 "got %d, shouldn't happen",
66 if (stat(buf, &info) != 0) {
67 G_warning(
"Can't stat file %s: %s,skipping\n", buf,
75 if (info.st_uid != uid)
78 if (
rmdir(buf) != 0) {
79 if (errno != ENOTEMPTY) {
80 G_warning(
"Can't remove empty directory %s: %s,skipping\n",
81 buf, strerror(errno));
85 G_warning(
"Removing directory %s\n", buf);
91 if (sscanf(cur_entry->
d_name,
"%d.%d", &pid, &n) == 2) {
95 G_warning(
"Can't remove file %s: %s,skipping\n",
96 buf, strerror(errno));
102 if ((now - info.st_mtime) >
107 G_warning(
"Can't remove file %s: %s,skipping\n",
108 buf, strerror(errno));
120 int main(
int argc,
char *argv[])
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);
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)
DIR * opendir(const char *name)
struct dirent * readdir(DIR *dir)