[Toybox] reboot

Rob Landley rob at landley.net
Fri Jun 24 13:27:29 PDT 2016


On 06/24/2016 11:46 AM, enh wrote:
> so, Android has a "reboot", but it's implementation is fundamentally
> different from the toys/other/reboot.c, and the options that
> toys/other/reboot.c has don't make sense, and it has the -p option
> (which toys/other/reboot.c should probably have too).
> 
> is there a reasonable way to handle this --- same command name but
> different arguments and implementation?

Ah, I'd missed that. reboot/reboot.c instead of toolbox/reboot.c.

The way toybox does it "reboot", "halt", and "poweroff" are three
separate commands. So reboot -p would be a synonym for "poweroff".
(Because that'show ubuntu and busybox both have that, although I don't
object to reboot having a -p if it matters to you.)

As for implementation... Hmmm.

#include <cutils/properties.h>
#include <cutils/android_reboot.h>

    const char *cmd = "reboot";
    c = getopt(argc, argv, "p");
    switch (c) {
    case 'p':
        cmd = "shutdown";
    prop_len = snprintf(property_val, sizeof(property_val), "%s,%s",
cmd, optarg);
    ret = property_set(ANDROID_RB_PROPERTY, property_val);

I.E. you do property_set() out of cutils/properties.h which is an
android-specific header, so that would require an #ifdef. I could bury
said ifdef in portability.h, but the API is different anyway so it's a
question whether it's a win.

But the funky bit is this:

    fprintf(stderr, "usage: %s [-p] [rebootcommand]\n", argv[0]);

You can have an arbitrary reboot command other than reboot or shutdown
on the command line. Is that used, and what are the other options? (Is
there an android web API like the online posix/lsb/man7.org pages?)

Also, _why_ do you copy the reboot string onto a stack array? Can't you
just pass in the existing string pointer from cmd or optarg? (Does
property_set write to this array? Do you have bounds checking just
_because_ you're copying it to an array, or does property_set care about
the length but not do its own bounds checking?)

Rob


More information about the Toybox mailing list