chiark / gitweb /
Prep v230: Add utmp support to make wall message to work properly.
[elogind.git] / src / basic / terminal-util.c
index 75a0d6fd8ee58268e92c6802757eafd07862dbad..cb75ad7c1defd64ba891262a05ac15d55706b2ff 100644 (file)
@@ -856,7 +856,6 @@ int make_null_stdio(void) {
         return make_stdio(null_fd);
 }
 
-#if 0 /// UNNEEDED by elogind
 int getttyname_malloc(int fd, char **ret) {
         size_t l = 100;
         int r;
@@ -906,7 +905,6 @@ int getttyname_harder(int fd, char **r) {
         *r = s;
         return 0;
 }
-#endif // 0
 
 int get_ctty_devnr(pid_t pid, dev_t *d) {
         int r;
@@ -1149,14 +1147,19 @@ int open_terminal_in_namespace(pid_t pid, const char *name, int mode) {
 #endif // 0
 
 bool colors_enabled(void) {
-        const char *colors;
+        static int enabled = -1;
 
-        colors = getenv("SYSTEMD_COLORS");
-        if (!colors) {
-                if (streq_ptr(getenv("TERM"), "dumb"))
-                        return false;
-                return on_tty();
+        if (_unlikely_(enabled < 0)) {
+                const char *colors;
+
+                colors = getenv("SYSTEMD_COLORS");
+                if (colors)
+                        enabled = parse_boolean(colors) != 0;
+                else if (streq_ptr(getenv("TERM"), "dumb"))
+                        enabled = false;
+                else
+                        enabled = on_tty();
         }
 
-        return parse_boolean(colors) != 0;
+        return enabled;
 }