[LEDE-DEV] [PATCH] procd: get rid of putenv usage.

Alexandru Ardelean ardeleanalex at gmail.com
Tue Jan 23 00:09:26 PST 2018


On Tue, Jan 23, 2018 at 4:57 AM, Rosen Penev <rosenp at gmail.com> wrote:
> setenv is prefered according to POSIX. Also allows staticly allocated strings.
>
> Saves 200 bytes when stripped. 400 without.
>
> Signed-off-by: Rosen Penev <rosenp at gmail.com>
> ---
>  service/instance.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/service/instance.c b/service/instance.c
> index 12c2efe..848679c 100644
> --- a/service/instance.c
> +++ b/service/instance.c
> @@ -279,7 +279,7 @@ instance_run(struct service_instance *in, int _stdout, int _stderr)
>         struct blobmsg_list_node *var;
>         struct blob_attr *cur;
>         char **argv;
> -       char *ld_preload;
> +       char *ld_preload = "/lib/libsetlbf.so";
>         int argc = 1; /* NULL terminated */
>         int rem, _stdin;
>         bool seccomp = !in->trace && !in->has_jail && in->seccomp;
> @@ -297,8 +297,8 @@ instance_run(struct service_instance *in, int _stdout, int _stderr)
>         if (seccomp)
>                 setenv("SECCOMP_FILE", in->seccomp, 1);
>
> -       if (setlbf && asprintf(&ld_preload, "LD_PRELOAD=/lib/libsetlbf.so") > 0)
> -               putenv(ld_preload);
> +       if (setlbf)
> +               setenv("LD_PRELOAD", ld_preload, 1);

if removing the aspintf() you could also remove the `ld_preload` var
altogether, and just do setenv("LD_PRELOAD", "/lib/libsetlbf.so", 1);

rest looks neat

>
>         blobmsg_list_for_each(&in->limits, var)
>                 instance_limits(blobmsg_name(var->data), blobmsg_data(var->data));
> --
> 2.7.4
>
>
> _______________________________________________
> Lede-dev mailing list
> Lede-dev at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/lede-dev



More information about the Lede-dev mailing list