diff options
Diffstat (limited to 'src/fbuilder/main.c')
-rw-r--r-- | src/fbuilder/main.c | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/src/fbuilder/main.c b/src/fbuilder/main.c index f4917aefc..aa49b2489 100644 --- a/src/fbuilder/main.c +++ b/src/fbuilder/main.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (C) 2014-2021 Firejail Authors | 2 | * Copyright (C) 2014-2022 Firejail Authors |
3 | * | 3 | * |
4 | * This file is part of firejail project | 4 | * This file is part of firejail project |
5 | * | 5 | * |
@@ -19,6 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | #include "fbuilder.h" | 20 | #include "fbuilder.h" |
21 | int arg_debug = 0; | 21 | int arg_debug = 0; |
22 | int arg_appimage = 0; | ||
22 | 23 | ||
23 | static void usage(void) { | 24 | static void usage(void) { |
24 | printf("Firejail profile builder\n"); | 25 | printf("Firejail profile builder\n"); |
@@ -39,7 +40,7 @@ printf("\n"); | |||
39 | int i; | 40 | int i; |
40 | int prog_index = 0; | 41 | int prog_index = 0; |
41 | FILE *fp = stdout; | 42 | FILE *fp = stdout; |
42 | int prof_file = 0; | 43 | char *prof_file = NULL; |
43 | 44 | ||
44 | // parse arguments and extract program index | 45 | // parse arguments and extract program index |
45 | for (i = 1; i < argc; i++) { | 46 | for (i = 1; i < argc; i++) { |
@@ -49,6 +50,8 @@ printf("\n"); | |||
49 | } | 50 | } |
50 | else if (strcmp(argv[i], "--debug") == 0) | 51 | else if (strcmp(argv[i], "--debug") == 0) |
51 | arg_debug = 1; | 52 | arg_debug = 1; |
53 | else if (strcmp(argv[i], "--appimage") == 0) | ||
54 | arg_appimage = 1; | ||
52 | else if (strcmp(argv[i], "--build") == 0) | 55 | else if (strcmp(argv[i], "--build") == 0) |
53 | ; // do nothing, this is passed down from firejail | 56 | ; // do nothing, this is passed down from firejail |
54 | else if (strncmp(argv[i], "--build=", 8) == 0) { | 57 | else if (strncmp(argv[i], "--build=", 8) == 0) { |
@@ -58,18 +61,23 @@ printf("\n"); | |||
58 | exit(1); | 61 | exit(1); |
59 | } | 62 | } |
60 | 63 | ||
64 | // don't run if the file exists | ||
65 | if (access(argv[i] + 8, F_OK) == 0) { | ||
66 | fprintf(stderr, "Error: the profile file already exists. Please use a different file name.\n"); | ||
67 | exit(1); | ||
68 | } | ||
69 | |||
61 | // check file access | 70 | // check file access |
62 | fp = fopen(argv[i] + 8, "w"); | 71 | fp = fopen(argv[i] + 8, "w"); |
63 | if (!fp) { | 72 | if (!fp) { |
64 | fprintf(stderr, "Error fbuild: cannot open profile file.\n"); | 73 | fprintf(stderr, "Error: cannot open profile file.\n"); |
65 | exit(1); | 74 | exit(1); |
66 | } | 75 | } |
67 | prof_file = 1; | 76 | prof_file = argv[i] + 8; |
68 | // do nothing, this is passed down from firejail | ||
69 | } | 77 | } |
70 | else { | 78 | else { |
71 | if (*argv[i] == '-') { | 79 | if (*argv[i] == '-') { |
72 | fprintf(stderr, "Error fbuilder: invalid program\n"); | 80 | fprintf(stderr, "Error: invalid program\n"); |
73 | usage(); | 81 | usage(); |
74 | exit(1); | 82 | exit(1); |
75 | } | 83 | } |
@@ -79,10 +87,13 @@ printf("\n"); | |||
79 | } | 87 | } |
80 | 88 | ||
81 | if (prog_index == 0) { | 89 | if (prog_index == 0) { |
82 | fprintf(stderr, "Error fbuilder: program and arguments required\n"); | 90 | fprintf(stderr, "Error : program and arguments required\n"); |
83 | usage(); | 91 | usage(); |
84 | if (prof_file) | 92 | if (prof_file) { |
85 | fclose(fp); | 93 | fclose(fp); |
94 | int rv = unlink(prof_file); | ||
95 | (void) rv; | ||
96 | } | ||
86 | exit(1); | 97 | exit(1); |
87 | } | 98 | } |
88 | 99 | ||