From: Karel Zak Date: Thu, 14 May 2026 10:13:39 +0000 (+0200) Subject: agetty: move fakehost to struct agetty_options X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=0293c3da7ab9add1092e40cd37eb6a49a0dcbd6d;p=thirdparty%2Futil-linux.git agetty: move fakehost to struct agetty_options 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 --- diff --git a/agetty-cmd/agetty.c b/agetty-cmd/agetty.c index 7ceff5f48..333dba2fa 100644 --- a/agetty-cmd/agetty.c +++ b/agetty-cmd/agetty.c @@ -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) diff --git a/agetty-cmd/agetty.h b/agetty-cmd/agetty.h index 4ff0db6f2..97ad81823 100644 --- a/agetty-cmd/agetty.h +++ b/agetty-cmd/agetty.h @@ -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, diff --git a/agetty-cmd/utils.c b/agetty-cmd/utils.c index 270b42d55..4c6b6b4cf 100644 --- a/agetty-cmd/utils.c +++ b/agetty-cmd/utils.c @@ -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"; }