[PATCH] Fix cygrunsrv invocation in cygcheck
Igor Pechtchanski
pechtcha@cs.nyu.edu
Tue Aug 16 16:38:00 GMT 2005
As mentioned in <http://cygwin.com/ml/cygwin/2005-08/msg00724.html>, I
noticed something strange in the "cygcheck -s" output:
/usr/bin/cygrunsrv: Exactly one of --install, --remove, --start, --stop, --query, or --list is required
Try `/usr/bin/cygrunsrv --help' for more information.
strace shows the following arguments:
106 11167 [main] cygrunsrv 2116 build_argv: argv[0] = 'C:\cygwin\bin\cygrunsrv.exe'
20 11187 [main] cygrunsrv 2116 build_argv: argv[1] = '--query'
19 11206 [main] cygrunsrv 2116 build_argv: argv[2] = 'in\cygrunsrv.exe'
18 11224 [main] cygrunsrv 2116 build_argv: argv[3] = '--list'
18 11242 [main] cygrunsrv 2116 build_argv: argc 4
which is obviously wrong. The attached patch fixes it. No copyright
assignment here, but the patch is trivial.
Besides the bug, the invocation code has a bit of an inefficiency. The
inefficiency is in the following code (in pseudocode, for conciseness):
f = popen("cygrunsrv --list");
fread(buf, 1, sizeof(buf), f);
pclose(f);
for (char *srv = strtok(buf, "\n"); srv; srv = strtok(NULL, "\n")) {
if (verbose)
f = popen("cygrunsrv --list --verbose");
else ...
copy_output(f, stdout);
if (verbose) break;
}
why not simply run "cygrunsrv --list --verbose" in verbose mode, instead
of actually going through one iteration of the loop? Simply to reuse the
"copy output" code? Brian?
Igor
==============================================================================
ChangeLog:
2005-08-16 Igor Pechtchanski <pechtcha@cs.nyu.edu>
* cygcheck.cc (dump_sysinfo_services): Terminate command output
before running strtok().
--
http://cs.nyu.edu/~pechtcha/
|\ _,,,---,,_ pechtcha@cs.nyu.edu
ZZZzz /,`.-'`' -. ;-;;,_ igor@watson.ibm.com
|,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski, Ph.D.
'---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow!
If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA
-------------- next part --------------
Index: cygcheck.cc
===================================================================
RCS file: /cvs/src/src/winsup/utils/cygcheck.cc,v
retrieving revision 1.76
diff -u -p -r1.76 cygcheck.cc
--- cygcheck.cc 19 Jul 2005 21:00:34 -0000 1.76
+++ cygcheck.cc 16 Aug 2005 16:34:28 -0000
@@ -929,7 +929,7 @@ dump_sysinfo_services ()
printf ("Failed to execute '%s', skipping services check.\n", buf);
return;
}
- size_t nchars = fread ((void *) buf, 1, sizeof (buf), f);
+ size_t nchars = fread ((void *) buf, 1, sizeof (buf) - 1, f);
pclose (f);
/* were any services found? */
@@ -939,6 +939,8 @@ dump_sysinfo_services ()
return;
}
+ buf[nchars] = '\0';
+
/* In verbose mode, just run 'cygrunsrv --list --verbose' and copy the
entire output. Otherwise run 'cygrunsrv --query' for each service. */
for (char *srv = strtok (buf, "\n"); srv; srv = strtok (NULL, "\n"))
More information about the Cygwin-patches
mailing list