Commit graph

16 commits

Author SHA1 Message Date
Tom Cherry
47031c8c88 ueventd: add no_fnm_pathname option
If a `*` appears within (but not at the end) of a /dev or /sys path in
a ueventd.rc file, then that path is matched with fnmatch() using the
FNM_PATHNAME, which means `*` will not match `/`.  That is not always
the intended behavior and this change creates the no_fnm_pathname
option, which will not use the FNM_PATHNAME flag and will have `*`
match `/`.

Bug: 172880724
Test: these unit tests
Change-Id: I85b813d89237dbf3af47564e5cbf6806df5d412f
2020-12-07 14:58:19 -08:00
Tom Cherry
7c1d87e490 init: fix clang-tidy performance issues
Test: boot, init unit tests
Change-Id: Iccf34d2fedfa543dd9f29e010cbb6d8fe9cf5983
2019-07-10 12:59:02 -07:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Bowgo Tsai
95591bd00e Removing block device by-num symlinks
The uevent.partition_num easily collides between partitions, for
example:

  Both /dev/block/sda3 and /dev/block/sdd3 will generate the same symlink:
    /dev/block/platform/soc/1da4000.ufshc/by-num/p3

This change remove those by-num symlinks as there seems no effective
user of it.

Bug: 78613232
Test: m init_tests && \
      adb push $OUT/data/nativetest64/init_tests/init_tests /data/. && \
      adb shell /data/init_tests

Change-Id: I8dfa8dc1a2f9fc9296aa30f33e905bf158b501de
2018-05-17 16:29:25 +08:00
Tom Cherry
c3692b3ea9 init: split security functions out of init.cpp
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
(cherry picked from commit 9afb86b25d8675927cb37c86119a7ecf19f74819)
2017-08-11 15:01:15 -07:00
Tom Cherry
b4dd881ffd ueventd: remove character device symlinks (/dev/usb/*)
While refactoring ueventd, I was looking for code the character device
symlinks (/dev/usb/*) that ueventd creates, such that I could test it
on a real device.  I found none in our tree, and history showing Xoom,
which was last supported years ago, was the last user.  If this code
is in fact obsolete, let's remove it.

Test: boot bullhead
Test: init unit tests

Change-Id: I601f7165eb06d36b31b6dcf69ee9e0a449d81a96
2017-06-26 13:58:57 -07:00
Tom Cherry
81f5d3ebef init: create android::init:: namespace
With some small fixups along the way

Test: Boot bullhead
Test: init unit tests
Change-Id: I7beaa473cfa9397f845f810557d1631b4a462d6a
2017-06-23 13:21:20 -07:00
Sandeep Patil
cd2ba0d184 Revert "Revert "ueventd: remove PlatformDeviceList""
This reverts commit 516ff99711.

Bug: 62864413
Bug: 62864413

Change-Id: Ie3980cd536c2c83adace063f0950128f68561105
Signed-off-by: Sandeep Patil <sspatil@google.com>
2017-06-21 15:04:57 -07:00
Tom Cherry
516ff99711 Revert "ueventd: remove PlatformDeviceList"
Bug: 62864413

This reverts commit c94ce7b130.

Change-Id: I014360251e5cda89c87adfec46d8b1e5000f3a9c
2017-06-21 18:42:07 +00:00
Tom Cherry
c94ce7b130 ueventd: remove PlatformDeviceList
In order to create symlinks for USB and block devices, the path for
their parent platform device must be known.

Previously, ueventd would save each platform device that it encounters
to a list and query this list when creating the symlinks.  That,
however, is racy because the uevent socket does not differentiate
uevents from RegenerateUevents() and uevents sent by the kernel when
probing a device first the first time.  The below scenario is the
faulty  case:

1) Kernel probes parent platform device for a block device
2) ueventd calls RegenerateUevents() and starts processing uevents
3) Kernel probes block device and sends its uevents
4) ueventd picks up the block device uevent during its uevent processing,
   without yet regenerating the platform device uevent, causing improper
   symlinks to be created.

This change stops storing the platform devices in a list, and instead
traverses up the directory structure for each USB or block device
until it reaches a platform device, defined as one whose subsystem is
the platform bus.  This fixes the race and simplifies the ueventd
code.

Bug: 62436493
Bug: 62681642
Test: Boot bullhead
Test: Boot sailfish
Test: Init unit tests
Test: Boot hikey + hotplug/unplug sdcard
Change-Id: I21636355d8e434f30e0cba568598a6cf139e67f9
2017-06-20 21:21:14 +00:00
Tom Cherry
ed506f7356 ueventd: Break devices.cpp into discrete classes
devices.cpp handles too many things for creating one class.  This
change breaks it up into various files and classes.

* Parsing is moved to ueventd_parser.cpp
* Reading from the uevent socket and Cold booting is moved to a
  UeventListener class, in uevent_listener.cpp
* Firmware handling is moved to firmware_handler.cpp
* The remaining contents form a DeviceHandler class within devices.cpp

Bug: 33785894

Test: boot bullhead x40, observe no major differences in /dev and /sys
Test: boot sailfish x40, observe no major differences in /dev and /sys
Test: init unit tests

Change-Id: I846a2e5995fbb344c7a8e349065c18a934fa6aba
2017-05-25 16:17:19 -07:00
Tom Cherry
cc054c9da8 ueventd: create classes for dev and sys permissions
Create classes for dev and sys permissions and store these permissions
in std::vector instead of the C list.

Test: boot bullhead
Test: init unit tests

Change-Id: I874039a3db29b4c70149506da8e407123ab7eca2
2017-04-17 19:33:04 +00:00
Tom Cherry
1ab8f55344 ueventd: convert platform_names from C list to std::vector
Also simplify this code a bit.

There's only one consumer that removes the /devices/platform prefix,
so have them handle it instead of storing two copies of the string.

Remove an unneeded search for '/' in get_character_device_symlinks()
as a / will always be the next character after a parent path, by
nature of FindPlatformDevice().

Test: boot bullhead
Test: init unit tests

Change-Id: I9d0482d137b1342ae7509ae993ff99198be814f0
2017-04-14 10:23:52 -07:00
Tom Cherry
e3e48214b7 ueventd: replace char* with std::string in struct uevent
Bug: 36250207

Test: Boot bullhead
Test: Boot sailfish, observe no boot time regression
Test: init unit tests

Change-Id: Ib82833bea56bdafbe1d7a045126aaa91a8725d98
2017-04-14 10:23:52 -07:00
Tom Cherry
2e344f9d22 ueventd: replace char** links with std::vector<std::string>
Additionally replace the associated C string parsing with C++ and write
unit tests.

Bug: 33785894
Bug: 36250207
Test: Boot bullhead + unit tests
Change-Id: Iee1f72d248bca3bd2e1227045628935b3dd6195a
2017-04-08 00:05:50 +00:00
Tom Cherry
c44f6a4073 ueventd: Write tests for the get_*_symlinks() functions
Bug: 33785894
Bug: 36250207
Test: Boot bullhead + new unit tests
Change-Id: Ia0f290542eb1cffce5ae876dfedb453dde960253
2017-04-05 18:21:39 -07:00