Search code examples
androidclinkerembedded-linuxstatic-linking

Android reboot command - Who calls reboot_main()?


I am looking at the source for the android shell reboot command.

int reboot_main(int argc, char *argv[])
  • What I am not clear about is if this is a standalone binary, who calls reboot_main() ?
  • In a standard glibc linked binary, I was expecting to find a "main()" as the entry point for the program.

What am I missing here, could someone help me understand what is going on ?

Thanks, vj


Solution

  • They are all compiled into one overall executable, with main in https://android.googlesource.com/platform/system/core.git/+/android-4.2.2_r1/toolbox/toolbox.c

    Then, based on the actual program name invoked (usually argv[0]) it calls the appropriate method.

    The commands are part of the build via the

    #define TOOL(name) int name##_main(int, char**);
    

    macro in toolbox.c which is used in the Android.mk file to generate tools.h.