History log of /system/core/init/util.cpp
Revision Date Author Comments (<<< Hide modified files) (Show modified files >>>)
682f8ba398aaba3f6d1aab493233fcfd7bd0e7c4 17-Apr-2017 Bowgo Tsai <bowgotsai@google.com> init: moving early mount logic into init_first_stage.cpp

Also renames "early mount" to "first stage mount" to prevent confusion
with "mount_all --early", which is run in the init second stage.

Also creates a base class: FirstStageMount and two derived classes:
FirstStageMountVBootV1 and FirstStageMountVBootV2 to replace/refactor
existing functions:

- early_mount() -> DoFirstStageMount() and FirstStageMount::DoFirstStageMount()

- vboot_1_0_early_partitions -> FirstStageMountVBootV1::GetRequiredDevices()
- vboot_2_0_early_partitions -> FirstStageMountVBootV2::GetRequiredDevices()

- vboot_1_0_mount_partitions ->
FirstStageMount::MountPartitions() and
FirstStageMountVBootV1::SetUpDmVerity()

- vboot_2_0_mount_partitions ->
FirstStageMount::MountPartitions() and
FirstStageMountVBootV2::SetUpDmVerity()

Bug: 37413399
Test: first stage mount /vendor with vboot 2.0 (avb) on bullhead
Test: first stage mount /system with without verity on bullhead
Test: first stage mount /vendor with vboot 1.0 on sailfish
Change-Id: I6584bdf7d832c9fbc8740f97c9b8b94e68a90783
Merged-In: I6584bdf7d832c9fbc8740f97c9b8b94e68a90783
(cherry picked from commit d262017fef0761e6cf6d1e449fa088338cdc68e6)
/system/core/init/util.cpp
67f6a530badb4bcc92ac6bf6766e22aca851cea2 28-Dec-2016 Yongqin Liu <yongqin.liu@linaro.org> init: use read_file and write_file to implement do_copy builtin

this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Bug: 36726045
Bug: 36576280
Test: manual with hikey
Test: boot and init tests on bullhead
Test: cast with fugu, per b/36726045
Merged-In: If3c30a2fff58cfece2fcd27e69c30382146e6808

Change-Id: If3c30a2fff58cfece2fcd27e69c30382146e6808
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
(cherry picked from commit dbe88e7953ed53961056c7f5531d91d229293462)
/system/core/init/util.cpp
ef52ae14abaf091b1bece89656d80850b497e084 01-Apr-2017 Tom Cherry <tomcherry@google.com> init: Use std::string for write_file()

The content parameter of write_file() previously took a char* that was
then converted to a std::string in WriteStringToFd(). One unfortunate
effect of this, is that it is impossible to write data that contains
'\0' within it, as the new string will only contain characters up
until the '\0'.

This changes write_file() to take an std::string, such that
std::string::size() is used to determine the length of the string,
allowing it to contain null characters.

Also change the path parameter of read_file() and write_file() for
consistency.

Lastly, add a test for handling strings with '\0' in them.

Bug: 36726045
Bug: 36576280
Test: Boot bullhead, run unit tests
Change-Id: Idad60e4228ee2de741ab3ab6a4917065b5e63cd8
(cherry picked from commit 53089aa25ca9707e22e45e862f794bfc958d302a)
/system/core/init/util.cpp
281531bdcbfc99128d54fc5220488a5a6612079b 31-Mar-2017 Wonsik Kim <wonsik@google.com> Revert "init: use read_file and write_file to implement do_copy builtin"

Bug: 36726045
Test: gts-tradefed run gts --abi x86 -m GtsMediaTestCases -t com.google.android.media.gts.MediaCodecCencTest#testCENC_DASH_FMP4_H264_360P_PLAYREADY_CENC
This reverts commit 82bac0de6d95bcdf45729516f6a4f29eb2681118.

Change-Id: I3b754f429499daec804a0ad25529294216c39a40
/system/core/init/util.cpp
e249097f6d85be2680b9a2898ff67548d47f9a70 29-Mar-2017 Tom Cherry <tomcherry@google.com> init: replace property_get with its android::base equivalent

Slowly try to decouple property_service.cpp from the rest of init.

Test: Boot bullhead
Change-Id: I267ae0b057bca0bf657b97cb8bfbb18199282729
(cherry picked from commit ccf23537eeacfa47e5f18dd3b75089886d177c1b)
/system/core/init/util.cpp
7f0d15a6f23172657974ad94ba7bbb49cc5df79b 24-Mar-2017 Treehugger Robot <treehugger-gerrit@google.com> Merge "init: use read_file and write_file to implement do_copy builtin"
82bac0de6d95bcdf45729516f6a4f29eb2681118 28-Dec-2016 Yongqin Liu <yongqin.liu@linaro.org> init: use read_file and write_file to implement do_copy builtin

this will make the implementation more cleaner,
and has error message output when failed on some operations

also add the O_TRUNC flag explicitly for the open function
called in write_file.

And add more test on read_file and write_file functions

Test: manual with hikey

