aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/cmdline.c
diff options
context:
space:
mode:
authorLibravatar thewisenerd <thewisenerd@protonmail.com>2016-12-19 01:27:35 +0530
committerLibravatar thewisenerd <thewisenerd@protonmail.com>2016-12-19 01:27:35 +0530
commit77783f1ec2cd91891161616c9cd0abaf60897cc0 (patch)
treefe7c15cdac87f0f08db8fbdfad8031bf7fb59441 /src/firejail/cmdline.c
parentprofile updates (diff)
downloadfirejail-77783f1ec2cd91891161616c9cd0abaf60897cc0.tar.gz
firejail-77783f1ec2cd91891161616c9cd0abaf60897cc0.tar.zst
firejail-77783f1ec2cd91891161616c9cd0abaf60897cc0.zip
appimage: pass commandline arguments
commandline arguments are not being passed to appimage, which hinders some functionality. This adds the function build_appimage_cmdline based on build_cmdline which works by calling quote_cmdline with passed argv, and then replaces initial argument with AppRun path generated in appimage_set. TODO: deal with extra memory allocation. The 'quoted' length of the first '*.AppImage' argument may or may not be greater than the 'quoted' AppRun path.
Diffstat (limited to 'src/firejail/cmdline.c')
-rw-r--r--src/firejail/cmdline.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/firejail/cmdline.c b/src/firejail/cmdline.c
index cadf4795d..dcb0a5424 100644
--- a/src/firejail/cmdline.c
+++ b/src/firejail/cmdline.c
@@ -157,3 +157,47 @@ void build_cmdline(char **command_line, char **window_title, int argc, char **ar
157 assert(*command_line); 157 assert(*command_line);
158 assert(*window_title); 158 assert(*window_title);
159} 159}
160
161void build_appimage_cmdline(char **command_line, char **window_title, int argc, char **argv, int index, char *apprun_path) {
162 // index == -1 could happen if we have --shell=none and no program was specified
163 // the program should exit with an error before entering this function
164 assert(index != -1);
165
166 unsigned argcount = argc - index;
167
168 int len1 = cmdline_length(argc, argv, index); // length of argv w/o changes
169 int len2 = cmdline_length(1, &argv[index], 0); // apptest.AppImage
170 int len3 = cmdline_length(1, &apprun_path, 0); // /run/firejail/appimage/.appimage-23304/AppRun
171 int len4 = (len1 - len2 + len3) + 1; // apptest.AppImage is replaced by /path/to/AppRun
172
173 if (len4 > ARG_MAX) {
174 errno = E2BIG;
175 errExit("cmdline_length");
176 }
177
178 // save created apprun in cfg.command_line
179 char *tmp1 = strdup(*command_line);
180 if (!tmp1)
181 errExit("strdup");
182
183 // TODO: deal with extra allocated memory.
184 char *command_line_tmp = malloc(len1 + len3 + 1);
185 if (!command_line_tmp)
186 errExit("malloc");
187 *window_title = malloc(len1 + len3 + 1);
188 if (!*window_title)
189 errExit("malloc");
190
191 // run default quote_cmdline
192 quote_cmdline(command_line_tmp, *window_title, len1, argc, argv, index);
193
194 assert(command_line_tmp);
195 assert(*window_title);
196
197 // 'fix' command_line now
198 if (asprintf(command_line, "'%s' %s", tmp1, command_line_tmp + len2) == -1)
199 errExit("asprintf");
200
201 // free strdup
202 free(tmp1);
203}