[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: printf cannot write more than one line to /proc/pid/uid_map
From: |
Pádraig Brady |
Subject: |
Re: printf cannot write more than one line to /proc/pid/uid_map |
Date: |
Tue, 25 Mar 2014 16:30:38 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130110 Thunderbird/17.0.2 |
On 03/25/2014 01:57 PM, Greg Wooledge wrote:
> On Tue, Mar 25, 2014 at 08:24:13PM +0900, Kusanagi Kouichi wrote:
>> Description:
>> Bash's builtin printf cannot write more than one line to
>> /proc/pid/uid_map because printf writes one line at a time
>> and uid_map can be written only once.
>
> Sounds like Bash is using the standard I/O library routines, in line
> buffering mode (i.e. setvbuf(..., _IOLBF, ...); ). It's not clear
> to me whether this can be considered a bug, as line-buffered output
> is common, and situations where it fails are rare.
>
>> Repeat-By:
>> # printf '0 0 1\n1 1 1' > /proc/31861/uid_map
>> printf: write error: Operation not permitted
>
> As a workaround, you might consider something like:
>
> printf '0 0 1\n1 1 1' | dd bs=1024 > /proc/31861/uid_map
Note dd will immediately write any short reads in that case too.
Though not a specific issue here (since the printf will issue a single write()),
to generall get dd to coalesce reads you needs to specify obs separately like:
printf '0 0 1\n1 1 1' | dd obs=1024 > /proc/31861/uid_map
BTW it's a bit surprising that bash doesn't use standard
"default buffering modes" mentioned here:
http://www.pixelbeat.org/programming/stdio_buffering/
If you want to use the external printf to achieve more
standard buffering modes, you can use `env` like:
env printf '%s' '0 0 1\n1 1 1' > /proc/31861/uid_map
thanks,
Pádraig.
Message not available