From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] state: Save on shutdown
Date: Fri, 22 Jul 2016 12:44:43 +0200 [thread overview]
Message-ID: <1469184283-2966-1-git-send-email-s.hauer@pengutronix.de> (raw)
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>
---
common/state/state.c | 15 +++++++++++++++
common/state/state.h | 1 +
2 files changed, 16 insertions(+)
diff --git a/common/state/state.c b/common/state/state.c
index 3997f81..9b1d4ed 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);
diff --git a/common/state/state.h b/common/state/state.h
index 7f9651a..32146ca 100644
--- a/common/state/state.h
+++ b/common/state/state.h
@@ -100,6 +100,7 @@ struct state {
struct list_head variables; /* Sorted list of variables */
unsigned int dirty;
+ unsigned int save_on_shutdown;
struct state_backend backend;
};
--
2.8.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
reply other threads:[~2016-07-22 10:45 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1469184283-2966-1-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox