]>
Commit | Line | Data |
---|---|---|
a84aa9df MF |
1 | /* |
2 | * exec_shell() - launch a shell, else exit! | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify it | |
5 | * under the terms of the GNU General Public License as published by the | |
6 | * Free Software Foundation; either version 2, or (at your option) any | |
7 | * later version. | |
8 | * | |
9 | * This program is distributed in the hope that it will be useful, but | |
10 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
12 | * General Public License for more details. | |
13 | * | |
14 | * You should have received a copy of the GNU General Public License along | |
15 | * with this program; if not, write to the Free Software Foundation, Inc., | |
16 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
17 | */ | |
18 | ||
57580694 ZJS |
19 | #include <stdlib.h> |
20 | #include <string.h> | |
21 | #include <unistd.h> | |
22 | #include <sys/types.h> | |
948d1f31 | 23 | #include <libgen.h> |
57580694 ZJS |
24 | |
25 | #include "nls.h" | |
26 | #include "c.h" | |
27 | #include "xalloc.h" | |
28 | ||
29 | #include "exec_shell.h" | |
30 | ||
31 | #define DEFAULT_SHELL "/bin/sh" | |
32 | ||
117d0791 | 33 | void __attribute__((__noreturn__)) exec_shell(void) |
a84aa9df | 34 | { |
7f79adb3 | 35 | const char *shell = getenv("SHELL"); |
82adb91f | 36 | char *shellc; |
7f79adb3 | 37 | const char *shell_basename; |
57580694 | 38 | char *arg0; |
7f79adb3 | 39 | |
57580694 ZJS |
40 | if (!shell) |
41 | shell = DEFAULT_SHELL; | |
42 | ||
82adb91f | 43 | shellc = xstrdup(shell); |
7f79adb3 | 44 | shell_basename = basename(shellc); |
57580694 ZJS |
45 | arg0 = xmalloc(strlen(shell_basename) + 2); |
46 | arg0[0] = '-'; | |
47 | strcpy(arg0 + 1, shell_basename); | |
48 | ||
49 | execl(shell, arg0, NULL); | |
0f6adf86 | 50 | errexec(shell); |
57580694 | 51 | } |