Commit graph

2014 commits

Author SHA1 Message Date
Andreas Huber
9c0804bbb0 Fix use-after-free of stack-allocated temporary string. am: c41b838baa am: a5efddda90
am: dbd2ac1202

Change-Id: I3afd60abcb45a9ae39388630edb274b8eca3ecc1
2017-08-21 17:46:28 +00:00
Andreas Huber
dbd2ac1202 Fix use-after-free of stack-allocated temporary string. am: c41b838baa
am: a5efddda90

Change-Id: Ic0871bfae738d3b1854a7543843c0a9cc72c049d
2017-08-21 17:40:57 +00:00
Andreas Huber
a5efddda90 Fix use-after-free of stack-allocated temporary string.
am: c41b838baa

Change-Id: I3eac4b22b885e7991256e5a7df8f37e6b9a10cce
2017-08-21 17:33:56 +00:00
Andreas Huber
c41b838baa Fix use-after-free of stack-allocated temporary string.
Bug: 64848081
Test: built and successfully booted again
Merged-In: I93c899249bf2cc5ab8d880c0eaff471518e73121

Change-Id: I93c899249bf2cc5ab8d880c0eaff471518e73121
2017-08-21 09:44:56 -07:00
Tom Cherry
9128a0ba32 Merge "init: only set ro.boottime.<service> properties once." am: fe0607575d am: a1a6826c59 am: a82cc92437
am: bc4a6c49d9

Change-Id: Ib7ae7cb1b93708f8302c48903cc89396d533f47a
2017-08-18 20:24:10 +00:00
Tom Cherry
bc4a6c49d9 Merge "init: only set ro.boottime.<service> properties once." am: fe0607575d am: a1a6826c59
am: a82cc92437

Change-Id: Id7cda0d04382c78a3978ceb79e087b37da38cd4a
2017-08-18 20:18:10 +00:00
Tom Cherry
a82cc92437 Merge "init: only set ro.boottime.<service> properties once." am: fe0607575d
am: a1a6826c59

Change-Id: I7ed7631167f0d65c2a72efe26a727c18007c1c78
2017-08-18 20:12:10 +00:00
Tom Cherry
ba20645490 Merge "ueventd: fix subsystem list logic issues" am: edf03e23bb am: 6698195d64 am: b843ae51a4
am: a74ad8d256

Change-Id: I707e019a2fe702c2e70d631699da813da8b0720e
2017-08-18 20:11:46 +00:00
Tom Cherry
a1a6826c59 Merge "init: only set ro.boottime.<service> properties once."
am: fe0607575d

Change-Id: I1ef16e0a09803a4b3681227135ce2f1ec17b6401
2017-08-18 20:05:45 +00:00
Tom Cherry
a74ad8d256 Merge "ueventd: fix subsystem list logic issues" am: edf03e23bb am: 6698195d64
am: b843ae51a4

Change-Id: I2f4002ba13d747db9ee8713b7bb59caaebd36033
2017-08-18 20:05:44 +00:00
Tom Cherry
b843ae51a4 Merge "ueventd: fix subsystem list logic issues" am: edf03e23bb
am: 6698195d64

Change-Id: I4b8e3285645ee956f313e3904c16825460b350e2
2017-08-18 20:00:14 +00:00
Tom Cherry
fe0607575d Merge "init: only set ro.boottime.<service> properties once." 2017-08-18 19:59:29 +00:00
Tom Cherry
6698195d64 Merge "ueventd: fix subsystem list logic issues"
am: edf03e23bb

Change-Id: I4ce43385af2376bc7246f25057dd3d7d76ec5dc8
2017-08-18 19:53:48 +00:00
Tom Cherry
edf03e23bb Merge "ueventd: fix subsystem list logic issues" 2017-08-18 19:47:28 +00:00
Tom Cherry
fed3373b5b init: only set ro.boottime.<service> properties once.
Currently, init attempts to set ro.boottime.<service> properties
whenever a service starts, however since these properties are ro. this
means that an error is printed whenever a service is restarted.

Since these properties are intended for reporting boottime, these
subsequent writes during restarts are erroneous and therefore this
change stops attempting to write them, thus silencing the error.

Test: boot bullhead, restart processes, observe no error print
Change-Id: I372f8d5c26590fc0661b92f632410e23e6418841
2017-08-18 10:47:46 -07:00
Tom Cherry
9c8d6dd7de ueventd: fix subsystem list logic issues
1) Check subsystems list before doing usb subsystem logic.  This allows
   developers to handle usb* subsystems in ueventd.rc files.
