]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: move fakehost to struct agetty_options
authorKarel Zak <kzak@redhat.com>
Thu, 14 May 2026 10:13:39 +0000 (12:13 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 14 May 2026 11:15:33 +0000 (13:15 +0200)
Move the file-scope fakehost variable into struct agetty_options
and drop the separate fakehost parameter from agetty_update_utmp()
and agetty_init_login_argv().

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

index 7ceff5f4866a37f09544e8082025cdca4933ae0e..333dba2fa6884503f8800ed65f21e56a2bc74664 100644 (file)
@@ -56,8 +56,6 @@ static ssize_t append(char *dest, size_t len, const char  *sep, const char *src)
 #endif
 
 
-/* Fake hostname for ut_host specified on command line. */
-static char *fakehost;
 
 #ifdef DEBUGGING
 # include "closestream.h"
@@ -261,7 +259,7 @@ static void parse_args(int argc, char **argv, struct agetty_options *op)
                        op->flags |= F_RTSCTS;
                        break;
                case 'H':
-                       fakehost = optarg;
+                       op->fakehost = optarg;
                        break;
                case 'i':
                        op->flags &= ~F_ISSUE;
@@ -473,7 +471,7 @@ int main(int argc, char **argv)
 
        /* Update the utmp file. */
 #ifdef SYSV_STYLE
-       agetty_update_utmp(&options, fakehost);
+       agetty_update_utmp(&options);
 #endif
        if (options.delay)
            sleep(options.delay);
@@ -590,7 +588,7 @@ int main(int argc, char **argv)
        sigaction(SIGQUIT, &sa_quit, NULL);
        sigaction(SIGINT, &sa_int, NULL);
 
-       agetty_init_login_argv(login_argv, &login_argc, &options, fakehost);
+       agetty_init_login_argv(login_argv, &login_argc, &options);
 
        if (options.chroot) {
                if (chroot(options.chroot) < 0)
index 4ff0db6f2a925d7ddbbc59906007bfe5d1a5201d..97ad81823e1e95de422848a9cc13f158e3ac18b9 100644 (file)
@@ -76,6 +76,7 @@ struct agetty_options {
        char *erasechars;               /* string with erase chars */
        char *killchars;                /* string with kill chars */
        char *username;                 /* login name, given to /bin/login */
+       char *fakehost;                 /* fake hostname for ut_host */
        char *osrelease;                /* /etc/os-release data */
        unsigned int delay;             /* Sleep seconds before prompt */
        int nice;                       /* Run login with this priority */
@@ -119,11 +120,11 @@ extern void agetty_load_credentials(struct agetty_options *op);
 
 extern char *agetty_xgethostname(void);
 extern char *agetty_xgetdomainname(void);
-extern void agetty_update_utmp(struct agetty_options *op, const char *fakehost);
+extern void agetty_update_utmp(struct agetty_options *op);
 extern void agetty_parse_speeds(struct agetty_options *op, char *arg);
 extern char *agetty_parse_initstring(const char *arg);
 extern void agetty_init_login_argv(char *argv[], int *argc,
-                                  struct agetty_options *op, const char *fakehost);
+                                  struct agetty_options *op);
 
 enum {
        CLOCAL_MODE_AUTO = 0,
index 270b42d551cf376ba33e00b9212e8ece30c0b61b..4c6b6b4cfff453c612372839f348b10ebf92ee5d 100644 (file)
@@ -88,7 +88,7 @@ char *agetty_xgetdomainname(void)
 }
 
 #ifdef SYSV_STYLE
-void agetty_update_utmp(struct agetty_options *op, const char *fakehost)
+void agetty_update_utmp(struct agetty_options *op)
 {
        struct utmpx ut;
        time_t t;
@@ -145,8 +145,8 @@ void agetty_update_utmp(struct agetty_options *op, const char *fakehost)
 
        str2memcpy(ut.ut_user, "LOGIN", sizeof(ut.ut_user));
        str2memcpy(ut.ut_line, line, sizeof(ut.ut_line));
-       if (fakehost)
-               str2memcpy(ut.ut_host, fakehost, sizeof(ut.ut_host));
+       if (op->fakehost)
+               str2memcpy(ut.ut_host, op->fakehost, sizeof(ut.ut_host));
        time(&t);
        ut.ut_tv.tv_sec = t;
        ut.ut_type = LOGIN_PROCESS;
@@ -300,7 +300,7 @@ err:
 }
 
 void agetty_init_login_argv(char *argv[], int *argc,
-                           struct agetty_options *op, const char *fakehost)
+                           struct agetty_options *op)
 {
        *argc = 0;
        argv[(*argc)++] = op->login;
@@ -312,9 +312,9 @@ void agetty_init_login_argv(char *argv[], int *argc,
                login_options_to_argv(argv, argc, op->logopt, op->username);
        } else {
                if (op->flags & F_REMOTE) {
-                       if (fakehost) {
+                       if (op->fakehost) {
                                argv[(*argc)++] = "-h";
-                               argv[(*argc)++] = (char *) fakehost;
+                               argv[(*argc)++] = op->fakehost;
                        } else if (op->flags & F_NOHOSTNAME)
                                argv[(*argc)++] = "-H";
                }