summaryrefslogtreecommitdiffstats
path: root/init/reboot.cpp
Commit message (Collapse)AuthorAgeFilesLines
* init: increase thermal shutdown timeout to 3sWei Wang2018-10-261-8/+7
| | | | | | | | | | | | 1) increase thermal shutdown timeout to 3s for process to save work 2) respect property "ro.build.shutdown_timeout" in thermal shutdown if it is set less than default time - "3s" Bug: 112432890 Test: Build Change-Id: Idc2b24dd44c1fab8f9b047fd2468de2ee45ff783 Merged-In: Idc2b24dd44c1fab8f9b047fd2468de2ee45ff783 (cherry picked from commit b5de088262b735267288bbdd3f4430f18f281967)
* Revert "init: Reboot after timeout passes during reboot"Tom Cherry2018-03-201-74/+34
| | | | | | | | | | | | | This reverts commit c9fec9d2be73a26a4f4b297ee6bee9f9c62cb854. Looks like ext4 can't handle a system reboot happening in the middle of an unmount. We'll have to find another way to handle this. Bug: 74817735 Bug: 75310371 Test: reboot device Merged-In: Ib4f7f7fd29988a31a99f146c40f6d987c1fef15e Change-Id: I7c097ba5734e2e4ff320c8b02fb58324d9380513
* init: Reboot after timeout passes during rebootTom Cherry2018-02-231-36/+77
| | | | | | | | | | | | | | | | | There is currently a timeout for reboot, however if the system gets stuck, particularly during file system operations, there is no safety mechanism that guarantees the system will still reboot. This change does all of the optional reboot steps in a separate thread and waits for this thread with a timeout, such that if the reboot steps get hung, the system is guaranteed to still reboot. This is specific to 'reboot'. Shutdown continues to run unbounded to run fsck. Bug: 72781711 Test: Reboot devices hitting and not hitting this timeout Change-Id: Id5e1b3693bab00602177e28b9b662e1499c32961
* Move ActionManager to its own fileTom Cherry2018-02-141-0/+1
| | | | | | Bug: 36970783 Test: build Change-Id: I08fa39052236b462249f79de1d02bf02bdbf4c84
* Init remove direct calls to light sys nodes.Steven Moreland2018-01-191-19/+9
| | | | | | | | | | These are halified. Instead launch blank_screen which does the same task w/o init itself having binder dependencies. Bug: 70846424 Test: manual + reboot appears similar Change-Id: If8b2a56cbc31077122ea81406721b06034e4498f
* init: call umount unconditionallyWei Wang2017-10-231-6/+6
| | | | | | | | | | | std::all_of is using std::find_if, which means, if any element the given predicate returns false, it stops further iteration and just returns false. std::all_of used in Reboot.cpp will cause umount not to be called on all block devices if some block device returns false in the middle. Bug: 68158923 Test: reboot Change-Id: I43ba6bd0c18018c1ed5fe2b63996552bc51cc67c
* init+bootstat: reduce last reboot reason to canonical aliasMark Salyzyn2017-10-101-2/+12
| | | | | | | | | | | | | | | | | To make parsing easier for last reboot reason. This also ensures that last boot reason matches the content that is typically returned by the bootloader or in turn landed in the canonical system boot reason. Simplify parsing in bootstat. Adjust and fix boot_reason_test.sh for new reality. Allow boot reason tests battery and kernel_panic to pass if device does not support pstore (empty before and after the test). If device somehow landed in fastboot mode while waiting for the display, issue a fastboot reboot to move the test along. Some cleanup and standardization changes to the test script. Test: system/core/bootstat/boot_reason_test.sh Bug: 63736262 Change-Id: I97d5467c0b4a6d65df3525f1a2d0051db813d5ad
* init/reboot: call MNT_FORCE at the last umount(2)Jaegeuk Kim2017-10-041-6/+7
| | | | | | | | | | The last one will avoid errors=panic in ext4. Test: Build Bug: 63981945 Bug: 65481582 Change-Id: I9c86afcce441767e24fc43668ab1ff6230155a9f Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
* init: run vendor commands in a separate SELinux contextTom Cherry2017-09-291-2/+1
| | | | | | | | | | | | | | | | | | | | | | One of the major aspects of treble is the compartmentalization of system and vendor components, however init leaves a huge gap here, as vendor init scripts run in the same context as system init scripts and thus can access and modify the same properties, files, etc as the system can. This change is meant to close that gap. It forks a separate 'subcontext' init that runs in a different SELinux context with permissions that match what vendors should have access to. Commands get sent over a socket to this 'subcontext' init that then runs them in this SELinux context and returns the result. Note that not all commands run in the subcontext; some commands such as those dealing with services only make sense in the context of the main init process. Bug: 62875318 Test: init unit tests, boot bullhead, boot sailfish Change-Id: Idf4a4ebf98842d27b8627f901f961ab9eb412aee
* init: shutdown,thermal shut off display immediatelyMark Salyzyn2017-09-261-0/+2
| | | | | | | Remove a source of heat. Test: manual Change-Id: I9a7391ddb121b6748a4f49f4b5bfb77453ca1514
* init: Allow clean system shutdown upon SIGTERMLuis Hector Chavez2017-09-071-4/+2
| | | | | | | | | | | | This allows Android to cleanly shutdown when running in a PID namespace in a way that does not rely on adbd running. This is useful to allow Android to be running in a container and its lifetime managed by an OCI-compliant tool. Bug: 65415372 Test: `kill -TERM 1` as root is correctly dropped. Test: `kill -TERM 1` from the init PID namespace causes init to cleanly shutdown. Change-Id: Ia66ebdb436221919081bc4723337c0c7f1e53b09
* Merge "init: log all failures of Service::Start()"Tom Cherry2017-08-281-2/+9
|\
| * init: log all failures of Service::Start()Tom Cherry2017-08-251-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | The move to returning Result from Service::Start() for better context when starting process through init's builtins stops Service::Start() failures from being logged from other contexts. This change adds those logs along with their context. Test: boot bullhead, fail to start services via `setprop ctl.start`, see the expected error in dmesg Change-Id: I45294f6abf00852f3d4c549a32eaf4920a51e6f0
* | Switch /data/misc/reboot/last_reboot_reason to persistent propertyMark Salyzyn2017-08-241-16/+14
|/ | | | | | | | | | | | | | | Switch from /data/misc/reboot/last_reboot_reason to persistent Android property persist.sys.boot.reason for indicating why the device is rebooted or shutdown. persist.sys.boot.reason has a standard as outlined in b/63736262 and the associated investigation. Made adjustments to the values so that we did not create a problem even before we started. Compliance is part of the tests in boot_reason_test.sh. Test: system/core/bootstat/boot_reason_test.sh Bug: 64687998 Change-Id: I812c55a12faf7cb7ff92101009be058ad9958d07
* Merge "init: replace panic() with LOG(FATAL)"Tom Cherry2017-08-181-3/+2
|\
| * init: replace panic() with LOG(FATAL)Tom Cherry2017-08-171-3/+2
| | | | | | | | | | | | | | | | | | | | | | Test: boot bullhead Test: Introduce LOG(FATAL) at various points of init and ensure that it reboots to the bootloader successfully Test: Introduce LOG(FATAL) during DoReboot() and ensure that it reboots instead of recursing infinitely Test: Ensure that fatal signals reboot to bootloader Change-Id: I409005b6fab379df2d635e3e33d2df48a1a97df3
* | Skip unnecessary sleep during shutdownWei Wang2017-08-161-15/+15
|/ | | | | | | | | Skip sleep if timeout is zero Skip sleep if first pass umount succeed Bug: 64768138 Test: reboot Change-Id: I5ef731611320ade51974b414f7e47520ce36b287
* init: use Result<T> for builtin functionsTom Cherry2017-08-141-1/+1
| | | | | | | | | | | | | | | | We currently throw out the return values from builtin functions and occasionally log errors with no supporting context. This change uses the newly introduced Result<T> class to communicate a successful result or an error back to callers in order to print an error with clear context when a builtin fails. Example: init: Command 'write /sys/class/leds/vibrator/trigger transient' action=init (/init.rc:245) took 0ms and failed: Unable to write to file '/sys/class/leds/vibrator/trigger': open() failed: No such file or directory Test: boot bullhead Merged-In: Idc18f331d2d646629c6093c1e0f2996cf9b42aec Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
* init: split security functions out of init.cppTom Cherry2017-08-141-0/+1
| | | | | | | | | | | | | | | | | This change splits out the selinux initialization and supporting functionality into selinux.cpp and splits the security related initialization of the rng, etc to security.cpp. It also provides additional documentation for SEPolicy loading as this has been requested by some teams. It additionally cleans up sehandle and sehandle_prop. The former is static within selinux.cpp and new wrapper functions are created around selabel_lookup*() to better serve the users. The latter is moved to property_service.cpp as it is isolated to that file for its usage. Test: boot bullhead Merged-In: Idc95d493cebc681fbe686b5160502f36af149f60 Change-Id: Idc95d493cebc681fbe686b5160502f36af149f60
* init: rename ServiceManager to ServiceList and clean it upTom Cherry2017-08-011-17/+20
| | | | | | | | | | | | | | ServiceManager is essentially just a list now that the rest of its functionality has been moved elsewhere, so the class is renamed appropriately. The ServiceList::Find* functions have been cleaned up into a single smaller interface. The ServiceList::ForEach functions have been removed in favor of ServiceList itself being directly iterable. Test: boot bullhead Change-Id: Ibd57c103338f03b83d81e8b48ea0e46cd48fd8f0
* init: move reaping from ServiceManager to signal_handler.cppTom Cherry2017-08-011-2/+3
| | | | | | | | signal_handler.cpp itself needs to be cleaned up, but this is a step to clean up ServiceManager. Test: boot bullhead Change-Id: I81f1e8ac4d09692cfb364bc702cbd3deb61aa55a
* init: move exec operations out of ServiceManagerTom Cherry2017-08-011-4/+2
| | | | | | | | | These can be implemented without ServiceManager, so we remove them and make ServiceManager slightly less of a God class. Test: boot bullhead Test: init unit tests Change-Id: Ia6e546fe5292255412245256f7d230af4ece135f
* init: shutdown services in the opposite order that they startedTom Cherry2017-07-261-3/+3
| | | | | | | | | | | | | | | | | | | Currently, the order that we kill to services during shutdown is the order of services_ in ServiceManager and that is defacto the order in which they were parsed, which is not a very useful ordering. Related to this, we have seen a few issues during shutdown that may be related to services with dependencies on other services, where the dependency is killed first and the dependent service then misbehaves. This change allows services to keep track of the order in which they were started and shutdown then uses that information to kill running services in the opposite order that they were started. Bug: 64067984 Test: Boot and reboot bullhead Change-Id: I6b4cacb03aed2a72ae98a346bce41ed5434a09c2
* Do not umount roofs even if it is R/W.Wei Wang2017-07-251-1/+2
| | | | | | | | Latest device has rootfs instead of "/system" mount point Bug: 37737296 Test: adb remount, reboot, and check log Change-Id: I315ecf71e85255fc55c3a80619920b456bad0956
* init: Fire shutdown trigger for thermal shutdownWei Wang2017-07-241-3/+1
| | | | | | | | | | Recent change in init has bring normal shutdown sequence in thermal-shutdown condition. This CL will make sure init fire shutdown trigger where holds custom shutdown actions for vendor SoC/platform. Bug: 63686426 Test: adb shell setprop sys.powerctl thermal-shutdown Change-Id: Ieb8579fdf9c30c1a81d60466a7375c9784f3ca98
* init: Do full shutdown even for thermal shutdownKeun-young Park2017-07-191-20/+19
| | | | | | | | | | | | | - Skipping SIGTERM / SIGKILL / umount brings race between block device driver and fs layer. Do umount before shutting down. - Reduce timeout to 1 sec for thermal shutdown and skip other time taking part like fsck. - Refactor waiting part to check time in ms so that 1 sec can have enough resolution. bug: 63686426 Test: adb shell setprop sys.powerctl thermal-shutdown, adb shell setprop sys.powerctl reboot and check dmesg Change-Id: I048bac767b328c8d656a97fe65dde5f2b5bf4ae5
* dump stack before kill allKeun-young Park2017-07-181-3/+3
| | | | | | | | | - If problematic process is from user, kill all kills it and dump does not show problematic process. bug: 37737296 Test: reboot and check log Change-Id: Iaa4f7d12f5a40fa7528c6672567c36e30b140372
* Do not umount /vendor, /system, and /oem even if they are R/W.Keun-young Park2017-07-171-1/+6
| | | | | | | | | | | | | | | | - /vendor, /system, /oem can be remounted to R/W for development purpose. - In such case, umounting these partitions can lead into some processes not running properly during shutdown or blocking umount of fs. - So skip them. As it is dev feature, it is up to each developer to understand the risk. But for normal adb sync - reboot should be ok as shutdown involves sync operations. bug: 37737296 Test: adb remount,reboot, and check last kmsg Change-Id: Iab6a6374bc558375d359b3b49b14db93d363b1ad
* Move Timer from init to libbaseTom Cherry2017-07-101-19/+21
| | | | | | | Test: boot bullhead Test: new libbase unit tests Change-Id: Ic398a1daa1fe92c10ea7bc1e6ac3f781cee9a5b5
* Merge "add "shutdown critical" to service"Treehugger Robot2017-07-061-1/+3
|\
| * add "shutdown critical" to serviceKeun-young Park2017-07-051-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - "shutdown critical" prevents killing the service during shutdown. And the service will be started if not running. - Without it, services will be killed by SIGTERM / SIGKILL during shutdown. - Even services with "shutdown critical" will be killed if shutdown times out. - Removes ueventd and vold from hard coded list. Each service's rc will be updated to add "shutdown critical". watchdogd is still kept in the list. bug: 37626581 Test: reboot and check last kmsg Change-Id: Ie8cc699d1efbc59b9a2561bdd40fec64aed5a4bb
* | init: Support custom shutdown actionsWei Wang2017-07-051-1/+24
|/ | | | | | | | | | | | | | | We have been seeing panics and errors during shutdown sequence in some vendor's platform, and it is required to disable error handling during shutdown. This CL separates the shutdown request to execute another "shutdown" trigger at the beginning of shutdown stage. And vendor can use this trigger to add custom commands needed for shutting down gracefully. Bug: 38203024 Bug: 62084631 Test: device reboot/shutdown Change-Id: I3fac4ed59f06667d86e477ee55ed391cf113717f
* Remove unnecessary SELinux dependenciesNick Kralevich2017-07-011-1/+0
| | | | | | | These are unused. Test: code compiles. Change-Id: Idd707dfcc8f6daac3a489c791ecc364841cf31f9
* init: Reland "Terminate gracefully when CAP_SYS_BOOT is absent"Luis Hector Chavez2017-06-291-0/+31
| | | | | | | | | | | | | This change makes it possible for Android running in a container to terminate cleanly instead of calling abort() when requested to shut down. Bug: 62388055 Test: `adb reboot` on bullhead causes no kernel panics Test: `adb reboot` on a system without CAP_SYS_BOOT makes init terminate nicely Change-Id: I36b2298610f5b4a2bf8b05103d04804883df2c88
* Revert "init: Terminate gracefully when CAP_SYS_BOOT is absent"Guang Zhu2017-06-281-23/+0
| | | | | | | | Bug: 63080844 This reverts commit 683ebc805982a6dbffd94d8a631c75e66c239a67. Change-Id: I6074ff09300fd30bfc66881ded1c4f868a845a91
* init: Terminate gracefully when CAP_SYS_BOOT is absentLuis Hector Chavez2017-06-271-0/+23
| | | | | | | | | | | This change makes it possible for Android running in a container to terminate cleanly instead of calling abort() when requested to shut down. Bug: 62388055 Test: setprop sys.powerctl reboot makes init terminate nicely Change-Id: I31c7b475d89d7cbd665e135d9b8951dfd4bca80d
* init: create android::init:: namespaceTom Cherry2017-06-231-0/+6
| | | | | | | | With some small fixups along the way Test: Boot bullhead Test: init unit tests Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
* add ueventd to shutdown critial processKeun-young Park2017-05-181-1/+1
| | | | | | | | | - In some devices, some drivers still try to load firmware while shutting down, and crashes the kernel. So keep ueventd to prevent such case. bug: 38203024 Test: reboots Change-Id: I4f1910723254ccb69f8e9c78e8727fbd8c7eed3e
* Merge "init: fix last_reboot_reason string"Treehugger Robot2017-04-271-3/+1
|\
| * init: fix last_reboot_reason stringTom Cherry2017-04-261-3/+1
| | | | | | | | | | | | | | | | This got moved when refactoring the reboot commands. Bug: 37540660 Test: verify bullhead's last_reboot_reason is correct Change-Id: I3b86496fc469ca41645df7e7ba8bb51dd25b6b38
* | Merge "set default shutdown timeout to 6 secs"Keun-young Park2017-04-261-2/+1
|\ \
| * | set default shutdown timeout to 6 secsKeun-young Park2017-04-261-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Test data shows that most shutdown finishes in 6 secs. - The original 10 secs is too long wih no shutdown animation running in screen. bug: 36657139 Test: check time with reboot Change-Id: I9a805ddfde8156b066485902048d0cd01365c453
* | | Merge "do not start shutdown animation from init"Treehugger Robot2017-04-261-9/+0
|\ \ \ | |/ / |/| |
| * | do not start shutdown animation from initKeun-young Park2017-04-191-9/+0
| |/ | | | | | | | | | | | | | | | | - init will only keep animation related services as shutdown critical. - external component like system server can start shutdown animation. bug: 37500823 Test: reboot Change-Id: Ief328306eba7e3b15402ae27e6236767095f508c
* / add additional dump for timeoutKeun-young Park2017-04-261-3/+7
|/ | | | | | | | | | - add sysrq-trigger current tasks dump - This helps detecting kernel thread stuck in a specific driver bug: 37573746 Test: python packages/services/Car/tools/bootanalyze/bootanalyze.py -r -c packages/services/Car/tools/bootanalyze/config.yaml -n 2000 -f -e 15 -w 30 -v -a Change-Id: Icb20b5fba63d601bb937f004f5889a9bc8340b34
* init: handle sys.powerctl immediatelyTom Cherry2017-04-171-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently if a process sets the sys.powerctl property, init adds this property change into the event queue, just like any other property. The actual logic to shutdown the device is not executed until init gets to the action associated with the property change. This is bad for multiple reasons, but explicitly causes deadlock in the follow scenario: A service is started with `exec` or `exec_start` The same service sets sys.powerctl indicating to the system to shutdown The same service then waits infinitely In this case, init doesn't process any further commands until the exec service completes, including the command to reboot the device. This change causes init to immediately handle sys.powerctl and reboot the device regardless of the state of the event queue, wait for exec, or wait for property conditions. Bug: 37209359 Bug: 37415192 Test: Init reboots normally Test: Update verifier can reboot the system Change-Id: Iff2295aed970840f47e56c4bacc93001b791fa35
* reboot: fix owner and permissions of last_reboot_reason fileTodd Poynor2017-04-131-1/+3
| | | | | | | | | Default signature WriteStringToFile creates world-writeable files. Set owner and group system and remove read/write for non-owner. Bug: 37251463 Test: Manual: reboot, inspect Change-Id: I6a29c678168dcae611b120dc52170f4eee7069a9
* poll umount completion from /proc/mountsKeun-young Park2017-04-101-138/+115
| | | | | | | | | | | | | | | | | | | | | - umount operation is asynchronous except for root partition. Returning from umount does not guarantee completion of umount. Poll /proc/mounts to confirm completion of umount. - Treat all devices mounting to /data as emulated devices. This is future proof when fs other than sdcardfs is used. - Drop quota sync from sync step. There is no differences in frequencies of quota error. - Run umount in reverse order from mounting order so that any hidden dependency can be auto-resolved. - Add dump of lsof and /proc/mounts when umount fails. lsof only runs when selinux is toggled into permissive mode. The dump is enabled only for non-user build. - Keep logcat until vold shutdown in case vold has any error to report. bug: 36551218 Test: python packages/services/Car/tools/bootanalyze/bootanalyze.py -r -c packages/services/Car/tools/bootanalyze/config.yaml -n 1000 -f -e 20 -w 30 Change-Id: I87b17b966d7004c205452d81460b02c6acf50d45
* init: more header cleanupTom Cherry2017-04-061-4/+4
| | | | | | | | | | Remove includes of "log.h" that really want <android-base/logging.h> Fix header include order Remove headers included in .cpp files that their associated .h already includes Remove some unused headers Test: boot bullhead Change-Id: I2b415adfe86a5c8bbe4fb1ebc53c7b0ee2253824
* add shutdown animationKeun-young Park2017-03-311-18/+35
| | | | | | | | | | | | | | - Run shutdown animation during shutdown if surfaceflinger is available / running. - services necessary for animation should be added to animation class. - Keep debugging tools while non-critical services are terminated: logd, adbd, tombstoned bug: 36526187 Test: many reboots Change-Id: I758f700a622c6005f3df9f29de2b55270055ad4d