Change-Id: Ifc1086a20e85db6980b497b1150a8a7952e672d6
Signed-off-by: Yongqin Liu <yongqin.liu@linaro.org>
/system/core/init/util.cpp
8d01f63f50fb001f41835a0dab636981f2ba76dd 13-Mar-2017 Keun-young Park <keunyoung@google.com> remove emergency shutdown and improve init's reboot logic

- Emergency shutdown just marks the fs as clean while leaving fs
in the middle of any state. Do not use it anymore.

- Changed android_reboot to set sys.powerctl property so that
all shutdown can be done by init.

- Normal reboot sequence changed to
1. Terminate processes (give time to clean up). And wait for
completion based on ro.build.shutdown_timeout.
Default value (when not set) is changed to 3 secs. If it is 0, do not
terminate processes.
2. Kill all remaining services except critical services for shutdown.
3. Shutdown vold using "vdc volume shutdown"
4. umount all emulated partitions. If it fails, just detach.
Wait in step 5 can handle it.
5. Try umounting R/W block devices for up to max timeout.
If it fails, try DETACH.
If umount fails to complete before reboot, it can be detected when
system reboots.
6. Reboot

- Log shutdown time and umount stat to log so that it can be collected after reboot

- To umount emulated partitions, all pending writes inside kernel should
be completed.
- To umount /data partition, all emulated partitions on top of /data should
be umounted and all pending writes should be completed.
- umount retry will only wait up to timeout. If there are too many pending
writes, reboot will discard them and e2fsck after reboot will fix any file system
issues.

bug: 36004738
bug: 32246772

Test: many reboots combining reboot from UI and adb reboot. Check last_kmsg and
fs_stat after reboot.

Change-Id: I6e74d6c68a21e76e08cc0438573d1586fd9aaee2
/system/core/init/util.cpp
40578ab91f48f0654ca71cd147d0ab9359478b4b 20-Mar-2017 Tom Cherry <tomcherry@google.com> init: Fix leaking fd and error print

read_file() does not close its fd if either stat() fails or the file
has group/world writable permissions.

Use unique_fd to ensure that all return paths close the fd and make
the same change to write_file() for consistency.

Replace PLOG() with LOG() after a simple if conditional, that does not
set errno.

Old:
init: skipping insecure file '/data/bootchart/header': No such device or address
New:
init: skipping insecure file '/data/bootchart/header'

Test: Cause an invalid file read and check the error log
Test: Ensure non-error read_file() and write_file() work
Change-Id: Ib15d94e38362e335d671d30b36aa5605254ec7ab
/system/core/init/util.cpp
c8ac0677734270f0b12d85ecf23b1de49054890c 14-Feb-2017 James Hawkins <jhawkins@google.com> Revert "bootstat: Refactor init/utils/boot_clock into base/chrono_utils."

This reverts commit 7c92e484503f239000ef97ef5b067907fbeaa4a6.

Mac sdk still broken (despite testing locally).

Change-Id: I7d9206e15997cd0efe081bd3fa17d53d2b20ec32
/system/core/init/util.cpp
7c92e484503f239000ef97ef5b067907fbeaa4a6 14-Feb-2017 James Hawkins <jhawkins@google.com> bootstat: Refactor init/utils/boot_clock into base/chrono_utils.

Use this for bootstat and init. This replaces the custom uptime parser in
bootstat.

This is a reland of aosp/332854 with a fix for Darwin.

Bug: 34352037
Test: chrono_utils_test
Change-Id: Ib2567d8df0e460ab59753ac1c053dd7f9f1008a7
/system/core/init/util.cpp
0e3167e203ae89817cc30ba4a5a2d328716b4826 08-Feb-2017 James Hawkins <jhawkins@google.com> Revert "bootstat: Remove custom uptime parser in favor of elapsedRealtime."

This reverts commit 26f40c04c3ad80e2bc449990010d39d1c1b9a5f0.

This change broke the Darwin SDK target.

Test: none
Change-Id: Ia54fe2c31da8d8fa2825e023b035fb8321dcd457
/system/core/init/util.cpp
26f40c04c3ad80e2bc449990010d39d1c1b9a5f0 06-Feb-2017 James Hawkins <jhawkins@google.com> bootstat: Remove custom uptime parser in favor of elapsedRealtime.

Refactored init/utils/boot_clock into base/chrono_utils.

Bug: 34352037
Test: none
Change-Id: Ied0c00867336b85922369d7ff37520e3d28fc61e
/system/core/init/util.cpp
77f0e9fda8839a21a4d360f128fe9af820b8819c 28-Dec-2016 Jorge Lucangeli Obes <jorgelo@google.com> init: Make 'write_file' return bool to match 'read_file'.

The mismatch of return values makes reasoning about the correctness of
CLs like https://android-review.googlesource.com/317923 quite hard.

Bug: 33941660
Test: Init builds, HiKey boots.
Change-Id: Ia4b8a9af420682997b154a594892740181980921
/system/core/init/util.cpp
978fd0ea254f11f84e38b41a74bbe70c81edc197 02-Dec-2016 Mark Salyzyn <salyzyn@google.com> init: service file command only opens existing files

