Skip to content

Commit

Permalink
Merge pull request #1 from xemul/master
Browse files Browse the repository at this point in the history
Update from origin
  • Loading branch information
aburluka committed Nov 25, 2014
2 parents f615f4a + 22f40bb commit 3b90ebd
Show file tree
Hide file tree
Showing 51 changed files with 4,687 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ before_install:
- sudo apt-get update -qq

install:
- sudo apt-get install make gcc autoconf autoconf-doc libtool bison flex
- sudo apt-get install make gcc autoconf autoconf-doc libtool bison flex libselinux1-dev libapparmor-dev

script:
- git submodule update --init --recursive
Expand Down
26 changes: 23 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include Makefile.config

MAKEFLAGS := -r -R --no-print-directory

ifeq ($(strip $(V)),)
Expand Down Expand Up @@ -52,7 +54,15 @@ ifneq ($(ARCH),x86)
$(error "The architecture $(ARCH) isn't supported"))
endif

ifneq ("$(wildcard /proc/vz)","")
VZ := 1
endif


cflags-y += -iquote src/include
cflags-y += -iquote src/include/vz
cflags-y += -iquote src/lsm
cflags-y += -iquote src
cflags-y += -fno-strict-aliasing
cflags-y += -I/usr/include
export cflags-y
Expand Down Expand Up @@ -86,6 +96,14 @@ else
CFLAGS += -O2
endif

ifdef CONFIG_APPARMOR
DEFINES += -DHAVE_APPARMOR
endif

ifdef CONFIG_SELINUX
DEFINES += -DHAVE_SELINUX
endif

CFLAGS += $(WARNINGS) $(DEFINES)

export E Q CC ECHO MAKE CFLAGS LIBS ARCH DEFINES MAKEFLAGS
Expand Down Expand Up @@ -119,14 +137,16 @@ src: $(EARLY-GEN)

.PHONY: src

$(LIBCT).so: src/$(LIBCT).so
$(LIBCT).a: src/$(LIBCT).a
$(E) " LN " $@
$(Q) $(LN) -sf $^ $@

$(LIBCT).a: src/$(LIBCT).a
$(LIBCT).so: src/$(LIBCT).so
$(E) " LN " $@
$(Q) $(LN) -sf $^ $@

src/$(LIBCT).so: src/$(LIBCT).a

all: $(LIBCT).so $(LIBCT).a
@true

Expand All @@ -143,7 +163,7 @@ tags:

clean:
$(Q) $(MAKE) $(build)=src clean
$(Q) $(MAKE) $(build)=test clean
$(Q) $(MAKE) -C test clean
$(Q) $(MAKE) -s -C Documentation clean
$(Q) $(RM) $(LIBCT)
$(Q) $(RM) $(CONFIG)
Expand Down
2 changes: 2 additions & 0 deletions Makefile.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export CONFIG_SELINUX=y
export CONFIG_APPARMOR=y
4 changes: 2 additions & 2 deletions scripts/Makefile.build
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,8 @@ $(obj)/$(lib-a).a: $(all-objs) $(libs-e)
$(E) " LINK " $@
$(Q) ar -cru -o $@ $^

_all += $(obj)/$(lib-so).so
cleanup-y += $(obj)/$(lib-so).so
_all += $(obj)/$(lib-a).a
cleanup-y += $(obj)/$(lib-a).a
endif

##
Expand Down
8 changes: 8 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ obj-y += util.o
obj-y += devnodes.o
obj-y += route.o
obj-y += process.o
obj-y += net_util.o
obj-y += vz/vz.o
obj-y += vz/vz_net.o
obj-y += vz/readelf.o
obj-y += lsm/lsm.o
obj-$(CONFIG_APPARMOR) += lsm/apparmor.o
obj-$(CONFIG_SELINUX) += lsm/selinux.o
obj-y += lsm/nop.o

cflags-y += -fPIC -Wa,--noexecstack -fno-stack-protector
cflags-so += -rdynamic
Expand Down
4 changes: 2 additions & 2 deletions src/cgroups.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static struct cg_config *cg_config_alloc(enum ct_controller ctype, char *param,
return cg;
}

static int config_controller(struct container *ct, enum ct_controller ctype,
int config_controller(struct container *ct, enum ct_controller ctype,
char *param, char *value)
{
char path[PATH_MAX], *t;
Expand Down Expand Up @@ -228,7 +228,7 @@ int local_config_controller(ct_handler_t h, enum ct_controller ctype,
return config_controller(ct, ctype, param, value) ? -LCTERR_CGCONFIG : 0;
}

static int cgroup_create_one(struct container *ct, struct controller *ctl)
int cgroup_create_one(struct container *ct, struct controller *ctl)
{
char path[PATH_MAX], *t;

Expand Down
55 changes: 45 additions & 10 deletions src/ct.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
#include "security.h"
#include "list.h"
#include "util.h"
#include "lsm.h"
#include "net.h"
#include "ct.h"
#include "fs.h"
#include "vz.h"

static enum ct_state local_get_state(ct_handler_t h)
{
Expand Down Expand Up @@ -272,6 +274,12 @@ static int ct_clone(void *arg)
if (ret < 0)
goto err_um;

if (p->lsm_label)
ret = lsm_process_label_set(p->lsm_label, false, p->lsm_on_exec);
p->lsm_on_exec = 0;
if (ret < 0)
goto err;

spawn_wake(ca->parent_wait_pipe, 0);

return ca->cb(ca->arg);
Expand Down Expand Up @@ -399,13 +407,6 @@ static int local_spawn_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *
return ret;
}

struct execv_args {
char *path;
char **argv;
char **env;
int *fds;
};

static int ct_execv(void *a)
{
struct execv_args *ea = a;
Expand All @@ -423,7 +424,8 @@ static int ct_execv(void *a)
goto err;
}
for (i = 0; i < 3; i++)
close(ea->fds[i]);
if (ea->fds[i] != i)
close(ea->fds[i]);
}

sigfillset(&mask);
Expand All @@ -441,12 +443,15 @@ static int ct_execv(void *a)
static int local_spawn_execve(ct_handler_t ct, ct_process_desc_t pr, char *path, char **argv, char **env, int *fds)
{
struct execv_args ea;
struct process_desc *p = prh2pr(pr);

ea.path = path;
ea.argv = argv;
ea.env = env;
ea.fds = fds;

p->lsm_on_exec = true;

return local_spawn_cb(ct, pr, ct_execv, &ea);
}

Expand Down Expand Up @@ -508,16 +513,19 @@ static int local_enter_cb(ct_handler_t h, ct_process_desc_t ph, int (*cb)(void *
return pid;
}

static int local_enter_execve(ct_handler_t h, ct_process_desc_t p, char *path, char **argv, char **env, int *fds)
static int local_enter_execve(ct_handler_t h, ct_process_desc_t pr, char *path, char **argv, char **env, int *fds)
{
struct execv_args ea = {};
struct process_desc *p = prh2pr(pr);

ea.path = path;
ea.argv = argv;
ea.env = env;
ea.fds = fds;

return local_enter_cb(h, p, ct_execv, &ea);
p->lsm_on_exec = true;

return local_enter_cb(h, pr, ct_execv, &ea);
}

static int local_ct_kill(ct_handler_t h)
Expand Down Expand Up @@ -714,3 +722,30 @@ ct_handler_t ct_create(char *name)

return NULL;
}

ct_handler_t vz_ct_create(char *name)
{
struct container *ct;

ct = xzalloc(sizeof(*ct));
if (ct) {
ct_handler_init(&ct->h);
ct->h.ops = get_vz_ct_ops();
ct->state = CT_STOPPED;
ct->name = xstrdup(name);
ct->tty_fd = -1;
INIT_LIST_HEAD(&ct->cgroups);
INIT_LIST_HEAD(&ct->cg_configs);
INIT_LIST_HEAD(&ct->ct_nets);
INIT_LIST_HEAD(&ct->ct_net_routes);
INIT_LIST_HEAD(&ct->fs_mnts);
INIT_LIST_HEAD(&ct->fs_devnodes);
INIT_LIST_HEAD(&ct->uid_map);
INIT_LIST_HEAD(&ct->gid_map);

return &ct->h;
}

return NULL;

}
Loading

0 comments on commit 3b90ebd

Please sign in to comment.