]> err.no Git - systemd/commitdiff
exec: automatically determine right TERM= setting based on tty name
authorLennart Poettering <lennart@poettering.net>
Mon, 15 Nov 2010 22:49:02 +0000 (23:49 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 15 Nov 2010 22:49:02 +0000 (23:49 +0100)
12 files changed:
TODO
src/execute.c
src/service.c
src/test-strv.c
src/util.c
src/util.h
units/emergency.service
units/fedora/halt-local.service
units/fedora/rc-local.service
units/getty@.service.m4
units/rescue.service.m4
units/serial-getty@.service.m4

diff --git a/TODO b/TODO
index 945f8d998ce62010cf0d84e349e464d78f70a8c6..8853dab24c6d21776fd50a2e43d0f591262d4de9 100644 (file)
--- 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
 
index 48e55ea4c2f60c08891ff64e63477b91deb0c048..05abd5aaac3aac964488ba564170307695a20041 100644 (file)
@@ -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,
index 184ddf91437f8d4a1e70845e5ff3dca7ce43cc09..0234151700e9fa696bec35d31cc82629bc6b897b 100644 (file)
@@ -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,
index 573436896b907b243200aa1a9dca75f6baf886ae..cfbf7fddc914aedf977167eff85041e679c23e11 100644 (file)
@@ -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;
 }
index 7f9f2b36a239be98f40ad69d0e7160b3179172d8..fb2eea341c9b36188633c7f14b6a28061a08aa30 100644 (file)
@@ -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",
index 63538fed8e4b9da3d40901d303f3a75f8db45aaa..7e1eacc6878a342aa984941304c4e7919becd2be 100644 (file)
@@ -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)
 
index 52f875c6f39d37d89ecc3ee2805f7b67c8d212cb..aa3d9856c03a3d5596d7f701e56dce452dd66465 100644 (file)
@@ -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.'
index 855924aec6b90fffd3bd80b004f115f4b3bd4745..79f8f12b7d2097bcb28d874801247e88a49d15f7 100644 (file)
@@ -14,7 +14,6 @@ Before=final.target
 
 [Service]
 Type=oneshot
-Environment=TERM=linux
 ExecStart=/sbin/halt.local
 TimeoutSec=0
 StandardOutput=tty
index 88846c16f8f4d789b4f577e8f7b73e2ab8dc8dd7..a21a5578c48665e5f5d318c36e10b0310fe62ac4 100644 (file)
@@ -11,7 +11,6 @@ ConditionPathExists=/etc/rc.local
 
 [Service]
 Type=forking
-Environment=TERM=linux
 ExecStart=/etc/rc.local start
 TimeoutSec=0
 StandardOutput=tty
index 11a71d7168528aadffdb115d5efdebe325a95c9b..d6bd9a9dbe9b4620c7f48a6999ac3a2aec23980e 100644 (file)
@@ -22,7 +22,6 @@ After=rc-local.service
 Before=getty.target
 
 [Service]
-Environment=TERM=linux
 ExecStart=-/sbin/agetty %I 38400
 Restart=always
 RestartSec=0
index d31282d37e972be50158b404232cf1cd6629d8d5..6e03c20d80b8afaf6e2cef9918e4f05e4a9d58d5 100644 (file)
@@ -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.'
index da9bd1946bb931006385ed4bbdf02ac81fb9065c..d454dce46875df16e635b837124bb8f38d2b4c16 100644 (file)
@@ -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