Mixing open or create, along with attribute(MAC) and permissions(DAC)
is a security and confusion issue.

Fix an issue where fcntl F_SETFD was called to clear O_NONBLOCK, when
it should have been F_SETFL. Did not present a problem because the
current user of this feature does writes and control messages only.

Test: gTest logd-unit-tests and check dmesg for logd content.
Bug: 32450474
Bug: 33242020
Change-Id: I23cb9a9be5ddb7e8e9c58c79838bc07536e766e6
/system/core/init/util.cpp
331cf2fb7c16b5b25064f8d2f00284105a9b413f 29-Nov-2016 Elliott Hughes <enh@google.com> Replace the "coldboot" timeout with a property.

Also rename init's existing boot-time related properties so they're
all "ro.*" properties.

Example result:

# Three properties showing when init started...
[ro.boottime.init]: [5294587604]
# ...how long it waited for ueventd...
[ro.boottime.init.cold_boot_wait]: [646956470]
# ...and how long SELinux initialization took...
[ro.boottime.init.selinux]: [45742921]

# Plus one property for each service, showing when it first started.
[ro.boottime.InputEventFind]: [10278767840]
[ro.boottime.adbd]: [8359267180]
[ro.boottime.atfwd]: [10338554773]
[ro.boottime.audioserver]: [10298157478]
[ro.boottime.bootanim]: [9323670089]
[ro.boottime.cameraserver]: [10299402321]
[ro.boottime.cnd]: [10335931856]
[ro.boottime.debuggerd]: [7001352774]
[ro.boottime.debuggerd64]: [7002261785]
[ro.boottime.drm]: [10301082113]
[ro.boottime.fingerprintd]: [10331443314]
[ro.boottime.flash-nanohub-fw]: [6995265534]
[ro.boottime.gatekeeperd]: [10340355242]
[ro.boottime.healthd]: [7856893380]
[ro.boottime.hwservicemanager]: [7856051088]
[ro.boottime.imscmservice]: [10290530758]
[ro.boottime.imsdatadaemon]: [10358136702]
[ro.boottime.imsqmidaemon]: [10289084872]
[ro.boottime.installd]: [10303296020]
[ro.boottime.irsc_util]: [10279807632]
[ro.boottime.keystore]: [10305034093]
[ro.boottime.lmkd]: [7863506714]
[ro.boottime.loc_launcher]: [10324525241]
[ro.boottime.logd]: [6526221633]
[ro.boottime.logd-reinit]: [7850662702]
[ro.boottime.mcfg-sh]: [10337268315]
[ro.boottime.media]: [10312152687]
[ro.boottime.mediacodec]: [10306852530]
[ro.boottime.mediadrm]: [10308707999]
[ro.boottime.mediaextractor]: [10310681177]
[ro.boottime.msm_irqbalance]: [7862451974]
[ro.boottime.netd]: [10313523104]
[ro.boottime.netmgrd]: [10285009351]
[ro.boottime.oem_qmi_server]: [10293329092]
[ro.boottime.per_mgr]: [7857915776]
[ro.boottime.per_proxy]: [8335121605]
[ro.boottime.perfd]: [10283443101]
[ro.boottime.qcamerasvr]: [10329644772]
[ro.boottime.qmuxd]: [10282346643]
[ro.boottime.qseecomd]: [6855708593]
[ro.boottime.qti]: [10286196851]
[ro.boottime.ril-daemon]: [10314933677]
[ro.boottime.rmt_storage]: [7859105047]
[ro.boottime.servicemanager]: [7864555881]
[ro.boottime.ss_ramdump]: [8337634938]
[ro.boottime.ssr_setup]: [8336268324]
[ro.boottime.surfaceflinger]: [7866921402]
[ro.boottime.thermal-engine]: [10281249924]
[ro.boottime.time_daemon]: [10322006542]
[ro.boottime.ueventd]: [5618663938]
[ro.boottime.vold]: [7003493920]
[ro.boottime.wificond]: [10316641073]
[ro.boottime.wpa_supplicant]: [18959816881]
[ro.boottime.zygote]: [10295295029]
[ro.boottime.zygote_secondary]: [10296637269]

Bug: http://b/31800756
Test: boots
Change-Id: I094cce0c1bab9406d950ca94212689dc2e15dba5
/system/core/init/util.cpp
a8d8434c42b27f0186be7ecd78c2acc9d459b068 15-Nov-2016 Paul Lawrence <paullawrence@google.com> Add flags to restorecon_recursive to traverse filesystems

Use to solve the problem of tracefs conditionally being mounted
under debugfs and needing restorecon'd without boot performance
penalty.

Also move skip-ce to a flag for consistency.

Test: Check that trace_mount has correct attributes after boot
Bug: 32849675
Change-Id: Ib6731f502b6afc393ea5ada96fa95b339f14da49
/system/core/init/util.cpp
d1d3bdd16fbaae87e0cfdb8d412f226e4aa390cf 16-Jul-2016 Jeff Sharkey <jsharkey@android.com> Only restorecon CE storage after unlocked.

