summaryrefslogtreecommitdiffstats
path: root/common/state/state.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2016-07-15 13:11:20 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2016-07-22 12:44:22 +0200
commita435c13e8809a5f92496fcbae3a38b7609cad515 (patch)
tree309621e020199e174e43d1158d6fccdf02755418 /common/state/state.c
parentea0e077ed65a003e4d7a1e023aee38cbe2d14898 (diff)
downloadbarebox-a435c13e8809a5f92496fcbae3a38b7609cad515.tar.gz
barebox-a435c13e8809a5f92496fcbae3a38b7609cad515.tar.xz
state: Save on shutdown
The state framework is meant for storing persistent variables. To make the state more persistent automatically save it on shutdown. This is now the default behaviour, but can be disabled using a 'save_on_shutdown' variable attached to the state. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/state/state.c')
-rw-r--r--common/state/state.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/common/state/state.c b/common/state/state.c
index 3997f8150c..9b1d4edef1 100644
--- a/common/state/state.c
+++ b/common/state/state.c
@@ -20,6 +20,7 @@
#include <errno.h>
#include <fs.h>
#include <crc.h>
+#include <init.h>
#include <linux/err.h>
#include <linux/list.h>
@@ -54,6 +55,9 @@ static struct state *state_new(const char *name)
state->dirty = 1;
dev_add_param_bool(&state->dev, "dirty", NULL, NULL, &state->dirty,
NULL);
+ state->save_on_shutdown = 1;
+ dev_add_param_bool(&state->dev, "save_on_shutdown", NULL, NULL,
+ &state->save_on_shutdown, NULL);
list_add_tail(&state->list, &state_list);
@@ -571,3 +575,14 @@ void state_info(void)
printf("(no backend)\n");
}
}
+
+static void state_shutdown(void)
+{
+ struct state *state;
+
+ list_for_each_entry(state, &state_list, list) {
+ if (state->save_on_shutdown)
+ state_save(state);
+ }
+}
+predevshutdown_exitcall(state_shutdown);