diff options
-rw-r--r-- | src/firejail/env.c | 10 | ||||
-rw-r--r-- | src/firejail/firejail.h | 1 | ||||
-rw-r--r-- | src/firejail/main.c | 20 |
3 files changed, 24 insertions, 7 deletions
diff --git a/src/firejail/env.c b/src/firejail/env.c index 213bd01d5..cccab966d 100644 --- a/src/firejail/env.c +++ b/src/firejail/env.c | |||
@@ -114,9 +114,13 @@ void env_defaults(void) { | |||
114 | //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' | 114 | //export PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] ' |
115 | if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) | 115 | if (setenv("PROMPT_COMMAND", "export PS1=\"\\[\\e[1;32m\\][\\u@\\h \\W]\\$\\[\\e[0m\\] \"", 1) < 0) |
116 | errExit("setenv"); | 116 | errExit("setenv"); |
117 | 117 | ||
118 | // if this is a terminal, set window title | 118 | // build the window title and set it |
119 | printf("\033]0;Firejail\007\n"); | 119 | char *title; |
120 | if (asprintf(&title, "\033]0;firejail %s\007\n", cfg.window_title) == -1) | ||
121 | errExit("asprintf"); | ||
122 | printf("%s", title); | ||
123 | free(title); | ||
120 | } | 124 | } |
121 | 125 | ||
122 | // parse and store the environment setting | 126 | // parse and store the environment setting |
diff --git a/src/firejail/firejail.h b/src/firejail/firejail.h index 39bc2beeb..90c3589d9 100644 --- a/src/firejail/firejail.h +++ b/src/firejail/firejail.h | |||
@@ -164,6 +164,7 @@ typedef struct config_t { | |||
164 | 164 | ||
165 | // command line | 165 | // command line |
166 | char *command_line; | 166 | char *command_line; |
167 | char *window_title; | ||
167 | char *command_name; | 168 | char *command_name; |
168 | char *shell; | 169 | char *shell; |
169 | char **original_argv; | 170 | char **original_argv; |
diff --git a/src/firejail/main.c b/src/firejail/main.c index bcddaf7ab..5b88481d1 100644 --- a/src/firejail/main.c +++ b/src/firejail/main.c | |||
@@ -1315,18 +1315,22 @@ int main(int argc, char **argv) { | |||
1315 | // build the sandbox command | 1315 | // build the sandbox command |
1316 | if (prog_index == -1 && arg_zsh) { | 1316 | if (prog_index == -1 && arg_zsh) { |
1317 | cfg.command_line = "/usr/bin/zsh"; | 1317 | cfg.command_line = "/usr/bin/zsh"; |
1318 | cfg.window_title = "/usr/bin/zsh"; | ||
1318 | cfg.command_name = "zsh"; | 1319 | cfg.command_name = "zsh"; |
1319 | } | 1320 | } |
1320 | else if (prog_index == -1 && arg_csh) { | 1321 | else if (prog_index == -1 && arg_csh) { |
1321 | cfg.command_line = "/bin/csh"; | 1322 | cfg.command_line = "/bin/csh"; |
1323 | cfg.window_title = "/bin/csh"; | ||
1322 | cfg.command_name = "csh"; | 1324 | cfg.command_name = "csh"; |
1323 | } | 1325 | } |
1324 | else if (prog_index == -1 && cfg.shell) { | 1326 | else if (prog_index == -1 && cfg.shell) { |
1325 | cfg.command_line = cfg.shell; | 1327 | cfg.command_line = cfg.shell; |
1328 | cfg.window_title = cfg.shell; | ||
1326 | cfg.command_name = cfg.shell; | 1329 | cfg.command_name = cfg.shell; |
1327 | } | 1330 | } |
1328 | else if (prog_index == -1) { | 1331 | else if (prog_index == -1) { |
1329 | cfg.command_line = "/bin/bash"; | 1332 | cfg.command_line = "/bin/bash"; |
1333 | cfg.window_title = "/bin/bash"; | ||
1330 | cfg.command_name = "bash"; | 1334 | cfg.command_name = "bash"; |
1331 | } | 1335 | } |
1332 | else { | 1336 | else { |
@@ -1341,16 +1345,24 @@ int main(int argc, char **argv) { | |||
1341 | cfg.command_line = malloc(len + 1); // + '\0' | 1345 | cfg.command_line = malloc(len + 1); // + '\0' |
1342 | if (!cfg.command_line) | 1346 | if (!cfg.command_line) |
1343 | errExit("malloc"); | 1347 | errExit("malloc"); |
1344 | char *ptr = cfg.command_line; | 1348 | cfg.window_title = malloc(len + 1); // + '\0' |
1349 | if (!cfg.window_title) | ||
1350 | errExit("malloc"); | ||
1351 | |||
1352 | char *ptr1 = cfg.command_line; | ||
1353 | char *ptr2 = cfg.window_title; | ||
1345 | for (i = 0; i < argcnt; i++) { | 1354 | for (i = 0; i < argcnt; i++) { |
1346 | // detect bash commands | 1355 | // detect bash commands |
1347 | if (strstr(argv[i + prog_index], "&&") || strstr(argv[i + prog_index], "||")) { | 1356 | if (strstr(argv[i + prog_index], "&&") || strstr(argv[i + prog_index], "||")) { |
1348 | sprintf(ptr, "%s ", argv[i + prog_index]); | 1357 | sprintf(ptr1, "%s ", argv[i + prog_index]); |
1349 | } | 1358 | } |
1350 | else { | 1359 | else { |
1351 | sprintf(ptr, "\"%s\" ", argv[i + prog_index]); | 1360 | sprintf(ptr1, "\"%s\" ", argv[i + prog_index]); |
1352 | } | 1361 | } |
1353 | ptr += strlen(ptr); | 1362 | sprintf(ptr2, "%s ", argv[i + prog_index]); |
1363 | |||
1364 | ptr1 += strlen(ptr1); | ||
1365 | ptr2 += strlen(ptr2); | ||
1354 | } | 1366 | } |
1355 | } | 1367 | } |
1356 | 1368 | ||