On FBE devices, the filenames inside credential-encrypted directories
are mangled until the key is installed. This means the initial
restorecon at boot needs to skip these directories until the keys
are installed.

This CL changes the implementation of the "restorecon_recursive"
built-in command to use the new SKIPCE flag to avoid labeling files
in CE directories. vold will request a restorecon when the keys
are actually installed.

(cherrypicked from commit 1635afe83d1ebd6b5f1fac1e9c6c6b5cd1c93204)

Bug: 30126557
Test: Cherry-picked from master
Change-Id: I320584574a4d712c493b5bbd8a79b56c0c04aa58
/system/core/init/util.cpp
290a228fdca935ab2e702db77516758314900c3a 15-Nov-2016 Elliott Hughes <enh@google.com> Switch fastboot/init/libprocessgroup to std::this_thread::sleep_for.

Bug: http://b/32878766
Test: boots
Change-Id: Ie0ddfb7e60f2da5f6eefbb10c83a92e88c137ae3
/system/core/init/util.cpp
9605a945f7a497c0307b512b9cd762f2d23973ca 11-Nov-2016 Elliott Hughes <enh@google.com> init start time tracking.

With this change, init sets a property "init.start" to show the
CLOCK_BOOTTIME time at which init itself started, and for each service
an "init.svc.<name>.start" property to show the CLOCK_BOOTTIME time at
which that service was most recently started.

These times can be used by tools like bootstat to track boot time.

As part of this change, move init over to std::chrono. Also, rather than
make the command-line argument handling more complex, I've switched to
using an environment variable for communication between first- and
second-stage init, and added another environment variable to pass the
start time of the first stage through to the second stage.

Bug: http://b/32780225
Test: manual
Change-Id: Ia65a623e1866ea688b9a5433d6507926ce301dfe
/system/core/init/util.cpp
db69107de6e16c2b5e636063a2032eb215f53854 07-Nov-2016 Mark Salyzyn <salyzyn@google.com> init: errno handling in create_file

Save errno before resetting global context. Use unique_fd.

Test: gTest init_tests
Bug: 32450474
Change-Id: If45eeaebc3ae379f84bf3ffa3c40194043191854
/system/core/init/util.cpp
62767fe29f8aaf62470781a3cf419ba11187d178 27-Oct-2016 Mark Salyzyn <salyzyn@google.com> init: service file keyword

Solve one more issue where privilege is required to open a file and
we do not want to grant such to the service. This is the service side
of the picture, android_get_control_file() in libcutils is the client.
The file's descriptor is placed into the environment as
"ANDROID_FILE_<path>". For socket and files where non-alpha and
non-numeric characters in the <name/path> are replaced with _. There
was an accompanying change in android_get_control_socket() to match
in commit 'libcutils: add android_get_control_socket() test'

Add a gTest unit test for this that tests create_file and
android_get_control_file().

Test: gTest init_tests --gtest_filter=util.create_file
Bug: 32450474
Change-Id: I96eb970c707db6d51a9885873329ba1cb1f23140
/system/core/init/util.cpp
f39f7f14281c1b98524c740cd8f50905da86cdb9 31-Aug-2016 Elliott Hughes <enh@google.com> Use android::base::Readlink in init.

Bug: http://b/30988271
Change-Id: Ia0000e9dd7883c31ccbd54fc01bf585c3f8b3fa7
/system/core/init/util.cpp
8f7b9e3d39cdae8363816aa7bcbab0d79fd70cea 28-Jul-2016 Chih-Hung Hsieh <chh@google.com> Fix clang-tidy performance warnings in syste/core.

* Use const reference type for parameters to avoid unnecessary copy.
* Suppress warning of not using faster overloaded string find function.

Bug: 30407689
Bug: 30411878
Change-Id: I6cfdbbd50cf5e8f3db6e5263076d3a17a9a791ee
Test: build with WITH_TIDY=1
Merged-In: Ie79dbe21899867bc62031f8618bb1322b8071525
/system/core/init/util.cpp
171a829c39d9298432505fe943ad7128aeefe2b2 30-Jun-2016 Elliott Hughes <enh@google.com> Make klog_fd thread-safe and make klog_init a no-op.

I'll come back and remove klog_init when I've removed other calls to it.

Change-Id: Iad7fd26d853b4ddc54e9abd44516b6f138cbbfcb
Test: booted N9, looked at "adb shell dmesg" output.
/system/core/init/util.cpp
f86b5a6b90619e02d1d034ef7b0adc3b439f4abb 25-Jun-2016 Elliott Hughes <enh@google.com> Move init to libbase logging.

Change-Id: Ibfbefeff587a69e948978a037c555fd12a5ade6a
/system/core/init/util.cpp
3195116e9718a4159f4149bcdc0d2a85339fcbf5 25-Jun-2016 Elliott Hughes <enh@google.com> Remove MTD cruft from init.

