Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dessent <brian@dessent.net>2005-08-17 04:52:43 +0400
committerBrian Dessent <brian@dessent.net>2005-08-17 04:52:43 +0400
commit9a99dcd39c3a40de0bc804f9d80d9a673198bee3 (patch)
treee7065348de684d4b19641cd4829356639b67c267 /winsup/utils/cygcheck.cc
parente448b01f6b5b69ee7eefa74f0be5176d92a78aac (diff)
* cygcheck.cc (dump_sysinfo_services): Properly null-terminate 'buf'.
Avoid extraneous cygrunsrv invocation if 'verbose' is true.
Diffstat (limited to 'winsup/utils/cygcheck.cc')
-rw-r--r--winsup/utils/cygcheck.cc74
1 files changed, 43 insertions, 31 deletions
diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc
index 6db0d04e0..af5871bca 100644
--- a/winsup/utils/cygcheck.cc
+++ b/winsup/utils/cygcheck.cc
@@ -888,6 +888,7 @@ dump_sysinfo_services ()
char buf[1024];
char buf2[1024];
FILE *f;
+ bool no_services = false;
if (givehelp)
printf ("\nChecking for any Cygwin services... %s\n\n",
@@ -922,49 +923,60 @@ dump_sysinfo_services ()
}
fclose (f);
- /* run cygrunsrv --list */
- snprintf (buf, sizeof (buf), "%s --list", cygrunsrv);
+ /* For verbose mode, just run cygrunsrv --list --verbose and copy output
+ verbatim; otherwise run cygrunsrv --list and then cygrunsrv --query for
+ each service. */
+ snprintf (buf, sizeof (buf), (verbose ? "%s --list --verbose" : "%s --list"),
+ cygrunsrv);
if ((f = popen (buf, "rt")) == NULL)
{
printf ("Failed to execute '%s', skipping services check.\n", buf);
return;
}
- size_t nchars = fread ((void *) buf, 1, sizeof (buf), f);
- pclose (f);
- /* were any services found? */
- if (nchars < 1)
+ if (verbose)
{
- puts ("No Cygwin services found.\n");
- return;
+ /* copy output to stdout */
+ size_t nchars = 0;
+ while (!feof (f) && !ferror (f))
+ nchars += fwrite ((void *) buf, 1,
+ fread ((void *) buf, 1, sizeof (buf), f), stdout);
+
+ /* cygrunsrv outputs nothing if there are no cygwin services found */
+ if (nchars < 1)
+ no_services = true;
+ pclose (f);
}
-
- /* 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"))
+ else
{
- if (verbose)
- snprintf (buf2, sizeof (buf2), "%s --list --verbose", cygrunsrv);
- else
- snprintf (buf2, sizeof (buf2), "%s --query %s", cygrunsrv, srv);
- if ((f = popen (buf2, "rt")) == NULL)
- {
- printf ("Failed to execute '%s', skipping services check.\n", buf2);
- return;
- }
-
- /* copy output to stdout */
- do
- {
- nchars = fread ((void *)buf2, 1, sizeof (buf2), f);
- fwrite ((void *)buf2, 1, nchars, stdout);
- }
- while (!feof (f) && !ferror (f));
+ /* read the output of --list, and then run --query for each service */
+ size_t nchars = fread ((void *) buf, 1, sizeof (buf) - 1, f);
+ buf[nchars] = 0;
pclose (f);
- if (verbose)
- break;
+ if (nchars > 0)
+ for (char *srv = strtok (buf, "\n"); srv; srv = strtok (NULL, "\n"))
+ {
+ snprintf (buf2, sizeof (buf2), "%s --query %s", cygrunsrv, srv);
+ if ((f = popen (buf2, "rt")) == NULL)
+ {
+ printf ("Failed to execute '%s', skipping services check.\n", buf2);
+ return;
+ }
+
+ /* copy output to stdout */
+ while (!feof (f) && !ferror (f))
+ fwrite ((void *) buf2, 1,
+ fread ((void *) buf2, 1, sizeof (buf2), f), stdout);
+ pclose (f);
+ }
+ else
+ no_services = true;
}
+
+ /* inform the user if nothing found */
+ if (no_services)
+ puts ("No Cygwin services found.\n");
}
static void