]> git.ipfire.org Git - thirdparty/plymouth.git/commitdiff
ply-utils: Add ply_get_primary_kernel_console_type ()
authornerdopolis <bluescreen_avenger@verizon.net>
Fri, 2 Aug 2024 11:59:14 +0000 (07:59 -0400)
committernerdopolis <bluescreen_avenger@verizon.net>
Tue, 6 Aug 2024 01:09:42 +0000 (21:09 -0400)
src/libply/ply-utils.c
src/libply/ply-utils.h

index d6d127f1be11fb7ea39340d72dfa8878f81b7d7f..155459dc23aaa3085ae7b1321898ce95fcfed86a 100644 (file)
@@ -1259,6 +1259,34 @@ ply_kernel_command_line_override (const char *command_line)
         kernel_command_line_is_set = true;
 }
 
+char *
+ply_get_primary_kernel_console_type (void)
+{
+        int fd;
+        int len;
+        char proc_consoles[4096] = "";
+        size_t return_length;
+
+        if (ply_file_exists ("/proc/consoles")) {
+                ply_trace ("opening /proc/consoles");
+
+                fd = open ("/proc/consoles", O_RDONLY);
+                len = read (fd, proc_consoles, sizeof(proc_consoles));
+                close (fd);
+
+                /* The device type for /dev/ttyS0 is "ttyS".
+                 * for /dev/ttynull it is "ttynull", which appears as "ttynull0" in /proc/consoles. Exclude any numbers at the end.
+                 */
+                for (return_length = 0; return_length < len; return_length++) {
+                        /* Read until the next digit or space, the digit should be first */
+                        if (isdigit (proc_consoles[return_length]) || isspace (proc_consoles[return_length]))
+                                return strndup (proc_consoles, return_length);
+                }
+        }
+
+        return NULL;
+}
+
 double ply_strtod (const char *str)
 {
         char *old_locale;
index 86d66384bc01e4474343f1ee51fb08a89f7bd710..1ee319609552b1e1aa658069dbd949afe30916e6 100644 (file)
@@ -176,6 +176,8 @@ bool ply_kernel_command_line_has_argument (const char *argument);
 void ply_kernel_command_line_override (const char *command_line);
 char *ply_kernel_command_line_get_key_value (const char *key);
 
+char *ply_get_primary_kernel_console_type (void);
+
 double ply_strtod (const char *str);
 
 bool ply_is_secure_boot_enabled (void);