]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
add the new pts instance configuration
authordlezcano <dlezcano>
Thu, 12 Feb 2009 14:47:36 +0000 (14:47 +0000)
committerdlezcano <dlezcano>
Thu, 12 Feb 2009 14:47:36 +0000 (14:47 +0000)
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>
src/lxc/error.c
src/lxc/error.h
src/lxc/lxc_conf.c
src/lxc/lxc_conf.h
src/lxc/lxc_config.c

index 4af8d10652e965476549853be70d29e1dac0cda6..153d89fcf2f95ebbf4c011368c982fcd7e8788ab 100644 (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",
index b79adf6964ee448fc89146f3139da0bb25492e50..94c8071d2ac3fa8ce3ee36804b7e947b1c915888 100644 (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,
index 7253acc9774232c29afd605f5d9753935af889e6..be716c00f2528fbb3c3bff187fd04e8c45f3d1d8 100644 (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;
 }
 
index 708a6ca8edbe1ad863bba99270645df7ab27bf7d..69681872cb66d19890ffbf4085d813357b0e2abd 100644 (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
index 8b83a83d5e3793bb09841c42c3680dc2bfa6a019..aa1c9c6144029b717700ee64362c0ee31e1b6852 100644 (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;