10 #include "local_proto.h" 30 #define BUF_MAX PATH_MAX 39 void clean_dir(
const char *pathname, uid_t uid, pid_t pid, time_t now,
44 struct dirent *cur_entry;
50 G_warning(
"Can't open directory %s: %s,skipping\n", pathname,
55 while ((cur_entry =
readdir(curdir))) {
64 (
"clean_temp: exceeded maximum pathname length %d, 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) {
82 (
"Can't remove empty directory %s: %s,skipping\n",
83 buf, strerror(errno));
87 G_warning(
"Removing directory %s\n", buf);
91 if (info.st_uid == uid) {
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) > max_age)
105 if (unlink(buf) != 0)
106 G_warning(
"Can't remove file %s: %s,skipping\n",
107 buf, strerror(errno));
119 int main(
int argc,
char *argv[])
134 sscanf(argv[1],
"%d", &ppid);
151 max_age = 4 * 24 * 60 * 60;
163 clean_dir(tmppath, uid, pid, now, max_age);
177 return (kill(pid, 0) == 0 || errno != ESRCH);
char * G_file_name(char *, const char *, const char *, const char *)
Builds full path names to GIS data files.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void clean_dir(const char *pathname, uid_t uid, pid_t pid, time_t now, int max_age)
void G_sleep(unsigned int)
void G_temp_element(char *)
Populates element with a path string.
int find_process(int pid)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
int main(int argc, char *argv[])
const char * G_mapset(void)
Get current mapset name.
int G_snprintf(char *, size_t, const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf