Unify zipfile implementations : Step 1.

Extract zip file processing logic from libdvm into a
standalone library.

This library is a stricter than the libdvm library in
several ways:
- Duplicate zip entry names are now disallowed. Files with
  such entries will fail to parse.
- We now verify CD file size information with the individual
  file header information. (This was pointed out as a deficiency
  of this implementation in past discussions.)
- We also add support for crc checking, which means we might
  need to parse the optional data descriptor footer (if one
  exists).

We also provide an API for iterating over the entries of
a zip file. This library is optimized for two use cases :

- Lookup for a single entry in the file, with the intention
  of processing or extracting the data associated with that
  entry
- Iterating over all entries in a file *and* processing
  / extracting their data.

Change-Id: Ia87de6184ef753cc470b0af755c47a4f92ac8198
Fix Mac OS build for libziparchive.

BSD off_t are implicitly 64 bit so the platform
doesn't define off64_t.

Change-Id: I51cbe94ead01d2d6bc7c5010d9472487bee7c2d3
Fix return code for ended iteration.

The API promises a return code of -1 for an
ended iteration and lower negative values for
errors.

Change-Id: I688a1ee2efad1bdfc6959cf27e49c0426ebf27f8
Add unit tests for libziparchive.

- Add a build rule for host tests
- Add basic tests for Find / Iterate and Extract
  for both deflated & stored entries.
- Fix an off by one error that the test uncovered.

Change-Id: If72009b1ea9791d5a265829f05c32ffe1c2752c4
Use FileMap from libcutil instead of rolling our own.

Adds windows support as a side effect.

Change-Id: I912c1f980f284d01d4f3936291999646ddf6250a
Get rid of some log spam.

We don't need a warning if an entry isn't found in a zip
file. It can happen as part of normal operation.

Change-Id: I86c132a040371f36f0dd981b49c02b3173821439
Fix ExtractEntryToFile.

We would always write uncompressed data at offset 0 instead
of the current filedescriptor offset.

Also adds a unit-test & a clarifying comment on the API.

Change-Id: If44757e96dde504ce63d81b4dec7115fc6f6d5fb
Fix a sporadic build breakage.

The issue here is that the makefile sets LOCAL_LDFLAGS
and asks for -llog without declaring a dependency on it.
This will cause build breakages if liblog hasn't already
been built yet.

Change-Id: Ia38761cda44a38b6c2a88902d6108cbe64a328ce
Fix entry handling for 0 length entries.

Two minor issues were fixed:
- The offset to entry data can be the same as the
  central directory offset when the last entry in the
  file has length 0 and is stored (not deflated). Fix
  a check that disallowed this. We already have a strict
  check that entry data must end before the central directory,
  so we're covered.
- We would attempt to map a segment of length 0 when writing
  an entry whose length is 0. We should just return early in
  this case.

bug: 12623277
Change-Id: I2a4ca0c4d170cc3cbf326e5ca13894acd9c434c9
Add free to CloseArchive.

Currently CloseArchive doesn't call free and call sites don't appear
to either. I could not find any call sites which manually freed the
archive by deleting the handle. This fixes several memory leaks.

Change-Id: I21f187dde60fd87e6e54bde06de9e76fd0791104
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
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>
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)
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>
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>