Bug: http://b/29250988
Change-Id: I38ab263192944e4ff291fd91b25db163a8848d75
/system/core/init/util.cpp
4b56162a33dbe36cce179e40afd0409072c10348 07-Jun-2016 Mark Salyzyn <salyzyn@google.com> init: Add support for ${x.y:-default} expansion

commit 00ede7d2626f9343d330dc6f5286bba3e99e41d0 (init: do
expand_props before calling the builtins) broke logpersist

Bug: 28120456
Bug: 22654233
Change-Id: Ib4d8231665b26ac083b02243177493fab41c8978
/system/core/init/util.cpp
3792e6cf21f0c9fbf64898ec68350e942923f33d 07-Apr-2016 William Roberts <william.c.roberts@intel.com> init: switch from android_ids to getpwnam

Start to move users of android_filesystem_config.h to use the
standard grp and pwd interface functions.

Advantages:
* one copy of android_ids in libc, removing it from init objects.
* immediately starts oem_xxx users and groups in rc.
* future will support _named_ oem ids via backend improvements.

Change-Id: Ib1ae1e0cbdcaaf60deb3759681a6030b615c069c
Bug: 27999086
Signed-off-by: William Roberts <william.c.roberts@intel.com>
/system/core/init/util.cpp
a27bbd272810e147f2d847cafb6e1ed4ee6fc8e0 24-Mar-2016 Dan Austin <danielaustin@google.com> Fix const issues in preparation for libcxx rebase.

Change-Id: Id57474eb63334873ee5383f61eb918941dbb0984
/system/core/init/util.cpp
3d9e27335926497c82bcfab228b90b84d732780f 03-Mar-2016 Nick Kralevich <nnk@google.com> Mount selinuxfs when other filesystems are mounted

Be consistent when mounting filesystems, and mount selinuxfs
at the same time other filesystems are mounted. In particular,
this ensures that a /sys/fs/selinux/null is available at early
boot, avoiding an unnecessary mknod call.

Change-Id: I01e6b3900f48b4cb3f12d8a928e1e95911524252
/system/core/init/util.cpp
9bcfd64b59f71641567464632b393dcd8aca6512 25-Feb-2016 Nick Kralevich <nnk@google.com> init: harden socket creation against symlinks

Instead of using chown, use the symlink safe lchown.

Instead of using chmod, use the symlink safe fchmodat
with AT_SYMLINK_NOFOLLOW.

Fix a bug where the SELinux filesystem creation context may
not be restored, and some memory not freed, if bind() fails.

Check the return values from the chown/chmod calls and unlink
the files if it ever fails.

(cherrypicked from commit ab5629c197ae278992039a9685df047fe34232b8)

Bug: 27337831
Change-Id: I28c5f4dee55aa706437eb51ad403c1fbf56138de
/system/core/init/util.cpp
4f71319df011d796a60a43fc1bc68e16fbf7d321 05-Dec-2015 Elliott Hughes <enh@google.com> Track rename of base/ to android-base/.

Change-Id: Idf9444fece4aa89c93e15640de59a91f6e758ccf
/system/core/init/util.cpp
83ccb1c76b2b88f62bfba2c58e2edd419b089756 24-Nov-2015 Nick Kralevich <nnk@google.com> init: Don't ignore setsockcreatecon errors

The init language supports setting the creation context of a socket
as the 6th argument to the socket keyword. For example, in the
following service, the context associated with the netd socket
is u:r:netd:s0

service netd /system/bin/netd
class main
socket netd stream 0660 root system u:r:netd:s0
socket dnsproxyd stream 0660 root inet
socket mdns stream 0660 root system
socket fwmarkd stream 0660 root inet

The 6 argument form of the socket statement is rarely if ever used,
since the init code supplies a sensible default.

Currently, there's no error checking on the value supplied as
the 6th argument. For example, if you have the following socket
statement:

socket netd stream 0660 root system graphics

a socket will attempt to get created with an invalid "graphics"
context. When setsockcreatecon fails, it retains the default socket
creation context, which for init is u:r:init:s0. This results in a
socket being created which is in an unexpected context.

Check the return value from the setsockcreatecon() call. If an
invalid context is specified, return early and don't subsequently
attempt to create the socket with the default context.

Bug: 25851205
Change-Id: Ic66cd6f7efe3897fb247b587ddeac5d35e1602b7
/system/core/init/util.cpp
cda81d01c6d8df84c67e5a2391356bb8407921dc 01-Sep-2015 Tom Cherry <tomcherry@google.com> am 54c70ca1: Merge "init: Use classes for parsing and clean up memory allocations"

* commit '54c70ca15660529466b5b4e091209a20a3e75dff':
init: Use classes for parsing and clean up memory allocations
b7349902a945903f9e36a569051f5131beb0bc24 26-Aug-2015 Tom Cherry <tomcherry@google.com> init: Use classes for parsing and clean up memory allocations

Create a Parser class that uses multiple SectionParser interfaces to
handle parsing the different sections of an init rc.

Create an ActionParser and ServiceParser that implement SectionParser
and parse the sections corresponding to Action and Service
classes.

Remove the legacy keyword structure and replace it with std::map's
that map keyword -> (minimum args, maximum args, function pointer) for
Commands and Service Options.

