blob: 95620cd4d89940f8b39f7bce038091060854f98a [file] [log] [blame]
bigbiff bigbiffe60683a2013-02-22 20:55:50 -05001#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
14void __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}