toolbox: Avoid issues with non-regular files

Toolbox uses open() in order to check for existence of a file, instead
of using stat(). This breaks when using non-regular files such as FIFO,
because opening a FIFO for reading blocks until a writer is available.

Change-Id: I008d246d68f7ce56040f4b4c36e5ff4f9c34f4dc
Merge remote-tracking branch 'cm/cm-11.0' into HEAD
init: device: fix memory leak issue

Fix some memory leak and null pointer issues reported by KW.

Change-Id: I61df734380498b68cdb4c3f66dcf5771e9e191eb
Signed-off-by: Hong-Mei Li <a21834@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/549753
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Patrick Auchter <auchter@motorola.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit dab2f49656556281f8e8ac313c7023355f705489)
init.rc: surfaceflinger: use min realtime sched priority

Use the rlimit service option to allow surfaceflinger to use the
minimum realtime scheduler priority. Surfaceflinger uses this priority
to minimize latency of vsync events.

Change-Id: Id3eec568a64d8957f1748eeee11abf92f29ab083
Reviewed-on: http://gerrit.pcs.mot.com/550181
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <c.fries@motorola.com>
Reviewed-by: Patrick Auchter <auchter@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Reviewed-by: Stephen Rossbach <ccpm12@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit 7d8919c0ceac940ce71ab49ba3d672b147ba5058)
init: Fix several memory leaks

1. Fix fd leak in do_mount function
2. Fix file1 and file2 leak in process_firmware_event function

Change-Id: Ic4271f2cf5e1df3cd32265544764a22b42271213
Signed-off-by: Hong-Mei Li <a21834@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/563988
SLTApproved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Yi-Wei Zhao <gbjc64@motorola.com>
SLTApproved: Yi-Wei Zhao <gbjc64@motorola.com>
Reviewed-by: Sheng-Zhe Zhao <a18689@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
(cherry picked from commit 0f13608cf4d753e494ea5ba848bdd67dcf59c317)
Dump hprof of java process on OOM

This commits is to porting:
(CR): Always generate hprof dump when an OOM is thrown
Change-Id: I7d5073e5ee6c450a96d954a7a44d0cc206885836
Reviewed-on: http://gerrit.pcs.mot.com/468598
Tested-by: Jira Key <JIRAKEY@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
init.rc: Give permissions to target_load

Give "system" permissions to target_load, so Power HAL might change
it.

Change-Id: Ied86c8e238e65ab2f9acf29f78444e899b0ab4a3
Reviewed-on: http://gerrit.pcs.mot.com/544110
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Christopher Fries <c.fries@motorola.com>
SLT-Approved: Christopher Fries <c.fries@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Reviewed-on: http://gerrit.pcs.mot.com/587341
SLTApproved: Christopher Fries <c.fries@motorola.com>
Submit-Approved: Christopher Fries <c.fries@motorola.com>
Tested-by: Christopher Fries <c.fries@motorola.com>
Don't let do_exec reap extra children

Change "wait()" loop to "waitpid(pid)", in order to ensure
we don't lose track of any of our children.

In a failure scenario, init could be busy processing an "exec" call
while some other services are exiting, and this wait in do_exec() must
not reap these children, or else the bookkeeping for the services is
lost.

Change-Id: Ic80ed0abf8709119aae790a719c68d86d73664fd
Reviewed-on: http://gerrit.pcs.mot.com/589643
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
SLTApproved: Christopher Fries <c.fries@motorola.com>
Handle SIGPIPE gracefully in logcat

logcat's output is sometimes redirected into a socket (ex: bugreport).
If that socket is then closed, logcat gets a SIGPIPE and crashes,
resulting in a tombstone.  Since this is a normal case, a tombstone is
not warranted.  It should just exit gracefully instead.

Change-Id: Ic2d2eca035f4b8a22778763d81932a064aeef5a5
Reviewed-on: http://gerrit.pcs.mot.com/536586
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
Handle SIGPIPE gracefully in top

top's output is sometimes redirected into a socket (ex: bugreport).
If that socket is then closed, top gets a SIGPIPE and crashes,
resulting in a tombstone.  Since this is a normal case, a tombstone is
not warranted.  It should just exit gracefully instead.

Change-Id: I0087401af36bfc72446d58b3043251ccd6884eda
Reviewed-on: http://gerrit.pcs.mot.com/536587
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Jeffrey Carlyle <jeff.carlyle@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>
ps exits when gets the signal SIGPIPE

ps's output is sometimes redirected into a socket (ex: bugreport). If
that socket is then closed, ps gets a SIGPIPE and crashes, resulting
in a tombstone.  It is better that ps just exits gracefully instead.

Change-Id: Id5bf73f626580dca2ab03b6f12a444be1640407c
Reviewed-on: http://gerrit.pcs.mot.com/537642
SLT-Approved: Slta Waiver <sltawvr@motorola.com>
Tested-by: Jira Key <jirakey@motorola.com>
Reviewed-by: Klocwork kwcheck <klocwork-kwcheck@sourceforge.mot.com>
Reviewed-by: Xue-Ying Hou <a16543@email.mot.com>
Reviewed-by: John Michelau <w14107@motorola.com>
Reviewed-by: Xin Guan <a18772@motorola.com>
Reviewed-by: David Ding <dding@motorola.com>
Submit-Approved: Jira Key <jirakey@motorola.com>