From 593a4992b4051ecb62f3e97fb7c6c1a617ecfe20 Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Sun, 7 Oct 2012 17:22:26 +0200 Subject: [PATCH] pty: set XDG_SEAT for childs Recent systemd was updated to parse XDG_SEAT in PAM so we can assign logins to the correct seat. This patch allows pty users to specify what seat they run on so the PTY can correctly set the seat variable. If no seat is specified, then XDG_SEAT is not set so we still allow non-seated logins. Note that if kmscon_pty is run with XDG_SEAT set, this will also be set for the client PTY so unset it if you don't want the environment to be copied to the client (like any environment variable). Signed-off-by: David Herrmann --- src/pty.c | 23 +++++++++++++++++++++-- src/pty.h | 1 + 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pty.c b/src/pty.c index bcd832f..b30cda0 100644 --- a/src/pty.c +++ b/src/pty.c @@ -60,6 +60,7 @@ struct kmscon_pty { char *term; char **argv; + char *seat; }; int kmscon_pty_new(struct kmscon_pty **out, kmscon_pty_input_cb input_cb, @@ -172,6 +173,22 @@ int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv) return 0; } +int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat) +{ + char *t; + + if (!pty || !seat) + return -EINVAL; + + t = strdup(seat); + if (!t) + return -ENOMEM; + free(pty->seat); + pty->seat = t; + + return 0; +} + int kmscon_pty_get_fd(struct kmscon_pty *pty) { if (!pty) @@ -222,7 +239,7 @@ static void pty_close(struct kmscon_pty *pty, bool user) } static void __attribute__((noreturn)) -exec_child(int pty_master, const char *term, char **argv) +exec_child(int pty_master, const char *term, char **argv, const char *seat) { if (!term) term = "vt220"; @@ -230,6 +247,8 @@ exec_child(int pty_master, const char *term, char **argv) argv = (char*[]){ "/bin/sh", "-l", NULL }; setenv("TERM", term, 1); + if (seat) + setenv("XDG_SEAT", seat, 1); execvp(argv[0], argv); log_err("failed to exec child %s: %m", argv[0]); @@ -347,7 +366,7 @@ static int pty_spawn(struct kmscon_pty *pty, int master, return -errno; case 0: setup_child(master, &ws); - exec_child(pty->fd, pty->term, pty->argv); + exec_child(pty->fd, pty->term, pty->argv, pty->seat); exit(EXIT_FAILURE); default: pty->fd = master; diff --git a/src/pty.h b/src/pty.h index b8eef09..6a35ec1 100644 --- a/src/pty.h +++ b/src/pty.h @@ -55,6 +55,7 @@ void kmscon_pty_ref(struct kmscon_pty *pty); void kmscon_pty_unref(struct kmscon_pty *pty); int kmscon_pty_set_term(struct kmscon_pty *pty, const char *term); int kmscon_pty_set_argv(struct kmscon_pty *pty, char **argv); +int kmscon_pty_set_seat(struct kmscon_pty *pty, const char *seat); int kmscon_pty_get_fd(struct kmscon_pty *pty); void kmscon_pty_dispatch(struct kmscon_pty *pty); -- 2.7.4