add the new pts instance configuration

From: Daniel Lezcano <dlezcano@fr.ibm.com>

This patch adds the configuration for a new pts instance.

Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
dlezcano 2009-02-12 14:47:36 +00:00
parent db4aa207ce
commit 10db618d7d
5 changed files with 59 additions and 2 deletions

View File

@ -42,6 +42,7 @@ static const char *const catalogue[] = {
[LXC_ERROR_CONF_NETWORK] = "Failed to configure the network",
[LXC_ERROR_CONF_TTY] = "Failed to configure the tty",
[LXC_ERROR_CONF_ROOTFS] = "Failed to configure the root fs",
[LXC_ERROR_CONF_PTS] = "Failed to configure the pts",
[LXC_ERROR_SETUP_CGROUP] = "Failed to setup the control group",
[LXC_ERROR_SETUP_MOUNT] = "Failed to setup the mount points",
@ -50,6 +51,7 @@ static const char *const catalogue[] = {
[LXC_ERROR_SETUP_CONSOLE] = "Failed to setup the console",
[LXC_ERROR_SETUP_TTY] = "Failed to setup the tty",
[LXC_ERROR_SETUP_ROOTFS] = "Failed to setup the root fs",
[LXC_ERROR_SETUP_PTS] = "Failed to setup the new pts instance",
[LXC_ERROR_TTY_DENIED] = "tty service denied",
[LXC_ERROR_TTY_EAGAIN] = "tty service is not available",

View File

@ -41,6 +41,7 @@ typedef enum {
LXC_ERROR_CONF_NETWORK,
LXC_ERROR_CONF_TTY,
LXC_ERROR_CONF_ROOTFS,
LXC_ERROR_CONF_PTS,
LXC_ERROR_SETUP_CGROUP,
LXC_ERROR_SETUP_MOUNT,
@ -49,6 +50,7 @@ typedef enum {
LXC_ERROR_SETUP_CONSOLE,
LXC_ERROR_SETUP_TTY,
LXC_ERROR_SETUP_ROOTFS,
LXC_ERROR_SETUP_PTS,
LXC_ERROR_TTY_DENIED,
LXC_ERROR_TTY_EAGAIN,

View File

@ -472,6 +472,28 @@ static int configure_rootfs(const char *name, const char *rootfs)
return symlink(absrootfs, path);
}
static int configure_pts(const char *name, int pts)
{
char path[MAXPATHLEN];
char *maxpts;
int ret;
if (asprintf(&maxpts, "%d", pts) < 0) {
lxc_log_error("failed to convert max pts number");
return -1;
}
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
ret = write_info(path, "pts", maxpts);
if (ret)
lxc_log_error("failed to write the pts info");
free(maxpts);
return ret;
}
static int configure_mount(const char *name, const char *fstab)
{
char path[MAXPATHLEN];
@ -625,6 +647,16 @@ static int unconfigure_rootfs(const char *name)
return 0;
}
static int unconfigure_pts(const char *name)
{
char path[MAXPATHLEN];
snprintf(path, MAXPATHLEN, LXCPATH "/%s", name);
delete_info(path, "pts");
return 0;
}
static int unconfigure_tty(const char *name)
{
char path[MAXPATHLEN];
@ -1143,6 +1175,11 @@ int lxc_configure(const char *name, struct lxc_conf *conf)
return -LXC_ERROR_CONF_MOUNT;
}
if (conf->pts && configure_pts(name, conf->pts)) {
lxc_log_error("failed to configure a new pts instance");
return -LXC_ERROR_CONF_PTS;
}
return 0;
}
@ -1158,7 +1195,7 @@ int lxc_unconfigure(const char *name)
lxc_log_error("failed to cleanup cgroup");
if (conf_has_tty(name) && unconfigure_tty(name))
lxc_log_error("failed to cleanup mount");
lxc_log_error("failed to cleanup tty");
if (conf_has_rootfs(name) && unconfigure_rootfs(name))
lxc_log_error("failed to cleanup rootfs");
@ -1166,6 +1203,9 @@ int lxc_unconfigure(const char *name)
if (conf_has_fstab(name) && unconfigure_mount(name))
lxc_log_error("failed to cleanup mount");
if (conf_has_pts(name) && unconfigure_pts(name))
lxc_log_error("failed to cleanup pts");
return 0;
}

View File

@ -119,6 +119,7 @@ struct lxc_conf {
char *rootfs;
char *fstab;
int tty;
int pts;
struct utsname *utsname;
struct lxc_list cgroup;
struct lxc_list networks;
@ -180,5 +181,5 @@ extern int conf_has(const char *name, const char *info);
#define conf_has_console(__name) conf_has(__name, "console")
#define conf_has_cgroup(__name) conf_has(__name, "cgroup")
#define conf_has_tty(__name) conf_has(__name, "tty")
#define conf_has_pts(__name) conf_has(__name, "pts")
#endif

View File

@ -37,6 +37,7 @@
typedef int (*file_cb)(char* buffer, void *data);
typedef int (*config_cb)(const char *, char *, struct lxc_conf *);
static int config_pts(const char *, char *, struct lxc_conf *);
static int config_tty(const char *, char *, struct lxc_conf *);
static int config_cgroup(const char *, char *, struct lxc_conf *);
static int config_mount(const char *, char *, struct lxc_conf *);
@ -57,6 +58,7 @@ struct config {
static struct config config[] = {
{ "lxc.pts", config_pts },
{ "lxc.tty", config_tty },
{ "lxc.cgroup", config_cgroup },
{ "lxc.mount", config_mount },
@ -419,6 +421,15 @@ static int config_network_ipv6(const char *key, char *value, struct lxc_conf *lx
return 0;
}
static int config_pts(const char *key, char *value, struct lxc_conf *lxc_conf)
{
int maxpts = atoi(value);
lxc_conf->pts = maxpts;
return 0;
}
static int config_tty(const char *key, char *value, struct lxc_conf *lxc_conf)
{
int nbtty = atoi(value);
@ -592,6 +603,7 @@ int lxc_config_init(struct lxc_conf *conf)
conf->fstab = NULL;
conf->utsname = NULL;
conf->tty = 0;
conf->pts = 0;
lxc_list_init(&conf->cgroup);
lxc_list_init(&conf->networks);
return 0;