blob: 2b263644d11c773fe4d1f1580179ba511f50c86b [file] [log] [blame]
bigbiff7b4c7a62015-01-01 19:44:14 -05001/*
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
19#include <stdlib.h>
20#include <string.h>
21#include <unistd.h>
22#include <sys/types.h>
23
24#include "nls.h"
25#include "c.h"
26#include "xalloc.h"
27
28#include "exec_shell.h"
29
30#define DEFAULT_SHELL "/bin/sh"
31
32void exec_shell(void)
33{
34 const char *shell = getenv("SHELL"), *shell_basename;
35 char *arg0;
36 if (!shell)
37 shell = DEFAULT_SHELL;
38
39 shell_basename = basename(shell);
40 arg0 = xmalloc(strlen(shell_basename) + 2);
41 arg0[0] = '-';
42 strcpy(arg0 + 1, shell_basename);
43
44 execl(shell, arg0, NULL);
45 err(EXIT_FAILURE, _("failed to execute %s"), shell);
46}