aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-07-17 07:55:36 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-07-17 07:55:36 +0000
commitc11cc2be5736ccd509d2f452ee83e1217a699835 (patch)
treeb1085d0fde2b9bd5ebe853db82335c5f5e4ae813
parentslave: break out command line tokenizer (diff)
main: allow user to override shell on the command line
-rw-r--r--main.c21
-rw-r--r--slave.c9
-rw-r--r--slave.h2
3 files changed, 21 insertions, 11 deletions
diff --git a/main.c b/main.c
index 6a8ab8a7..faf8b926 100644
--- a/main.c
+++ b/main.c
@@ -30,6 +30,7 @@
#include "shm.h"
#include "slave.h"
#include "terminal.h"
+#include "tokenize.h"
#include "vt.h"
#define min(x, y) ((x) < (y) ? (x) : (y))
@@ -305,6 +306,9 @@ main(int argc, char *const *argv)
}
}
+ argc -= optind;
+ argv += optind;
+
setlocale(LC_ALL, "");
setenv("TERM", "xterm-direct", 1); /* TODO: configurable */
@@ -558,7 +562,19 @@ main(int argc, char *const *argv)
case 0:
/* Child */
close(fork_pipe[0]); /* Close read end */
- slave_spawn(term.ptmx, conf.shell, fork_pipe[1]);
+
+ char **_shell_argv = NULL;
+ char *const *shell_argv = argv;
+
+ if (argc == 0) {
+ if (!tokenize_cmdline(conf.shell, &_shell_argv)) {
+ (void)!write(fork_pipe[1], &errno, sizeof(errno));
+ _exit(0);
+ }
+ shell_argv = _shell_argv;
+ }
+
+ slave_spawn(term.ptmx, shell_argv, fork_pipe[1]);
assert(false);
break;
@@ -576,7 +592,8 @@ main(int argc, char *const *argv)
LOG_ERRNO("failed to read from pipe");
goto out;
} else if (ret == sizeof(_errno)) {
- LOG_ERRNO("%s: failed to execute", conf.shell);
+ LOG_ERRNO(
+ "%s: failed to execute", argc == 0 ? conf.shell : argv[0]);
goto out;
} else
LOG_DBG("%s: successfully started", conf.shell);
diff --git a/slave.c b/slave.c
index 86d5b94f..18fcf3ad 100644
--- a/slave.c
+++ b/slave.c
@@ -11,18 +11,13 @@
#define LOG_MODULE "slave"
#define LOG_ENABLE_DBG 0
#include "log.h"
-#include "tokenize.h"
void
-slave_spawn(int ptmx, char *cmd, int err_fd)
+slave_spawn(int ptmx, char *const argv[], int err_fd)
{
int pts = -1;
const char *pts_name = ptsname(ptmx);
- char **argv = NULL;
- if (!tokenize_cmdline(cmd, &argv))
- goto err;
-
if (grantpt(ptmx) == -1) {
LOG_ERRNO("failed to grantpt()");
goto err;
@@ -61,8 +56,6 @@ slave_spawn(int ptmx, char *cmd, int err_fd)
err:
(void)!write(err_fd, &errno, sizeof(errno));
- if (argv)
- free(argv);
if (pts != -1)
close(pts);
if (ptmx != -1)
diff --git a/slave.h b/slave.h
index d801ec2c..4161dbda 100644
--- a/slave.h
+++ b/slave.h
@@ -1,4 +1,4 @@
#pragma once
#include <stdbool.h>
-void slave_spawn(int ptmx, char *cmd, int err_fd);
+void slave_spawn(int ptmx, char *const argv[], int err_fd);