2) Fix a bug where each subsystem_ instance is not reinitialized, but
   rather only the name_ member was set.

Test: boot bullhead
Test: check that multiple uevent_devname subsystems work when
      specified in ueventd.rc
Change-Id: Ifcac04763afcaf72a3b14ef5f3a6cb89981b51a1
2017-08-18 10:39:48 -07:00
Tom Cherry
0be5ecf56a Merge "init: replace panic() with LOG(FATAL)" am: 57a89f3ba0 am: ce2325895f am: 0ae159a920
am: 18966c55e9

Change-Id: I460028050b79b9e759996485124561e33c8cc3fa
2017-08-18 16:15:58 +00:00
Tom Cherry
18966c55e9 Merge "init: replace panic() with LOG(FATAL)" am: 57a89f3ba0 am: ce2325895f
am: 0ae159a920

Change-Id: Id6f265cd11c133269afc4b4d87370ad14a2fb7a8
2017-08-18 16:09:57 +00:00
Tom Cherry
0ae159a920 Merge "init: replace panic() with LOG(FATAL)" am: 57a89f3ba0
am: ce2325895f

Change-Id: Ia46b3e10ce0280e60c8c8dc289d3c2f01ac472e2
2017-08-18 16:03:57 +00:00
Tom Cherry
ce2325895f Merge "init: replace panic() with LOG(FATAL)"
am: 57a89f3ba0

Change-Id: Ib00187f9296ea8afd2bd323a87e290e7424a864e
2017-08-18 15:58:26 +00:00
Tom Cherry
57a89f3ba0 Merge "init: replace panic() with LOG(FATAL)" 2017-08-18 15:49:46 +00:00
Tom Cherry
2e9773a30a Merge "init: fix copy/paste mistake" am: f85404521e am: ad42b33eaa am: c3398d9e87
am: 3cbfff1615

Change-Id: I736005a89352b5e313960355d4bd28bdbeb18476
2017-08-18 02:36:28 +00:00
Tom Cherry
3cbfff1615 Merge "init: fix copy/paste mistake" am: f85404521e am: ad42b33eaa
am: c3398d9e87

Change-Id: Ibafc7fc324cebeeea04f365ee949a2fa9989b37e
2017-08-18 02:20:22 +00:00
Tom Cherry
c3398d9e87 Merge "init: fix copy/paste mistake" am: f85404521e
am: ad42b33eaa

Change-Id: I341f0cefac7433737f1c226a39cd3dc818baeed9
2017-08-18 02:07:25 +00:00
Tom Cherry
ad42b33eaa Merge "init: fix copy/paste mistake"
am: f85404521e

Change-Id: Id7382a959f5a22e4f4897ad593ea7202aae95c19
2017-08-18 01:55:43 +00:00
Treehugger Robot
f85404521e Merge "init: fix copy/paste mistake" 2017-08-18 01:49:40 +00:00
Tom Cherry
d8db7ab80d init: replace panic() with LOG(FATAL)
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
2017-08-17 18:16:51 -07:00
Tom Cherry
94f3bcdbc1 init: fix copy/paste mistake
Test: boot bullhead
Change-Id: I0fedb48a9684e21a27a1d260b84cb49a1038ce3f
2017-08-17 16:52:10 -07:00
Wei Wang
9f37a996ce Merge "Skip unnecessary sleep during shutdown" am: e3e4ec7c97 am: 57f94aa4bc am: 0660919ccf
am: 7bba2bf2d9

Change-Id: I3b26971430325fc9b14d9de72366ee269770b5cc
2017-08-17 02:08:34 +00:00
Wei Wang
7bba2bf2d9 Merge "Skip unnecessary sleep during shutdown" am: e3e4ec7c97 am: 57f94aa4bc
am: 0660919ccf

Change-Id: I95f30c8f6f4b24daae103156dbd9996f68e38c33
2017-08-17 02:03:05 +00:00
Wei Wang
0660919ccf Merge "Skip unnecessary sleep during shutdown" am: e3e4ec7c97
am: 57f94aa4bc

Change-Id: I6eed1052bcf74bf46511ad879fdb1348e507f0f6
2017-08-17 01:56:17 +00:00
Wei Wang
57f94aa4bc Merge "Skip unnecessary sleep during shutdown"
am: e3e4ec7c97

Change-Id: Iaa8af758ebcb2c7a300dde32902d14a11b6c53d6
2017-08-17 01:54:18 +00:00
Wei Wang
8c00e42f20 Skip unnecessary sleep during shutdown
Skip sleep if timeout is zero
Skip sleep if first pass umount succeed

