[BusyBox 0001619]: BusyBox 1.8.2 fdisk doesn't read from stdin
bugs at busybox.net
bugs at busybox.net
Sun Feb 10 11:13:19 UTC 2008
The following issue has been CLOSED
======================================================================
http://busybox.net/bugs/view.php?id=1619
======================================================================
Reported By: vicser
Assigned To: BusyBox
======================================================================
Project: BusyBox
Issue ID: 1619
Category: Standards Compliance
Reproducibility: always
Severity: major
Priority: normal
Status: closed
Resolution: open
Fixed in Version:
======================================================================
Date Submitted: 11-30-2007 01:53 PST
Last Modified: 02-10-2008 03:13 PST
======================================================================
Summary: BusyBox 1.8.2 fdisk doesn't read from stdin
Description:
busybox is used for unattended Linux installations.
During the installation hard drive is partitioned by means of fdisk.
fdisk is used in a batch mode.
This means text file with fdisk commands is prepared -
see attached fdisk-commands file
(partition size values are variable, fdisk-commands is used to create 3
partitions -boot root and swap).
And then fdisk-commands file is passed to fdisk through the stdin.
Somthing like
fdisk /dev/hda < fdisk-commands
In all busybox till 1.7.3 this works fine
But in busybox 1.8.0-1.8.2 fdisk doesn't read commands from stdin.
======================================================================
----------------------------------------------------------------------
vda - 12-01-07 19:41
----------------------------------------------------------------------
Just built busybox 1.8.2 and tested it:
# echo q >Q
# strace -o fdisk.log ./busybox fdisk /dev/sda1 <Q
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF
disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that the previous content
won't be recoverable.
Warning: invalid flag 0x00,0x00 of partition table 4 will be corrected by
w(rite)
Command (m for help): q
#
strace log clearly shows that it did read from stdin:
write(1, "Command (m for help): ", 22) = 22
read(0, "q", 1) = 1
write(1, "q", 1) = 1
read(0, "\n", 1) = 1
write(1, "\n", 1) = 1
Please provide more details (your .config, and strace log of fdisk
invocation which doesn't work for you)
----------------------------------------------------------------------
iluxa - 01-30-08 12:55
----------------------------------------------------------------------
Apparently this busybox version expects all input to be line-buffered.
As a workaround, calling sync after sending each line will fix the
problem.
(line reading should be fixed instead, of course)
----------------------------------------------------------------------
vda - 02-03-08 17:08
----------------------------------------------------------------------
> Apparently this busybox version expects all input to be line-buffered.
1.9.0 uses fgets() in fdisk (indirectly through read_line_input)
if input is coming from non-tty. What is the problem?
> As a workaround, calling sync after sending each line will fix the
problem.
What "sync"?
> (line reading should be fixed instead, of course)
I need understandable bug report first.
----------------------------------------------------------------------
hshao - 02-04-08 13:22
----------------------------------------------------------------------
it is noticed that some changes in libbb/lineedit.c cause this problem. A
quick fix is to follow the patch below:
--- busybox-1.8.2/libbb/lineedit.c.orig 2008-02-04 11:38:51.000000000
-0800
+++ busybox-1.8.2/libbb/lineedit.c 2008-02-04 11:39:47.000000000 -0800
@@ -1270,6 +1270,8 @@
smalluint prevc;
#endif
+//fix the issue: fdisk can't take input from non-tty mode
+#if 0
getTermSettings(0, (void *) &initial_settings);
/* Happens when e.g. stty -echo was run before */
if (!(initial_settings.c_lflag & ECHO)) {
@@ -1278,6 +1280,7 @@
fgets(command, maxsize, stdin);
return strlen(command);
}
+#endif
// FIXME: audit & improve this
if (maxsize > MAX_LINELEN)
@@ -1296,6 +1299,7 @@
command_ps = command;
command[0] = '\0';
+ getTermSettings(0, (void *) &initial_settings);
memcpy(&new_settings, &initial_settings, sizeof(new_settings));
new_settings.c_lflag &= ~ICANON; /* unbuffered input */
/* Turn off echoing and CTRL-C, so we can trap it */
----------------------------------------------------------------------
iluxa - 02-04-08 20:30
----------------------------------------------------------------------
I took a look at 1.8 code, and it comes down to the same fgets call.
This may be a bug in the way busybox and glibc interact, since in this
case it is busybox statically linked with glibc 2.3
The "sync" I was referring to above was sync command. Example:
Original way:
fdisk /dev/sda << EOF
n
p
1
w
EOF
Had to be replaced with:
(echo n;sync; echo p; sync; echo 1; sync; echo; sync; echo; sync; echo
w;)|fdisk /dev/sda
----------------------------------------------------------------------
vda - 02-08-08 10:43
----------------------------------------------------------------------
Oh. It seems to be a simple thing which is fixed in 1.9.0 already.
Does this patch help?
http://busybox.net/downloads/fixes-1.8.2/busybox-1.8.2-lineedit.patch
----------------------------------------------------------------------
iluxa - 02-10-08 00:33
----------------------------------------------------------------------
The patch (slightly modified) worked.
Will attach my version.
----------------------------------------------------------------------
vda - 02-10-08 03:13
----------------------------------------------------------------------
Thanks for testing/fixing. Closing the issue.
Issue History
Date Modified Username Field Change
======================================================================
11-30-07 01:53 vicser New Issue
11-30-07 01:53 vicser Status new => assigned
11-30-07 01:53 vicser Assigned To => BusyBox
11-30-07 01:53 vicser File Added: fdisk-commands
11-30-07 02:04 vicser Issue Monitored: vicser
11-30-07 02:04 vicser Issue End Monitor: vicser
12-01-07 19:41 vda Note Added: 0002994
12-01-07 19:41 vda Status assigned => feedback
01-30-08 12:55 iluxa Note Added: 0003624
02-03-08 17:08 vda Note Added: 0003674
02-04-08 13:22 hshao Note Added: 0003704
02-04-08 20:30 iluxa Note Added: 0003714
02-08-08 10:43 vda Note Added: 0003744
02-10-08 00:33 iluxa Note Added: 0003784
02-10-08 00:34 iluxa File Added: fixlineinput.patch
02-10-08 03:13 vda Status feedback => closed
02-10-08 03:13 vda Note Added: 0003814
======================================================================
More information about the busybox-cvs
mailing list