aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/ls.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/ls.c')
-rw-r--r--src/firejail/ls.c34
1 files changed, 15 insertions, 19 deletions
diff --git a/src/firejail/ls.c b/src/firejail/ls.c
index bd4a4e347..b814af445 100644
--- a/src/firejail/ls.c
+++ b/src/firejail/ls.c
@@ -25,6 +25,9 @@
25#include <dirent.h> 25#include <dirent.h>
26#include <pwd.h> 26#include <pwd.h>
27#include <grp.h> 27#include <grp.h>
28//#include <dirent.h>
29//#include <stdio.h>
30//#include <stdlib.h>
28 31
29// uid/gid cache 32// uid/gid cache
30static uid_t c_uid = 0; 33static uid_t c_uid = 0;
@@ -169,27 +172,20 @@ static void print_directory(const char *path) {
169 return; 172 return;
170 assert(S_ISDIR(s.st_mode)); 173 assert(S_ISDIR(s.st_mode));
171 174
172 DIR *dir; 175 struct dirent **namelist;
173 if (!(dir = opendir(path))) { 176 int i;
174 // sleep 2 seconds and try again 177 int n;
175 sleep(2); 178
176 if (!(dir = opendir(path))) { 179 n = scandir(path, &namelist, 0, alphasort);
177 fprintf(stderr, "Error: cannot open directory %s\n", path); 180 if (n < 0)
178 exit(1); 181 errExit("scandir");
182 else {
183 for (i = 0; i < n; i++) {
184 print_file_or_dir(path, namelist[i]->d_name, 0);
185 free(namelist[i]);
179 } 186 }
180 } 187 }
181 188 free(namelist);
182 struct dirent *entry;
183 while ((entry = readdir(dir))) {
184 if (strcmp(entry->d_name, ".") == 0)
185 continue;
186 if (strcmp(entry->d_name, "..") == 0)
187 continue;
188
189 print_file_or_dir(path, entry->d_name, 0);
190 }
191
192 closedir(dir);
193} 189}
194 190
195void ls_name(const char *name, const char *path) { 191void ls_name(const char *name, const char *path) {