]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: introduce USE_NETLINK to separate netlink from reload
authorKarel Zak <kzak@redhat.com>
Tue, 3 Mar 2026 11:30:34 +0000 (12:30 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 3 Mar 2026 11:30:34 +0000 (12:30 +0100)
The netlink functionality (network address display in issue file)
and the reload mechanism (inotify-based) are separate features that
shared the same AGETTY_RELOAD ifdef guard. Additionally, the netlink
code in output_special_char() used a different guard
(#if defined(RTMGRP_IPV4_IFADDR) && defined(RTMGRP_IPV6_IFADDR))
creating inconsistency.

Introduce USE_NETLINK, defined when AGETTY_RELOAD is enabled and
the required RTMGRP constants are available. Use it consistently
for all netlink-specific code (nl field, helper functions, socket
handling, escape sequences \4, \6, \a, \A).

Keep AGETTY_RELOAD for the inotify/reload mechanism only.

Signed-off-by: Karel Zak <kzak@redhat.com>
term-utils/agetty.c

index ca404a10054e6a3850e2891b44dce7ec84aefe89..f0dc66e788c135708b48256445587ee2b0b34f61 100644 (file)
 #include "path.h"
 #include "fileutils.h"
 #ifdef AGETTY_RELOAD
-#include "netaddrq.h"
+# include "netaddrq.h"
+# if defined(RTMGRP_IPV4_IFADDR) && defined(RTMGRP_IPV6_IFADDR)
+#  define USE_NETLINK
+# endif
 #endif
 
 #include "logindefs.h"
  */
 #ifdef AGETTY_RELOAD
 # include <sys/inotify.h>
-# include <linux/netlink.h>
-# include <linux/rtnetlink.h>
 # define AGETTY_RELOAD_FILENAME "/run/agetty.reload"   /* trigger file */
 # define AGETTY_RELOAD_FDNONE  -2                      /* uninitialized fd */
 static int inotify_fd = AGETTY_RELOAD_FDNONE;
+#endif
+#ifdef USE_NETLINK
 static uint32_t netlink_groups;
 #endif
 
@@ -153,8 +156,10 @@ struct issue {
        char *mem;
        size_t mem_sz;
 
-#ifdef AGETTY_RELOAD
+#ifdef USE_NETLINK
        struct ul_nl_data nl;
+#endif
+#ifdef AGETTY_RELOAD
        char *mem_old;
 #endif
        unsigned int do_tcsetattr : 1,
@@ -365,7 +370,7 @@ int main(int argc, char **argv)
        };
        struct issue issue = {
                .mem = NULL,
-#ifdef AGETTY_RELOAD
+#ifdef USE_NETLINK
                .nl.fd = -1
 #endif
        };
@@ -1641,11 +1646,13 @@ static int wait_for_term_input(struct issue *ie, int fd)
                        FD_SET(inotify_fd, &rfds);
                        nfds = max(nfds, inotify_fd);
                }
+
+#ifdef USE_NETLINK
                if (ie->nl.fd >= 0) {
                        FD_SET(ie->nl.fd, &rfds);
                        nfds = max(nfds, ie->nl.fd);
                }
-
+#endif
                /* If waiting fails, just fall through, presumably reading input will fail */
                if (select(nfds + 1, &rfds, NULL, NULL, NULL) < 0)
                        return 1;
@@ -1655,6 +1662,7 @@ static int wait_for_term_input(struct issue *ie, int fd)
 
                }
 
+#ifdef USE_NETLINK
                if (ie->nl.fd >= 0 && FD_ISSET(ie->nl.fd, &rfds)) {
                        int rc;
 
@@ -1669,7 +1677,9 @@ static int wait_for_term_input(struct issue *ie, int fd)
                        while (!rc || rc == UL_NL_SOFT_ERROR);
 
                /* Just drain the inotify buffer */
-               } else if (inotify_fd >= 0 && FD_ISSET(inotify_fd, &rfds)) {
+               } else
+#endif /* USE_NETLINK */
+               if (inotify_fd >= 0 && FD_ISSET(inotify_fd, &rfds)) {
                        while (read(inotify_fd, buffer, sizeof (buffer)) > 0);
                }
 
@@ -1879,7 +1889,7 @@ static void eval_issue_file(struct issue *ie,
        if (!(op->flags & F_ISSUE))
                goto done;
 
-#ifdef AGETTY_RELOAD
+#ifdef USE_NETLINK
 /* TODO:
  * Two pass processing for eval_issue_file()
  * Implement pass 1: Just evaluate list of netlink_groups (IP protocols) and
@@ -1913,7 +1923,7 @@ error:
        ul_nl_close(&(ie->nl));
        ie->nl.fd = -1;
 skip:
-#endif
+#endif /* USE_NETLINK */
        /*
         * The custom issue file or directory list specified by:
         *   agetty --issue-file <path[:path]...>
@@ -1980,7 +1990,7 @@ static void show_issue(struct options *op)
 {
        struct issue ie = {
                .output = NULL,
-#ifdef AGETTY_RELOAD
+#ifdef USE_NETLINK
                .nl.fd = -1
 #endif
        };
@@ -2596,7 +2606,7 @@ static void log_warn(const char *fmt, ...)
        va_end(ap);
 }
 
-#ifdef AGETTY_RELOAD
+#ifdef USE_NETLINK
 static void print_iface_best(struct issue *ie,
                             const char *ifname,
                             uint8_t ifa_family)
@@ -2762,7 +2772,7 @@ static void dump_iface_all(struct issue *ie,
        if (!first)
                fputs("\n", ie->output);
 }
-#endif /* AGETTY_RELOAD */
+#endif /* USE_NETLINK */
 
 /*
  * parses \x{argument}, if not argument specified then returns NULL, the @fd
@@ -2956,7 +2966,7 @@ static void output_special_char(struct issue *ie,
                        fprintf (ie->output, "%d ", users);
                break;
        }
-#if defined(RTMGRP_IPV4_IFADDR) && defined(RTMGRP_IPV6_IFADDR)
+#ifdef USE_NETLINK
        case '4':
        case '6':
        {
@@ -3001,7 +3011,7 @@ static void output_special_char(struct issue *ie,
                }
        }
        break;
-#endif
+#endif /* USE_NETLINK */
        default:
                putc(c, ie->output);
                break;