Create an ImportParser that implements SectionParser and handles the
import 'section'.

Clean up the unsafe memory handling of the Action class by using
std::unique_ptr.

Change-Id: Ic5ea5510cb956dbc3f78745a35096ca7d6da7085
/system/core/init/util.cpp
42f669a144e2b92ff7473f802af66cd65dfd2a68 28-Jul-2015 Lee Campbell <leecam@google.com> am f75b5ff1: am fe39394e: Merge "init: Adding support to import directories"

* commit 'f75b5ff17529e3eb163b9c7c49fc49842d443126':
init: Adding support to import directories
f13b1b31399aa501514eb9beeef303d1ae2e0e14 25-Jul-2015 Lee Campbell <leecam@google.com> init: Adding support to import directories

Support added so init scripts can now import directories.

BUG: 22721249
Change-Id: I02b566bfb50ea84469f1ea0c6ad205435a1df286
TEST: Tested importing a folder on arm64 emulator
/system/core/init/util.cpp
7cba86656964f464c7500809c81bcb52f15b6759 19-Jun-2015 Nick Kralevich <nnk@google.com> am 8d855ba9: am d2e7f002: Merge "init/util.cpp: don\'t return a negative unsigned value"

* commit '8d855ba983d7e794fd75a20557ee92f4f8db2465':
init/util.cpp: don't return a negative unsigned value
d2104df69b464721a17c21b4cd27931dc3bca612 19-Jun-2015 Nick Kralevich <nnk@google.com> init/util.cpp: don't return a negative unsigned value

android_name_to_id() returns -1U on error, which causes a
crash when the following clang options are enabled:

-fsanitize=signed-integer-overflow,unsigned-integer-overflow
-ftrap-function=abort
-fsanitize-undefined-trap-on-error

Rather than returning a negative unsigned value (which doesn't
make a lot of sense, IMHO), return a positive unsigned value.

While we're here, add logging on decode_uid failures.

Bug: 21880301
Change-Id: I652e4c1daa07c7494cceca2b4e1656b9158f2604
/system/core/init/util.cpp
af02e2403af69769daee9ad4a06901bb3a05ac8d 27-May-2015 Elliott Hughes <enh@google.com> am 9fc83437: Don\'t use TEMP_FAILURE_RETRY on close in system/core.

* commit '9fc834377297cb2dcc418e4ce7e38e89dd09812b':
Don't use TEMP_FAILURE_RETRY on close in system/core.
9fc834377297cb2dcc418e4ce7e38e89dd09812b 16-May-2015 Elliott Hughes <enh@google.com> Don't use TEMP_FAILURE_RETRY on close in system/core.

Bug: http://b/20501816
Change-Id: I1839b48ee4f891b8431ecb809e37a4566a5b3e50
(cherry picked from commit 47b0134ec2b5e8c8b5b5671cd4a3e41261275532)
/system/core/init/util.cpp
604e75449d8a2138c920b2497c21dc400983f544 23-May-2015 Thierry Strudel <tstrudel@google.com> am 91cf41cf: init: wait_for_file use smaller time resolution

* commit '91cf41cf43847930a8e55b3789d4943a8e22f73a':
init: wait_for_file use smaller time resolution
91cf41cf43847930a8e55b3789d4943a8e22f73a 23-May-2015 Thierry Strudel <tstrudel@google.com> init: wait_for_file use smaller time resolution

As 1s timeout can be requested, using second resolution time to check
for timeout prevent from being accurate on the actual time we wait.
Use available gettime_ns instead.

Bug: 21374269
Change-Id: I8be1b69e02beacc7196427f97855e036addf54d1
Signed-off-by: Thierry Strudel <tstrudel@google.com>
/system/core/init/util.cpp
47b0134ec2b5e8c8b5b5671cd4a3e41261275532 16-May-2015 Elliott Hughes <enh@google.com> Don't use TEMP_FAILURE_RETRY on close in system/core.

Bug: http://b/20501816
Change-Id: I1839b48ee4f891b8431ecb809e37a4566a5b3e50
/system/core/init/util.cpp
2550355ceb2bd5e2815f333067e0ccff11fbf275 13-May-2015 Elliott Hughes <enh@google.com> resolved conflicts for merge of d410a9b3 to mnc-dev-plus-aosp

Change-Id: I2e8e6c9a2024e0a753d3912111ccd1c2bfbfef10
cce7e93b287835ffe9cdc3dad3fac52972d84560 12-May-2015 Tom Cherry <tomcherry@google.com> Fix insmod module size

read_file() used to append a new line character to the end of the buffer it
returns, because parse_config() isn't able to cope with input that's not
'\n'-terminated. Fix read_file() to be less insane, and push the workarounds
into the parse_config() callers.

Longer term we should rewrite parse_config().

Bug: http://b/21079470
Change-Id: Ie9d9a7adcd33b66621726aef20c4b8cc51c08be7
(cherry picked from commit eaa3b4ec6f79fe06163b8dd6fe8ba2581d3b9c0b)
/system/core/init/util.cpp
eaa3b4ec6f79fe06163b8dd6fe8ba2581d3b9c0b 12-May-2015 Tom Cherry <tomcherry@google.com> Fix insmod module size

