cttyhack: remove the trailing newline when reading console name from sysfs
authorKevin Cernekee <cernekee@gmail.com>
Wed, 13 Jul 2011 16:29:55 +0000 (09:29 -0700)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 16 Aug 2011 21:29:54 +0000 (23:29 +0200)
Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
shell/cttyhack.c

index 4261289b45da7b8e58540cf59f40d1ebf1255ffb..37ea13723eef838e32015bf54ce904db03b9b96f 100644 (file)
@@ -122,10 +122,12 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
                do {
 #ifdef __linux__
                        int s = open_read_close("/sys/class/tty/console/active",
-                               console + 5, sizeof(console) - 5 - 1);
+                               console + 5, sizeof(console) - 5);
                        if (s > 0) {
-                               /* found active console via sysfs (Linux 2.6.38+) */
-                               console[5 + s] = '\0';
+                               /* found active console via sysfs (Linux 2.6.38+)
+                                * sysfs string looks like "ttyS0\n" so zap the newline:
+                                */
+                               console[4 + s] = '\0';
                                break;
                        }