[sf-perl] [ot?] no pipe for you

Joseph Brenner doom at kzsu.stanford.edu
Tue Sep 18 16:20:22 PDT 2012


Hm.  Never heard of this one...

David Alban <extasia at extasia.org> wrote:

> a user said that one of my perl library routines that does sudo
> commands was hanging.  the user was using the routine to restart a
> system service (i.e., invoke an /etc/init.d script via /sbin/service).
>
> i started poking and it was hanging in my routine at the line:
>
>   @results = qx{ $command 2>&1 };
>
> we've used this routine for a few years without anything like this happening.
>
> so i poke some more and found that all of these act "normally":
>
>   $ sudo service foo restart
>   $ sudo service foo stop
>   $ sudo service foo start
>   $ sudo bash -xv /etc/init.d/foo stop 2>&1 | tee junk
>
> but...  these do their actions successfully (start and restart) and
> then subsequently fail to return the command prompt (i.e., hang):
>
>   $ sudo bash -xv /etc/init.d/foo start 2>&1 | tee junk
>   $ sudo bash -xv /etc/init.d/foo restart 2>&1 | tee junk
>
> these "hang", too:
>
>   $ sudo service wso2am start 2>&1 | tee ~/junk
>   $ sudo service wso2am restart 2>&1 | tee ~/junk
>
> i remember discovering that the ps command behaves different if its
> output goes to a pipe (it doesn't truncate the output at the edge of
> your screen), but might anyone here have an idea about why the start
> and restart hang when their output it going to a pipe?

Speculating wildly...

Do the scripts involved play games with checking `tty -s` for non-zero return?
Maybe fancy sudo redirect pipe combos can convince them there's
nothing connected to stdin or stdout?  (Seems unlikely).

Could there be a peculiar permissions problem on teeing to ~/junk?
Typically you'd expect "sudo" to give you higher permissions, but if
it's just giving you *different* permissions, you might have trouble
accessing a location in a networked file system.  (Also seems
unlikely).

Are you really multiplying redirects, like this (I've never tried
this... don't see why it would cause something to hang, but it seems
funny):

   sudo bash -xv /etc/init.d/foo start 2>&1 | tee junk 2>%1


More information about the SanFrancisco-pm mailing list