move the capabilities function to caps.c

Move the reset of the capabilities to the caps.c file and
initialize correctly the capabilities for lxc-init.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
Daniel Lezcano 2010-07-20 13:45:44 +02:00
parent 0ed9cc8b00
commit 05cda563bf
3 changed files with 27 additions and 23 deletions

View File

@ -30,6 +30,25 @@
lxc_log_define(lxc_caps, lxc);
int lxc_caps_reset(void)
{
cap_t cap = cap_init();
int ret = 0;
if (!cap) {
ERROR("cap_init() failed : %m");
return -1;
}
if (cap_set_proc(cap)) {
ERROR("cap_set_proc() failed : %m");
ret = -1;
}
cap_free(cap);
return ret;
}
int lxc_caps_down(void)
{
cap_t caps;

View File

@ -23,6 +23,7 @@
#ifndef _caps_h
#define _caps_h
extern int lxc_caps_reset(void);
extern int lxc_caps_down(void);
extern int lxc_caps_up(void);
extern int lxc_caps_init(void);

View File

@ -30,12 +30,12 @@
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/capability.h>
#define _GNU_SOURCE
#include <getopt.h>
#include <lxc/log.h>
#include <lxc/error.h>
#include "log.h"
#include "caps.h"
#include "error.h"
#include "utils.h"
lxc_log_define(lxc_init, lxc);
@ -49,25 +49,6 @@ static struct option options[] = {
static int was_interrupted = 0;
static int cap_reset(void)
{
cap_t cap = cap_init();
int ret = 0;
if (!cap) {
ERROR("cap_init() failed : %m");
return -1;
}
if (cap_set_proc(cap)) {
ERROR("cap_set_proc() failed : %m");
ret = -1;
}
cap_free(cap);
return ret;
}
int main(int argc, char *argv[])
{
@ -95,6 +76,9 @@ int main(int argc, char *argv[])
nbargs++;
}
if (lxc_caps_init())
exit(err);
if (lxc_log_init(NULL, 0, basename(argv[0]), quiet))
exit(err);
@ -128,7 +112,7 @@ int main(int argc, char *argv[])
if (lxc_setup_fs())
exit(err);
if (cap_reset())
if (lxc_caps_reset())
exit(err);
pid = fork();