[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk 3.1.0 getgroups problem
From: |
Aharon Robbins |
Subject: |
Re: gawk 3.1.0 getgroups problem |
Date: |
Tue, 4 Dec 2001 15:44:17 +0200 |
Greetings. Re this:
> Date: Mon, 3 Dec 2001 01:06:26 -0800
> From: "John H. DuBois III" <address@hidden>
> To: address@hidden
> Subject: gawk 3.1.0 getgroups problem
>
> Under SCO OpenServer 5.0.6a using gawk 3.1.0 compiled with gcc 2.95.2, if a
> process has more than 8 supplemental groups, any reference to PROCINFO[]
> gives:
>
> $ gawk 'BEGIN{print PROCINFO["pid"]}'
> gawk: cmd. line:1: fatal: could not find groups: Invalid argument
>
> This is because gawk is using getgroups(8):
>
> getgroups(8, 134508692) = EINVAL
>
> The most common approach for determining the size of the array to pass to
> getgroups is to first check how many groups the process is in:
>
> getgroups(0, 0) = 18
> malloc...
> getgroups(18, 134559144) = 18
>
> John
> --
> John DuBois address@hidden KC6QKZ/AE http://www.armory.com./~spcecdt/
The following unofficial patch does the trick.
Arnold Robbins
---------------------------------------------------------
diff -cr gawk-3.1.1/awk.h gawk-sco-test/awk.h
*** gawk-3.1.1/awk.h Sun Nov 4 10:50:26 2001
--- gawk-sco-test/awk.h Mon Dec 3 13:59:37 2001
***************
*** 648,653 ****
--- 648,658 ----
extern int in_end_rule;
extern int whiny_users;
+ #if defined (HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0
+ extern GETGROUPS_T *groupset;
+ extern int ngroups;
+ #endif
+
extern const char *myname;
extern char quote;
diff -cr gawk-3.1.1/configure gawk-sco-test/configure
*** gawk-3.1.1/configure Tue Nov 13 17:28:52 2001
--- gawk-sco-test/configure Mon Dec 3 13:58:00 2001
***************
*** 5113,5119 ****
echo "$ac_t""no" 1>&6
fi
! for ac_func in memset memcpy memcmp fmod setlocale strchr strerror \
strftime strncasecmp strtod system tzset
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
--- 5113,5119 ----
echo "$ac_t""no" 1>&6
fi
! for ac_func in getgroups memset memcpy memcmp fmod setlocale strchr strerror \
strftime strncasecmp strtod system tzset
do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
diff -cr gawk-3.1.1/configure.in gawk-sco-test/configure.in
*** gawk-3.1.1/configure.in Tue Nov 13 17:28:48 2001
--- gawk-sco-test/configure.in Mon Dec 3 13:47:05 2001
***************
*** 128,134 ****
esac
AC_CHECK_LIB(m, fmod)
! AC_CHECK_FUNCS(memset memcpy memcmp fmod setlocale strchr strerror \
strftime strncasecmp strtod system tzset)
dnl check for dynamic linking
--- 128,134 ----
esac
AC_CHECK_LIB(m, fmod)
! AC_CHECK_FUNCS(getgroups memset memcpy memcmp fmod setlocale strchr strerror \
strftime strncasecmp strtod system tzset)
dnl check for dynamic linking
diff -cr gawk-3.1.1/io.c gawk-sco-test/io.c
*** gawk-3.1.1/io.c Sun Nov 4 10:50:48 2001
--- gawk-sco-test/io.c Mon Dec 3 13:57:28 2001
***************
*** 1351,1360 ****
{
char tbuf[BUFSIZ], *cp;
int i;
- #if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
- GETGROUPS_T groupset[NGROUPS_MAX];
- int ngroups;
- #endif
warning(_("use `PROCINFO[...]' instead of `/dev/user'"));
--- 1351,1356 ----
***************
*** 1362,1371 ****
cp = tbuf + strlen(tbuf);
#if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
- ngroups = getgroups(NGROUPS_MAX, groupset);
- if (ngroups == -1)
- fatal(_("could not find groups: %s"), strerror(errno));
-
for (i = 0; i < ngroups; i++) {
*cp++ = ' ';
sprintf(cp, "%d", (int) groupset[i]);
--- 1358,1363 ----
diff -cr gawk-3.1.1/main.c gawk-sco-test/main.c
*** gawk-3.1.1/main.c Thu Aug 30 15:17:04 2001
--- gawk-sco-test/main.c Mon Dec 3 13:59:15 2001
***************
*** 54,59 ****
--- 54,60 ----
static void nostalgia P((void));
static void version P((void));
static void init_fds P((void));
+ static void init_groupset P((void));
/* These nodes store all the special variables AWK uses */
NODE *ARGC_node, *ARGIND_node, *ARGV_node, *BINMODE_node, *CONVFMT_node;
***************
*** 125,130 ****
--- 126,136 ----
extern char *version_string; /* current version, for printing */
+ #if defined (HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0
+ GETGROUPS_T *groupset; /* current group set */
+ int ngroups; /* size of said set */
+ #endif
+
/* The parse tree is stored here. */
NODE *expression_value;
***************
*** 242,247 ****
--- 248,256 ----
/* Robustness: check that 0, 1, 2, exist */
init_fds();
+ /* load group set */
+ init_groupset();
+
/* worst case */
emalloc(srcfiles, struct src *, argc * sizeof(struct src), "main");
memset(srcfiles, '\0', argc * sizeof(struct src));
***************
*** 777,786 ****
NODE **aptr;
char name[100];
AWKNUM value;
- #if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
- GETGROUPS_T groupset[NGROUPS_MAX];
- int ngroups;
- #endif
PROCINFO_node = install("PROCINFO",
node(Nnull_string, Node_var, (NODE *) NULL));
--- 786,791 ----
***************
*** 828,838 ****
aptr = assoc_lookup(PROCINFO_node, tmp_string("FS", 2), FALSE);
*aptr = make_string("FS", 2);
! #if defined(NGROUPS_MAX) && NGROUPS_MAX > 0
! ngroups = getgroups(NGROUPS_MAX, groupset);
! if (ngroups == -1)
! fatal(_("could not find groups: %s"), strerror(errno));
!
for (i = 0; i < ngroups; i++) {
sprintf(name, "group%d", i + 1);
value = groupset[i];
--- 833,839 ----
aptr = assoc_lookup(PROCINFO_node, tmp_string("FS", 2), FALSE);
*aptr = make_string("FS", 2);
! #if defined (HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0
for (i = 0; i < ngroups; i++) {
sprintf(name, "group%d", i + 1);
value = groupset[i];
***************
*** 1005,1008 ****
--- 1006,1034 ----
#endif
}
}
+ }
+
+ /* init_groupset --- initialize groupset */
+
+ static void
+ init_groupset()
+ {
+ #if defined(HAVE_GETGROUPS) && defined(NGROUPS_MAX) && NGROUPS_MAX > 0
+ /*
+ * If called with 0 for both args, return value is
+ * total number of groups.
+ */
+ ngroups = getgroups(0, NULL);
+ if (ngroups == -1)
+ fatal(_("could not find groups: %s"), strerror(errno));
+ else if (ngroups == 0)
+ return;
+
+ /* fill in groups */
+ emalloc(groupset, GETGROUPS_T *, ngroups * sizeof(GETGROUPS_T),
"init_groupset");
+
+ ngroups = getgroups(ngroups, groupset);
+ if (ngroups == -1)
+ fatal(_("could not find groups: %s"), strerror(errno));
+ #endif
}