Bug: 64768138
Test: reboot
Change-Id: I5ef731611320ade51974b414f7e47520ce36b287
2017-08-16 15:41:12 -07:00
Tom Cherry
db640d87cd Merge changes I7f00c5f0,Idc18f331,I1e7d3a88
am: 334929b525

Change-Id: If6526adf256c1e5958d5aa6135d9e7efd11cf1cf
2017-08-14 22:52:34 +00:00
Tom Cherry
89bcc85edf init: use Result<T> for the parsing functions
Test: boot bullhead
Merged-In: I7f00c5f0f54dd4fe05df73e1d6a89b56d788e113
Change-Id: I7f00c5f0f54dd4fe05df73e1d6a89b56d788e113
2017-08-14 14:07:49 -07:00
Tom Cherry
557946e57c init: use Result<T> for builtin functions
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
2017-08-14 14:07:39 -07:00
Tom Cherry
11a3aeeae3 init: introduce Result<T> for return values and error handling
init tries to propagate error information up to build context before
logging errors.  This is a good thing, however too often init has the
overly verbose paradigm for error handling, below:

bool CalculateResult(const T& input, U* output, std::string* err)

bool CalculateAndUseResult(const T& input, std::string* err) {
  U output;
  std::string calculate_result_err;
  if (!CalculateResult(input, &output, &calculate_result_err)) {
    *err = "CalculateResult " + input + " failed: " +
      calculate_result_err;
      return false;
  }
  UseResult(output);
  return true;
}

Even more common are functions that return only true/false but also
require passing a std::string* err in order to see the error message.

This change introduces a Result<T> that is use to either hold a
successful return value of type T or to hold an error message as a
std::string.  If the functional only returns success or a failure with
an error message, Result<Success> may be used.  The classes Error and
ErrnoError are used to indicate a failed Result<T>.

A successful Result<T> is constructed implicitly from any type that
can be implicitly converted to T or from the constructor arguments for
T.  This allows you to return a type T directly from a function that
returns Result<T>.

Error and ErrnoError are used to construct a Result<T> has
failed. Each of these classes take an ostream as an input and are
implicitly cast to a Result<T> containing that failure.  ErrnoError()
additionally appends ": " + strerror(errno) to the end of  the failure
string to aid in interacting with C APIs.

The end result is that the above code snippet is turned into the much
clearer example below:

Result<U> CalculateResult(const T& input);

Result<Success> CalculateAndUseResult(const T& input) {
  auto output = CalculateResult(input);
  if (!output) {
    return Error() << "CalculateResult " << input << " failed: "
                   << output.error();
  }
  UseResult(*output);
  return Success();
}

This change also makes this conversion for some of the util.cpp
functions that used the old paradigm.

Test: boot bullhead, init unit tests
Merged-In: I1e7d3a8820a79362245041251057fbeed2f7979b
Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14 14:07:30 -07:00
Tom Cherry
009c13083a Merge changes I7f00c5f0,Idc18f331,I1e7d3a88 into oc-dr1-dev-plus-aosp
am: 08adddec07

Change-Id: I582ced4450761fe8540e5f11ead33c561717b1de
2017-08-14 20:31:41 +00:00
Tom Cherry
c317009410 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-14 11:07:27 -07:00
Tom Cherry
b592dd8aff init: use Result<T> for the parsing functions
Test: boot bullhead
Change-Id: I7f00c5f0f54dd4fe05df73e1d6a89b56d788e113
2017-08-14 10:27:33 -07:00
Tom Cherry
7fa62c58d6 init: use Result<T> for builtin functions
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

Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
2017-08-14 10:27:23 -07:00
Tom Cherry
62ca663475 init: introduce Result<T> for return values and error handling
init tries to propagate error information up to build context before
logging errors.  This is a good thing, however too often init has the
overly verbose paradigm for error handling, below:

bool CalculateResult(const T& input, U* output, std::string* err)

bool CalculateAndUseResult(const T& input, std::string* err) {
  U output;
  std::string calculate_result_err;
  if (!CalculateResult(input, &output, &calculate_result_err)) {
    *err = "CalculateResult " + input + " failed: " +
      calculate_result_err;
      return false;
  }
  UseResult(output);
  return true;
}

Even more common are functions that return only true/false but also
require passing a std::string* err in order to see the error message.

