* cygcheck.cc (dump_sysinfo_services): Properly null-terminate 'buf'.
Avoid extraneous cygrunsrv invocation if 'verbose' is true.
This commit is contained in:
parent
e448b01f6b
commit
9a99dcd39c
|
@ -1,3 +1,8 @@
|
|||
2005-08-16 Brian Dessent <brian@dessent.net>
|
||||
|
||||
* cygcheck.cc (dump_sysinfo_services): Properly null-terminate 'buf'.
|
||||
Avoid extraneous cygrunsrv invocation if 'verbose' is true.
|
||||
|
||||
2005-08-03 Corinna Vinschen <corinna@vinschen.de>
|
||||
|
||||
* mount.cc (longopts): Fix typo which disallows --options option.
|
||||
|
|
|
@ -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,30 +923,40 @@ 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);
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
/* 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);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 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);
|
||||
|
||||
/* were any services found? */
|
||||
if (nchars < 1)
|
||||
{
|
||||
puts ("No Cygwin services found.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* In verbose mode, just run 'cygrunsrv --list --verbose' and copy the
|
||||
entire output. Otherwise run 'cygrunsrv --query' for each service. */
|
||||
if (nchars > 0)
|
||||
for (char *srv = strtok (buf, "\n"); srv; srv = strtok (NULL, "\n"))
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
@ -954,17 +965,18 @@ dump_sysinfo_services ()
|
|||
}
|
||||
|
||||
/* copy output to stdout */
|
||||
do
|
||||
{
|
||||
nchars = fread ((void *)buf2, 1, sizeof (buf2), f);
|
||||
fwrite ((void *)buf2, 1, nchars, stdout);
|
||||
}
|
||||
while (!feof (f) && !ferror (f));
|
||||
while (!feof (f) && !ferror (f))
|
||||
fwrite ((void *) buf2, 1,
|
||||
fread ((void *) buf2, 1, sizeof (buf2), f), stdout);
|
||||
pclose (f);
|
||||
|
||||
if (verbose)
|
||||
break;
|
||||
}
|
||||
else
|
||||
no_services = true;
|
||||
}
|
||||
|
||||
/* inform the user if nothing found */
|
||||
if (no_services)
|
||||
puts ("No Cygwin services found.\n");
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in New Issue