Commit 540f932a by Stéphane Graber

Allow unsetting daemonize and close_fds

As mentioned in a previous commit, this does two changes: - Make want_daemonize return a bool (false on failure, true on success) - Make both want_daemonize and want_close_all_fds take a "state" argument so the user can choose to unset those flags. This commit also updates all occurences of those two functions and turns the daemonize attribute from an int to a bool. Signed-off-by: 's avatarStéphane Graber <stgraber@ubuntu.com> Acked-by: 's avatarSerge Hallyn <serge.hallyn@ubuntu.com>
parent c1ee94cf
......@@ -156,7 +156,7 @@ static int container_start(lua_State *L)
argv[j] = NULL;
}
c->want_daemonize(c);
c->want_daemonize(c, true);
lua_pushboolean(L, !!c->start(c, useinit, argv));
return 1;
}
......
......@@ -325,7 +325,7 @@ int main(int argc, char *argv[])
}
if (my_args.daemonize) {
c->want_daemonize(c);
c->want_daemonize(c, true);
}
if (pid_fp != NULL) {
......@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
}
if (my_args.close_all_fds)
c->want_close_all_fds(c);
c->want_close_all_fds(c, true);
err = c->start(c, 0, args) ? 0 : -1;
......
......@@ -455,21 +455,23 @@ static bool lxcapi_load_config(struct lxc_container *c, const char *alt_file)
return ret;
}
static void lxcapi_want_daemonize(struct lxc_container *c)
static bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
{
if (!c || !c->lxc_conf)
return;
return false;
if (container_mem_lock(c)) {
ERROR("Error getting mem lock");
return;
return false;
}
c->daemonize = 1;
c->daemonize = state;
/* daemonize implies close_all_fds so set it */
c->lxc_conf->close_all_fds = 1;
if (state == 1)
c->lxc_conf->close_all_fds = 1;
container_mem_unlock(c);
return true;
}
static bool lxcapi_want_close_all_fds(struct lxc_container *c)
static bool lxcapi_want_close_all_fds(struct lxc_container *c, bool state)
{
if (!c || !c->lxc_conf)
return false;
......@@ -477,7 +479,7 @@ static bool lxcapi_want_close_all_fds(struct lxc_container *c)
ERROR("Error getting mem lock");
return false;
}
c->lxc_conf->close_all_fds = 1;
c->lxc_conf->close_all_fds = state;
container_mem_unlock(c);
return true;
}
......@@ -549,7 +551,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
{
int ret;
struct lxc_conf *conf;
int daemonize = 0;
bool daemonize = false;
char *default_args[] = {
"/sbin/init",
'\0',
......
......@@ -93,7 +93,7 @@ struct lxc_container {
int error_num;
/*! Whether container wishes to be daemonized */
int daemonize;
bool daemonize;
/*! Full path to configuration file */
char *config_path;
......@@ -209,7 +209,7 @@ struct lxc_container {
*
* \return \c true if container wants to be daemonised, else \c false.
*/
void (*want_daemonize)(struct lxc_container *c);
bool (*want_daemonize)(struct lxc_container *c, bool state);
/*!
* \brief Determine whether container wishes all file descriptors
......@@ -220,7 +220,7 @@ struct lxc_container {
* \return \c true if container wants all file descriptors closed,
* else \c false.
*/
bool (*want_close_all_fds)(struct lxc_container *c);
bool (*want_close_all_fds)(struct lxc_container *c, bool state);
/*!
* \brief Return current config file name.
......
......@@ -1301,11 +1301,17 @@ Container_start(Container *self, PyObject *args, PyObject *kwds)
}
if (close_fds && close_fds == Py_True) {
self->container->want_close_all_fds(self->container);
self->container->want_close_all_fds(self->container, true);
}
else {
self->container->want_close_all_fds(self->container, false);
}
if (!daemonize || daemonize == Py_True) {
self->container->want_daemonize(self->container);
self->container->want_daemonize(self->container, true);
}
else {
self->container->want_daemonize(self->container, false);
}
if (self->container->start(self->container, init_useinit, init_args))
......
......@@ -315,7 +315,7 @@ static struct lxc_container *test_ct_create(const char *lxcpath,
if (lsm_enabled())
test_attach_lsm_set_config(ct);
ct->want_daemonize(ct);
ct->want_daemonize(ct, true);
if (!ct->startl(ct, 0, NULL)) {
TSTERR("starting container %s", name);
goto out2;
......
......@@ -172,7 +172,7 @@ static int test_container(const char *lxcpath,
goto out2;
}
c->load_config(c, NULL);
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL)) {
TSTERR("starting container %s", name);
goto out3;
......
......@@ -88,7 +88,7 @@ static void do_function(void *arguments)
}
} else if(strcmp(args->mode, "start") == 0) {
if (c->is_defined(c) && !c->is_running(c)) {
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->start(c, false, NULL)) {
fprintf(stderr, "Starting the container (%s) failed...\n", name);
goto out;
......
......@@ -145,7 +145,7 @@ static int test_console(const char *lxcpath,
c->load_config(c, NULL);
c->set_config_item(c, "lxc.tty", TTYCNT_STR);
c->save_config(c, NULL);
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL)) {
TSTERR("starting container %s", name);
goto out3;
......
......@@ -225,7 +225,7 @@ int main(int argc, char *argv[])
goto out;
/* non-daemonized is tested in 'startone' */
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL, NULL)) {
fprintf(stderr, "%d: %s failed to start daemonized\n", __LINE__, c->name);
goto out;
......
......@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
}
c->load_config(c, NULL);
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL)) {
fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
goto out;
......
......@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
}
c->load_config(c, NULL);
c->want_daemonize(c);
c->want_daemonize(c, true);
if (!c->startl(c, 0, NULL)) {
fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
goto out;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment