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);
char * G_mapset(void)
current mapset name
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
int G__temp_element(char *element)
Populates element with a path string.
void clean_dir(const char *pathname, uid_t uid, pid_t pid, time_t now, int max_age)
int G_snprintf(char *str, size_t size, const char *fmt,...)
snprintf() clone.
int find_process(int pid)
char * G__file_name(char *path, const char *element, const char *name, const char *mapset)
Builds full path names to GIS data files.
int main(int argc, char *argv[])
void G_sleep(unsigned int seconds)
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.