diff options
author | startx2017 <vradu.startx@yandex.com> | 2017-03-27 10:02:43 -0400 |
---|---|---|
committer | startx2017 <vradu.startx@yandex.com> | 2017-03-27 10:02:43 -0400 |
commit | 880fecdfb6a5f3370b5269284b3b0fd648d87560 (patch) | |
tree | f48c9d2a8de8c805ec0ddfc6b34990daac4850d8 /src/firecfg/main.c | |
parent | blacklist more KDE files (#1163) (diff) | |
download | firejail-880fecdfb6a5f3370b5269284b3b0fd648d87560.tar.gz firejail-880fecdfb6a5f3370b5269284b3b0fd648d87560.tar.zst firejail-880fecdfb6a5f3370b5269284b3b0fd648d87560.zip |
create ~/.local/share/applications directory if it doesn't exist - fixing #1081
Diffstat (limited to 'src/firecfg/main.c')
-rw-r--r-- | src/firecfg/main.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/src/firecfg/main.c b/src/firecfg/main.c index 054df9e09..670b3d839 100644 --- a/src/firecfg/main.c +++ b/src/firecfg/main.c | |||
@@ -295,30 +295,45 @@ static void set(void) { | |||
295 | } | 295 | } |
296 | 296 | ||
297 | static void fix_desktop_files(void) { | 297 | static void fix_desktop_files(void) { |
298 | struct stat sb; | ||
299 | |||
300 | // check user | ||
298 | if (getuid() == 0) { | 301 | if (getuid() == 0) { |
299 | fprintf(stderr, "Error: you should run --fix as user\n"); | 302 | fprintf(stderr, "Error: this option is not supported for root user; please run as a regular user.\n"); |
300 | exit(1); | 303 | exit(1); |
301 | } | 304 | } |
302 | |||
303 | char *homedir = getenv("HOME"); | 305 | char *homedir = getenv("HOME"); |
304 | if (!homedir) | 306 | if (!homedir) |
305 | errExit("getenv"); | 307 | errExit("getenv"); |
306 | 308 | ||
309 | // destination | ||
310 | // create ~/.local/share/applications directory if necessary | ||
307 | char *user_apps_dir; | 311 | char *user_apps_dir; |
308 | if (asprintf(&user_apps_dir, "%s/.local/share/applications", homedir) == -1) | 312 | if (asprintf(&user_apps_dir, "%s/.local/share/applications", homedir) == -1) |
309 | errExit("asprintf"); | 313 | errExit("asprintf"); |
314 | if (stat(user_apps_dir, &sb) == -1) { | ||
315 | int rv = mkdir(user_apps_dir, 0700); | ||
316 | if (rv) { | ||
317 | fprintf(stderr, "Error: cannot create ~/.local/application directory\n"); | ||
318 | perror("mkdir"); | ||
319 | exit(1); | ||
320 | } | ||
321 | rv = chmod(user_apps_dir, 0700); | ||
322 | (void) rv; | ||
323 | } | ||
310 | 324 | ||
325 | // source | ||
311 | DIR *dir = opendir("/usr/share/applications"); | 326 | DIR *dir = opendir("/usr/share/applications"); |
312 | if (!dir) { | 327 | if (!dir) { |
313 | perror("Error: cannot open /usr/share/applications directory"); | 328 | perror("Error: cannot open /usr/share/applications directory"); |
314 | exit(1); | 329 | exit(1); |
315 | } | 330 | } |
316 | |||
317 | if (chdir("/usr/share/applications")) { | 331 | if (chdir("/usr/share/applications")) { |
318 | perror("Error: cannot chdir to /usr/share/applications"); | 332 | perror("Error: cannot chdir to /usr/share/applications"); |
319 | exit(1); | 333 | exit(1); |
320 | } | 334 | } |
321 | 335 | ||
336 | // copy | ||
322 | struct dirent *entry; | 337 | struct dirent *entry; |
323 | while ((entry = readdir(dir)) != NULL) { | 338 | while ((entry = readdir(dir)) != NULL) { |
324 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) | 339 | if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) |
@@ -337,8 +352,6 @@ static void fix_desktop_files(void) { | |||
337 | // skip links | 352 | // skip links |
338 | if (is_link(filename)) | 353 | if (is_link(filename)) |
339 | continue; | 354 | continue; |
340 | |||
341 | struct stat sb; | ||
342 | if (stat(filename, &sb) == -1) | 355 | if (stat(filename, &sb) == -1) |
343 | errExit("stat"); | 356 | errExit("stat"); |
344 | 357 | ||