Skip to content

Instantly share code, notes, and snippets.

@msg555
Created February 3, 2012 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msg555/1732995 to your computer and use it in GitHub Desktop.
Save msg555/1732995 to your computer and use it in GitHub Desktop.
// From dalvik/vm/native/dalvik_system_Zygote.c
/*
* Calls POSIX setgroups() using the int[] object as an argument.
* A NULL argument is tolerated.
*/
static int setgroupsIntarray(ArrayObject* gidArray)
{
gid_t *gids;
u4 i;
s4 *contents;
const int extra = 5;
size_t length = (gidArray == NULL ? 0 : gidArray->length) + extra;
size_t pos = 0;
/* just in case gid_t and u4 are different... */
gids = alloca(sizeof(gid_t) * length);
/* Note not actually a read from memory so it's ok if gidArray is NULL. */
contents = (s4 *)gidArray->contents;
for (i = 0 ; i + extra < length; i++) {
gids[pos++] = (gid_t) contents[i];
}
gids[pos++] = 1001;
gids[pos++] = 1010;
gids[pos++] = 3001;
gids[pos++] = 3002;
gids[pos++] = 3003;
return setgroups(length, gids);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment