[OpenWrt-Devel] [PATCH procd] system: support passing "options" to the "sysupgrade" ubus method
Jo-Philipp Wich
jo at mein.io
Sat Aug 17 06:30:56 EDT 2019
Hi,
> [...]
> +
> + blobmsg_for_each_attr(option, options, rem) {
> + const char *prefix = "UPGRADE_OPT_";
> + char *name = malloc(strlen(prefix) + strlen(blobmsg_name(option)));
> + char value[11];
> + char *c;
> + int tmp;
> +
> + if (!name) {
> + continue;
> + }
> + sprintf(name, "%s%s", prefix, blobmsg_name(option));
> + for (c = name + strlen(prefix); *c; c++) {
I'd propose some more sanity checking here:
if (isalnum(*c) || *c == '_') {
> + *c = toupper(*c);
}
else {
c = NULL;
break;
}
> + }
if (!c) {
fprintf(stderr, "Option \"%s\" contains invalid
characters\n", blobmsg_name(option));
free(name);
continue;
}
> +
> + switch (blobmsg_type(option)) {
> + case BLOBMSG_TYPE_INT32:
> + tmp = blobmsg_get_u32(option);
> + break;
> + case BLOBMSG_TYPE_INT16:
> + tmp = blobmsg_get_u16(option);
> + break;
> + case BLOBMSG_TYPE_INT8:
> + tmp = blobmsg_get_u8(option);
> + break;
> + default:
> + fprintf(stderr, "Option \"%s\" has unsupported type: %d\n",
> + blobmsg_name(option), blobmsg_type(option));
> + free(name);
> + continue;
> + }
> + snprintf(value, sizeof(value), "%u", tmp);
> +
> + setenv(name, value, 1);
> +
> + free(name);
> + }
> +
> execvp(argv[0], argv);
>
> /* Cleanup on failure */
> diff --git a/sysupgrade.h b/sysupgrade.h
> index 8c09fc9..c84e494 100644
> --- a/sysupgrade.h
> +++ b/sysupgrade.h
> @@ -14,8 +14,10 @@
> #ifndef __PROCD_SYSUPGRADE_H
> #define __PROCD_SYSUPGRADE_H
>
> +struct blob_attr;
>
> -void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command);
> +void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command,
> + struct blob_attr *options);
>
>
> #endif
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20190817/796a0cda/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list