summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-11-15 23:49:02 +0100
committerLennart Poettering <lennart@poettering.net>2010-11-15 23:49:02 +0100
commite3aa71c38cbecb24e6333411ee19814796a5b1d0 (patch)
tree5ae80b4fcbf3bc4f93e3905cecab2fc40f1cb1da /src
parent96a8cbfae1b37cf0a9c0591bfef93f9de1561bc4 (diff)
exec: automatically determine right TERM= setting based on tty name
Diffstat (limited to 'src')
-rw-r--r--src/execute.c12
-rw-r--r--src/service.c10
-rw-r--r--src/test-strv.c13
-rw-r--r--src/util.c15
-rw-r--r--src/util.h2
5 files changed, 40 insertions, 12 deletions
diff --git a/src/execute.c b/src/execute.c
index 48e55ea4c2..05abd5aaac 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 184ddf9143..0234151700 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 573436896b..cfbf7fddc9 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 7f9f2b36a2..fb2eea341c 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 63538fed8e..7e1eacc687 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)