Ok, I may be missing something obvious here because this seems a bit fundamental... however here goes anyway smile

uci get/export always seem to return the current state of config files AFTER applying changes which have not yet been committed. The upshot of this is most obvious when using a web config interface such as Xwrt, but would affect any such interface. To see what I mean, try this:

Change an IP address in your favourite config interface, save the change but DON'T apply it.
In an ssh session, do /etc/init.d/network restart

Et voila.... your new IP address will have been set, despite the fact that you didn't actually apply the change.

Like I said, this seems like a pretty fundamental problem to me!

Not sure whether this is a deliberate "feature," a problem with UCI, or a problem with OpenWRT, but in my usual style I've hacked what seems to be a fix of sorts. The patch below goes in to package/uci/patches as something like 120-selective_history.patch. What it does is add -H ( never use history, ) and -h ( always use history ) to the command line uci. The default behaviour for everything except get and export is as it was ( i.e. use history. ) The default behaviour for get and export is to use the history if $REMOTE_USER is in the environment, or don't use history if not. The logic to this is that any system commands should NEVER use uncommitted changes as their basis for doing anything, whilst configuration web interfaces need to use the current state in order to show it on their pages. This was the only way that I could think of "fixing" this issue without re-writing loads of stuff.

I've created a patch in this way because as I said, not sure if this is the way things are meant to be or not - in this form its easy to either include the patch or not depending on how people feel!

Adam

diff -rupN uci-12012009.6/cli.c uci-adam/cli.c
--- uci-12012009.6/cli.c        2010-08-14 09:39:58.000000000 +0100
+++ uci-adam/cli.c      2011-02-17 08:31:22.050053001 +0000
@@ -28,6 +28,7 @@ static enum {
        CLI_FLAG_BATCH =    (1 << 3),
        CLI_FLAG_SHOW_EXT = (1 << 4),
        CLI_FLAG_NOPLUGINS= (1 << 5),
+       CLI_FLAG_HISTSET =  (1 << 6),
 } flags;
 
 static FILE *input;
@@ -149,6 +150,8 @@ static void uci_usage(void)
                "\t-s         force strict mode (stop on parser errors, default)\n"
                "\t-S         disable strict mode\n"
                "\t-X         do not use extended syntax on 'show'\n"
+               "\t-H         force history to be ignored.\n"
+               "\t-h         force history to be used.\n"
                "\n",
                appname
        );
@@ -539,6 +542,17 @@ static int uci_batch(void)
        return 0;
 }
 
+void set_history_use()
+{
+       if(!(flags & CLI_FLAG_HISTSET))
+       {
+               if(getenv("REMOTE_USER"))
+                       ctx->flags |= UCI_FLAG_USE_HISTORY;
+               else
+                       ctx->flags &= ~UCI_FLAG_USE_HISTORY;
+       }
+}
+
 static int uci_cmd(int argc, char **argv)
 {
        int cmd = 0;
@@ -550,11 +564,17 @@ static int uci_cmd(int argc, char **argv
        else if (!strcasecmp(argv[0], "changes"))
                cmd = CMD_CHANGES;
        else if (!strcasecmp(argv[0], "export"))
+       {
                cmd = CMD_EXPORT;
+               set_history_use();
+       }
        else if (!strcasecmp(argv[0], "commit"))
                cmd = CMD_COMMIT;
        else if (!strcasecmp(argv[0], "get"))
+       {
                cmd = CMD_GET;
+               set_history_use();
+       }
        else if (!strcasecmp(argv[0], "set"))
                cmd = CMD_SET;
        else if (!strcasecmp(argv[0], "ren") ||
@@ -618,7 +638,7 @@ int main(int argc, char **argv)
                return 1;
        }
 
-       while((c = getopt(argc, argv, "c:d:f:LmnNp:P:sSqX")) != -1) {
+       while((c = getopt(argc, argv, "c:d:f:LmnNp:P:sSqXHh")) != -1) {
                switch(c) {
                        case 'c':
                                uci_set_confdir(ctx, optarg);
@@ -666,6 +686,14 @@ int main(int argc, char **argv)
                        case 'X':
                                flags &= ~CLI_FLAG_SHOW_EXT;
                                break;
+                       /* Adam H - Two args to control history usage */
+                       case 'H':
+                               flags |= CLI_FLAG_HISTSET;
+                               ctx->flags &= ~UCI_FLAG_USE_HISTORY;
+                               break;
+                       case 'h':
+                               flags |= CLI_FLAG_HISTSET;
+                               break;
                        default:
                                uci_usage();
                                return 0;
diff -rupN uci-12012009.6/history.c uci-adam/history.c
--- uci-12012009.6/history.c    2010-08-14 09:39:58.000000000 +0100
+++ uci-adam/history.c  2011-02-17 09:59:55.907129002 +0000
@@ -155,6 +155,9 @@ static void uci_parse_history_line(struc
        if (ctx->flags & UCI_FLAG_SAVED_HISTORY)
                uci_add_history(ctx, &p->saved_history, cmd, ptr.section, ptr.option, ptr.value);
 
+       /* Adam H History change. Formatting deliberately wrong so patch file doesn't include switch */
+       if (ctx->flags & UCI_FLAG_USE_HISTORY)
+       {
        switch(cmd) {
        case UCI_CMD_REORDER:
                expand_ptr(ctx, &ptr, true);
@@ -179,6 +182,7 @@ static void uci_parse_history_line(struc
                        uci_to_section(e)->anonymous = true;
                break;
        }
+       }
        return;
 error:
        UCI_THROW(ctx, UCI_ERR_PARSE);
diff -rupN uci-12012009.6/libuci.c uci-adam/libuci.c
--- uci-12012009.6/libuci.c     2010-08-14 09:39:58.000000000 +0100
+++ uci-adam/libuci.c   2011-02-17 07:13:46.600053001 +0000
@@ -64,7 +64,7 @@ struct uci_context *uci_alloc_context(vo
        uci_list_init(&ctx->backends);
        uci_list_init(&ctx->hooks);
        uci_list_init(&ctx->plugins);
-       ctx->flags = UCI_FLAG_STRICT | UCI_FLAG_SAVED_HISTORY;
+       ctx->flags = UCI_FLAG_STRICT | UCI_FLAG_SAVED_HISTORY | UCI_FLAG_USE_HISTORY;
 
        ctx->confdir = (char *) uci_confdir;
        ctx->savedir = (char *) uci_savedir;
diff -rupN uci-12012009.6/uci.h uci-adam/uci.h
--- uci-12012009.6/uci.h        2010-08-14 09:39:58.000000000 +0100
+++ uci-adam/uci.h      2011-02-17 07:32:45.490053001 +0000
@@ -348,6 +348,7 @@ enum uci_flags {
        UCI_FLAG_PERROR =        (1 << 1), /* print parser error messages */
        UCI_FLAG_EXPORT_NAME =   (1 << 2), /* when exporting, name unnamed sections */
        UCI_FLAG_SAVED_HISTORY = (1 << 3), /* store the saved history in memory as well */
+       UCI_FLAG_USE_HISTORY =   (1 << 4), /* Adam H - Use history to generate results */
 };
 
 struct uci_element