]> git.proxmox.com Git - mirror_lxcfs.git/commitdiff
add autoconf boilerplate and cgmanager fns
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 12 Dec 2014 18:47:20 +0000 (12:47 -0600)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Fri, 12 Dec 2014 18:52:43 +0000 (12:52 -0600)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
ChangeLog [new file with mode: 0644]
Makefile.am [new file with mode: 0644]
NEWS [new file with mode: 0644]
README [new file with mode: 0644]
bootstrap.sh [new file with mode: 0755]
cgmanager.c [new file with mode: 0644]
cgmanager.h [new file with mode: 0644]
configure.ac [new file with mode: 0644]
lxcfs.c [new file with mode: 0644]

diff --git a/ChangeLog b/ChangeLog
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/Makefile.am b/Makefile.am
new file mode 100644 (file)
index 0000000..c3aaa65
--- /dev/null
@@ -0,0 +1,13 @@
+ACLOCAL_AMFLAGS = -I m4
+
+VERSION_CURRENT  = 0
+VERSION_REVISION = 0
+VERSION_AGE      = 0
+
+AM_CFLAGS = -Wall -ggdb -D_GNU_SOURCE -DSBINDIR=\"$(SBINDIR)\"
+AM_CFLAGS += $(DBUS_CFLAGS) $(NIH_CFLAGS) $(NIH_DBUS_CFLAGS) $(CGMANAGER_CFLAGS) $(FUSE_CFLAGS)
+AM_LDFLAGS = $(DBUS_LIBS) $(NIH_LIBS) $(NIH_DBUS_LIBS) $(CGMANAGER_LIBS) $(FUSE_LIBS)
+
+bin_PROGRAMS = lxcfs
+
+lxcfs_SOURCES = lxcfs.c cgmanager.c
diff --git a/NEWS b/NEWS
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/README b/README
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/bootstrap.sh b/bootstrap.sh
new file mode 100755 (executable)
index 0000000..cf6eef5
--- /dev/null
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+# 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
+
+set -x
+set -e
+
+test -d autom4te.cache && rm -rf autom4te.cache
+aclocal
+libtoolize
+autoheader
+autoconf
+automake --add-missing --copy
diff --git a/cgmanager.c b/cgmanager.c
new file mode 100644 (file)
index 0000000..ac6225e
--- /dev/null
@@ -0,0 +1,205 @@
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2008
+ * (C) Copyright Canonical, Inc, 2014
+ *
+ * Authors:
+ * Daniel Lezcano <daniel.lezcano at free.fr>
+ * Serge Hallyn <serge.hallyn@ubuntu.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <unistd.h>
+#include <string.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <pthread.h>
+#include <grp.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/inotify.h>
+#include <sys/mount.h>
+#include <netinet/in.h>
+#include <net/if.h>
+#include <stdbool.h>
+
+#include <nih-dbus/dbus_connection.h>
+#include <cgmanager/cgmanager-client.h>
+#include <nih/alloc.h>
+#include <nih/error.h>
+#include <nih/string.h>
+
+#include "cgmanager.h"
+
+static NihDBusProxy *cgroup_manager = NULL;
+static int32_t api_version;
+
+static void cgm_dbus_disconnect(void)
+{
+       if (cgroup_manager) {
+              dbus_connection_flush(cgroup_manager->connection);
+              dbus_connection_close(cgroup_manager->connection);
+               nih_free(cgroup_manager);
+       }
+       cgroup_manager = NULL;
+}
+
+#define CGMANAGER_DBUS_SOCK "unix:path=/sys/fs/cgroup/cgmanager/sock"
+static bool cgm_dbus_connect(void)
+{
+       DBusError dbus_error;
+       static DBusConnection *connection;
+
+       dbus_error_init(&dbus_error);
+
+       connection = dbus_connection_open_private(CGMANAGER_DBUS_SOCK, &dbus_error);
+       if (!connection) {
+               fprintf(stderr, "Failed opening dbus connection: %s: %s",
+                               dbus_error.name, dbus_error.message);
+               dbus_error_free(&dbus_error);
+               return false;
+       }
+       dbus_connection_set_exit_on_disconnect(connection, FALSE);
+       dbus_error_free(&dbus_error);
+       cgroup_manager = nih_dbus_proxy_new(NULL, connection,
+                               NULL /* p2p */,
+                               "/org/linuxcontainers/cgmanager", NULL, NULL);
+       dbus_connection_unref(connection);
+       if (!cgroup_manager) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "Error opening cgmanager proxy: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+
+       // get the api version
+       if (cgmanager_get_api_version_sync(NULL, cgroup_manager, &api_version) != 0) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "Error cgroup manager api version: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+       return true;
+}
+
+bool cgm_get_controllers(char ***contrls)
+{
+       if (!cgm_dbus_connect()) {
+               return false;
+       }
+
+       if ( cgmanager_list_controllers_sync(NULL, cgroup_manager, contrls) != 0 ) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "call to list_controllers failed: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+
+       cgm_dbus_disconnect();
+       return true;
+}
+
+bool cgm_list_keys(const char *controller, const char *cgroup, struct cgm_keys ***keys)
+{
+       if (!cgm_dbus_connect()) {
+               return false;
+       }
+
+       if ( cgmanager_list_keys_sync(NULL, cgroup_manager, controller, cgroup,
+                               (CgmanagerListKeysOutputElement ***)keys) != 0 ) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "call to list_keys failed: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+
+       cgm_dbus_disconnect();
+       return true;
+}
+
+bool cgm_list_children(const char *controller, const char *cgroup, char ***list)
+{
+       if (!cgm_dbus_connect()) {
+               return false;
+       }
+
+       if ( cgmanager_list_children_sync(NULL, cgroup_manager, controller, cgroup, list) != 0 ) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "call to list_children failed: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+
+       cgm_dbus_disconnect();
+       return true;
+}
+
+char *cgm_get_pid_cgroup(pid_t pid, const char *controller)
+{
+       char *output = NULL;
+
+       if (!cgm_dbus_connect()) {
+               return NULL;
+       }
+
+       if ( cgmanager_get_pid_cgroup_sync(NULL, cgroup_manager, controller, pid, &output) != 0 ) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "call to get_pid_cgroup failed: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return NULL;
+       }
+
+       cgm_dbus_disconnect();
+       return output;
+}
+
+bool cgm_escape_cgroup(void)
+{
+       if (!cgm_dbus_connect()) {
+               return false;
+       }
+
+       if ( cgmanager_move_pid_abs_sync(NULL, cgroup_manager, "all", "/", (int32_t) getpid()) != 0 ) {
+               NihError *nerr;
+               nerr = nih_error_get();
+               fprintf(stderr, "call to move_pid_abs failed: %s", nerr->message);
+               nih_free(nerr);
+               cgm_dbus_disconnect();
+               return false;
+       }
+
+       cgm_dbus_disconnect();
+       return true;
+}
diff --git a/cgmanager.h b/cgmanager.h
new file mode 100644 (file)
index 0000000..e556f47
--- /dev/null
@@ -0,0 +1,12 @@
+struct cgm_keys {
+       char *name;
+       uint32_t uid, gid;
+       uint32_t mode;
+};
+
+bool cgm_get_controllers(char ***contrls);
+bool cgm_list_keys(const char *controller, const char *cgroup, struct cgm_keys ***keys);
+bool cgm_list_children(const char *controller, const char *cgroup, char ***list);
+char *cgm_get_pid_cgroup(pid_t pid, const char *controller);
+
+bool cgm_escape_cgroup(void);
diff --git a/configure.ac b/configure.ac
new file mode 100644 (file)
index 0000000..4cc078a
--- /dev/null
@@ -0,0 +1,26 @@
+# Process this file with autoconf to produce a configure script.
+
+AC_PREREQ(2.61)
+AC_INIT([lxcfs], [0.01], [lxc-devel@lists.linuxcontainers.org])
+
+AC_GNU_SOURCE
+AC_CONFIG_HEADERS([config.h])
+AC_CONFIG_FILES([
+       Makefile ])
+
+AM_INIT_AUTOMAKE
+
+LT_INIT
+AC_PROG_CC
+
+AC_PROG_CC_C99
+
+PKG_CHECK_MODULES([NIH], [libnih >= 1.0.2])
+PKG_CHECK_MODULES([NIH_DBUS], [libnih-dbus >= 1.0.0])
+PKG_CHECK_MODULES([DBUS], [dbus-1 >= 1.2.16])
+PKG_CHECK_MODULES([CGMANAGER], [libcgmanager >= 0.0.0])
+PKG_CHECK_MODULES(FUSE, fuse)
+
+AC_PATH_PROG(HELP2MAN, help2man, false // No help2man //)
+
+AC_OUTPUT
diff --git a/lxcfs.c b/lxcfs.c
new file mode 100644 (file)
index 0000000..53f4080
--- /dev/null
+++ b/lxcfs.c
@@ -0,0 +1,6 @@
+#include <stdio.h>
+
+int main()
+{
+       printf("hello, world\n");
+}