init: Safely restart services to avoid race conditions.

Previously, service restarts (either an explicit "restart", or a "stop,
start" pair) exhibited a race condition whereby the new (restarting)
service process was often spawned before the old (stopping) process had
terminated.  This may have resulted in the new service process failing to
acquire a limited resource (file lock, socket bind, etc.) that the old
process had not yet released.

Now, a stopping service remains in the SVC_RUNNING state until its exiting
process has been reaped by waitpid.  This prevents a "stop, start" sequence
from spawning a second service process before resources held by the first
are released.  This enables safe service restarts by stopping the service,
waiting for the old service process to terminate, and (only then) starting
the new service process.  In the event of "restarting" an already stopped
service, the previous behavior is maintained whereby the service is simply
started.

This scenario could be special-cased by the restart command, however, we
have observed instances where services are, unintentionally, stopped and
started "too quickly," and so simultaneous processes for the same service
should never be allowed.

Note that this commit alters the behaviors for explicit restarts of
critical and oneshot services.  Previously these serivces would simply be
restarted, whereas now, an explicit restart of a critical service counts as
a crash (which may result in a recovery reboot) and oneshot services go
into the disabled state.
init: Retain traditional restart behavior for critical and oneshot services.

Adds an SVC_RESTART state that's used for an explicit "restart" of a
running service.  This retains the traditional restart behavior for
critical and oneshot services (previously altered by 7e36edd8), whereby
these services are "simply restarted" instead of counting as a crash (for a
critical serivce) or going into the disabled state (for a oneshot service).
adb: fix reported transfer size for transfer over 4 GiB

When transferring files over 4 GiB with adb, the size of the transfer
is misreported.

Change-Id: Ia3d4cae1e9f82b4f7432341820b101ea9a44f85b
Signed-off-by: Jeff Smith <whydoubt@gmail.com>
adb: add vendor ID's for Nook, Haier, Hisense, and MTK

Change-Id: I156ff750ef9ae66113d1e0e3ceffea047abc03b9
Signed-off-by: Jeff Smith <whydoubt@gmail.com>
Merge "adb: add vendor ID's for Nook, Haier, Hisense, and MTK"
Merge "adb: fix reported transfer size for transfer over 4 GiB"
init: switch property_get to use __system_property_get

(cherry picked from commit 2deedfe0b1ac86ebd62d19cf7da9e7dcb508ab09)

Change-Id: If3fba2cc1dd5c167b0924ddfe42dbe2e6387208a
init: move the system property writer implementation

Move the system property writer implementation into bionic to keep
it next to the reader implementation and allow for better testing.

(cherry picked from commit 9f5af635010a7ba92edf1fca543f7271cc9d75c8)

Change-Id: Idf6100d1d0170751acd5163a22597912bff480f0
init: verify size of property buffers passed to property_get

Verify that the buffer passed as the value parameter to property_get
is always big enough.

(cherry picked from commit 88ac54a4e8d2a63e4fd9c465e115795ace316776)

Change-Id: Iacc2b42bfe4069e0bfcbb1c48474f30126a93139
toolbox: hide property implementation from watchprops

(cherry picked from commit 91779634debc79bc75d3df4e0f59d964ad4f5f78)

Change-Id: I7a2d8aa507ac61cedc5f67c563531a7d4ec8e4c2
init: fix copying boot properties

The previous patch "init: verify size of property buffers passed
to property_get" incorrectly modified one of the callers,
resulting in ro.serialno, ro.bootmode, ro.baseband, and
ro.bootloader always being set to their default values.

Bug: 9469860

(cherry picked from commit 67e3663fc93c65b69b5d121db05b0833b98d97f1)

Change-Id: Ia7b337e1fab6e334729f47ee1269e6c736615177
Merge changes Ia7b337e1,I7a2d8aa5,Iacc2b42b,Idf6100d1,If3fba2cc

* changes:
  init: fix copying boot properties
  toolbox: hide property implementation from watchprops
  init: verify size of property buffers passed to property_get
  init: move the system property writer implementation
  init: switch property_get to use __system_property_get
Add Qisda usb config

add Qisda usb config
Signed-off-by: esther <esther530@gmail.com>

Change-Id: I5b8a0e5bd2218ecdf417de357c9a7d9307c91932

Conflicts:
	adb/usb_vendors.c
Merge "Add Qisda usb config"
libcutils: reimplement property_list() using __system_property_foreach()

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit e7bb159d16f9e60850a3c79cc388587959015a65)

Change-Id: I0f66144eb8a4a48e04e4fcd125ad37f19ad94b8e
toolbox: reimplement watchprops using __system_property_foreach()

Internally, replace the watchlist array with a hashmap since the array
assumes properties are enumerated in a consistent order and foreach()
probably won't.  (find_nth() never guaranteed this either but it usually
worked in practice.)

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit 389e358017ad15485f2bd9120feebfffa489131b)

Change-Id: I1db3137b130474f4bb205f01f0bdcf37cf974764
Merge changes I1db3137b,I0f66144e

* changes:
  toolbox: reimplement watchprops using __system_property_foreach()
  libcutils: reimplement property_list() using __system_property_foreach()
property_service: make /dev/__properties__ readable

Currently, system properties are passed via the environment
variable ANDROID_PROPERTY_WORKSPACE and a file descriptor passed
from parent to child. This is insecure for setuid executables,
as the environment variable can be changed by the caller.

Make the /dev/__properties__ file accessible, so an app can
get properties directly from the file, rather than relying on
environment variables.

Preserve the environment variable for compatibility with pre-existing
apps.

Bug: 8045561

(cherry picked from commit 7ece0a862cf97e85bbe69458a32a2bd165456874)

Change-Id: I762da21ef4075f288745efed0ec7d16c2b71303c
init: move initial property area allocation into bionic

bionic's __system_property_add() now expands the property area as needed
by mapping in more pages.  Rather than duplicate the mapping code, move
it inside bionic and have bionic's __system_property_area_init() set up
the first page.

Signed-off-by: Greg Hackmann <ghackmann@google.com>

(cherry picked from commit f14eef0c3c456bfe39f7e9d57c8f7ae4ec775972)

Change-Id: Ieb94caab1527c71f2155efe3795490b0ea215a29
Merge changes Ib54f39fd,I7e36edd8

* changes:
  init: Retain traditional restart behavior for critical and oneshot services.
  init: Safely restart services to avoid race conditions.