read_file() used to append a new line character to the end of the buffer it
returns, because parse_config() isn't able to cope with input that's not
'\n'-terminated. Fix read_file() to be less insane, and push the workarounds
into the parse_config() callers.

Longer term we should rewrite parse_config().

Change-Id: Ie9d9a7adcd33b66621726aef20c4b8cc51c08be7
/system/core/init/util.cpp
b7f8b91040cc0910ca12b51ad7318515595705af 09-May-2015 Andres Morales <anmorales@google.com> am 86aeb11e: Merge "load ro.recovery_id property from recovery partition" into mnc-dev

* commit '86aeb11ed047b3698948c4eee8fbaccd20131ecb':
load ro.recovery_id property from recovery partition
cb3fce80fafa2848fd4962d9f242c21eef3d82f9 08-May-2015 Andres Morales <anmorales@google.com> load ro.recovery_id property from recovery partition

Change-Id: I9dc1f325e353375d9c1c8ed949636e2404601076
(cherry picked from commit db5f5d43679546ecde2b85151c0a8b8ccd605b07)
/system/core/init/util.cpp
db5f5d43679546ecde2b85151c0a8b8ccd605b07 08-May-2015 Andres Morales <anmorales@google.com> load ro.recovery_id property from recovery partition

Change-Id: I9dc1f325e353375d9c1c8ed949636e2404601076
/system/core/init/util.cpp
fdf2546ae7f5a58a0f846acd17c943cd9a2dadd8 07-May-2015 Elliott Hughes <enh@google.com> am a5aa7a11: am 55c2e1f4: Merge "Clean up init /proc/cmdline handling."

* commit 'a5aa7a11266f1d407275b78981fc864c6c863358':
Clean up init /proc/cmdline handling.
e5ce30fed81d1918a259be092dcd8bfffc3c2649 07-May-2015 Elliott Hughes <enh@google.com> Clean up init /proc/cmdline handling.

Helped debug a problem where the N9 bootloader incorrectly
concatenated the various command lines.

Bug: http://b/20906691
Change-Id: I0580b06f4185129c7eedf0bdf74b5ce17f88bf9c
/system/core/init/util.cpp
eab1e21996884fb1918e696efd21c175d96f6195 27-Apr-2015 Nick Kralevich <nnk@google.com> am ecf184c9: am 9c9280d8: Merge "init: get rid of the remaining double mounts"

* commit 'ecf184c901b78994773d687763c1478752e9375e':
init: get rid of the remaining double mounts
14adea307d86507fabdbb61a1ca27cf846f1f73e 27-Apr-2015 Nick Kralevich <nnk@google.com> am 45a49d0e: am ccac2be8: Merge "init: use SELinux /dev/null if available"

* commit '45a49d0eb7e2e9fc3d2c48884c84f6a6c7397720':
init: use SELinux /dev/null if available
ada332e4a01a3bb290be26f8a5b67993bd10af14 26-Apr-2015 Nick Kralevich <nnk@google.com> am ecf184c9: am 9c9280d8: Merge "init: get rid of the remaining double mounts"

* commit 'ecf184c901b78994773d687763c1478752e9375e':
init: get rid of the remaining double mounts
ec9bd166cc406d8079b7d33d04b3e04708183d96 26-Apr-2015 Nick Kralevich <nnk@google.com> am 45a49d0e: am ccac2be8: Merge "init: use SELinux /dev/null if available"

* commit '45a49d0eb7e2e9fc3d2c48884c84f6a6c7397720':
init: use SELinux /dev/null if available
f667a3247a7e814355feedbc08c6bbc92a9409b5 26-Apr-2015 Nick Kralevich <nnk@google.com> init: get rid of the remaining double mounts

Don't double mount /dev and its subdirectories anymore. Instead, the
first stage init is solely responsible for mounting it.

Don't have init prepare the property space. This is the responsibility
of the second stage init.

Don't have SELinux use the property space to determine how we should
be running. Instead, create a new function and extract the data we
need directly from /proc/cmdline. SELinux needs this information in
the first stage init process where the property service isn't available.

Change-Id: I5b4f3bec79463a7381a68f30bdda78b5cc122a96
/system/core/init/util.cpp
e34577ce1bd4a8de53ff3d9178b4f78c86086dc8 26-Apr-2015 Nick Kralevich <nnk@google.com> init: use SELinux /dev/null if available

SELinux provides it's own /dev/null character device at
/sys/fs/selinux/null. This character device is exactly the same
as /dev/null, including the same major/minor numbers, and can
be used wherever /dev/null is used.

Use /sys/fs/selinux/null instead of trying to create our own
/dev/__null__ device. This moves us one step closer to eliminating
all uses of mknod() by init.

/sys/fs/selinux/null is only available once the /sys/fs/selinux filesystem
is mounted. It's not available to the first stage init, so we
still have to fall back to mknod then.

