]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
agetty: move init_special_char() to utils.c
authorKarel Zak <kzak@redhat.com>
Thu, 14 May 2026 09:33:15 +0000 (11:33 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 14 May 2026 11:14:57 +0000 (13:14 +0200)
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 <kzak@redhat.com>
agetty-cmd/agetty.c
agetty-cmd/agetty.h
agetty-cmd/utils.c

index ff33cffc87830eaf816389d90913a9f0bc473267..00c06ab1fc8d1a2d6ff63da5067f81d1fe3aaa1c 100644 (file)
@@ -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
 /*
index 08d03a49516e81e7c4ed008eaee08497645f2b4d..d584b2d43257e37d022fca3715fbcb9c0600365e 100644 (file)
@@ -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,
index 0ed8addd17c4455a63c87acb81c44418ed3afb39..493ba6407e4dad509091dfa3cbb112336817ea99 100644 (file)
@@ -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;
+}