]> git.ipfire.org Git - thirdparty/util-linux.git/blob - lib/exec_shell.c
Merge branch 'patch-1' of https://github.com/dtrebbien/util-linux
[thirdparty/util-linux.git] / lib / exec_shell.c
1 #include <stdlib.h>
2 #include <string.h>
3 #include <unistd.h>
4 #include <sys/types.h>
5
6 #include "nls.h"
7 #include "c.h"
8 #include "xalloc.h"
9
10 #include "exec_shell.h"
11
12 #define DEFAULT_SHELL "/bin/sh"
13
14 void __attribute__((__noreturn__)) exec_shell(void) {
15 const char *shell = getenv("SHELL"), *shell_basename;
16 char *arg0;
17 if (!shell)
18 shell = DEFAULT_SHELL;
19
20 shell_basename = basename(shell);
21 arg0 = xmalloc(strlen(shell_basename) + 2);
22 arg0[0] = '-';
23 strcpy(arg0 + 1, shell_basename);
24
25 execl(shell, arg0, NULL);
26 err(EXIT_FAILURE, _("failed to execute %s"), shell);
27 }