Skip to content

Commit

Permalink
use non-thread-safe getpwuid and getpwgid for android
Browse files Browse the repository at this point in the history
We only call it (so far) after doing a fork(), so this is fine.  If we
ever need such a thing from threaded context, we'll simply need to write
our own version for android.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
  • Loading branch information
hallyn authored and stgraber committed Jul 31, 2014
1 parent 97e9cfa commit a96a8e8
Showing 1 changed file with 11 additions and 36 deletions.
47 changes: 11 additions & 36 deletions src/lxc/conf.c
Expand Up @@ -4674,56 +4674,31 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data)
return -1;
}

/* not thread-safe, do not use from api without first forking */
static char* getuname(void)
{
struct passwd pwd, *result;
char *buf, *ret = NULL;
size_t bufsize;
int s;
struct passwd *result;

bufsize = sysconf(_SC_GETPW_R_SIZE_MAX);
if (bufsize == -1)
bufsize = 16384;

buf = malloc(bufsize);
if (!buf)
result = getpwuid(geteuid());
if (!result)
return NULL;

s = getpwuid_r(geteuid(), &pwd, buf, bufsize, &result);
if (s || result == NULL)
goto out;

ret = strdup(pwd.pw_name);
out:
free(buf);
return ret;
return strdup(result->pw_name);
}

/* not thread-safe, do not use from api without first forking */
static char *getgname(void)
{
struct group grp, *result;
char *buf, *ret = NULL;
size_t bufsize;
int s;
struct group *result;

bufsize = sysconf(_SC_GETGR_R_SIZE_MAX);
if (bufsize == -1)
bufsize = 16384;

buf = malloc(bufsize);
if (!buf)
result = getgrgid(getegid());
if (!result)
return NULL;

s = getgrgid_r(geteuid(), &grp, buf, bufsize, &result);
if (s || result == NULL)
goto out;

ret = strdup(grp.gr_name);
out:
free(buf);
return ret;
return strdup(result->gr_name);
}

/* not thread-safe, do not use from api without first forking */
void suggest_default_idmap(void)
{
FILE *f;
Expand Down

0 comments on commit a96a8e8

Please sign in to comment.