#include "cgmanager.h"
-static NihDBusProxy *cgroup_manager = NULL;
-static int32_t api_version;
+static __thread NihDBusProxy *cgroup_manager = NULL;
+static __thread int32_t api_version;
static void cgm_dbus_disconnect(void)
{
PKG_CHECK_MODULES(FUSE, fuse)
AC_CHECK_LIB(cgmanager, cgmanager_list_controllers_sync, [], AC_MSG_ERROR(["cgmanager 0.35 or higher is required"]))
AC_CHECK_LIB(cgmanager, cgmanager_list_keys_sync, [], AC_MSG_ERROR(["cgmanager 0.35 or higher is required"]))
+AC_CHECK_LIB(nih, nih_alloc)
+AC_CHECK_FUNCS(nih_threadsafe, , , libnih)
AC_PATH_PROG(HELP2MAN, help2man, false // No help2man //)
AM_CONDITIONAL([HAVE_HELP2MAN], [test "x$HELP2MAN" != "xfalse // No help2man //" ])
#include <nih/alloc.h>
#include <nih/string.h>
+#include <nih/error.h>
#include "cgmanager.h"
#include "config.h" // for VERSION
}
}
+bool detect_libnih_threadsafe(void)
+{
+#ifdef HAVE_NIH_THREADSAFE
+ if (nih_threadsafe())
+ return true;
+#endif
+ return false;
+}
+
int main(int argc, char *argv[])
{
int ret = -1;
* what we pass to fuse_main is:
* argv[0] -s -f -o allow_other,directio argv[1] NULL
*/
-#define NARGS 7
- char *newargv[7];
+ int nargs = 6;
+ bool threadsafe = detect_libnih_threadsafe();
+ char *newargv[7]; // one more than if needed if threadsafe
+
+ if (threadsafe)
+ nargs = 5;
/* accomodate older init scripts */
swallow_arg(&argc, argv, "-s");
d = NIH_MUST( malloc(sizeof(*d)) );
- newargv[0] = argv[0];
- newargv[1] = "-s";
- newargv[2] = "-f";
- newargv[3] = "-o";
- newargv[4] = "allow_other,direct_io";
- newargv[5] = argv[1];
- newargv[6] = NULL;
+ int cnt = 0;
+ newargv[cnt++] = argv[0];
+ if (!threadsafe)
+ newargv[cnt++] = "-s";
+ newargv[cnt++] = "-f";
+ newargv[cnt++] = "-o";
+ newargv[cnt++] = "allow_other,direct_io";
+ newargv[cnt++] = argv[1];
+ newargv[cnt++] = NULL;
if (!cgm_escape_cgroup())
fprintf(stderr, "WARNING: failed to escape to root cgroup\n");
if (!cgm_get_controllers(&d->subsystems))
goto out;
- ret = fuse_main(NARGS - 1, newargv, &lxcfs_ops, d);
+ ret = fuse_main(nargs, newargv, &lxcfs_ops, d);
out:
free(d);