From: Karel Zak Date: Thu, 14 May 2026 09:33:15 +0000 (+0200) Subject: agetty: move init_special_char() to utils.c X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=10b4e3f13b40171a7b4cf708552f9a15f353c35c;p=thirdparty%2Futil-linux.git agetty: move init_special_char() to utils.c Rename to agetty_parse_initstring() and change the interface to return the parsed string instead of modifying struct agetty_options directly. Signed-off-by: Karel Zak --- diff --git a/agetty-cmd/agetty.c b/agetty-cmd/agetty.c index ff33cffc8..00c06ab1f 100644 --- a/agetty-cmd/agetty.c +++ b/agetty-cmd/agetty.c @@ -104,7 +104,6 @@ static int inotify_fd = AGETTY_RELOAD_FDNONE; #define serial_tty_option(opt, flag) \ (((opt)->flags & (F_VCONSOLE|(flag))) == (flag)) -static void init_special_char(char* arg, struct agetty_options *op); static void parse_args(int argc, char **argv, struct agetty_options *op); static void parse_speeds(struct agetty_options *op, char *arg); static int wait_for_term_input(struct agetty_issue *ie, int fd); @@ -585,7 +584,7 @@ static void parse_args(int argc, char **argv, struct agetty_options *op) op->flags &= ~F_ISSUE; break; case 'I': - init_special_char(optarg, op); + op->initstring = agetty_parse_initstring(optarg); op->flags |= F_INITSTRING; break; case 'J': @@ -1232,47 +1231,6 @@ static int wait_for_term_input(struct agetty_issue *ie, int fd) } #endif /* AGETTY_RELOAD */ -static void init_special_char(char* arg, struct agetty_options *op) -{ - char ch, *p, *q; - int i; - - op->initstring = malloc(strlen(arg) + 1); - if (!op->initstring) - agetty_log_err(_("failed to allocate memory: %m")); - - /* - * Copy optarg into op->initstring decoding \ddd octal - * codes into chars. - */ - q = op->initstring; - p = arg; - while (*p) { - /* The \\ is converted to \ */ - if (*p == '\\') { - p++; - if (*p == '\\') { - ch = '\\'; - p++; - } else { - /* Handle \000 - \177. */ - ch = 0; - for (i = 1; i <= 3; i++) { - if (*p >= '0' && *p <= '7') { - ch <<= 3; - ch += *p - '0'; - p++; - } else { - break; - } - } - } - *q++ = ch; - } else - *q++ = *p++; - } - *q = '\0'; -} #ifdef KDGKBLED /* diff --git a/agetty-cmd/agetty.h b/agetty-cmd/agetty.h index 08d03a495..d584b2d43 100644 --- a/agetty-cmd/agetty.h +++ b/agetty-cmd/agetty.h @@ -112,6 +112,7 @@ 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 char *agetty_parse_initstring(const char *arg); enum { CLOCAL_MODE_AUTO = 0, diff --git a/agetty-cmd/utils.c b/agetty-cmd/utils.c index 0ed8addd1..493ba6407 100644 --- a/agetty-cmd/utils.c +++ b/agetty-cmd/utils.c @@ -155,3 +155,39 @@ void agetty_update_utmp(struct agetty_options *op, const char *fakehost) updwtmpx(_PATH_WTMP, &ut); } #endif + +char *agetty_parse_initstring(const char *arg) +{ + char ch, *str, *p, *q; + int i; + + str = malloc(strlen(arg) + 1); + if (!str) + agetty_log_err(_("failed to allocate memory: %m")); + + q = str; + p = (char *) arg; + while (*p) { + if (*p == '\\') { + p++; + if (*p == '\\') { + ch = '\\'; + p++; + } else { + ch = 0; + for (i = 1; i <= 3; i++) { + if (*p >= '0' && *p <= '7') { + ch <<= 3; + ch += *p - '0'; + p++; + } else + break; + } + } + *q++ = ch; + } else + *q++ = *p++; + } + *q = '\0'; + return str; +}