bug with cygserver-config not working anymore

Brian Inglis Brian.Inglis@SystematicSW.ab.ca
Thu May 1 12:29:13 GMT 2025


On 2025-04-30 15:30, Christian Lupien via Cygwin wrote:
> On a recent system install, I tried to install cygserver by executing
>   cygserver-config
> but it failed saying that cygserver was already running.
> 
> I have done that same install for many years with success.
> 
> I tracked down the problem to the service discovery line inside the
> script (line 92) that uses:
>   ps -ef | grep -v grep | grep -q ${service_name}
> but since ps -f was changed in commit (2024-01-31)
> 1ce9756ee61e8dff5e3319851e14ebf310a0bdd8 to return the cmdline which it
> did not before, this fails because the script finds itself (cygserver-
> config is found by grep -q ${service_name})
> 
> I think the solution would be to remove the -f option to ps. So a patch
> would be like:
> --- cygserver-config.orig	2025-04-30 17:23:24.461779400 -0400
> +++ cygserver-config	2025-04-30 17:23:47.067576200 -0400
> @@ -89,7 +89,7 @@
>   _nt=`expr "${_sys}" : "CYGWIN_NT"`
>   
>   # Check for running cygserver processes first.
> -if ps -ef | grep -v grep | grep -q ${service_name}
> +if ps -e | grep -v grep | grep -q ${service_name}
>   then
>     echo
>     echo "There is a cygserver (${service_name}) already running. Nothing to do, apparently."

Could use cygrunsrv -L | grep, or cygrunsrv -Q cygserver (preferred); or
ps -es (aka --summary) instead of -ef; or
grep -q `which cygserver` and also skip grep -v; or
both; or
have cygserver (or cygrunsrv after fork, delay, check) create/rm a standard pid 
file /var/run/cygserver.pid like a good little daemon should, crond, inetd, and 
sshd do, and syslogd/-ng can; maybe adding -P, --pidfile override like inetd.

Daemon configs do:

/bin/cron-config:    cygrunsrv -Q cron > /dev/null 2>&1
/bin/cron-config:	echo "Cron is already installed as a service under account 
${cronusername}."
--
/bin/cron-config:    if ps -es | grep -Fqi '/usr/sbin/cron'; then
/bin/cron-config:	echo "INFO: A cron daemon is already running."

/bin/cygserver-config:if ps -ef | grep -v grep | grep -q ${service_name}
/bin/cygserver-config-then
/bin/cygserver-config-  echo
/bin/cygserver-config:  echo "There is a cygserver (${service_name}) already 
running. Nothing to do, apparently."
/
--
/bin/cygserver-config:  # But only if it is not already installed
/bin/cygserver-config:  if ! cygrunsrv -Q ${service_name} > /dev/null 2>&1

/bin/iu-config:  if ! cygrunsrv -Q inetd >/dev/null 2>&1
--
/bin/iu-config:      # now, if successfully installed, set ownership of the 
affected files
/bin/iu-config:      if cygrunsrv -Q inetd >/dev/null 2>&1

/bin/ssh-host-config:  if /usr/bin/cygrunsrv -Q ${service_name} >/dev/null 2>&1
/bin/ssh-host-config-  then
/bin/ssh-host-config:    csih_inform "Sshd service is already installed."
--
/bin/ssh-host-config:      if /usr/bin/cygrunsrv -Q ${service_name} >/dev/null 2>&1
--
/bin/ssh-host-config:if /usr/bin/ps -ef | /usr/bin/grep -q '/sshd\?$'
/bin/ssh-host-config-then
/bin/ssh-host-config-  echo
/bin/ssh-host-config:  csih_error "There are still ssh processes running. Please 
shut them down first."

/bin/syslog-ng-config:# Check if syslogd is installed and remove on user request.
/bin/syslog-ng-config:if cygrunsrv -Q syslogd > /dev/null 2>&1
/bin/syslog-ng-config-then
/bin/syslog-ng-config:  echo "Warning: The syslogd service is already installed. 
  You can not"
--
/bin/syslog-ng-config:# Install syslog-ng service if it is not already installed
/bin/syslog-ng-config:if ! cygrunsrv -Q syslog-ng > /dev/null 2>&1


Usage and man page of ps need synced to add -hVW to usage and update -f:

$ diff <(ps -h) <(man ps) # edited
-Usage: ps [-aefls] [-u UID] [-p PID]
- -f, --full      show process uids, ppids and command line
+       ps [-aeflsW] [-u UID] [-p PID]
+       ps -h | -V
+            -f, --full      show process uids, ppids

-- 
Take care. Thanks, Brian Inglis              Calgary, Alberta, Canada

La perfection est atteinte                   Perfection is achieved
non pas lorsqu'il n'y a plus rien à ajouter  not when there is no more to add
mais lorsqu'il n'y a plus rien à retrancher  but when there is no more to cut
                                 -- Antoine de Saint-Exupéry


More information about the Cygwin mailing list