uci: patch for static host build
[openwrt/staging/yousong.git] / package / system / uci / patches / 0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch
diff --git a/package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch b/package/system/uci/patches/0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch
new file mode 100644 (file)
index 0000000..801420d
--- /dev/null
@@ -0,0 +1,58 @@
+From 8ae26f2c0152c6bd58b7404a400e41405b034cc9 Mon Sep 17 00:00:00 2001
+From: Yousong Zhou <yszhou4tech@gmail.com>
+Date: Sun, 5 Mar 2017 13:43:05 +0800
+Subject: [PATCH 3/3] libuci: allow setting confdir and savedir with
+ environment variables
+
+-p and -P option of uci cli utitlity is not enough for 2 reasons
+
+ - Compile-time default cannot be ignored
+ - CLI_FLAG_NOCOMMIT will be in effect with -P option
+
+Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
+---
+ libuci.c | 21 +++++++++++++++++++--
+ 1 file changed, 19 insertions(+), 2 deletions(-)
+
+diff --git a/libuci.c b/libuci.c
+index a9e70e8..19ea20f 100644
+--- a/libuci.c
++++ b/libuci.c
+@@ -24,6 +24,7 @@
+ #include <stdio.h>
+ #include <dlfcn.h>
+ #include <glob.h>
++#include <libubox/utils.h>
+ #include "uci.h"
+ static const char *uci_errstr[] = {
+@@ -40,8 +41,24 @@ static const char *uci_errstr[] = {
+ #include "uci_internal.h"
+ #include "list.c"
+-__private const char *uci_confdir = UCI_CONFDIR;
+-__private const char *uci_savedir = UCI_SAVEDIR;
++__private const char *uci_confdir;
++__private const char *uci_savedir;
++
++static const char *uci_getenv_default(const char *var, const char *defval)
++{
++      const char *val;
++
++      val = getenv(var);
++      if (val)
++              return val;
++      else
++              return defval;
++}
++
++static void __constructor uci_dir_init(void) {
++      uci_confdir = uci_getenv_default("UCI_CONFDIR", UCI_CONFDIR);
++      uci_savedir = uci_getenv_default("UCI_SAVEDIR", UCI_SAVEDIR);
++}
+ /* exported functions */
+ struct uci_context *uci_alloc_context(void)
+-- 
+2.6.4
+