const lxc_cmd_t cmd)
{
if (cmd == LXC_CMD_ADD_STATE_CLIENT) {
- struct lxc_list *cur, *next;
-
- lxc_list_for_each_safe(cur, &handler->conf->state_clients, next) {
- struct lxc_state_client *client = cur->elem;
+ struct lxc_state_client *client, *nclient;
+ list_for_each_entry_safe(client, nclient, &handler->conf->state_clients, head) {
if (client->clientfd != fd)
continue;
- /*
- * Only kick client from list so it can't be found
- * anymore. The actual close happens, as for all other
- * file descriptors, below.
- */
- lxc_list_del(cur);
- free(cur->elem);
- free(cur);
+ list_del(&client->head);
+ free(client);
/*
* No need to walk the whole list. If we found the state
lxc_state_t states[MAX_STATE])
{
__do_free struct lxc_state_client *newclient = NULL;
- __do_free struct lxc_list *tmplist = NULL;
int state;
newclient = zalloc(sizeof(*newclient));
memcpy(newclient->states, states, sizeof(newclient->states));
newclient->clientfd = state_client_fd;
- tmplist = zalloc(sizeof(*tmplist));
- if (!tmplist)
- return -ENOMEM;
-
state = handler->state;
if (states[state] != 1) {
- lxc_list_add_elem(tmplist, move_ptr(newclient));
- lxc_list_add_tail(&handler->conf->state_clients, move_ptr(tmplist));
+ list_add_tail(&newclient->head, &handler->conf->state_clients);
+ move_ptr(newclient);
} else {
TRACE("Container already in requested state");
return state;
DIR *dir;
struct dirent *direntp;
unsigned int listen_fds_max;
+ struct lxc_state_client *client, *nclient;
if (conf && conf->close_all_fds)
closeall = true;
while ((direntp = readdir(dir))) {
int ret;
- struct lxc_list *cur;
bool matched = false;
if (strequal(direntp->d_name, "."))
/* Keep state clients that wait on reboots. */
if (conf) {
- lxc_list_for_each(cur, &conf->state_clients) {
- struct lxc_state_client *client = cur->elem;
-
+ list_for_each_entry_safe(client, nclient, &conf->state_clients, head) {
if (client->clientfd != fd)
continue;
int lxc_serve_state_clients(const char *name, struct lxc_handler *handler,
lxc_state_t state)
{
+ struct lxc_msg msg = {
+ .type = lxc_msg_state,
+ .value = state,
+ };
size_t retlen;
ssize_t ret;
- struct lxc_list *cur, *next;
- struct lxc_msg msg = {.type = lxc_msg_state, .value = state};
+ struct lxc_state_client *client, *nclient;
if (state == THAWED)
handler->state = RUNNING;
TRACE("Set container state to %s", lxc_state2str(state));
- if (lxc_list_empty(&handler->conf->state_clients))
+ if (list_empty(&handler->conf->state_clients))
return log_trace(0, "No state clients registered");
retlen = strlcpy(msg.name, name, sizeof(msg.name));
if (retlen >= sizeof(msg.name))
return -E2BIG;
- lxc_list_for_each_safe(cur, &handler->conf->state_clients, next) {
- struct lxc_state_client *client = cur->elem;
-
+ list_for_each_entry_safe(client, nclient, &handler->conf->state_clients, head) {
if (client->states[state] == 0) {
TRACE("State %s not registered for state client %d",
lxc_state2str(state), client->clientfd);
SYSERROR("Failed to send message to client");
/* kick client from list */
- lxc_list_del(cur);
+ list_del(&client->head);
close(client->clientfd);
- free(cur->elem);
- free(cur);
+ free(client);
}
return 0;
handler->state_socket_pair[0] = -EBADF;
handler->state_socket_pair[1] = -EBADF;
if (handler->conf->reboot == REBOOT_NONE)
- lxc_list_init(&handler->conf->state_clients);
+ INIT_LIST_HEAD(&handler->conf->state_clients);
for (lxc_namespace_t idx = 0; idx < LXC_NS_MAX; idx++) {
handler->nsfd[idx] = -EBADF;
void lxc_end(struct lxc_handler *handler)
{
int ret;
- struct lxc_list *cur, *next;
const char *name = handler->name;
struct cgroup_ops *cgroup_ops = handler->cgroup_ops;
+ struct lxc_state_client *client, *nclient;
/* The STOPPING state is there for future cleanup code which can take
* awhile.
/* The command socket is now closed, no more state clients can register
* themselves from now on. So free the list of state clients.
*/
- lxc_list_for_each_safe(cur, &handler->conf->state_clients, next) {
- struct lxc_state_client *client = cur->elem;
-
+ list_for_each_entry_safe(client, nclient, &handler->conf->state_clients, head) {
/* Keep state clients that want to be notified about reboots. */
if ((handler->conf->reboot > REBOOT_NONE) &&
(client->states[RUNNING] == 2))
continue;
/* close state client socket */
- lxc_list_del(cur);
+ list_del(&client->head);
close(client->clientfd);
- free(cur->elem);
- free(cur);
+ free(client);
}
if (handler->conf->ephemeral == 1 && handler->conf->reboot != REBOOT_REQ)