Bug 5540 - Parse error in ash when redirecting value to sysfs
Summary: Parse error in ash when redirecting value to sysfs
Status: RESOLVED INVALID
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: unspecified
Hardware: All All
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-09-19 07:25 UTC by Henri Bragge
Modified: 2012-09-20 09:32 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments
echo 128> ... (3.63 KB, text/plain)
2012-09-19 09:56 UTC, Henri Bragge
Details
echo 128 > ... (3.65 KB, text/plain)
2012-09-19 10:00 UTC, Henri Bragge
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Henri Bragge 2012-09-19 07:25:10 UTC
When echoing a value and redirecting it to a file under sysfs, ash just prints an empty line but does not store the value. This only happens when ">" character is typed right after the command.

For example, this works:
# echo 250 > /sys/class/backlight/pwm-backlight.0/brightness
# cat /sys/class/backlight/pwm-backlight.0/brightness
250

But this does not:
# echo 128> /sys/class/backlight/pwm-backlight.0/brightness

# cat /sys/class/backlight/pwm-backlight.0/brightness
250

Redirecting in similar way to a normal file works:
# echo hello> /tmp/world
# cat /tmp/world
hello
Comment 1 Henri Bragge 2012-09-19 07:25:48 UTC
Tested with busybox 1.19.4 and 1.20.2
Comment 2 Denys Vlasenko 2012-09-19 09:34:45 UTC
Please strace it:

strace -oLOG -s99 ash -c 'echo 128> /sys/class/backlight/pwm-backlight.0/brightness'

and post the LOG file
Comment 3 Henri Bragge 2012-09-19 09:56:45 UTC
Created attachment 4538 [details]
echo 128> ...
Comment 4 Henri Bragge 2012-09-19 10:00:50 UTC
Created attachment 4544 [details]
echo 128 > ...

In LOG-error, there is something interesting in line 48:
fcntl64(128, F_DUPFD, 10)               = -1 EBADF (Bad file descriptor)
dup2(3, 128)                            = 128
close(3)                                = 0
wait4(-1, 0x7e8fa6dc, WNOHANG, NULL)    = -1 ECHILD (No child processes)
write(1, "\n", 1)                       = 1
close(128)                              = 0

In LOG-ok, this looks like:
fcntl64(1, F_DUPFD, 10)                 = 10
dup2(3, 1)                              = 1
close(3)                                = 0
wait4(-1, 0x7ecc66dc, WNOHANG, NULL)    = -1 ECHILD (No child processes)
write(1, "128\n", 4)                    = 4
dup2(10, 1)                             = 1
close(10)                               = 0
Comment 5 Henri Bragge 2012-09-19 10:20:34 UTC
Small correction, though you probably noticed it already. Problem actually occurs similarly in normal files and sysfs. Instead, there is something special in the way ash handles numbers that are not separated from ">" character with a whitespace:

Both of these do not work as expected:
# echo 66> /sys/class/backlight/pwm-backlight.0/brightness

# echo 66>/tmp/world

# cat /tmp/world
#
Comment 6 Henri Bragge 2012-09-19 10:32:22 UTC
I tested this again with bash on my PC and it seems to behave exactly the same (dealing numbers as file handles?). Nothing strange in it after all.

Maybe should have given it a bit more thought before reporting :)