[systemd-commits] 4 commits - src/cgroup.c src/execute.c src/pam-module.c src/service.c src/test-strv.c src/util.c src/util.h TODO units/emergency.service units/fedora units/getty at .service.m4 units/rescue.service.m4 units/serial-getty at .service.m4

Lennart Poettering lennart at kemper.freedesktop.org
Mon Nov 15 15:15:11 PST 2010


 TODO                            |    4 ---
 src/cgroup.c                    |    8 +++++-
 src/execute.c                   |   12 ++++++++--
 src/pam-module.c                |   46 +++++++++++++++++++++++++++-------------
 src/service.c                   |   10 --------
 src/test-strv.c                 |   13 +++++++++++
 src/util.c                      |   15 +++++++++++++
 src/util.h                      |    2 +
 units/emergency.service         |    1 
 units/fedora/halt-local.service |    1 
 units/fedora/rc-local.service   |    1 
 units/getty at .service.m4         |    1 
 units/rescue.service.m4         |    1 
 units/serial-getty at .service.m4  |    1 
 14 files changed, 79 insertions(+), 37 deletions(-)

New commits:
commit d90b9d27af56f808a275789c7aa228f6300175d7
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Nov 16 00:10:57 2010 +0100

    pam: always rely on loginuid instead of uid to determine cgroup and XDG_RUNTIME_DIR

diff --git a/TODO b/TODO
index 8853dab..69670d3 100644
--- a/TODO
+++ b/TODO
@@ -71,8 +71,6 @@
 
 * allow runtime changing of log level and target
 
-* in the PAM module rely on loginuid to figure out XDG_RUNTIME_DIR
-
 * automatically determine TERM= based on tty name even for /dev/console
 
 * declare /etc/os-release cross-distro standard
