[PATCH/cygwin] Fix cygwin specific Makefile and a bug in the ssh-host-config script

Bob Proulx bob at proulx.com
Sat Nov 8 05:16:14 EST 2008


Daniel Kahn Gillmor wrote:
> Corinna Vinschen wrote:
> > diff -u -p -r1.22 ssh-host-config
> > -if ps -ef | grep -v grep | grep -q ssh
> > +if ps -ef | grep -v grep | grep -q 'sshd*$'
> 
> Sorry: i should have offered a solution to the grep -v grep thing
> instead of just pointing out the problem.  One way to avoid grep
> matching itself when scanning the process table is to use a
> non-self-matching regex.
> 
> So for example, instead of doing:
> 
>   ps -ef | grep -q 'sshd'
> 
> You could do:
> 
>   ps -ef | grep -q '[s]shd'

Using the brackets to avoid the self match is a good improvement.  But
I think it is better to avoid the -f and avoid the problem that way.
I think people get into the habit of using -f and then forget about
using ps without it.

  ps -e | grep -q sshd

Doing it this way we are at least as good as before.  But of course
that matches "abcsshd" too the same as the previous.  If 'awk' is
available it can make exact matching on the final column very easy.

  ps -e | awk '$NF=="sshd"'

One way to turn this into a boolean is this way:

  if ! ps -e | awk '$NF=="sshd"{exit(1);}'

But to me the reversal of exit value is unfortunate.  Therefore I
would use the presence of output as the way to determine status.  To
my eye the next is more easily understood and has less subtleties

  if [ -n "$(ps -e | awk '$NF=="sshd"')" ]

In summary to me using 'ps -e' seems more correct that using 'ps -ef'
and then filtering out the -f part of the output.

Of course it still fails if a process is executing and the name of the
process contains spaces and the last part after the space is "sshd".
But if someone is doing that it would seem to me that they are simply
setting themselves up for trouble.

Bob


More information about the openssh-unix-dev mailing list