[CRIU] [PATCH] cgroup: props -- Make --cgroup-props option config dependant

Cyrill Gorcunov gorcunov at openvz.org
Thu Jan 22 01:46:08 PST 2015


At moment we require Jansson library to be present in the
system to support JSON parsing of --cgroup-props. But if
someone doesn't need custom properties lets don't force
him to setup Jansson library for nothing.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---

This patch is on top of cgroup properties series.

 Makefile                  |  2 +-
 Makefile.config           |  9 +++++++--
 cgroup-props.c            | 15 +++++++++++++--
 scripts/feature-tests.mak | 10 ++++++++++
 4 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index a0ccfa2cd765..a896e334ea1f 100644
--- a/Makefile
+++ b/Makefile
@@ -91,7 +91,7 @@ cflags-y		+= -iquote $(ARCH_DIR) -iquote $(ARCH_DIR)/include
 cflags-y		+= -fno-strict-aliasing
 export cflags-y
 
-LIBS		:= -lrt -lpthread -lprotobuf-c -ldl -ljansson
+LIBS		:= -lrt -lpthread -lprotobuf-c -ldl
 
 DEFINES		+= -D_FILE_OFFSET_BITS=64
 DEFINES		+= -D_GNU_SOURCE
diff --git a/Makefile.config b/Makefile.config
index ac54775fc4cd..d544b2d9d296 100644
--- a/Makefile.config
+++ b/Makefile.config
@@ -8,6 +8,11 @@ ifeq ($(call try-cc,$(LIBBSD_DEV_TEST),-lbsd),y)
 	DEFINES += -DCONFIG_HAS_LIBBSD
 endif
 
+ifeq ($(call try-cc,$(LIBJANSSON_TEST),-ljansson),y)
+	LIBS += -ljansson
+	JANSSON = y
+endif
+
 $(CONFIG): scripts/utilities.mak scripts/feature-tests.mak include/config-base.h
 	$(E) "  GEN     " $@
 	$(Q) @echo '#ifndef __CR_CONFIG_H__' > $@
@@ -33,8 +38,8 @@ endif
 ifeq ($(VDSO),y)
 	$(Q) @echo '#define CONFIG_VDSO' >> $@
 endif
-ifeq ($(call try-cc,$(SETPROCTITLE_INIT_TEST),-lbsd),y)
-	$(Q) @echo '#define CONFIG_HAS_SETPROCTITLE_INIT' >> $@
+ifeq ($(JANSSON),y)
+	$(Q) @echo '#define CONFIG_HAS_LIBJANSSON' >> $@
 endif
 	$(Q) @echo '#endif /* __CR_CONFIG_H__ */' >> $@
 
diff --git a/cgroup-props.c b/cgroup-props.c
index eefcc128ce09..81460172729c 100644
--- a/cgroup-props.c
+++ b/cgroup-props.c
@@ -7,16 +7,19 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 
-#include <jansson.h>
-
 #include "compiler.h"
 #include "cgroup-props.h"
+#include "config.h"
 #include "xmalloc.h"
 #include "util.h"
 #include "list.h"
 #include "log.h"
 #include "bug.h"
 
+#ifdef CONFIG_HAS_LIBJANSSON
+# include <jansson.h>
+#endif
+
 #undef	LOG_PREFIX
 #define LOG_PREFIX "cg-prop: "
 
@@ -172,6 +175,7 @@ int cgp_init(char *arg, size_t len)
 	return 0;
 }
 
+#ifdef CONFIG_HAS_LIBJANSSON
 int cgp_parse(char *stream, size_t len)
 {
 	json_t *root, *controller_obj;
@@ -252,6 +256,13 @@ err:
 	cgp_free(cgp_p);
 	return ret;
 }
+#else
+int cgp_parse(char *stream, size_t len)
+{
+	pr_err("No JSON parser is compiled in. Feature unsupported\n");
+	return -1;
+}
+#endif
 
 const cgp_t *cgp_get_props(const char *name)
 {
diff --git a/scripts/feature-tests.mak b/scripts/feature-tests.mak
index 519eb52694f9..2897dc54fbec 100644
--- a/scripts/feature-tests.mak
+++ b/scripts/feature-tests.mak
@@ -92,3 +92,13 @@ int main(int argc, char *argv[], char *envp[])
 }
 
 endef
+
+define LIBJANSSON_TEST
+
+#include <jansson.h>
+
+int main(int argc, char *argv[], char *envp[])
+{
+	return 0;
+}
+endef
-- 
1.9.3



More information about the CRIU mailing list