diff --git a/src/pam-module.c b/src/pam-module.c
index d9458df..bc99684 100644
--- a/src/pam-module.c
+++ b/src/pam-module.c
@@ -128,7 +128,7 @@ static uint64_t get_session_id(int *mode) {
                 r = safe_atou32(s, &u);
                 free(s);
 
-                if (r >= 0 && u != (uint32_t) -1) {
+                if (r >= 0 && u != (uint32_t) -1 && u > 0) {
                         *mode = SESSION_ID_AUDIT;
                         return (uint64_t) u;
                 }
@@ -179,31 +179,49 @@ static int get_user_data(
                 const char **ret_username,
                 struct passwd **ret_pw) {
 
-        const char *username;
-        struct passwd *pw;
+        const char *username = NULL;
+        struct passwd *pw = NULL;
         int r;
+        bool have_loginuid = false;
+        char *s;
 
         assert(handle);
         assert(ret_username);
         assert(ret_pw);
 
-        if ((r = pam_get_user(handle, &username, NULL)) != PAM_SUCCESS) {
-                pam_syslog(handle, LOG_ERR, "Failed to get user name.");
-                return r;
+        if (read_one_line_file("/proc/self/loginuid", &s) >= 0) {
+                uint32_t u;
+
+                r = safe_atou32(s, &u);
+                free(s);
+
+                if (r >= 0 && u != (uint32_t) -1 && u > 0) {
+                        have_loginuid = true;
+                        pw = pam_modutil_getpwuid(handle, u);
+                }
         }
 
-        if (!username || !*username) {
-                pam_syslog(handle, LOG_ERR, "User name not valid.");
-                return PAM_AUTH_ERR;
+        if (!have_loginuid) {
+                if ((r = pam_get_user(handle, &username, NULL)) != PAM_SUCCESS) {
+                        pam_syslog(handle, LOG_ERR, "Failed to get user name.");
+                        return r;
+                }
+
+                if (!username || !*username) {
+                        pam_syslog(handle, LOG_ERR, "User name not valid.");
+                        return PAM_AUTH_ERR;
+                }
+
+                pw = pam_modutil_getpwnam(handle, username);
         }
 
-        if (!(pw = pam_modutil_getpwnam(handle, username))) {
+        if (!pw) {
                 pam_syslog(handle, LOG_ERR, "Failed to get user data.");
                 return PAM_USER_UNKNOWN;
         }
 
         *ret_pw = pw;
-        *ret_username = username;
+        *ret_username = username ? username : pw->pw_name;
 
         return PAM_SUCCESS;
 }

commit 0baf24ddd51fe3399ede0ed5a92f02e54e5ea1ef
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 15 23:55:53 2010 +0100

    cgroup: call root cgroup system instead of systemd-1

diff --git a/src/cgroup.c b/src/cgroup.c
index 5130d3a..57c9c9e 100644
--- a/src/cgroup.c
+++ b/src/cgroup.c
@@ -230,8 +230,12 @@ int manager_setup_cgroup(Manager *m) {
         if ((r = cg_get_by_pid(SYSTEMD_CGROUP_CONTROLLER, 0, &current)) < 0)
                 goto finish;
 
-        snprintf(suffix, sizeof(suffix), "/systemd-%lu", (unsigned long) getpid());
-        char_array_0(suffix);
+        if (m->running_as == MANAGER_SYSTEM)
+                strcpy(suffix, "/system");
+        else {
+                snprintf(suffix, sizeof(suffix), "/systemd-%lu", (unsigned long) getpid());
+                char_array_0(suffix);
+        }
 
         free(m->cgroup_hierarchy);
         if (endswith(current, suffix)) {

commit e3aa71c38cbecb24e6333411ee19814796a5b1d0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 15 23:49:02 2010 +0100

    exec: automatically determine right TERM= setting based on tty name

diff --git a/TODO b/TODO
index 945f8d9..8853dab 100644
--- a/TODO
+++ b/TODO
@@ -73,7 +73,7 @@
 
 * in the PAM module rely on loginuid to figure out XDG_RUNTIME_DIR
 
-* automatically determine TERM= based on tty name. (TERM=linux vs. TERM=vt100-nav)
+* automatically determine TERM= based on tty name even for /dev/console
 
 * declare /etc/os-release cross-distro standard
 
diff --git a/src/execute.c b/src/execute.c
index 48e55ea..05abd5a 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -1252,7 +1252,7 @@ int exec_spawn(ExecCommand *command,
                                 }
                 }
 
-                if (!(our_env = new0(char*, 6))) {
+                if (!(our_env = new0(char*, 7))) {
                         r = EXIT_MEMORY;
                         goto fail;
                 }
@@ -1277,7 +1277,15 @@ int exec_spawn(ExecCommand *command,
                                 goto fail;
                         }
 
-                assert(n_env <= 6);
+                if (is_terminal_input(context->std_input) ||
+                    context->std_output == EXEC_OUTPUT_TTY ||
+                    context->std_error == EXEC_OUTPUT_TTY)
+                        if (!(our_env[n_env++] = strdup(default_term_for_tty(tty_path(context))))) {
+                                r = EXIT_MEMORY;
+                                goto fail;
+                        }
+
+                assert(n_env <= 7);
 
                 if (!(final_env = strv_env_merge(
                                       4,
diff --git a/src/service.c b/src/service.c
index 184ddf9..0234151 100644
--- a/src/service.c
+++ b/src/service.c
@@ -1609,16 +1609,6 @@ static int service_spawn(
                         goto fail;
                 }
 
-#ifdef HAVE_SYSV_COMPAT
-        /* Make sure we set TERM=linux for SysV scripts, since some
-         * require it to be set from the kernel */
-        if (s->sysv_path && !strv_env_get(s->meta.manager->environment, "TERM"))
-                if (!(our_env[n_env++] = strdup("TERM=linux"))) {
-                        r = -ENOMEM;
-                        goto fail;
-                }
-#endif
-
         if (!(final_env = strv_env_merge(2,
                                          s->meta.manager->environment,
                                          our_env,
diff --git a/src/test-strv.c b/src/test-strv.c
index 5734368..cfbf7fd 100644
--- a/src/test-strv.c
+++ b/src/test-strv.c
@@ -37,5 +37,18 @@ int main(int argc, char *argv[]) {
                 free(t);
         }
 
+        printf("%s\n", default_term_for_tty("/dev/tty23"));
+        printf("%s\n", default_term_for_tty("/dev/ttyS23"));
+        printf("%s\n", default_term_for_tty("/dev/tty0"));
+        printf("%s\n", default_term_for_tty("/dev/pty0"));
+        printf("%s\n", default_term_for_tty("/dev/pts/0"));
+        printf("%s\n", default_term_for_tty("/dev/console"));
+        printf("%s\n", default_term_for_tty("tty23"));
+        printf("%s\n", default_term_for_tty("ttyS23"));
+        printf("%s\n", default_term_for_tty("tty0"));
+        printf("%s\n", default_term_for_tty("pty0"));
+        printf("%s\n", default_term_for_tty("pts/0"));
+        printf("%s\n", default_term_for_tty("console"));
+
         return 0;
 }
diff --git a/src/util.c b/src/util.c
index 7f9f2b3..fb2eea3 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3470,6 +3470,21 @@ void filter_environ(const char *prefix) {
         environ[j] = NULL;
 }
 
+const char *default_term_for_tty(const char *tty) {
+        assert(tty);
+
+        if (startswith(tty, "/dev/"))
+                tty += 5;
+
+        if (startswith(tty, "tty") &&
+            tty[3] >= '0' && tty[3] <= '9')
+                return "TERM=linux";
+
+        /* FIXME: Proper handling of /dev/console would be cool */
+
+        return "TERM=vt100-nav";
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",
diff --git a/src/util.h b/src/util.h
index 63538fe..7e1eacc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -372,6 +372,8 @@ char *fstab_node_to_udev_node(const char *p);
 
 void filter_environ(const char *prefix);
 
+const char *default_term_for_tty(const char *tty);
+
 #define NULSTR_FOREACH(i, l)                                    \
         for ((i) = (l); (i) && *(i); (i) = strchr((i), 0)+1)
 
diff --git a/units/emergency.service b/units/emergency.service
index 52f875c..aa3d985 100644
--- a/units/emergency.service
+++ b/units/emergency.service
@@ -15,7 +15,6 @@ Before=shutdown.target
 
 [Service]
 Environment=HOME=/root
-Environment=TERM=vt100-nav
 WorkingDirectory=/root
 ExecStartPre=-/bin/plymouth --hide-splash
 ExecStartPre=-/bin/echo 'Welcome to emergency mode. Use "systemctl default" or ^D to activate default mode.'
diff --git a/units/fedora/halt-local.service b/units/fedora/halt-local.service
index 855924a..79f8f12 100644
--- a/units/fedora/halt-local.service
+++ b/units/fedora/halt-local.service
@@ -14,7 +14,6 @@ Before=final.target
 
 [Service]
 Type=oneshot
-Environment=TERM=linux
 ExecStart=/sbin/halt.local
 TimeoutSec=0
 StandardOutput=tty
diff --git a/units/fedora/rc-local.service b/units/fedora/rc-local.service
index 88846c1..a21a557 100644
--- a/units/fedora/rc-local.service
+++ b/units/fedora/rc-local.service
@@ -11,7 +11,6 @@ ConditionPathExists=/etc/rc.local
 
 [Service]
 Type=forking
-Environment=TERM=linux
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
diff --git a/units/getty at .service.m4 b/units/getty at .service.m4
index 11a71d7..d6bd9a9 100644
--- a/units/getty at .service.m4
+++ b/units/getty at .service.m4
@@ -22,7 +22,6 @@ After=rc-local.service
 Before=getty.target
 
 [Service]
-Environment=TERM=linux
 ExecStart=-/sbin/agetty %I 38400
 Restart=always
 RestartSec=0
diff --git a/units/rescue.service.m4 b/units/rescue.service.m4
index d31282d..6e03c20 100644
--- a/units/rescue.service.m4
+++ b/units/rescue.service.m4
@@ -16,7 +16,6 @@ Before=shutdown.target
 
 [Service]
 Environment=HOME=/root
-Environment=TERM=vt100-nav
 WorkingDirectory=/root
 ExecStartPre=-/bin/plymouth --hide-splash
 ExecStartPre=-/bin/echo 'Welcome to rescue mode. Use "systemctl default" or ^D to activate default mode.'
diff --git a/units/serial-getty at .service.m4 b/units/serial-getty at .service.m4
index da9bd19..d454dce 100644
--- a/units/serial-getty at .service.m4
+++ b/units/serial-getty at .service.m4
@@ -22,7 +22,6 @@ After=rc-local.service
 Before=getty.target
 
 [Service]
-Environment=TERM=vt100-nav
 m4_ifdef(`TARGET_FEDORA',
 ExecStartPre=-/sbin/securetty %I
 )m4_dnl

commit 96a8cbfae1b37cf0a9c0591bfef93f9de1561bc4
Author: Lennart Poettering <lennart at poettering.net>
Date:   Mon Nov 15 23:22:05 2010 +0100

    pam: rename master user cgroup to 'master'

diff --git a/src/pam-module.c b/src/pam-module.c
index 5f2df4b..d9458df 100644
--- a/src/pam-module.c
+++ b/src/pam-module.c
@@ -335,7 +335,7 @@ _public_ PAM_EXTERN int pam_sm_open_session(
 
                 r = asprintf(&buf, "/user/%s/%s", username, id);
         } else
-                r = asprintf(&buf, "/user/%s/user", username);
+                r = asprintf(&buf, "/user/%s/master", username);
 
         if (r < 0) {
                 r = PAM_BUF_ERR;
@@ -369,7 +369,7 @@ static int session_remains(pam_handle_t *handle, const char *user_path) {
 
         while ((r = cg_read_subgroup(d, &subgroup)) > 0) {
 
-                remains = !streq(subgroup, "user");
+                remains = !streq(subgroup, "master");
                 free(subgroup);
 
                 if (remains)
@@ -430,7 +430,7 @@ _public_ PAM_EXTERN int pam_sm_close_session(
         if ((id = pam_getenv(handle, "XDG_SESSION_ID")) && created) {
 
                 if (asprintf(&session_path, "/user/%s/%s", username, id) < 0 ||
-                    asprintf(&nosession_path, "/user/%s/user", username) < 0) {
+                    asprintf(&nosession_path, "/user/%s/master", username) < 0) {
                         r = PAM_BUF_ERR;
                         goto finish;
                 }



More information about the systemd-commits mailing list