personality.h: Make the personality code optional

Some platforms don't have personality.h in their C library, this change
adds buildtime detection for the header and turns off the personality setting
code in those cases.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2013-01-03 12:24:13 -05:00
parent 495d2046f6
commit 6ff05e18a3
4 changed files with 28 additions and 5 deletions

View File

@ -221,7 +221,7 @@ AM_CONDITIONAL([IS_BIONIC], [test "x$is_bionic" = "xyes"])
AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>]) AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>])
# Check for some headers # Check for some headers
AC_CHECK_HEADERS([sys/signalfd.h pty.h sys/capability.h]) AC_CHECK_HEADERS([sys/signalfd.h pty.h sys/capability.h sys/personality.h])
# Check for some functions # Check for some functions
AC_CHECK_FUNCS([openpty]) AC_CHECK_FUNCS([openpty])

View File

@ -48,7 +48,6 @@
#include <sys/mount.h> #include <sys/mount.h>
#include <sys/mman.h> #include <sys/mman.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/personality.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <fcntl.h> #include <fcntl.h>
@ -74,6 +73,10 @@
#include <sys/capability.h> #include <sys/capability.h>
#endif #endif
#if HAVE_SYS_PERSONALITY_H
#include <sys/personality.h>
#endif
#include "lxcseccomp.h" #include "lxcseccomp.h"
lxc_log_define(lxc_conf, lxc); lxc_log_define(lxc_conf, lxc);
@ -1198,6 +1201,7 @@ out:
static int setup_personality(int persona) static int setup_personality(int persona)
{ {
#if HAVE_SYS_PERSONALITY_H
if (persona == -1) if (persona == -1)
return 0; return 0;
@ -1207,6 +1211,7 @@ static int setup_personality(int persona)
} }
INFO("set personality to '0x%x'", persona); INFO("set personality to '0x%x'", persona);
#endif
return 0; return 0;
} }

View File

@ -31,12 +31,12 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/param.h> #include <sys/param.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include <sys/personality.h>
#include <arpa/inet.h> #include <arpa/inet.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if.h> #include <net/if.h>
#include "parse.h" #include "parse.h"
#include "config.h"
#include "confile.h" #include "confile.h"
#include "utils.h" #include "utils.h"
@ -44,6 +44,10 @@
#include <lxc/conf.h> #include <lxc/conf.h>
#include "network.h" #include "network.h"
#if HAVE_SYS_PERSONALITY_H
#include <sys/personality.h>
#endif
lxc_log_define(lxc_confile, lxc); lxc_log_define(lxc_confile, lxc);
static int config_personality(const char *, const char *, struct lxc_conf *); static int config_personality(const char *, const char *, struct lxc_conf *);
@ -1301,6 +1305,7 @@ int lxc_config_define_load(struct lxc_list *defines, struct lxc_conf *conf)
signed long lxc_config_parse_arch(const char *arch) signed long lxc_config_parse_arch(const char *arch)
{ {
#if HAVE_SYS_PERSONALITY_H
struct per_name { struct per_name {
char *name; char *name;
unsigned long per; unsigned long per;
@ -1318,6 +1323,7 @@ signed long lxc_config_parse_arch(const char *arch)
if (!strcmp(pername[i].name, arch)) if (!strcmp(pername[i].name, arch))
return pername[i].per; return pername[i].per;
} }
#endif
return -1; return -1;
} }
@ -1333,18 +1339,22 @@ static int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v)
static int lxc_get_arch_entry(struct lxc_conf *c, char *retv, int inlen) static int lxc_get_arch_entry(struct lxc_conf *c, char *retv, int inlen)
{ {
int len, fulllen = 0; int fulllen = 0;
if (!retv) if (!retv)
inlen = 0; inlen = 0;
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
#if HAVE_SYS_PERSONALITY_H
int len = 0;
switch(c->personality) { switch(c->personality) {
case PER_LINUX32: strprint(retv, inlen, "x86"); break; case PER_LINUX32: strprint(retv, inlen, "x86"); break;
case PER_LINUX: strprint(retv, inlen, "x86_64"); break; case PER_LINUX: strprint(retv, inlen, "x86_64"); break;
default: break; default: break;
} }
#endif
return fulllen; return fulllen;
} }
@ -1664,11 +1674,13 @@ void write_config(FILE *fout, struct lxc_conf *c)
fprintf(fout, "lxc.pts = %d\n", c->pts); fprintf(fout, "lxc.pts = %d\n", c->pts);
if (c->ttydir) if (c->ttydir)
fprintf(fout, "lxc.devttydir = %s\n", c->ttydir); fprintf(fout, "lxc.devttydir = %s\n", c->ttydir);
#if HAVE_SYS_PERSONALITY_H
switch(c->personality) { switch(c->personality) {
case PER_LINUX32: fprintf(fout, "lxc.arch = x86\n"); break; case PER_LINUX32: fprintf(fout, "lxc.arch = x86\n"); break;
case PER_LINUX: fprintf(fout, "lxc.arch = x86_64\n"); break; case PER_LINUX: fprintf(fout, "lxc.arch = x86_64\n"); break;
default: break; default: break;
} }
#endif
#if HAVE_APPARMOR #if HAVE_APPARMOR
if (c->aa_profile) if (c->aa_profile)
fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile); fprintf(fout, "lxc.aa_profile = %s\n", c->aa_profile);

View File

@ -29,19 +29,23 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/personality.h>
#include "attach.h" #include "attach.h"
#include "commands.h" #include "commands.h"
#include "arguments.h" #include "arguments.h"
#include "caps.h" #include "caps.h"
#include "cgroup.h" #include "cgroup.h"
#include "config.h"
#include "confile.h" #include "confile.h"
#include "start.h" #include "start.h"
#include "sync.h" #include "sync.h"
#include "log.h" #include "log.h"
#include "namespace.h" #include "namespace.h"
#if HAVE_SYS_PERSONALITY_H
#include <sys/personality.h>
#endif
lxc_log_define(lxc_attach_ui, lxc); lxc_log_define(lxc_attach_ui, lxc);
static const struct option my_longopts[] = { static const struct option my_longopts[] = {
@ -273,6 +277,7 @@ int main(int argc, char *argv[])
} }
} }
#if HAVE_SYS_PERSONALITY_H
if (new_personality < 0) if (new_personality < 0)
new_personality = init_ctx->personality; new_personality = init_ctx->personality;
@ -281,6 +286,7 @@ int main(int argc, char *argv[])
strerror(errno)); strerror(errno));
return -1; return -1;
} }
#endif
if (!elevated_privileges && lxc_attach_drop_privs(init_ctx)) { if (!elevated_privileges && lxc_attach_drop_privs(init_ctx)) {
ERROR("could not drop privileges"); ERROR("could not drop privileges");