[Toybox] reboot

enh enh at google.com
Fri Jun 24 18:35:46 PDT 2016


On Fri, Jun 24, 2016 at 1:27 PM, Rob Landley <rob at landley.net> wrote:
> 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.)

yeah, that's not my problem. my problem is that Android's reboot
doesn't support the same arguments as the current toybox reboot (and
they make no sense on Android).

> 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?)

whatever the OEM happens to have in their bootloader. there's a
well-known subset, but it is actually an arbitrary string :-/

> 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?)

no, it's actually <cmd>,<optarg>.

> Rob



-- 
Elliott Hughes - http://who/enh - http://jessies.org/~enh/
Android native code/tools questions? Mail me/drop by/add me as a reviewer.



More information about the Toybox mailing list