2013-06-27 19:05:18 -05:00
|
|
|
/*
|
|
|
|
* exec_shell() - launch a shell, else exit!
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-02-13 20:05:48 -06:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/types.h>
|
2016-02-09 05:52:20 -06:00
|
|
|
#include <libgen.h>
|
2013-02-13 20:05:48 -06:00
|
|
|
|
|
|
|
#include "nls.h"
|
|
|
|
#include "c.h"
|
|
|
|
#include "xalloc.h"
|
|
|
|
|
|
|
|
#include "exec_shell.h"
|
|
|
|
|
|
|
|
#define DEFAULT_SHELL "/bin/sh"
|
|
|
|
|
2018-02-01 05:25:39 -06:00
|
|
|
void __attribute__((__noreturn__)) exec_shell(void)
|
2013-06-27 19:05:18 -05:00
|
|
|
{
|
2016-02-10 20:45:11 -06:00
|
|
|
const char *shell = getenv("SHELL");
|
2018-06-24 20:34:31 -05:00
|
|
|
char *shellc;
|
2016-02-10 20:45:11 -06:00
|
|
|
const char *shell_basename;
|
2013-02-13 20:05:48 -06:00
|
|
|
char *arg0;
|
2016-02-10 20:45:11 -06:00
|
|
|
|
2013-02-13 20:05:48 -06:00
|
|
|
if (!shell)
|
|
|
|
shell = DEFAULT_SHELL;
|
|
|
|
|
2018-06-24 20:34:31 -05:00
|
|
|
shellc = xstrdup(shell);
|
2016-02-10 20:45:11 -06:00
|
|
|
shell_basename = basename(shellc);
|
2013-02-13 20:05:48 -06:00
|
|
|
arg0 = xmalloc(strlen(shell_basename) + 2);
|
|
|
|
arg0[0] = '-';
|
|
|
|
strcpy(arg0 + 1, shell_basename);
|
|
|
|
|
2020-10-29 12:49:07 -05:00
|
|
|
execl(shell, arg0, (char *)NULL);
|
2018-02-01 08:38:24 -06:00
|
|
|
errexec(shell);
|
2013-02-13 20:05:48 -06:00
|
|
|
}
|