Re: [PATCH 3/6] checktty: Use NGROUPS_MAX instead of NGROUPS

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Jun 9, 2011 at 00:52, Josiah Worcester <josiahw@xxxxxxxxx> wrote:
> -static gid_t mygroups[NGROUPS];
> +static gid_t mygroups[NGROUPS_MAX];

That might fix issue with musl libc, but is that truly an enhancement?
How about using sysconf(_SC_NGROUPS_MAX), e.g. see attachment.

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/
From bf4382f2f49c99f8cb3db360b54d8825525c153d Mon Sep 17 00:00:00 2001
From: Sami Kerola <kerolasa@xxxxxx>
Date: Thu, 9 Jun 2011 21:23:13 +0200
Subject: [PATCH] checktty: NGROUP -> sysconf

Use sysconf return value instead of NGROUP definition to determine size of
grouplist array.

http://pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/checktty.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/login-utils/checktty.c b/login-utils/checktty.c
index f849057..e39d1e2 100644
--- a/login-utils/checktty.c
+++ b/login-utils/checktty.c
@@ -33,13 +33,14 @@
 #include "pathnames.h"
 #include "login.h"
 #include "strutils.h"
+#include "xalloc.h"
 #include "c.h"
 
 #ifndef TTY_MAJOR
 #define TTY_MAJOR 4
 #endif
 
-static gid_t mygroups[NGROUPS];
+static gid_t *mygroups;
 static int   num_groups;
 
 #define NAMELEN 128
@@ -311,6 +312,7 @@ main(int argc, char **argv)
 		{ NULL, NULL }
 	}, *item;
 
+	mygroups = xmalloc(sizeof(gid_t) * sysconf(_SC_NGROUPS_MAX));
 	memset(&hints, 0, sizeof(hints));
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_flags = AI_NUMERICHOST |  AI_PASSIVE | AI_ADDRCONFIG;
@@ -342,6 +344,7 @@ main(int argc, char **argv)
 			printf("getaddrinfo() failed\n");
 
 	}
+	free(mygroups);
 	return EXIT_SUCCESS;
 }
 #endif /* MAIN_TEST_CHECKTTY */
-- 
1.7.5.2


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux