]> git.proxmox.com Git - mirror_lxc.git/commitdiff
cleanup state.h
authorDaniel Lezcano <daniel.lezcano@free.fr>
Mon, 30 Mar 2009 12:02:19 +0000 (14:02 +0200)
committerDaniel Lezcano <dlezcano@fr.ibm.com>
Mon, 30 Mar 2009 12:02:19 +0000 (14:02 +0200)
Rename lxc_state.h to state.h

Signed-off-by: Daniel Lezcano <daniel.lezcano@free.fr>
src/lxc/Makefile.am
src/lxc/lxc.h
src/lxc/lxc_state.c [deleted file]
src/lxc/lxc_state.h [deleted file]
src/lxc/state.c [new file with mode: 0644]
src/lxc/state.h [new file with mode: 0644]

index c30bd51490360091d10677ba9db8a369f64b7128..a48db135e5d86f667086a46ed77eef5a65376267 100644 (file)
@@ -13,7 +13,7 @@ pkginclude_HEADERS = \
                conf.h \
                list.h \
                log.h \
-               lxc_state.h
+               state.h
 
 
 liblxc_la_SOURCES = \
@@ -36,7 +36,7 @@ liblxc_la_SOURCES = \
        namespace.h \
        conf.c conf.h \
        list.h \
-       lxc_state.c lxc_state.h \
+       state.c state.h \
        log.c log.h \
        \
        network.c network.h \
index 663999e77605456c71524a3522f889ff52a940b4..e374678045c28d59c4f43aac5142c9592b82618d 100644 (file)
@@ -33,7 +33,7 @@ extern "C" {
  lxc/lxc.h will contain exports of liblxc
  **/
 
-#include <lxc/lxc_state.h>
+#include <lxc/state.h>
 #include <lxc/list.h>
 #include <lxc/log.h>
 #include <lxc/conf.h>
diff --git a/src/lxc/lxc_state.c b/src/lxc/lxc_state.c
deleted file mode 100644 (file)
index 830d68a..0000000
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#include <stdio.h>
-#include <string.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/file.h>
-
-#include <lxc/lxc.h>
-
-static char *strstate[] = {
-       "STOPPED", "STARTING", "RUNNING", "STOPPING",
-       "ABORTING", "FREEZING", "FROZEN",
-};
-
-const char *lxc_state2str(lxc_state_t state)
-{
-       if (state < STOPPED || state > MAX_STATE - 1)
-               return NULL;
-       return strstate[state];
-}
-
-lxc_state_t lxc_str2state(const char *state)
-{
-       int i, len;
-       len = sizeof(strstate)/sizeof(strstate[0]);
-       for (i = 0; i < len; i++)
-               if (!strcmp(strstate[i], state))
-                       return i;
-       return -1;
-}
-
-int lxc_setstate(const char *name, lxc_state_t state)
-{
-       int fd, err;
-       char file[MAXPATHLEN];
-       const char *str = lxc_state2str(state);
-
-       if (!str)
-               return -1;
-
-       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
-
-       fd = open(file, O_WRONLY);
-       if (fd < 0) {
-               lxc_log_syserror("failed to open %s file", file);
-               return -1;
-       }
-
-       if (flock(fd, LOCK_EX)) {
-               lxc_log_syserror("failed to take the lock to %s", file);
-               goto out;
-       }
-
-       if (ftruncate(fd, 0)) {
-               lxc_log_syserror("failed to truncate the file %s", file);
-               goto out;
-       }
-
-       if (write(fd, str, strlen(str)) < 0) {
-               lxc_log_syserror("failed to write state to %s", file);
-               goto out;
-       }
-
-       err = 0;
-out:
-       close(fd);
-
-       lxc_monitor_send_state(name, state);
-
-       /* let the event to be propagated, crappy but that works,
-        * otherwise the events will be folded into only one event,
-        * and I want to have them to be one by one in order
-        * to follow the different states of the container.
-        */
-       usleep(200000);
-
-       return -err;
-}
-
-int lxc_mkstate(const char *name)
-{
-       int fd;
-       char file[MAXPATHLEN];
-
-       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
-       fd = creat(file, S_IRUSR|S_IWUSR);
-       if (fd < 0) {
-               lxc_log_syserror("failed to create file %s", file);
-               return -1;
-       }
-       close(fd);
-       return 0;
-}
-
-int lxc_rmstate(const char *name)
-{
-       char file[MAXPATHLEN];
-       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
-       unlink(file);
-       return 0;
-}
-
-lxc_state_t lxc_getstate(const char *name)
-{
-       int fd, err;
-       char file[MAXPATHLEN];
-
-       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
-
-       fd = open(file, O_RDONLY);
-       if (fd < 0) {
-               lxc_log_syserror("failed to open %s", file);
-               return -1;
-       }
-
-       if (flock(fd, LOCK_SH)) {
-               lxc_log_syserror("failed to take the lock to %s", file);
-               close(fd);
-               return -1;
-       }
-
-       err = read(fd, file, strlen(file));
-       if (err < 0) {
-               lxc_log_syserror("failed to read file %s", file);
-               close(fd);
-               return -1;
-       }
-       file[err] = '\0';
-
-       close(fd);
-       return lxc_str2state(file);
-}
-
-static int freezer_state(const char *name)
-{
-       char freezer[MAXPATHLEN];
-       char status[MAXPATHLEN];
-       FILE *file;
-       int err;
-       
-       snprintf(freezer, MAXPATHLEN,
-                LXCPATH "/%s/freezer.state", name);
-
-       file = fopen(freezer, "r");
-       if (!file)
-               return -1;
-
-       err = fscanf(file, "%s", status);
-       fclose(file);
-
-       if (err == EOF) {
-               lxc_log_syserror("failed to read %s", freezer);
-               return -1;
-       }
-
-       return lxc_str2state(status);
-}
-
-lxc_state_t lxc_state(const char *name)
-{
-       int state = freezer_state(name);
-       if (state != FROZEN && state != FREEZING)
-               state = lxc_getstate(name);
-       return state;
-}
diff --git a/src/lxc/lxc_state.h b/src/lxc/lxc_state.h
deleted file mode 100644 (file)
index 871d1a8..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * lxc: linux Container library
- *
- * (C) Copyright IBM Corp. 2007, 2008
- *
- * Authors:
- * Daniel Lezcano <dlezcano at fr.ibm.com>
- *
- * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-#ifndef _state_h
-#define _state_h
-
-typedef enum {
-       STOPPED, STARTING, RUNNING, STOPPING,
-       ABORTING, FREEZING, FROZEN, MAX_STATE,
-} lxc_state_t;
-
-extern int lxc_mkstate(const char *name);
-extern int lxc_rmstate(const char *name);
-extern int lxc_setstate(const char *name, lxc_state_t state);
-extern lxc_state_t lxc_getstate(const char *name);
-
-extern lxc_state_t lxc_str2state(const char *state);
-extern const char *lxc_state2str(lxc_state_t state);
-
-#endif
diff --git a/src/lxc/state.c b/src/lxc/state.c
new file mode 100644 (file)
index 0000000..e542230
--- /dev/null
@@ -0,0 +1,191 @@
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2008
+ *
+ * Authors:
+ * Daniel Lezcano <dlezcano at fr.ibm.com>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/file.h>
+
+#include <lxc/lxc.h>
+
+static char *strstate[] = {
+       "STOPPED", "STARTING", "RUNNING", "STOPPING",
+       "ABORTING", "FREEZING", "FROZEN",
+};
+
+const char *lxc_state2str(lxc_state_t state)
+{
+       if (state < STOPPED || state > MAX_STATE - 1)
+               return NULL;
+       return strstate[state];
+}
+
+lxc_state_t lxc_str2state(const char *state)
+{
+       int i, len;
+       len = sizeof(strstate)/sizeof(strstate[0]);
+       for (i = 0; i < len; i++)
+               if (!strcmp(strstate[i], state))
+                       return i;
+       return -1;
+}
+
+int lxc_setstate(const char *name, lxc_state_t state)
+{
+       int fd, err;
+       char file[MAXPATHLEN];
+       const char *str = lxc_state2str(state);
+
+       if (!str)
+               return -1;
+
+       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
+
+       fd = open(file, O_WRONLY);
+       if (fd < 0) {
+               lxc_log_syserror("failed to open %s file", file);
+               return -1;
+       }
+
+       if (flock(fd, LOCK_EX)) {
+               lxc_log_syserror("failed to take the lock to %s", file);
+               goto out;
+       }
+
+       if (ftruncate(fd, 0)) {
+               lxc_log_syserror("failed to truncate the file %s", file);
+               goto out;
+       }
+
+       if (write(fd, str, strlen(str)) < 0) {
+               lxc_log_syserror("failed to write state to %s", file);
+               goto out;
+       }
+
+       err = 0;
+out:
+       close(fd);
+
+       lxc_monitor_send_state(name, state);
+
+       /* let the event to be propagated, crappy but that works,
+        * otherwise the events will be folded into only one event,
+        * and I want to have them to be one by one in order
+        * to follow the different states of the container.
+        */
+       usleep(200000);
+
+       return -err;
+}
+
+int lxc_mkstate(const char *name)
+{
+       int fd;
+       char file[MAXPATHLEN];
+
+       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
+       fd = creat(file, S_IRUSR|S_IWUSR);
+       if (fd < 0) {
+               lxc_log_syserror("failed to create file %s", file);
+               return -1;
+       }
+       close(fd);
+       return 0;
+}
+
+int lxc_rmstate(const char *name)
+{
+       char file[MAXPATHLEN];
+       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
+       unlink(file);
+       return 0;
+}
+
+lxc_state_t lxc_getstate(const char *name)
+{
+       int fd, err;
+       char file[MAXPATHLEN];
+
+       snprintf(file, MAXPATHLEN, LXCPATH "/%s/state", name);
+
+       fd = open(file, O_RDONLY);
+       if (fd < 0) {
+               lxc_log_syserror("failed to open %s", file);
+               return -1;
+       }
+
+       if (flock(fd, LOCK_SH)) {
+               lxc_log_syserror("failed to take the lock to %s", file);
+               close(fd);
+               return -1;
+       }
+
+       err = read(fd, file, strlen(file));
+       if (err < 0) {
+               lxc_log_syserror("failed to read file %s", file);
+               close(fd);
+               return -1;
+       }
+       file[err] = '\0';
+
+       close(fd);
+       return lxc_str2state(file);
+}
+
+static int freezer_state(const char *name)
+{
+       char freezer[MAXPATHLEN];
+       char status[MAXPATHLEN];
+       FILE *file;
+       int err;
+
+       snprintf(freezer, MAXPATHLEN,
+                LXCPATH "/%s/freezer.state", name);
+
+       file = fopen(freezer, "r");
+       if (!file)
+               return -1;
+
+       err = fscanf(file, "%s", status);
+       fclose(file);
+
+       if (err == EOF) {
+               lxc_log_syserror("failed to read %s", freezer);
+               return -1;
+       }
+
+       return lxc_str2state(status);
+}
+
+lxc_state_t lxc_state(const char *name)
+{
+       int state = freezer_state(name);
+       if (state != FROZEN && state != FREEZING)
+               state = lxc_getstate(name);
+       return state;
+}
diff --git a/src/lxc/state.h b/src/lxc/state.h
new file mode 100644 (file)
index 0000000..871d1a8
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2008
+ *
+ * Authors:
+ * Daniel Lezcano <dlezcano at fr.ibm.com>
+ *
+ * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _state_h
+#define _state_h
+
+typedef enum {
+       STOPPED, STARTING, RUNNING, STOPPING,
+       ABORTING, FREEZING, FROZEN, MAX_STATE,
+} lxc_state_t;
+
+extern int lxc_mkstate(const char *name);
+extern int lxc_rmstate(const char *name);
+extern int lxc_setstate(const char *name, lxc_state_t state);
+extern lxc_state_t lxc_getstate(const char *name);
+
+extern lxc_state_t lxc_str2state(const char *state);
+extern const char *lxc_state2str(lxc_state_t state);
+
+#endif