/* * Calculate a container's cgroup path for a particular subsystem. This * is the cgroup path relative to the root of the cgroup filesystem. * @path: A char ** into which we copy the char* containing the answer * @subsystem: the cgroup subsystem of interest (i.e. freezer) * @name: container name * @lxcpath: the lxcpath in which the container is running. * * Returns 0 on success, -1 on error. * * Note that the char* copied into *path is a static char[MAXPATHLEN] in * commands.c:receive_answer(). It should not be freed. */ extern int lxc_get_cgpath(const char **path, const char *subsystem, const char *name, const char *lxcpath) { struct lxc_command command = { .request = { .type = LXC_COMMAND_CGROUP }, }; int ret, stopped = 0; ret = lxc_command(name, &command, &stopped, lxcpath); if (ret < 0) { if (!stopped) ERROR("failed to send command"); return -1; } if (!ret) { WARN("'%s' has stopped before sending its state", name); return -1; } if (command.answer.ret < 0 || command.answer.pathlen < 0) { ERROR("failed to get state for '%s': %s", name, strerror(-command.answer.ret)); return -1; } *path = command.answer.path; return 0; }
static lxc_state_t __lxc_getstate(const char *name) { struct lxc_command command = { .request = { .type = LXC_COMMAND_STATE }, }; int ret, stopped = 0; ret = lxc_command(name, &command, &stopped); if (ret < 0 && stopped) return STOPPED; if (ret < 0) { ERROR("failed to send command"); return -1; } if (!ret) { WARN("'%s' has stopped before sending its state", name); return -1; } if (command.answer.ret < 0) { ERROR("failed to get state for '%s': %s", name, strerror(-command.answer.ret)); return -1; } DEBUG("'%s' is in '%s' state", name, lxc_state2str(command.answer.ret)); return command.answer.ret; }