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:
authorChristopher Faylor <me@cgf.cx>2004-10-14 21:35:46 +0400
committerChristopher Faylor <me@cgf.cx>2004-10-14 21:35:46 +0400
commit902edd4512f1ab29d0d764effb8c10912e9581ba (patch)
treee5f49dfdf9d1f71a3e684acab8e46b71fb5d4dff /winsup/utils
parent2457f34144fdd0c3304182678c9454f4f59a68b4 (diff)
* cygcheck.cc (pretty_id): Correct column calculations. Abort if id is acting
funny.
Diffstat (limited to 'winsup/utils')
-rw-r--r--winsup/utils/ChangeLog6
-rw-r--r--winsup/utils/cygcheck.cc61
2 files changed, 36 insertions, 31 deletions
diff --git a/winsup/utils/ChangeLog b/winsup/utils/ChangeLog
index f84ddebaa..9b236f031 100644
--- a/winsup/utils/ChangeLog
+++ b/winsup/utils/ChangeLog
@@ -1,3 +1,9 @@
+2004-10-14 Christopher Faylor <cgf@timesys.com>
+ Bas van Gompel <cygwin-patch.buzz@bavag.tmfweb.nl>
+
+ * cygcheck.cc (pretty_id): Correct column calculations. Abort if id is
+ acting funny.
+
2004-10-10 Bas van Gompel <cygwin-patch.buzz@bavag.tmfweb.nl>
* cygcheck.cc (add_path): Don't leak memory when path is already in
diff --git a/winsup/utils/cygcheck.cc b/winsup/utils/cygcheck.cc
index 1c3ae4ab8..327e3ccec 100644
--- a/winsup/utils/cygcheck.cc
+++ b/winsup/utils/cygcheck.cc
@@ -20,6 +20,8 @@
#include "cygwin/include/sys/cygwin.h"
#include "cygwin/include/mntent.h"
+#define alloca __builtin_alloca
+
int verbose = 0;
int registry = 0;
int sysinfo = 0;
@@ -791,7 +793,6 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
FILE *f = popen (id, "rt");
char buf[16384];
- static char empty[] = "";
buf[0] = '\0';
fgets (buf, sizeof (buf), f);
pclose (f);
@@ -799,20 +800,33 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
if (uid)
uid += strlen ("uid=");
else
- uid = empty;
+ {
+ fprintf (stderr, "garbled output from `id' command - no uid= found\n");
+ exit (1);
+ }
char *gid = strtok (NULL, ")");
if (gid)
gid += strlen ("gid=") + 1;
else
- gid = empty;
- char **ng;
- size_t sz = 0;
- for (ng = groups; (*ng = strtok (NULL, ",")); ng++)
+ {
+ fprintf (stderr, "garbled output from `id' command - no gid= found\n");
+ exit (1);
+ }
+
+ char **ng = groups - 1;
+ size_t len_uid = strlen (uid);
+ size_t len_gid = strlen (gid);
+ *++ng = groups[0] = (char *) alloca (len_uid += sizeof ("UID: )"));
+ *++ng = groups[1] = (char *) alloca (len_uid += sizeof ("GID: )"));
+ sprintf (groups[0], "UID: %s)", uid);
+ sprintf (groups[1], "GID: %s)", gid);
+ size_t sz = max (len_uid, len_gid);
+ while ((*++ng = strtok (NULL, ",")))
{
char *p = strchr (*ng, '\n');
if (p)
*p = '\0';
- if (ng == groups)
+ if (ng == groups + 2)
*ng += strlen (" groups=");
size_t len = strlen (*ng);
if (sz < len)
@@ -820,32 +834,17 @@ pretty_id (const char *s, char *cygwin, size_t cyglen)
}
printf ("\nOutput from %s (%s)\n", id, s);
- size_t szmaybe = strlen ("UID: ") + strlen (uid);
- if (sz < szmaybe)
- sz = szmaybe;
- sz += 1;
int n = 80 / (int) sz;
- sz = -sz;
- ng[0] += strlen ("groups=");
- printf ("UID: %.*s) GID: %s)\n", sz + (sizeof ("UID: ") - 1), uid, gid);
- int i = 0;
+ sz = -(sz + 1);
+ int i = n - 2;
for (char **g = groups; g < ng; g++)
- {
- if (i < n)
- i++;
- else
- {
- i = 0;
- puts ("");
- }
- if (++i <= n && g != (ng - 1))
- printf ("%*s ", sz, *g);
- else
- {
- printf ("%s\n", *g);
- i = 0;
- }
- }
+ if ((g != ng - 1) && (++i < n))
+ printf ("%*s ", sz, *g);
+ else
+ {
+ puts (*g);
+ i = 0;
+ }
}
static void