svn commit: trunk/busybox: coreutils include

vda at busybox.net vda at busybox.net
Sat Sep 13 12:51:10 UTC 2008


Author: vda
Date: 2008-09-13 05:51:10 -0700 (Sat, 13 Sep 2008)
New Revision: 23388

Log:
id: code shrink

function                                             old     new   delta
id_main                                              494     462     -32



Modified:
   trunk/busybox/coreutils/id.c
   trunk/busybox/include/usage.h


Changeset:
Modified: trunk/busybox/coreutils/id.c
===================================================================
--- trunk/busybox/coreutils/id.c	2008-09-12 09:58:11 UTC (rev 23387)
+++ trunk/busybox/coreutils/id.c	2008-09-13 12:51:10 UTC (rev 23388)
@@ -45,7 +45,7 @@
 	uid_t uid;
 	gid_t gid;
 	gid_t *groups;
-	int grp;
+	int n;
 	unsigned long flags;
 	short status;
 #if ENABLE_SELINUX
@@ -72,17 +72,17 @@
 		/* in this case PRINT_REAL is the same */
 	}
 
-	grp = getgroups(0, 0);
-	groups = (gid_t *)xmalloc(sizeof(gid_t) * grp);
-	getgroups(grp, (gid_t *)groups);
+	n = getgroups(0, NULL);
+	groups = xmalloc(sizeof(groups[0]) * n);
+	getgroups(n, groups);
 
-	if (flags & (JUST_ALL_GROUPS)) {
-		while (grp--) {
+	if (flags & JUST_ALL_GROUPS) {
+		while (n--) {
 			if (flags & NAME_NOT_NUMBER)
 				printf("%s", bb_getgrgid(NULL, 0, *groups++));
 			else
-				printf("%d", *groups++);
-			bb_putchar((grp > 0) ? ' ' : '\n');
+				printf("%d", (int) *groups++);
+			bb_putchar((n > 0) ? ' ' : '\n');
 		}
 		/* exit */
 		fflush_stdout_and_exit(EXIT_SUCCESS);
@@ -105,7 +105,7 @@
 #if ENABLE_SELINUX
 		if (flags & JUST_CONTEXT) {
 			selinux_or_die();
-			if (argc - optind == 1) {
+			if (argv[optind]) {
 				bb_error_msg_and_die("user name can't be passed with -Z");
 			}
 
@@ -122,16 +122,17 @@
 	/* Print full info like GNU id */
 	/* bb_getpwuid(0) doesn't exit on failure (returns NULL) */
 	status = printf_full(uid, bb_getpwuid(NULL, 0, uid), "uid=");
-	bb_putchar(' ');
-	status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), "gid=");
-	printf(" groups=");
-	while (grp--) {
-		status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), "");
-		if (grp > 0)
-			bb_putchar(',');
-		groups++;
+	status |= printf_full(gid, bb_getgrgid(NULL, 0, gid), " gid=");
+	{
+		const char *msg = " groups=";
+		while (n--) {
+			status |= printf_full(*groups, bb_getgrgid(NULL, 0, *groups), msg);
+			msg = ",";
+			groups++;
+		}
 	}
-	/* Don't free groups */
+	/* we leak groups vector... */
+
 #if ENABLE_SELINUX
 	if (is_selinux_enabled()) {
 		security_context_t mysid;

Modified: trunk/busybox/include/usage.h
===================================================================
--- trunk/busybox/include/usage.h	2008-09-12 09:58:11 UTC (rev 23387)
+++ trunk/busybox/include/usage.h	2008-09-13 12:51:10 UTC (rev 23388)
@@ -1602,9 +1602,9 @@
 	USE_SELINUX( \
      "\n	-Z	Print the security context" \
 	) \
-     "\n	-G	Print all group IDs" \
+     "\n	-u	Print user ID" \
      "\n	-g	Print group ID" \
-     "\n	-u	Print user ID" \
+     "\n	-G	Print supplementary group IDs" \
      "\n	-n	Print name instead of a number" \
      "\n	-r	Print real user ID instead of effective ID" \
 




More information about the busybox-cvs mailing list