-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <daniel.lezcano at free.fr>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "config.h"
+
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include "cgroup.h"
#include "commands.h"
#include "commands_utils.h"
-#include "config.h"
#include "log.h"
#include "lxc.h"
#include "monitor.h"
const char *lxc_state2str(lxc_state_t state)
{
if (state < STOPPED || state > MAX_STATE - 1)
- return NULL;
+ return "INVALID STATE";
return strstate[state];
}
lxc_state_t lxc_str2state(const char *state)
{
size_t len;
- lxc_state_t i;
- len = sizeof(strstate)/sizeof(strstate[0]);
- for (i = 0; i < len; i++)
- if (!strcmp(strstate[i], state))
+
+ len = sizeof(strstate) / sizeof(strstate[0]);
+ for (lxc_state_t i = 0; i < len; i++) {
+ if (strequal(strstate[i], state))
return i;
+ }
ERROR("invalid state '%s'", state);
return -1;
if (state >= 0)
break;
- if (errno != ECONNREFUSED) {
- SYSERROR("Failed to receive state from monitor");
- return -1;
- }
+ if (errno != ECONNREFUSED)
+ return log_error_errno(-1, errno, "Failed to receive state from monitor");
if (timeout > 0)
timeout--;
(void)nanosleep(&onesec, NULL);
}
- if (state < 0) {
- ERROR("Failed to retrieve state from monitor");
- return -1;
- }
-
TRACE("Retrieved state of container %s", lxc_state2str(state));
- if (!s[state])
+ if ((state < STOPPED || state > MAX_STATE - 1) || !s[state])
return -1;
return 0;