[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [1.16.2] Can't stop "ping" with CTRL+c
From:       Kevin Cernekee <cernekee () gmail ! com>
Date:       2011-07-13 17:29:50
Message-ID: CAJiQ=7AFXjP9m_67ZovXhhoMqYYc1b6j258CEBFf526-T+3Lpg () mail ! gmail ! com
[Download RAW message or body]

On Wed, Jul 13, 2011 at 8:10 AM, Kevin Cernekee <cernekee@gmail.com> wrote:
> On Wed, Jul 13, 2011 at 12:31 AM, Denys Vlasenko
> <vda.linux@googlemail.com> wrote:
> > +                                  ssize_t s = \
> > open_read_close("/sys/class/tty/console/active", +                                \
> > &console[5], sizeof(console) - 5); +                                  if (s > 0) \
> > { +                                              /* found active console via \
> > sysfs (Linux 2.6.38+ only) */ +                                              \
> > console[4 + s] = 0; 
> > Why 4, not 5? And if changed to 5, it can overflow console[],
> > need to use sizeof(console) - 6 in read.
> 
> The last character read from sysfs is a newline, which needs to be
> removed in order to have a valid pathname.

Attaching fix + improved comment.  This applies against the head of tree.

The current busybox head of tree will not be able to open the device
because it leaves the newline intact:

starting pid 479, tty '': '/bin/cttyhack /bin/sh -l'
cttyhack: can't open '/dev/ttyS0
': No such file or directory


["0001-cttyhack-remove-the-trailing-newline-when-reading-co.patch" (text/x-patch)]

From abc9a26d5f9915ebe1e896e6dca9c50454be293e Mon Sep 17 00:00:00 2001
From: Kevin Cernekee <cernekee@gmail.com>
Date: Wed, 13 Jul 2011 09:29:55 -0700
Subject: [PATCH] cttyhack: remove the trailing newline when reading console
 name from sysfs

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
---
 shell/cttyhack.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/shell/cttyhack.c b/shell/cttyhack.c
index 4261289..37ea137 100644
--- a/shell/cttyhack.c
+++ b/shell/cttyhack.c
@@ -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;
 			}
 
-- 
1.7.6



_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic