char *lxchook_names[NUM_LXC_HOOKS] = {"pre-start", "pre-mount", "mount",
"autodev", "start", "stop",
- "post-stop", "clone", "destroy"};
+ "post-stop", "clone", "destroy",
+ "start-host"};
struct mount_opt {
char *name;
if (strcmp(hook, "pre-start") == 0)
which = LXCHOOK_PRESTART;
+ else if (strcmp(hook, "start-host") == 0)
+ which = LXCHOOK_START_HOST;
else if (strcmp(hook, "pre-mount") == 0)
which = LXCHOOK_PREMOUNT;
else if (strcmp(hook, "mount") == 0)
{ "lxc.hook.destroy", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.post-stop", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
+ { "lxc.hook.start-host", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.pre-start", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.pre-mount", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
{ "lxc.hook.start", false, set_config_hooks, get_config_hooks, clr_config_hooks, },
if (strcmp(key + 9, "pre-start") == 0)
return add_hook(lxc_conf, LXCHOOK_PRESTART, copy);
+ else if (strcmp(key + 9, "start-host") == 0)
+ return add_hook(lxc_conf, LXCHOOK_START_HOST, copy);
else if (strcmp(key + 9, "pre-mount") == 0)
return add_hook(lxc_conf, LXCHOOK_PREMOUNT, copy);
else if (strcmp(key + 9, "autodev") == 0)
strprint(retv, inlen, "post-stop\n");
strprint(retv, inlen, "pre-mount\n");
strprint(retv, inlen, "pre-start\n");
+ strprint(retv, inlen, "start-host\n");
strprint(retv, inlen, "start\n");
strprint(retv, inlen, "stop\n");
} else if (!strcmp(key, "lxc.cap")) {
{
int i, flags, ret;
const char *name = handler->name;
+ char pidstr[20];
bool wants_to_map_ids;
int saved_ns_fd[LXC_NS_MAX];
struct lxc_list *id_map;
cgroup_disconnect();
cgroups_connected = false;
+ snprintf(pidstr, 20, "%d", handler->pid);
+ if (setenv("LXC_PID", pidstr, 1))
+ SYSERROR("Failed to set environment variable: LXC_PID=%s.", pidstr);
+
+ /* Run any host-side start hooks */
+ if (run_lxc_hooks(name, "start-host", handler->conf, handler->lxcpath, NULL)) {
+ ERROR("Failed to run lxc.hook.start-host for container \"%s\".", name);
+ return -1;
+ }
+
/* Tell the child to complete its initialization and wait for it to exec
* or return an error. (The child will never return
- * LXC_SYNC_POST_CGROUP+1. It will either close the sync pipe, causing
+ * LXC_SYNC_READY_START+1. It will either close the sync pipe, causing
* lxc_sync_barrier_child to return success, or return a different
* value, causing us to error out).
*/
- if (lxc_sync_barrier_child(handler, LXC_SYNC_POST_CGROUP))
+ if (lxc_sync_barrier_child(handler, LXC_SYNC_READY_START))
return -1;
if (lxc_network_recv_name_and_ifindex_from_child(handler) < 0) {