Change-Id: Ic733767ea6220a130537de33cc478ae79578ce20
/system/core/init/util.cpp
2ae7d4eefddf2cd7ac4bba60fb6d057e2b01731b 26-Apr-2015 Nick Kralevich <nnk@google.com> am 6b6df173: am f8b0743e: Merge "init: fix write_file checkreqprot logic error"

* commit '6b6df1733711ace006e0f4f9d44c718f85d2f70d':
init: fix write_file checkreqprot logic error
eedbe81f753fd19e5eb2238187c5618e9153bf55 25-Apr-2015 Nick Kralevich <nnk@google.com> init: fix write_file checkreqprot logic error

write_file() returned -errno on error, not -1. Callers who check for
-1 would falsely believe that the write was successful when it wasn't.
Fixup write_file so that it return -1 on error consistent
with other functions.

Change-Id: Ic51aaf8678d8d97b2606bd171f11b3b11f642e39
/system/core/init/util.cpp
438443e742d9cfb91c1193144a3b41744ffad34b 14-Apr-2015 Ed Tam <etam@google.com> resolved conflicts for merge of 79f33846 to lmp-mr1-dev-plus-aosp

Change-Id: I24c60a2747931917a3ea09b953905ce0f4145280
da40c00137f75543a69972f1be506e2d14a41845 28-Mar-2015 Elliott Hughes <enh@google.com> Log more timing information from init.

Also make important events in init's life NOTICE rather than INFO,
and ensure that NOTICE events actually make it to the kernel log.

Also fix the logging so that if you have a printf format string
error, the compiler now catches it.

Also give messages from init, ueventd, and watchdogd distinct tags.
(Previously they'd all call themselves "init", and dmesg doesn't
include pids, so you couldn't untangle them.)

Also include the tag in SELinux messages.

Bug: 19544788
Change-Id: Ica6daea065bfdb80155c52c0b06f346a7df208fe
/system/core/init/util.cpp
bbc01d825448a738160716f95d9cc38f2be5f4f1 20-Mar-2015 Elliott Hughes <enh@google.com> Merge "Remove /proc/cpuinfo parsing"
c007bc3856a4cf86b8f610eb045f26a9dedc2894 16-Mar-2015 Dan Albert <danalbert@google.com> Revert "Revert "Create libbase.""

This reverts commit a7870d88167f619e758b5bcd15b410d16da7c16b.
/system/core/init/util.cpp
a7870d88167f619e758b5bcd15b410d16da7c16b 16-Mar-2015 Nicolas Geoffray <ngeoffray@google.com> Revert "Create libbase."

Breaks internal master.

This reverts commit 98ff77204cef9bb8f0f27420833233622060a09e.

Change-Id: I18dc6021cb43efff8aa88486c2d980dc2b8eedba
/system/core/init/util.cpp
98ff77204cef9bb8f0f27420833233622060a09e 14-Mar-2015 Dan Albert <danalbert@google.com> Create libbase.

Move StringPrintf and the string based file I/O from libutils to
libbase.

Change-Id: I0297a6063874b9d92100e0dd5123fddfbda932fe
/system/core/init/util.cpp
74b34f3cb79aa8f2c5ba6a9dcc46d0dd84cdac86 28-Feb-2015 Rom Lemarchand <romlem@android.com> Remove /proc/cpuinfo parsing

- Clean up the paths for ro.revision and ro.hardware parsing
- Use ro.hardwre in ueventd instead of parsing the kernel command line

(cherry-pick of 38b340a52f8e864650db8bae1eb88d5c00485db0.)

Bug: 19366018
Change-Id: I018a293f3d46e736a8b65132b5b00b0f7c20edae
/system/core/init/util.cpp
f682b4786a4093efb23bf80d69bf80eb274b145b 06-Feb-2015 Elliott Hughes <enh@google.com> Clean up reading and writing in init.

This isn't particularly useful in and of itself, but it does introduce the
first (trivial) unit test, improves the documentation (including details
about how to debug init crashes), and made me aware of how unpleasant the
existing parser is.

I also fixed a bug in passing --- unless you thought the "peboot" and "pm"
commands were features...

Bug: 19217569
Change-Id: I6ab76129a543ce3ed3dab52ef2c638009874c3de
/system/core/init/util.cpp
24627906bfee8c4a9eede3deefd12365a78351bf 04-Feb-2015 Elliott Hughes <enh@google.com> Use TEMP_FAILURE_RETRY, always build bootchart.cpp.

Also switch the revision parsing over to sscanf as promised. I haven't
done the hardware parsing because I don't yet know whether we actually need
to keep the space-stripping code.

Change-Id: Ic33378345cd515cb08d00c543acf44eb72673396
/system/core/init/util.cpp
f3cf438714aa1284d8a58e2f3b108ba93f6d3abb 04-Feb-2015 Elliott Hughes <enh@google.com> Build init as C++.

This is just the minimal change to keep it building.

Change-Id: I245c5b8413a1db114576c81462eb5737f5ffcef2
/system/core/init/util.cpp