aboutsummaryrefslogtreecommitdiffstats
path: root/src/firejail/join.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/firejail/join.c')
-rw-r--r--src/firejail/join.c59
1 files changed, 24 insertions, 35 deletions
diff --git a/src/firejail/join.c b/src/firejail/join.c
index 0b5b6a34a..80ed1dc51 100644
--- a/src/firejail/join.c
+++ b/src/firejail/join.c
@@ -330,32 +330,21 @@ void join(pid_t pid, int argc, char **argv, int index) {
330 } 330 }
331 } 331 }
332 332
333 // run cmdline trough /bin/bash 333 // run cmdline trough shell
334 if (cfg.command_line == NULL) { 334 if (cfg.command_line == NULL) {
335 cfg.shell = guess_shell();
336 if (!cfg.shell) {
337 fprintf(stderr, "Error: unable to guess your shell, please set explicitly by using --shell option.\n");
338 exit(1);
339 }
340 if (arg_debug)
341 printf("Autoselecting %s as shell\n", cfg.shell);
335 342
336 // replace the process with a shell 343 // replace the process with a shell
337 if (cfg.shell) 344 execlp(cfg.shell, cfg.shell, NULL);
338 execlp(cfg.shell, cfg.shell, NULL);
339 else if (arg_zsh)
340 execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL);
341 else if (arg_csh)
342 execlp("/bin/csh", "/bin/csh", NULL);
343 else {
344 struct stat s;
345 if (stat("/bin/bash", &s) == 0)
346 execlp("/bin/bash", "/bin/bash", NULL);
347 else if (stat("/usr/bin/zsh", &s) == 0)
348 execlp("/usr/bin/zsh", "/usr/bin/zsh", NULL);
349 else if (stat("/bin/csh", &s) == 0)
350 execlp("/bin/csh", "/bin/csh", NULL);
351 else if (stat("/bin/sh", &s) == 0)
352 execlp("/bin/sh", "/bin/sh", NULL);
353 }
354 345
355 // no shell found, print an error and exit 346 // it should never get here
356 fprintf(stderr, "Error: no POSIX shell found\n"); 347 errExit("execlp");
357 sleep(5);
358 exit(1);
359 } 348 }
360 else { 349 else {
361 // run the command supplied by the user 350 // run the command supplied by the user
@@ -398,19 +387,16 @@ void join(pid_t pid, int argc, char **argv, int index) {
398 execvp(cfg.original_argv[cfg.original_program_index], &cfg.original_argv[cfg.original_program_index]); 387 execvp(cfg.original_argv[cfg.original_program_index], &cfg.original_argv[cfg.original_program_index]);
399 exit(1); 388 exit(1);
400 } else { 389 } else {
401 // choose the shell requested by the user, or use bash as default 390// assert(cfg.shell);
402 char *sh; 391 cfg.shell = guess_shell();
403 if (cfg.shell) 392 if (!cfg.shell) {
404 sh = cfg.shell; 393 fprintf(stderr, "Error: unable to guess your shell, please set explicitly by using --shell option.\n");
405 else if (arg_zsh) 394 exit(1);
406 sh = "/usr/bin/zsh"; 395 }
407 else if (arg_csh) 396 if (arg_debug)
408 sh = "/bin/csh"; 397 printf("Autoselecting %s as shell\n", cfg.shell);
409 else
410 sh = "/bin/bash";
411
412 char *arg[5]; 398 char *arg[5];
413 arg[0] = sh; 399 arg[0] = cfg.shell;
414 arg[1] = "-c"; 400 arg[1] = "-c";
415 if (arg_debug) 401 if (arg_debug)
416 printf("Starting %s\n", cfg.command_line); 402 printf("Starting %s\n", cfg.command_line);
@@ -423,7 +409,10 @@ void join(pid_t pid, int argc, char **argv, int index) {
423 arg[3] = cfg.command_line; 409 arg[3] = cfg.command_line;
424 arg[4] = NULL; 410 arg[4] = NULL;
425 } 411 }
426 execvp("/bin/bash", arg); 412 execvp(arg[0], arg);
413
414 // it should never get here
415 errExit("execvp");
427 } 416 }
428 } 417 }
429 418