summaryrefslogtreecommitdiff
path: root/system.c
diff options
context:
space:
mode:
authorDaniel Golle <daniel@makrotopia.org>2021-02-15 07:06:42 +0000
committerDaniel Golle <daniel@makrotopia.org>2021-02-23 00:42:37 +0000
commit37eed131e9967a35f47bacb3437a9d3c8a57b3f4 (patch)
tree7497116b9f5244e80021273d1ae6cd38aed430c1 /system.c
parent2be57ed3fbee3ca61edf4e36e01a7ebece11fb28 (diff)
downloadprocd-37eed131e9967a35f47bacb3437a9d3c8a57b3f4.tar.gz
system: expose if system was booted from initramfs
It can be good for UI to show to the user that the system was booted from initramfs ie. no writable permanent storage is available. I imagine LuCI only serving applications which are explicitely marked as being shown even in initramfs mode, ie. nothing but status, network->interfaces, network->wireless, system->upgrade, system->backup, system->backuprestore tabs. Also sysupgrade could take into account we are running on initramfs and perform offline backup/restore of whatever is in the flash. In that way OpenWrt-generated initramfs-images can serve as recovery OS on devices with dual-boot in a meaningful way. Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Diffstat (limited to 'system.c')
-rw-r--r--system.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/system.c b/system.c
index 7855659..83aea42 100644
--- a/system.c
+++ b/system.c
@@ -36,6 +36,7 @@
static struct blob_buf b;
static int notify;
static struct ubus_context *_ctx;
+static int initramfs;
enum vjson_state {
VJSON_ERROR,
@@ -55,6 +56,9 @@ static int system_board(struct ubus_context *ctx, struct ubus_object *obj,
blob_buf_init(&b, 0);
+ if (initramfs)
+ blobmsg_add_u8(&b, "initramfs", 1);
+
if (uname(&utsname) >= 0)
{
blobmsg_add_string(&b, "kernel", utsname.release);
@@ -759,6 +763,11 @@ void ubus_init_system(struct ubus_context *ctx)
int ret;
_ctx = ctx;
+
+ initramfs = !!getenv("INITRAMFS");
+ if (initramfs)
+ unsetenv("INITRAMFS");
+
ret = ubus_add_object(ctx, &system_object);
if (ret)
ERROR("Failed to add object: %s\n", ubus_strerror(ret));