Re: /bin/dash -c != /bin/bash -c with pgrep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24/01/12 03:17 PM, Richard Retanubun wrote:
On 24/01/12 02:43 PM, Jonathan Nieder wrote:
Hi Richard,

Richard Retanubun wrote:

/bin/dash -c "pgrep -f /usr/sbin/atftpd"; echo $?
-vs-
/bin/bash -c "pgrep -f /usr/sbin/atftpd"; echo $?

The dash version returns the PID of the grep itself and thus always succeeds.
The bash version works as expected.

As the pgrep(1) manual explains, the running pgrep or pkill process
will never report itself as a match.  However, when running pgrep
through dash, it reports the process id of the shell executing pgrep,
while the bash version and recent dash versions optimize "sh -c
'single command'" to

	sh -c 'exec pgrep -f /usr/sbin/atftpd'

so there is no shell process left to report.

If that "exec" is specified explicitly, the result is the same in both
shells.

Hope that helps,
Jonathan
It sure does, thanks a lot Jonathan.

As an addendum, I find using "pgrep -x atftpd" in this case also yields the
expected output in both shell.

Thanks for your time.

-- RR --
Sorry, one more question to clarify, which "recent dash versions" have the optimization?

Debian changelog from wheezy (0.5.7-2) says this:

0005-SHELL-Disable-sh-c-...diff: back out the optimization
that makes dash -c "script" avoid a fork().  It caused
several packages to fail to build from source (thx Stéphane Glondu, closes: #642922).

So it used to, but does not currently?

-- Richard
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux