uci: patch for static host build
[openwrt/staging/yousong.git] / package / system / uci / patches / 0003-libuci-allow-setting-confdir-and-savedir-with-enviro.patch
1 From 8ae26f2c0152c6bd58b7404a400e41405b034cc9 Mon Sep 17 00:00:00 2001
2 From: Yousong Zhou <yszhou4tech@gmail.com>
3 Date: Sun, 5 Mar 2017 13:43:05 +0800
4 Subject: [PATCH 3/3] libuci: allow setting confdir and savedir with
5 environment variables
6
7 -p and -P option of uci cli utitlity is not enough for 2 reasons
8
9 - Compile-time default cannot be ignored
10 - CLI_FLAG_NOCOMMIT will be in effect with -P option
11
12 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
13 ---
14 libuci.c | 21 +++++++++++++++++++--
15 1 file changed, 19 insertions(+), 2 deletions(-)
16
17 diff --git a/libuci.c b/libuci.c
18 index a9e70e8..19ea20f 100644
19 --- a/libuci.c
20 +++ b/libuci.c
21 @@ -24,6 +24,7 @@
22 #include <stdio.h>
23 #include <dlfcn.h>
24 #include <glob.h>
25 +#include <libubox/utils.h>
26 #include "uci.h"
27
28 static const char *uci_errstr[] = {
29 @@ -40,8 +41,24 @@ static const char *uci_errstr[] = {
30 #include "uci_internal.h"
31 #include "list.c"
32
33 -__private const char *uci_confdir = UCI_CONFDIR;
34 -__private const char *uci_savedir = UCI_SAVEDIR;
35 +__private const char *uci_confdir;
36 +__private const char *uci_savedir;
37 +
38 +static const char *uci_getenv_default(const char *var, const char *defval)
39 +{
40 + const char *val;
41 +
42 + val = getenv(var);
43 + if (val)
44 + return val;
45 + else
46 + return defval;
47 +}
48 +
49 +static void __constructor uci_dir_init(void) {
50 + uci_confdir = uci_getenv_default("UCI_CONFDIR", UCI_CONFDIR);
51 + uci_savedir = uci_getenv_default("UCI_SAVEDIR", UCI_SAVEDIR);
52 +}
53
54 /* exported functions */
55 struct uci_context *uci_alloc_context(void)
56 --
57 2.6.4
58