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
7 -p and -P option of uci cli utitlity is not enough for 2 reasons
9 - Compile-time default cannot be ignored
10 - CLI_FLAG_NOCOMMIT will be in effect with -P option
12 Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
14 libuci.c | 21 +++++++++++++++++++--
15 1 file changed, 19 insertions(+), 2 deletions(-)
17 diff --git a/libuci.c b/libuci.c
18 index a9e70e8..19ea20f 100644
25 +#include <libubox/utils.h>
28 static const char *uci_errstr[] = {
29 @@ -40,8 +41,24 @@ static const char *uci_errstr[] = {
30 #include "uci_internal.h"
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;
38 +static const char *uci_getenv_default(const char *var, const char *defval)
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);
54 /* exported functions */
55 struct uci_context *uci_alloc_context(void)