mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-01 07:15:32 -04:00
main: allow user to override shell on the command line
This commit is contained in:
parent
2046dc0fbd
commit
c11cc2be57
3 changed files with 21 additions and 11 deletions
21
main.c
21
main.c
|
|
@ -30,6 +30,7 @@
|
||||||
#include "shm.h"
|
#include "shm.h"
|
||||||
#include "slave.h"
|
#include "slave.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
#include "tokenize.h"
|
||||||
#include "vt.h"
|
#include "vt.h"
|
||||||
|
|
||||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
#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, "");
|
setlocale(LC_ALL, "");
|
||||||
setenv("TERM", "xterm-direct", 1); /* TODO: configurable */
|
setenv("TERM", "xterm-direct", 1); /* TODO: configurable */
|
||||||
|
|
||||||
|
|
@ -558,7 +562,19 @@ main(int argc, char *const *argv)
|
||||||
case 0:
|
case 0:
|
||||||
/* Child */
|
/* Child */
|
||||||
close(fork_pipe[0]); /* Close read end */
|
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);
|
assert(false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -576,7 +592,8 @@ main(int argc, char *const *argv)
|
||||||
LOG_ERRNO("failed to read from pipe");
|
LOG_ERRNO("failed to read from pipe");
|
||||||
goto out;
|
goto out;
|
||||||
} else if (ret == sizeof(_errno)) {
|
} 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;
|
goto out;
|
||||||
} else
|
} else
|
||||||
LOG_DBG("%s: successfully started", conf.shell);
|
LOG_DBG("%s: successfully started", conf.shell);
|
||||||
|
|
|
||||||
9
slave.c
9
slave.c
|
|
@ -11,18 +11,13 @@
|
||||||
#define LOG_MODULE "slave"
|
#define LOG_MODULE "slave"
|
||||||
#define LOG_ENABLE_DBG 0
|
#define LOG_ENABLE_DBG 0
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "tokenize.h"
|
|
||||||
|
|
||||||
void
|
void
|
||||||
slave_spawn(int ptmx, char *cmd, int err_fd)
|
slave_spawn(int ptmx, char *const argv[], int err_fd)
|
||||||
{
|
{
|
||||||
int pts = -1;
|
int pts = -1;
|
||||||
const char *pts_name = ptsname(ptmx);
|
const char *pts_name = ptsname(ptmx);
|
||||||
|
|
||||||
char **argv = NULL;
|
|
||||||
if (!tokenize_cmdline(cmd, &argv))
|
|
||||||
goto err;
|
|
||||||
|
|
||||||
if (grantpt(ptmx) == -1) {
|
if (grantpt(ptmx) == -1) {
|
||||||
LOG_ERRNO("failed to grantpt()");
|
LOG_ERRNO("failed to grantpt()");
|
||||||
goto err;
|
goto err;
|
||||||
|
|
@ -61,8 +56,6 @@ slave_spawn(int ptmx, char *cmd, int err_fd)
|
||||||
|
|
||||||
err:
|
err:
|
||||||
(void)!write(err_fd, &errno, sizeof(errno));
|
(void)!write(err_fd, &errno, sizeof(errno));
|
||||||
if (argv)
|
|
||||||
free(argv);
|
|
||||||
if (pts != -1)
|
if (pts != -1)
|
||||||
close(pts);
|
close(pts);
|
||||||
if (ptmx != -1)
|
if (ptmx != -1)
|
||||||
|
|
|
||||||
2
slave.h
2
slave.h
|
|
@ -1,4 +1,4 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
void slave_spawn(int ptmx, char *cmd, int err_fd);
|
void slave_spawn(int ptmx, char *const argv[], int err_fd);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue