[Toybox] new Android toys: start/stop

Rob Landley rob at landley.net
Sat Jun 25 13:07:29 PDT 2016


On 06/24/2016 05:03 PM, enh wrote:
> * start.c - Start/stop system services.
>  *
>  * Copyright 2016 The Android Open Source Project
> 
> USE_START(NEWTOY(start, "", TOYFLAG_USR|TOYFLAG_SBIN))
> USE_STOP(NEWTOY(stop, "", TOYFLAG_USR|TOYFLAG_SBIN))
...
> static void start_stop(int start)
> {
>   const char* property = start ? "ctl.start" : "ctl.stop";
>   int i;
> 
>   if (getuid() != 0) error_exit("must be root");

In theory we have TOYFLAG_NEEDROOT that can check this (and error out)
before main gets called. But that:

A) depends on CFG_TOYBOX_SUID (which doesn't require the suid bit is
set, but enables the chunk of infrastructure for dropping permissions if
it is).

B) Checks geteuid() rather than getuid(). :)

>   if (*toys.optargs) {
>     for (i = 0; toys.optargs[i]; i++) property_set(property, toys.optargs[i]);

Error checking? (Looks like we always return true, even for something
like "start rutabega"?)

>   } else if (start) {
>     for (i = 0; i < ARRAY_LEN(services); ++i) {
>       property_set(property, services[i]);
>     }
>   } else {
>     for (i = ARRAY_LEN(services) - 1; i >= 0; --i) {
>       property_set(property, services[i]);
>     }
>   }
> }
> 
> void start_main(void)
> {
>   start_stop(1);
> }
> 
> #define CLEANUP_start
> #define FOR_stop
> #include "generated/flags.h"

You're not using any flags or globals after this, so no need to context
shift.

I checked in a curly bracket cleanup. (Ok, and I unified the three loops
calling "property_set()" identially 3 times. I really, REALLY need to
install an AOSP environment on here. Lemme see if I can clear enough
space. 9 gigs free ain't gonna cut it...)

Rob



More information about the Toybox mailing list