* /bin/dash -c != /bin/bash -c with pgrep @ 2012-01-24 15:51 Richard Retanubun 2012-01-24 19:43 ` Jonathan Nieder 0 siblings, 1 reply; 5+ messages in thread From: Richard Retanubun @ 2012-01-24 15:51 UTC (permalink / raw) To: dash Hello, my dash version is 0.5.5.1-7.4 (from debian/stable I believe) I ran these two commands on a system where atftpd is not running and I am getting different results /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. Sorry if this is an old bug that is already fixed... Has it been reported? (and fixed?) I saw a patch about the "-c" mode in but it was reverted... -- Richard Retanubun ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /bin/dash -c != /bin/bash -c with pgrep 2012-01-24 15:51 /bin/dash -c != /bin/bash -c with pgrep Richard Retanubun @ 2012-01-24 19:43 ` Jonathan Nieder 2012-01-24 20:17 ` Richard Retanubun 0 siblings, 1 reply; 5+ messages in thread From: Jonathan Nieder @ 2012-01-24 19:43 UTC (permalink / raw) To: Richard Retanubun; +Cc: dash 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /bin/dash -c != /bin/bash -c with pgrep 2012-01-24 19:43 ` Jonathan Nieder @ 2012-01-24 20:17 ` Richard Retanubun 2012-01-24 20:53 ` Richard Retanubun 0 siblings, 1 reply; 5+ messages in thread From: Richard Retanubun @ 2012-01-24 20:17 UTC (permalink / raw) To: Jonathan Nieder; +Cc: dash@vger.kernel.org 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 -- ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /bin/dash -c != /bin/bash -c with pgrep 2012-01-24 20:17 ` Richard Retanubun @ 2012-01-24 20:53 ` Richard Retanubun 2012-01-24 21:03 ` Jonathan Nieder 0 siblings, 1 reply; 5+ messages in thread From: Richard Retanubun @ 2012-01-24 20:53 UTC (permalink / raw) To: Jonathan Nieder; +Cc: dash@vger.kernel.org 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: /bin/dash -c != /bin/bash -c with pgrep 2012-01-24 20:53 ` Richard Retanubun @ 2012-01-24 21:03 ` Jonathan Nieder 0 siblings, 0 replies; 5+ messages in thread From: Jonathan Nieder @ 2012-01-24 21:03 UTC (permalink / raw) To: Richard Retanubun; +Cc: dash@vger.kernel.org Richard Retanubun wrote: > Sorry, one more question to clarify, which "recent dash versions" > have the optimization? Upstream versions, or you can grab Debian packaging from the proposed-experimental branch at [1]. Cheers, Jonathan [1] git://repo.or.cz/dash/debian/jrn.git ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-01-24 21:04 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2012-01-24 15:51 /bin/dash -c != /bin/bash -c with pgrep Richard Retanubun 2012-01-24 19:43 ` Jonathan Nieder 2012-01-24 20:17 ` Richard Retanubun 2012-01-24 20:53 ` Richard Retanubun 2012-01-24 21:03 ` Jonathan Nieder
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.