This change introduces a Result<T> that is use to either hold a
successful return value of type T or to hold an error message as a
std::string.  If the functional only returns success or a failure with
an error message, Result<Success> may be used.  The classes Error and
ErrnoError are used to indicate a failed Result<T>.

A successful Result<T> is constructed implicitly from any type that
can be implicitly converted to T or from the constructor arguments for
T.  This allows you to return a type T directly from a function that
returns Result<T>.

Error and ErrnoError are used to construct a Result<T> has
failed. Each of these classes take an ostream as an input and are
implicitly cast to a Result<T> containing that failure.  ErrnoError()
additionally appends ": " + strerror(errno) to the end of  the failure
string to aid in interacting with C APIs.

The end result is that the above code snippet is turned into the much
clearer example below:

Result<U> CalculateResult(const T& input);

Result<Success> CalculateAndUseResult(const T& input) {
  auto output = CalculateResult(input);
  if (!output) {
    return Error() << "CalculateResult " << input << " failed: "
                   << output.error();
  }
  UseResult(*output);
  return Success();
}

This change also makes this conversion for some of the util.cpp
functions that used the old paradigm.

Test: boot bullhead, init unit tests
Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14 10:26:57 -07:00
Tom Cherry
2958df83a7 init: use Result<T> for the parsing functions
Test: boot bullhead
Change-Id: I7f00c5f0f54dd4fe05df73e1d6a89b56d788e113
2017-08-14 10:25:35 -07:00
Tom Cherry
568947d7d1 init: use Result<T> for builtin functions
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

Change-Id: Idc18f331d2d646629c6093c1e0f2996cf9b42aec
2017-08-14 10:25:26 -07:00
Tom Cherry
de09d52328 init: introduce Result<T> for return values and error handling
init tries to propagate error information up to build context before
logging errors.  This is a good thing, however too often init has the
overly verbose paradigm for error handling, below:

bool CalculateResult(const T& input, U* output, std::string* err)

bool CalculateAndUseResult(const T& input, std::string* err) {
  U output;
  std::string calculate_result_err;
  if (!CalculateResult(input, &output, &calculate_result_err)) {
    *err = "CalculateResult " + input + " failed: " +
      calculate_result_err;
      return false;
  }
  UseResult(output);
  return true;
}

Even more common are functions that return only true/false but also
require passing a std::string* err in order to see the error message.

This change introduces a Result<T> that is use to either hold a
successful return value of type T or to hold an error message as a
std::string.  If the functional only returns success or a failure with
an error message, Result<Success> may be used.  The classes Error and
ErrnoError are used to indicate a failed Result<T>.

A successful Result<T> is constructed implicitly from any type that
can be implicitly converted to T or from the constructor arguments for
T.  This allows you to return a type T directly from a function that
returns Result<T>.

Error and ErrnoError are used to construct a Result<T> has
failed. Each of these classes take an ostream as an input and are
implicitly cast to a Result<T> containing that failure.  ErrnoError()
additionally appends ": " + strerror(errno) to the end of  the failure
string to aid in interacting with C APIs.

The end result is that the above code snippet is turned into the much
clearer example below:

Result<U> CalculateResult(const T& input);

Result<Success> CalculateAndUseResult(const T& input) {
  auto output = CalculateResult(input);
  if (!output) {
    return Error() << "CalculateResult " << input << " failed: "
                   << output.error();
  }
  UseResult(*output);
  return Success();
}

This change also makes this conversion for some of the util.cpp
functions that used the old paradigm.

Test: boot bullhead, init unit tests
Change-Id: I1e7d3a8820a79362245041251057fbeed2f7979b
2017-08-14 10:25:14 -07:00
Tom Cherry
b6b9629f02 Merge "init: split security functions out of init.cpp" into oc-dev-plus-aosp
am: 08228116a8

Change-Id: I3fc6288cf03cd1e262852ceb3fc9dbcedb32c7c3
2017-08-14 16:50:01 +00:00
Tom Cherry
08228116a8 Merge "init: split security functions out of init.cpp" into oc-dev-plus-aosp 2017-08-14 16:45:19 +00:00
Tom Cherry
0c8d6d2730 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
2017-08-14 09:40:01 -07:00
Tom Cherry
658064ae37 Merge "init: split security functions out of init.cpp" into oc-mr1-dev-plus-aosp 2017-08-14 16:16:44 +00:00
Tom Cherry
2c486f593c Merge "init: fix format issue" am: f95338f634
am: a1051005a9

Change-Id: Ied41953b37104906e2a9551c3f5c2c34dc8168a1
2017-08-12 00:17:52 +00:00