]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: Always use syslog
authorTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 7 Apr 2026 18:40:33 +0000 (20:40 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Tue, 7 Apr 2026 18:46:43 +0000 (20:46 +0200)
No known systems exist which use agetty and are neither Linux, GNU,
nor FreeBSD. Even MinGW/MSYS use syslog.

Alternative systems which could use the fallback do not build agetty,
e.g. OpenIndiana or other such systems.

This gets rid of a bug in custom /dev/console code in which the
formatter could be modified by a link to agetty containing more
printf modifiers in its name.

It's not worth to fix it.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
term-utils/agetty.c

index 0ce8fca61a7c06a2882bb330b90999a014a8da11..ee7ce5feb6f39a5a9e8877fbb47a8e0afe42929a 100644 (file)
@@ -34,6 +34,7 @@
 #include <pwd.h>
 #include <netdb.h>
 #include <sys/utsname.h>
+#include <syslog.h>
 
 #include "strutils.h"
 #include "all-io.h"
 
 #ifdef __linux__
 #  include <sys/kd.h>
-#  define USE_SYSLOG
-#elif defined(__GNU__)
-#  define USE_SYSLOG
-#endif
-
-#ifdef __FreeBSD_kernel__
-#define USE_SYSLOG
-#endif
-
-/* If USE_SYSLOG is undefined all diagnostics go to /dev/console. */
-#ifdef USE_SYSLOG
-#  include <syslog.h>
 #endif
 
 /*
@@ -689,9 +678,6 @@ static void output_version(void)
 #ifdef AGETTY_RELOAD
                "reload",
 #endif
-#ifdef USE_SYSLOG
-               "syslog",
-#endif
 #ifdef USE_SYSTEMD
                "systemd",
 #endif
@@ -2539,44 +2525,16 @@ static void list_speeds(void)
 }
 
 /*
- * Helper function reports errors to console or syslog.
+ * Helper function reports errors to syslog.
  * Will be used by log_err() and log_warn() therefore
  * it takes a format as well as va_list.
  */
 static void dolog(int priority
-#ifndef USE_SYSLOG
-                 __attribute__((__unused__))
-#endif
                  , const char *fmt, va_list ap)
 {
-#ifdef USE_SYSLOG
-       /*
-        * If the diagnostic is reported via syslog(3), the process name is
-        * automatically prepended to the message. If we write directly to
-        * /dev/console, we must prepend the process name ourselves.
-        */
        openlog("agetty", LOG_PID, LOG_AUTHPRIV);
        vsyslog(priority, fmt, ap);
        closelog();
-#else
-       /*
-        * Write the diagnostic directly to /dev/console if we do not use
-        * the syslog(3) facility.
-        */
-       char buf[BUFSIZ];
-       char new_fmt[BUFSIZ];
-       int fd;
-
-       snprintf(new_fmt, sizeof(new_fmt), "%s: %s\r\n",
-                program_invocation_short_name, fmt);
-       /* Terminate with CR-LF since the console mode is unknown. */
-       vsnprintf(buf, sizeof(buf), new_fmt, ap);
-
-       if ((fd = open("/dev/console", 1)) >= 0) {
-               write_all(fd, buf, strlen(buf));
-               close(fd);
-       }
-#endif /* USE_SYSLOG */
 }
 
 static void exit_slowly(int code)