aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/preproc.c
diff options
context:
space:
mode:
authorLibravatar startx2017 <vradu.startx@yandex.com>2018-03-18 10:03:41 -0400
committerLibravatar startx2017 <vradu.startx@yandex.com>2018-03-18 10:03:41 -0400
commitcc9183d70224babdb65d9dbb9d29e6d14876ca2b (patch)
treeabe1cf1d4142e869cc61ae027a154b137412930f /src/firejail/preproc.c
parentharden konversation and kwrite, minor fixes (diff)
downloadfirejail-cc9183d70224babdb65d9dbb9d29e6d14876ca2b.tar.gz
firejail-cc9183d70224babdb65d9dbb9d29e6d14876ca2b.tar.zst
firejail-cc9183d70224babdb65d9dbb9d29e6d14876ca2b.zip
more run files fixing - problem when running on symlinks
Diffstat (limited to 'src/firejail/preproc.c')
-rw-r--r--src/firejail/preproc.c51
1 files changed, 28 insertions, 23 deletions
diff --git a/src/firejail/preproc.c b/src/firejail/preproc.c
index 1f4cf9e54..45399bd48 100644
--- a/src/firejail/preproc.c
+++ b/src/firejail/preproc.c
@@ -107,6 +107,31 @@ void preproc_mount_mnt_dir(void) {
107 } 107 }
108} 108}
109 109
110static void clean_dir(const char *name, int *pidarr, int start_pid, int max_pids) {
111 DIR *dir;
112 if (!(dir = opendir(name))) {
113 fwarning("cannot clean %s directory\n", name);
114 return; // we live to fight another day!
115 }
116
117 // clean leftover files
118 struct dirent *entry;
119 char *end;
120 while ((entry = readdir(dir)) != NULL) {
121 pid_t pid = strtol(entry->d_name, &end, 10);
122 pid %= max_pids;
123 if (end == entry->d_name || *end)
124 continue;
125
126 if (pid < start_pid)
127 continue;
128 if (pidarr[pid] == 0)
129 delete_run_files(pid);
130 }
131 closedir(dir);
132}
133
134
110// clean run directory 135// clean run directory
111void preproc_clean_run(void) { 136void preproc_clean_run(void) {
112 int max_pids=32769; 137 int max_pids=32769;
@@ -153,29 +178,9 @@ void preproc_clean_run(void) {
153 } 178 }
154 closedir(dir); 179 closedir(dir);
155 180
156 // open /run/firejail/profile directory 181 // clean profile and name directories
157 if (!(dir = opendir(RUN_FIREJAIL_PROFILE_DIR))) { 182 clean_dir(RUN_FIREJAIL_PROFILE_DIR, pidarr, start_pid, max_pids);
158 // sleep 2 seconds and try again 183 clean_dir(RUN_FIREJAIL_NAME_DIR, pidarr, start_pid, max_pids);
159 sleep(2);
160 if (!(dir = opendir(RUN_FIREJAIL_PROFILE_DIR))) {
161 fprintf(stderr, "Error: cannot open %s directory\n", RUN_FIREJAIL_PROFILE_DIR);
162 exit(1);
163 }
164 }
165
166 // read /run/firejail/profile directory and clean leftover files
167 while ((entry = readdir(dir)) != NULL) {
168 pid_t pid = strtol(entry->d_name, &end, 10);
169 pid %= max_pids;
170 if (end == entry->d_name || *end)
171 continue;
172
173 if (pid < start_pid)
174 continue;
175 if (pidarr[pid] == 0)
176 delete_run_files(pid);
177 }
178 closedir(dir);
179 184
180 free(pidarr); 185 free(pidarr);
181} 186}