summaryrefslogtreecommitdiff
path: root/src/pty.c
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@googlemail.com>2012-12-12 21:20:45 +0100
committerDavid Herrmann <dh.herrmann@googlemail.com>2012-12-12 21:20:45 +0100
commitdd481c2fa64a93840d3429cc47ffc73fa8c9f9eb (patch)
tree9f6c11d611b084da75458a2ba20e8a9b32c3c281 /src/pty.c
parentd50f80a72f291eb5c58f70a67ac238a3e20c1c80 (diff)
pty: add env_reset property
This property controls whether the environment should be reset before spawning the child process. Defaults to "no" and affects whether "-p" is passed as default argument to /bin/login. Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
Diffstat (limited to 'src/pty.c')
-rw-r--r--src/pty.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/pty.c b/src/pty.c
index 8cdfb82..46045d5 100644
--- a/src/pty.c
+++ b/src/pty.c
@@ -63,6 +63,7 @@ struct kmscon_pty {
char *colorterm;
char **argv;
char *seat;
+ bool env_reset;
};
int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb,
@@ -192,6 +193,14 @@ int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat)
return 0;
}
+void kmscon_pty_set_env_reset(struct kmscon_pty *pty, bool do_reset)
+{
+ if (!pty)
+ return;
+
+ pty->env_reset = do_reset;
+}
+
int kmscon_pty_get_fd(struct kmscon_pty *pty)
{
if (!pty)
@@ -215,19 +224,39 @@ static bool pty_is_open(struct kmscon_pty *pty)
static void __attribute__((noreturn))
exec_child(const char *term, const char *colorterm, char **argv,
- const char *seat)
+ const char *seat, bool env_reset)
{
+ char **env;
+ char **def_argv;
+
+ if (env_reset) {
+ env = malloc(sizeof(char*));
+ if (!env) {
+ log_error("cannot allocate memory for environment (%d): %m",
+ errno);
+ exit(EXIT_FAILURE);
+ }
+
+ memset(env, 0, sizeof(char*));
+ environ = env;
+
+ def_argv = (char*[]){ "/bin/login", "-p", NULL };
+ } else {
+ def_argv = (char*[]){ "/bin/login", NULL };
+ }
+
if (!term)
term = "vt220";
if (!argv)
- argv = (char*[]){ "/bin/login", NULL };
+ argv = def_argv;
setenv("TERM", term, 1);
if (colorterm)
setenv("COLORTERM", colorterm, 1);
if (seat)
setenv("XDG_SEAT", seat, 1);
- execvp(argv[0], argv);
+
+ execve(argv[0], argv, environ);
log_err("failed to exec child %s: %m", argv[0]);
@@ -343,7 +372,8 @@ static int pty_spawn(struct kmscon_pty *pty, int master,
return -errno;
case 0:
setup_child(master, &ws);
- exec_child(pty->term, pty->colorterm, pty->argv, pty->seat);
+ exec_child(pty->term, pty->colorterm, pty->argv, pty->seat,
+ pty->env_reset);
exit(EXIT_FAILURE);
default:
log_debug("forking child %d", pid);