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).
Reconcile with jb-mr1-release

Change-Id: Ibc7b4524bee9979836a9c7610fb69cc64bf9624b
am 35fc46d8: am 018227f5: am ce76e2d0: Merge "Modify init.rc and init.goldfish.rc for SE Android."

* commit '35fc46d8e338181ee3caedc30f3627bad2ffe35e':
  Modify init.rc and init.goldfish.rc for SE Android.
Reconcile with jb-mr1-release - do not merge

Change-Id: Ic967f2cc0110dd1ceca4f30c552430bb57c03bb6
am 6cc883ca: libusbhost: Fix possible missed "device added" notification

* commit '6cc883ca098f34bd126478a6aa19d5cce48d71a9':
  libusbhost: Fix possible missed "device added" notification
am f4de0783: libusbhost: Fix USB device discovery on boot

* commit 'f4de078388242fff9b68c04b122e8a095cab9b0e':
  libusbhost: Fix USB device discovery on boot
am cba158a6: Merge "add command-line arguments to mkbootimg to move kernel, ramdisk, etc." into jb-mr1-dev

* commit 'cba158a6f69dc0eb942a3fa8e5b42c6e5e51c2ae':
  add command-line arguments to mkbootimg to move kernel, ramdisk, etc.
am b2b46dc4: Merge "Added a cmd for configuring number of video buffers for camera, if supported" into jb-mr1-dev

* commit 'b2b46dc48c01c03e824ef49a88fc947ab2a65b28':
  Added a cmd for configuring number of video buffers for camera, if supported
Reconcile with jb-mr1-release - do not merge

Change-Id: I67e44ab1acd80a961b813639d41737ac187bbd99
am 60479afa: Merge changes I943b04dd,I645b6a2d into jb-mr1-dev

* commit '60479afa182330b42c5be04759b0340d8fd9e7c8':
  init: fix return value for android uid/gid check
  init.rc: make last_kmsg readable only by user system and group log
Reconcile with jb-mr1-release - do not merge

Change-Id: If02ab00e12b60a3852ec58a1f7eba47e2675da1a
am a8afd723: Allow AID_BLUETOOTH to update persist.service.bdroid

* commit 'a8afd723a4bdd68eda34a552a472a6adc0c26369':
  Allow AID_BLUETOOTH to update persist.service.bdroid
Reconcile with jb-mr1-release - do not merge

Change-Id: Ib9d575cce6450d7d9b4df6fb731f7618192c2858
am f2e4d7ff: Merge "Native utils for working with user and app IDs." into jb-mr1-dev

* commit 'f2e4d7ff0308171d63e4c133e8769b0dba304ece':
  Native utils for working with user and app IDs.
am 1d421490: Merge "Include to define uid_t." into jb-mr1-dev

* commit '1d4214900cc5c07eceb3a98618fcfecdfa8dc903':
  Include to define uid_t.
am e0346fa7: am b2a32cb9: am 8fb0caa7: Merge "config_mbr: Fix integer overflow"

* commit 'e0346fa7fa715f785ea60966f38a474f337278ca':
  config_mbr: Fix integer overflow
am 8268a75e: am c5db017c: am 63b2c577: Merge "Conditionally use SIGSTKFLT"

* commit '8268a75e86c086c4618c2f8d8e9531eb8d7b30f5':
  Conditionally use SIGSTKFLT
am 21c2c849: am b9994d22: am 8261d271: Merge "restorecon tombstone directory."

* commit '21c2c8493a8b72407690935971179f2c4b5b3d41':
  restorecon tombstone directory.
am ff5c802e: am faad67fa: am ef3f7fa3: Merge "Set the SELinux security label on new directories."

* commit 'ff5c802e6ce489a36ac28e3d93b7e8541b3e4d81':
  Set the SELinux security label on new directories.