Bug 263 - bash process substitution fails
bash process substitution fails
Status: RESOLVED INVALID
Product: Sudo
Classification: Unclassified
Component: Sudo
1.6.9
PC Linux
: low normal
Assigned To: Todd C. Miller
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-24 10:38 MDT by Martijn Ras
Modified: 2007-09-24 12:20 MDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martijn Ras 2007-09-24 10:38:15 MDT
Hello,

I changed a shell script to sudo a number of commands. In all but one case this worked fine. After a lot of debugging i finally managed to figure out why it fails. The problem was with the bash process substitution on the original command line. I just downloaded and compiled 1.6.9p5, it also has this problem with bash process substitution.

Here's an example of a command and the work-around i'm currently using:

$ cat <(ls -al) [MR: This prints the contents of the current directory]

$ sudo cat <(ls -al) [MR: This prints "cat: /dev/fd/63: No such file or directory"]

$ sudo bash -c "cat <(ls -al)" [MR: This work-around prints the contents of the current directory]

It looks like the process substitution is performed before the command line is actually executed by sudo, i'd have expected sudo to take the command line as is and execute it.
Comment 1 Todd C. Miller 2007-09-24 12:20:55 MDT
This is not a bug.  Both the redirection and the substitution are done by the shell before sudo is even run.  Now, in this case bash is running "sudo /dev/fd/63" after opening file descriptor 63.  The reason this fails is that as part of its sanity checks, sudo closes file descriptors other than 1, 2, and 3 when starting.  In sudo 1.7 (still in alpha) it will be possible to control this behavior.

However, "sudo cat <(ls -al)" seeme like an odd way to do things.  Is there really any reason to not just do "sudo ls -al"?  I suppose "sudo ls -al | cat" or "cat <(sudo ls -al)" would work too but I just don't see the reason for using cat in this case.