This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] cygrunsrv: don't bail on first error when listing services


Currently, when listing services with cygrunsrv -L, the first error
condition causes an immediate abort.  This sucks when there is a service
that the user does not have rights to query or there is the stub of a
service that was deleted but is still in the system's cache.  I'm not
sure exactly how this latter condition comes to happen but it happens
for me every now and then, and I've seen it in people's cygcheck.out on
the cygwin@ list.

This patch simply makes it a nonfatal warning if OpenService or
QueryServiceConfig fail, and continues trying to list services.  It also
prints the name of the service that it couldn't access, which is handy
for troubleshooting.

Example, before:

$ cygrunsrv -L
cygrunsrv: Error enumerating services: QueryServiceConfig:  Win32 error
2:
The system cannot find the file specified.

After:

$ cygrunsrv -L
cygrunsrv: warning: QueryServiceConfig failed for 'Amsierve': Win32
error 2
The system cannot find the file specified.
apache
cron
cygserver
mailtun
sshd
syslog-ng

Brian
2007-04-19  Brian Dessent  <brian@dessent.net>

	* cygrunsrv.cc (list_services): Make failure of OpenService or
	QueryServiceConfig nonfatal.


Index: cygrunsrv.cc
===================================================================
RCS file: /cvs/cygwin-apps/cygrunsrv/cygrunsrv.cc,v
retrieving revision 1.37
diff -u -p -r1.37 cygrunsrv.cc
--- cygrunsrv.cc	18 Apr 2007 09:53:09 -0000	1.37
+++ cygrunsrv.cc	19 Apr 2007 09:11:30 -0000
@@ -1270,13 +1270,20 @@ list_services (bool verbose)
     {
       /* get details of this service and see if it's one of ours.  */
       if (!(sh = OpenService (sm, srv_buf[i].lpServiceName, GENERIC_READ)))
-        err_out (OpenService);
+        {
+          fprintf (stderr, "%s: warning: OpenService failed for '%s': "
+                   "Win32 error %lu\n%s", appname, srv_buf[i].lpServiceName,
+                   GetLastError (), winerror (GetLastError ()));
+          continue;
+        }
       
       if (!QueryServiceConfig (sh, qsc_buf, QSC_BUF_SIZE, &bytes_needed))
-        err_out (QueryServiceConfig);
-      
+        fprintf (stderr, "%s: warning: QueryServiceConfig failed for '%s': "
+                 "Win32 error %lu\n%s", appname, srv_buf[i].lpServiceName,
+                 GetLastError (), winerror (GetLastError ()));
+
       /* is this us? */
-      if (same_filename (qsc_buf->lpBinaryPathName, mypath))
+      else if (same_filename (qsc_buf->lpBinaryPathName, mypath))
         {          
           if (!verbose)
             printf ("%s\n", srv_buf[i].lpServiceName);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]