Commit graph

379 commits

Author SHA1 Message Date
Tom Cherry
13b1f34279 Add android::base::GetPids() function to return all pids
We loop over /proc to iterate through pids in a lot of code, so let's
consolidate this into a single function in libbase.

Test: new unit test
Change-Id: I908fab90b603546d0e3e8b8acdc8dadfc3552d62
2019-07-01 13:55:46 -07:00
Mohammad Samiul Islam
9f24c38fe3 Prevent definitions of expected.h from being included twice
Bug: 135683564
Test: Included expected.h from two different files. Builds succesfully
    with the fix. Does not build without the fix.

Change-Id: If1962a3b70f7580fa652a043aaf29bf592d1926c
2019-06-20 19:03:32 +01:00
Tom Cherry
b90dcc07d3 Create android-base/format.h that includes fmtlib headers
We're already including fmtlib statically in libbase, so let's also
expose its functionality directly.

Also create a small benchmark of the most common operations for
format() and StringPrintf(): int, float, and string arguments.  Note
that fmt::format is faster than StringPrintf() in all of these cases.

Test: build, run benchmark
Change-Id: I1e18f13673dd89ea936ea5c51418fad723495b08
2019-06-14 14:55:27 -07:00
Jiyong Park
20524ed6a2 Add Errorf and ErrnoErrorf
String formatting for error message can be done by using Errorf and
ErrnoErrorf. e.g. `return Errorf("{} failures", num_failure);`

The string format follows that of fmtlib, not printf.

Bug: 132145659
Test: libbase_test
Change-Id: I65f45d5f12ed23e2c14d6eb442278f467cc42e83
2019-06-14 14:29:36 +09:00
Jooyung Han
df7d32753e fix: passing ResultError to Error thru operator<<
It is typical to pass error to callers like following;

    if (!result) {
      return Error() << result.error();
    }

To transfer errno(or ResultError#code()), Error defines a specialization
operator<<(const ResultError&).

This change fixes so that ResultError is properly handled

Bug: 132145659
Test: atest libbase_test
Change-Id: Ib35457da2d4b923d8e652c54ac510a75546cf918
2019-06-11 13:38:01 +09:00
Tom Cherry
91e6f888d7 Remove Result<Success> in favor of Result<void>
Result<void> is the correct way to do this.

Bug: 132145659
Test: libbase and init unit tests
Change-Id: I9c2e16cee6657a1895f215016df41a8b290383c7
2019-06-10 12:53:15 -07:00
Tom Cherry
383e1418ff base: Add MmapFile as a synonym for MappedFile
I was looking for 'MmapFile' earlier and couldn't find it.  After
being pointed to it, we thought that adding this synonym would help
others trying to find this file.

Test: n/a
Change-Id: I7fbfd8e090f21183a5de3603a76f884562b99c4a
2019-06-07 13:05:22 -07:00
Treehugger Robot
bb1b83e325 Merge "Add expected<void,E>" 2019-06-07 07:17:47 +00:00
Treehugger Robot
2ba59c5b81 Merge "Move result.h from init to libbase" 2019-06-06 23:27:29 +00:00
Jiyong Park
b2a85c4333 Add expected<void,E>
Result<void> could be used instead of Result<Success>.

Bug: 132145659
Test: libbase_test
Change-Id: I7f079a94d06c5ecb8b0303ced981f0995253dc40
2019-06-07 08:10:32 +09:00
Jiyong Park
8fd64c8af1 Move result.h from init to libbase
The Result, Error, ErrnoError are quite generic. Moving them from init
to libbase so that they can be used from other places.

Bug: 132145659
Test: libbase_test
Change-Id: Id774a587f74380fadd7a0fc88c0aa892c3d9a489
2019-06-06 08:58:55 +09:00
Treehugger Robot
44cabca1ef Merge "base: fix out of date documentation with PropertySet()" 2019-06-05 21:24:23 +00:00
Tom Cherry
ef2469e547 base: fix out of date documentation with PropertySet()
As of Android-P, __system_property_set() is synchronous and only will
return '0' if the property was successfully set.

Test: n/a
Change-Id: Icbc0a6d8be1ae683565f378c534ea8e5c5f25357
2019-06-05 10:31:33 -07:00
Treehugger Robot
41f690ba2a Merge "Fix leak of mapped zip central directories" 2019-06-04 12:36:52 +00:00
Jiyong Park
5c06e6e17b Minor fixes on android::base::expected
This is a follow-up change of 7d89fb164b.

- Some of the missing conditions for SFNAIE were added
- Fixed indentation
- The assignment operator became "= default"

Bug: 132145659
Test: libbase_test

Change-Id: Ib5232a6e5e1d3df67e185d6e8c03374105c1ce94
2019-05-29 08:37:32 +09:00
Ryan Mitchell
ce1c49da6f Fix leak of mapped zip central directories
Memory mapping the central directory of specific APKs caused memory
mappings to build up over time because they were never unmapped
correctly. This is because MappedFile is not calling munmap with the
size of the data after aligning the mmap offset to a page boundary.

Bug: 133463863
Test: install APKs and verify that the entire mapped CD is unmaped
Test: ran aapt2 as daemon and confirmed that mapped CD is unmapped
Change-Id: I26bda27c83615d1a166d92e43a2327909c453b89
2019-05-28 22:59:53 +00:00
Jiyong Park
7d89fb164b Add android::base::expected
android::base::expected is an Android implementation of the
std::expected proposal.
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0323r7.html

For usage, refer to the expected.h header file and
expected_test.cpp

Bug: 132145659
Test: libbase_test

Change-Id: I65d3a1ecf8654d9858989755dfd0065c81f7b209
2019-05-22 06:39:27 +09:00
Josh Gao
fe1d1e815f Merge "Revert "Revert "Add a way to turn off unique_fd's operator int.""" 2019-05-09 23:09:38 +00:00
Josh Gao
27241a7a96 Revert "Revert "Add a way to turn off unique_fd's operator int.""
The original commit broke aosp-master-with-phones, because of
vendor libraries the depended on the int versions of libbase functions.

This patch reverts the revert, and also adds ABI-compatibility shims for
the replaced functions.

This reverts commit 2c58e1924a.

Bug: http://b/131312539
Test: treehugger
Test: forrest run of aosp-master-with-phones
Change-Id: I75cc84ec8d963e20862f7662e8e2f409471f41cc
2019-05-06 16:18:02 -07:00
dimitry
a808b1150a Enable native_bridge_support
Enable native bridge support for libbase, liblog,
libziparchive and libpropertyinfoparser.

This makes it possible to use them in binaries for translated
architectures.

Bug: http://b/77159578
Test: make
Change-Id: If67ce92288b17a052ea1e79a268e284f7d941439
2019-05-06 14:05:05 +02:00
Elliott Hughes
b4dc7be6c5 libbase: add ConsumePrefix/ConsumeSuffix.
adb was already using ConsumePrefix, and now we have another would-be
user in cutils. (There appears to be one place in adb that should use
ConsumeSuffix, so I'm assuming we'll want that sooner or later.)

I've kept these inline because adb and google3's versions both were, and
I'm easily led.

Test: treehugger
Change-Id: I29d99032f6f6ccbfaefece59725db8afb02a4c87
2019-05-03 12:49:31 -07:00
Ian Kasprzak
2c58e1924a Revert "Add a way to turn off unique_fd's operator int."
This reverts commit 93d63c010a.

Reason for revert: b/131312539 - All aosp-master-with-phones phones failing boot / health check.

Change-Id: Id4239f93484b7d6b8d9bcd355a59cbd40d9766e2
2019-04-25 15:59:28 +00:00
Josh Gao
93d63c010a Add a way to turn off unique_fd's operator int.
unique_fd's implicit conversion to int has led to tons of problems (see
all of the overloads for close, fdopen, fdopendir, etc.). Add a switch
that can turn it off, and reduce the ridiculous amount of work to fix up
callers by introducing a borrowed_fd type that can be constructed from
either int or unique_fd.

Test: treehugger
Change-Id: If77cf5cbcaddacdaec5919a15b3520fb68f51a62
2019-04-24 12:59:42 -07:00
Bernie Innocenti
7cb72c96b4 Disallow operator!() on unique_fd
This catches a common mistake where client code checks for errors using
the common idiom that works for std::iostream and other file-like
classes:

  unique_fd fd = open(...);
  if (!fd) {
  }

Test: atest libbase_test
Test: m droid
Change-Id: I9629a7795537ecb3b57be9c741c06f80967e4cc2
2019-03-28 15:56:07 +09:00
Yifan Hong
f959fffc1c Merge changes from topic "lpdumpd"
* changes:
  libbase: realpath is wrapped with TEMP_FAILURE_RETRY
  liblp: Replace open with GetControlFileOrOpen
  init: expand prop in 'file'
  libcutils: android_get_control_file uses realpath.
2019-03-26 20:35:36 +00:00
Yifan Hong
5f4cb8a240 libbase: realpath is wrapped with TEMP_FAILURE_RETRY
Although man page for realpath doesn't say so, the bionic
implementation of realpath may exit with error code
EINTR. In such cases, retry.

Test: boots (sanity)
Change-Id: Ic5feb7152374a81bd2f475ad74c4bc8c3afb3a20
2019-03-22 14:26:25 -07:00
Yurii Zubrytskyi
59d876c7a2 [base] Convert Starts/Ends/Equals string functions to string_view
Test: UTs

Change-Id: I3751656d44e7a814488169c53d3e8af0da44f262
2019-03-21 16:29:46 +00:00
Pirama Arumuga Nainar
5d7f84144d Support zero-length mapped files
Bug: http://b/119818070 "app crashes when reading asset of zero length"

Add support for zero-length mappings for the Windows code path as well.

Test: ran libbase_test on Windows under wine.
Change-Id: Iccb65fa800c636444100c9369f41e36d24a53a99
2019-03-07 16:12:55 -08:00
Josh Gao
d3387380f7 Hopefully fix more darwin build breakage.
Silence narrowing warnings by manually casting to a smaller type,
convert static_asserts to CHECKs, and switch from using MSG_CMSG_CLOEXEC
to manually setting FD_CLOEXEC.

Test: mma
Change-Id: I8aa02804179d754de860279fe34773800b937ab6
2019-02-19 14:37:02 -08:00
Josh Gao
b57dc7a670 Fix darwin build break.
The <malloc.h> include was vestigial from a previous revision.

Test: mma on linux
Change-Id: Iaf8351bec23c2792cefca0e5c9bd42664488f5c4
2019-02-19 13:17:23 -08:00
Josh Gao
8954d0bc98 Merge changes from topic "base_cmsg"
* changes:
  adb: switch to base::{Send,Receive}FileDescriptors.
  debuggerd: switch to base::{Send,Receive}FileDescriptors.
  base: add helpers for sending/receiving file descriptors.
2019-02-19 20:53:01 +00:00
Josh Gao
14f9500a35 base: add helpers for sending/receiving file descriptors.
Almost all of the uses of cmsg(3) in our source tree are wrong in at
least one of the following ways:

  - not aligning the cmsg buffer
  - leaking fds if more fds are received than expected
  - blindly dereferencing CMSG_DATA without checking the header
  - using CMSG_SPACE instead of CMSG_LEN for .cmsg_len
  - using CMSG_LEN instead of CMSG_SPACE for .msg_controllen
  - using a length specified in number of fds instead of bytes

Implement wrapper functions that implement this dumpster fire of an
API correctly.

Bug: http://b/122047630
Test: libbase_test32
Change-Id: I6ac34d67bbbf1bfa9727ab598248fc178ea19df9
2019-02-13 13:21:54 -08:00
Josh Gao
982f7bd345 base: add ScopedLockAssertion.
This is a useful helper for anyone that's using thread safety
annotations alongside std::condition_variable, extract it from adb and
move it to libbase.

Test: mma
Change-Id: Ic51e2f2a0e6a16628034b29d8ff32bf2155afccd
2019-02-12 16:32:35 -08:00
Elliott Hughes
eb0ef145fd MappedFile and FileMap should support zero-length mappings.
Bug: http://b/119818070 "app crashes when reading asset of zero length"
Test: ran tests
Change-Id: Idd2ad6f6e72c8e445aff78a460fac96dea41c950
2019-02-06 14:29:35 -08:00
Josh Gao
92ee52cc38 base: don't overwrite errno in unique_fd::~unique_fd.
unique_fd's destructor potentially mangling errno makes it difficult to
use correctly in code that sets errno (or, in reality, it makes it so
that errno values get randomly stomped upon if close actually sets
errno, because no one accounts for this case).

Preserve errno ourselves to avoid this.

Test: treehugger
Change-Id: Ib06e6f65866d86fff4032b2311021eaf9226a1af
2019-01-30 15:18:56 -08:00
Yabin Cui
e2841044a0 base: support optional flags in android::base::Pipe.
Bug: none
Test: build and use it manually.
Test: run libbase_tests.

Change-Id: I50b5251e8da23ddce94711807859612bf890406b
2019-01-18 14:25:13 -08:00
Andreas Gampe
468ffaeecf Libbase: NOLINT legacy unique_fd operator int
The use in implicit conversion is intentional.

Test: m
Change-Id: I6c756e772b274e8a525ba2ad792cc4a8e1fc0176
2019-01-10 08:54:45 -08:00
Elliott Hughes
9082e7af37 Build libbase with _FILE_OFFSET_BITS=64.
sehr points out that we already have two bugs caused by not doing this:
file.cpp has a call to pread with an off64_t that gets truncated, and
mapped_file.cpp does similar with mmap.

Bug: N/A
Test: ran tests
Change-Id: Ia098a836457e5adf109541235ad71c0ad7219da8
2018-12-19 12:55:17 -08:00
Florian Mayer
3f1f2e07ab Add missing includes.
Test: Builds.
Change-Id: Ia8b79154902503cdd774dc3b4523466123b4324c
2018-12-06 10:09:20 -08:00
Andreas Gampe
2819c0b831 Base: Explicitly set abort message on FATAL
Currently bionic only stores the first invocation of
android_set_abort_message, libbase splits the logging invocations
into discrete lines, and liblog automatically calls bionic when
fatal severity is used. This leads to only the first line of
LOG(FATAL) being stored for tombstoned.

Eagerly set the abort message directly before logging when the
severity is FATAL. This ensures the complete message will be
available.

Bug: 120506942
Test: m
Test: manual
Change-Id: I104d6960a2b1f66f21f5ada383fb4ab0f35e96a9
2018-12-05 12:59:15 -08:00
Josh Gao
946f7d44c2 Merge "base: add more error-checking overloads for unique_fd." 2018-12-03 22:41:22 +00:00
Mark Salyzyn
d2f5888894 base: TemporaryDir add DoNotRemove() method
Recursively delete all contents in a temporary directory in the
destructor.  If the caller wants the contents preserved, then
call DoNotRemove().

Test: compile
Bug: 119313545
Change-Id: I3601c06334920055a60dd3074b249824f4d6f510
2018-11-14 12:54:08 -08:00
Mark Salyzyn
46c2df5812 base: TemporaryDir rm -rf directory in destructor
Recursively delete all contents in a temporary directory in the
destructor.

Test: compile
Bug: 119313545
Change-Id: I9570a8591f4e51f8f4f1157e75ccc1b781f8a19d
2018-11-14 12:52:42 -08:00
Mark Salyzyn
6009a2debc base: Add sensitivity to TMPDIR environment for TemporaryDir and TemporaryFile
Test: compile
Bug: 119313545
Change-Id: I2917847f0e90df94d74f4bfc0b13fbc6a5f243c3
2018-11-14 12:52:13 -08:00
Mark Salyzyn
9f1cf25332 switch to using android-base/file.h instead of android-base/test_utils.h
Test: compile
Bug: 119313545
Change-Id: I4f7ad84743e974b4b4d1d7256088f6c8b749a237
2018-11-14 09:35:34 -08:00
Mark Salyzyn
0790b2465a base: move TemporaryFile and TemporaryDir to android-base/file.h
Allow a wider legitimate audience to use TemporaryFile and
TemporaryDir by moving them from android-base/test_utils.h to
android-base/file.h.

Test: compile
Bug: 119313545
Change-Id: Ie558c5873ce5b3937914918b6bfb427e5b61d0da
2018-11-13 12:44:21 -08:00
Josh Gao
1390e81d1c base: add more error-checking overloads for unique_fd.
unique_fd::operator int was a mistake...

Bug: http://b/118818285
Test: treehugger
Change-Id: I3775dd7b4666abec8b5ce2a43092d9601eb1128f
2018-11-02 10:54:42 -07:00
Mathieu Chartier
1666bafa70 libbase: add Fdopendir that takes a unique_fd.
Using fdopendir with unique_fd correctly is more annoying than it
should be, because fdopendir doesn't close the file descriptor
received upon failure.

Add an android::base::Fdopendir that does that handles the failure
case.

Bug: 118818285
Test: treehugger
Change-Id: I5dbbe0eb82242bc7716f84735ffc7644febcfd65
2018-11-02 08:24:38 -07:00
Yabin Cui
a656b98634 libbase: support char parameter in StartsWith/EndsWith.
Bug: 117568547
Test: run libbase_test.
Change-Id: I5a6a412733c594f5a116f333b8e091d2d9f60e06
2018-10-30 17:20:50 -07:00
Elliott Hughes
46e0cc27ca libbase: a slightly cleaner solution to libbase's off64_t problem.
Given that I can't actually go back in time and just make bionic's
`off_t` be 64-bit.

Bug: N/A
Test: builds
Change-Id: Ic93336b07bffc0977bd0e9caad6a22ce29ca06ed
2018-10-25 16:29:02 -07:00
Treehugger Robot
602f9a29b0 Merge "libbase: quick fix for Mac build." 2018-10-25 22:37:30 +00:00
Elliott Hughes
985438653d libbase: quick fix for Mac build.
I'll come back for the better fix later...

Bug: N/A
Test: builds
Change-Id: I967c2436cf5816cf9a0edcd3f04f307969e48bcb
2018-10-25 10:23:55 -07:00
Elliott Hughes
2a8460721c Merge "libbase: add O_CLOEXEC to <android-base/file.h>." 2018-10-25 15:21:06 +00:00
Elliott Hughes
514edae27c libbase: remove ARRAYSIZE_UNSAFE.
Also fix the indentation of a neighboring comment.

Bug: N/A
Test: builds
Change-Id: Iebe5f518b2ac14718f3cae91007e62b61bed9dc0
2018-10-24 14:34:52 -07:00
Elliott Hughes
32df7ee5c8 libbase: add O_CLOEXEC to <android-base/file.h>.
We already expose O_BINARY, and O_CLOEXEC seems equally legitimate.

Bug: N/A
Test: builds
Change-Id: I7f07e1bb2a5d6b5c5f293783c39ceab148fabefb
2018-10-24 14:06:45 -07:00
Elliott Hughes
48a0e186a7 Merge "Add a simple MappedFile to libbase and switch fastboot and libziparchive over." 2018-10-24 20:16:59 +00:00
Elliott Hughes
e8f4b14301 Add a simple MappedFile to libbase and switch fastboot and libziparchive over.
This allows us to remove libziparchive's dependency on libutils.

Bug: http://b/79112958
Test: ran libbase and libziparchive tests, ran fastboot manually
Change-Id: I95c651976dad222863e5b8c37d4514b778f5dce7
2018-10-23 13:20:49 -07:00
Elliott Hughes
4679a39610 adb: rationalize fatal/error logging.
Let's use LOG(FATAL)/PLOG(FATAL) for actual fatal stuff.

Add a Windows error(3) and move folks who didn't really mean "abort"
fatal over to it. Also get rid of syntax_error which wasn't adding a
lot of value, and most of the places it was adding "usage: " didn't seem
entirely appropriate anyway.

In particular, we seemed to have confused fastdeploy.cpp into aborting
in most user error cases, and none of the reviewers noticed. Clearly
we'd all lost track of far too many options.

(I've also cleaned up a few random instances of fprintf(3) + exit(2).)

Bug: N/A
Test: manual
Change-Id: I3e8440848a24e30d928de9eded505916bc324786
2018-10-19 14:04:24 -07:00
Pirama Arumuga Nainar
a2ccce870c Merge changes from topic "windows-libcxx"
* changes:
  Do not enable -Wold-style-cast for Windows
  Add sys/types.h in utf8.h
  Adapt to switch to libc++ for Windows
2018-10-11 17:00:53 +00:00
Tom Cherry
bc64e50bd7 Assert that ParseInt/ParseUint are only used with signed/unsigned numbers respectively
Test: build fails when the signedness is mismatched
Test: build succeeds otherwise
Change-Id: Idd6b146cc167d4607eafc81dbad6c2a79b167094
2018-10-05 14:30:39 -07:00
Chih-Hung Hsieh
747eb149d0 Add noexcept to move constructors and assignment operators.
Bug: 116614593
Test: build with WITH_TIDY=1
Change-Id: I5a7461386946ca623ab509609092aa0ac8418b80
2018-10-05 16:43:47 +00:00
Pirama Arumuga Nainar
ca6ee8331f Enable -Wexit-time-destructor for all targets
This warning should be available for Windows as well.

Test: mmma system/core/base
Change-Id: Id2e7e4da2e5105870a8d1e10c793e4a54c5b3d04
2018-09-26 23:31:00 -07:00
Pirama Arumuga Nainar
18a1606a88 Add sys/types.h in utf8.h
Bug: http://b/91353691

It's needed for mode_t.

Test: Build and test Windows modules under Wine.
Change-Id: I3fa6b2946316a9bd2a0d800ae928ba5de480a283
2018-09-21 10:46:35 -07:00
Chih-Hung Hsieh
502f4864d6 Suppress implicit-fallthrough warnings.
Add FALLTHROUGH_INTENDED for clang compiler.

Bug: 112564944
Test: build with global -Wimplicit-fallthrough.
Change-Id: I40f8bbf94e207c9dd90921e9b762ba51abab5777
2018-09-17 16:50:11 +00:00
Christopher Ferris
4a16630270 Merge "Add Start/Stop/Reset to CapturedStdFd." 2018-09-05 19:50:51 +00:00
Christopher Ferris
eea85c9aab Add Start/Stop/Reset to CapturedStdFd.
Move the fd() function to be private since it should not have been
exposed in the first place.

Fix the way logging_test uses CapturedXXX.

Adding this because the new isolated testing doesn't print errors to
stderr so the ASSERT_ EXPECT_ messages can get swallowed. Also, it's easier
to reuse a CapturedXXX object in a test with these functions.

Test: New unit tests pass.
Change-Id: I38b113fc184146ce434802f80a9b7997fa83e78a
2018-09-04 14:29:23 -07:00
Josh Gao
a3c868879c libbase: add Fdopen that takes a unique_fd.
Using fdopen with unique_fd correctly is more annoying than it should
be, because fdopen doesn't close the file descriptor received upon
failure, which means you have to something like the following:

    unique_fd ufd = ...;
    int fd = ufd.release();
    FILE* file = fdopen(fd, "...");
    if (!file) {
        close(fd);
        return;
    }

Add an android::base::Fdopen that does that dance for you.

Bug: http://b/113880863
Test: treehugger
Change-Id: I6325acf1ff06484005c1053fe09672c5eeeecaa1
2018-09-04 13:13:50 -07:00
Christopher Ferris
9d3f45339a Set errno for all error return cases.
Test: Updated unit tests pass.
Change-Id: I2c1f14ed44ce144a46cb2866c146fca89a05539e
2018-08-29 10:47:06 -07:00
Tom Cherry
958fcbdf8a Fix typo in parseint.untouched_on_failure test
This test means to check both that ParseInt() and ParseUint() do not
change the result on failure, however it erroneously tested ParseInt()
twice.

Test: unit tests
Change-Id: If534e2525827e19aba6cae0eef45668d57623efb
2018-08-23 02:00:17 +00:00
Tom Cherry
8e3f0b1b2a Fix two ParseInt edge cases
1) ParseInt and ParseUint accept strings that have spaces followed by
   a valid number, however the base check for determining hex numbers
   does not take this into account currently, but now does this this
   change.
2) ParseUint rejects negative numbers except in the case that the
   template argument is unsigned long long.  That is a mistake; it
   should reject negative numbers in all cases and this change does
   that by rejecting any string with a - prefix.

Bug: 112668205
Test: new (and old) unit tests
Change-Id: I0179b42e50adc1b169cf0e6d830283b71210a029
2018-08-22 15:02:57 -07:00
Spencer Low
991eedd102 base: remove execute bit from utf8.h
I originally accidentally created this file with the execute bit on.

Test: mma

Change-Id: I8075ffdbb114475434ad48912a9dd24f19a9025b
Signed-off-by: Spencer Low <CompareAndSwap@gmail.com>
2018-08-11 12:28:39 -07:00
Steven Moreland
f1911f4ba3 ParseFloat/ParseDouble, also take std::string
For convenience and to match the integer parsing functions.

Bug: 110758329
Test: m only
Change-Id: I33620d9a29465e1f425872fd57063ac32031988a
2018-08-09 10:49:45 -07:00
Steven Moreland
9ce0de0ed1 Merge "Add ParseFloat (in parsedouble.h)." 2018-08-09 16:14:18 +00:00
Treehugger Robot
4842b1b53e Merge "ParseDouble: allow validation only." 2018-08-09 02:38:27 +00:00
Steven Moreland
586ef26f74 Add ParseFloat (in parsedouble.h).
Bug: 110758329 # for using here
Test: libbase_test (added float_smoke)
Change-Id: I640f85655567c707cbee625ca9c88db2ab91da66
2018-08-08 18:17:21 -07:00
Josh Gao
fa06fc79e2 base: move unique_fd fdsan tests into bionic.
EXPECT_DEATH forks behind the scenes, which turns off fdsan, leading to
these tests failing. Instead of duplicating the special
EXPECT_FDSAN_DEATH macro, just move these tests into the bionic fdsan
tests.

Test: none
Change-Id: Ia7b65d4560601d5a78d143aced887a6773b401c0
2018-08-08 17:38:04 -07:00
Steven Moreland
1b8981e972 ParseDouble: allow validation only.
This change also updates documentation for Parse(Ui|I)nt functions
which recently had a corresponding change applied.

Bug: 110758329
Test: libbase_test
Change-Id: I4842c0500a6e49498eeb8a63d1117c06727fffdf
2018-08-08 16:50:27 -07:00
Tomasz Wasilczyk
3b70eedfa0 Remove unused logging symbols.
Bug: 35361699
Test: flash sailfish, it boots
Change-Id: Ie545145789faa299e1228b6c91566e0767f7ea79
2018-07-31 16:33:38 -07:00
Treehugger Robot
d4abb70a98 Merge "Revert "Revert "base: add support for tagged fd closure to unique_fd.""" 2018-07-20 23:09:27 +00:00
Josh Gao
22666feacc Revert "Revert "base: add support for tagged fd closure to unique_fd.""
Use __attribute__((weak)) to check for fdsan availability at runtime,
to support being used when built with the NDK while targeting older
platform versions.

This reverts commit af798acaea49b8d9150b94eb9f5f11450a6b8893.

Bug: http://b/110100358
Test: m libjnitest
Change-Id: Ie59d041d69cc3d4b6c59412d706f702dd1d2dab2
2018-07-20 13:50:15 -07:00
Steven Moreland
a96e43d3d6 ParseInt/ParseUint: allow validation only.
Removes segfault if T* out != nullptr and just
returns validation result.

Bug: 110758329
Test: libbase_test
Change-Id: I0f304533a7076bba977fbd1a715b9cc0d9e58e75
2018-07-20 11:02:47 -07:00
Josh Gao
30dd7d4dff Revert "base: add support for tagged fd closure to unique_fd."
This reverts commit fcf2c01b55.

Commit broke full-eng, because libbase is being compiled against the NDK.

Test: treehugger
Change-Id: I8447b6a7fc33e6aa34cec0f037727322fa824446
2018-07-20 01:42:02 +00:00
Josh Gao
c954ec09c5 debuggerd_handler: use syscall(__NR_close) instead of close.
Avoid bionic's file descriptor ownership checks by calling the close
syscall manually.

Test: debuggerd_test
Change-Id: I10af6aca0e66fe030fd7a53506ae61c87695641d
2018-07-18 18:11:46 -07:00
Josh Gao
fcf2c01b55 base: add support for tagged fd closure to unique_fd.
Test: libbase_test
Change-Id: Ibba5e60d7007265a566eb8f76021d5dbeb734532
2018-07-18 18:11:46 -07:00
liwugang
c63cb07063 libbase: return different result depend on the errno
In the RemoveFileIfExists it always return true even if error appeared
when using stat function.

It should distinguish different error. Such as ENOENT and ENOTDIR
we exactly know the file does not exist. But EACCES(current user has not
all search permission in the file path) and other errors appeared
we can't know whether file exits. So we should return false indicate
there are some error appeared.

Test: ran unit tests
Change-Id: I75788bf0621040812413d52596b5effb628fd0b1
Signed-off-by: liwugang <liwugang@xiaomi.com>
2018-07-12 17:35:17 -07:00
Elliott Hughes
38488907a0 Move libbacktrace off cutils.
There's still <cutils/atomic.h> in a test, but I don't understand why
that isn't just std::atomic.

Also add a shared tgkill wrapper to libbase.

Bug: N/A
Test: ran tests
Change-Id: Idd4baa1e1670a84b3a8f35803cc5ffe5aae008a6
2018-07-11 13:55:07 -07:00
Elliott Hughes
98c76496be libbase: assume clang.
Bug: N/A
Test: builds
Change-Id: Ic3d3bee26496025324a3d070e3fcbf6d7b917709
2018-07-02 10:53:22 -07:00
Inseob Kim
ad9f6b12e2 Fix misleading comments
Bug: N/A
Test: N/A
Change-Id: I714a0f523eb803cb619acaddff4f769622cfc8b6
2018-06-29 18:09:55 +09:00
Elliott Hughes
4d8bbc6f8b libbase: switch to #pragma once.
Bug: N/A
Test: builds
Change-Id: I125498ac4257ac4e901c6f2a5f1bfac1432d859d
2018-06-26 17:17:41 -07:00
Elliott Hughes
d8a4c60276 Simplify __attribute__((__printf__)) use.
We don't need this now everyone's using clang...

Bug: http://b/69933068
Test: ran tests
Change-Id: I88f0cf03981ade47e210387fd6f3a2706dfeb9b8
2018-06-26 13:07:21 -07:00
Pirama Arumuga Nainar
a2df1ef441 Do not customize __format__ for Windows/MinGW to gnu_printf
Bug: http://b/69933090
Bug: http://b/69933068

MinGW uses gnu_printf to force C99 printf analysis with GCC, but clang
does not support gnu_printf.  So just use the default that's used for
other platforms.  This also mirrors upstream commit
015e637b4b/.

Test: m native-host-cross with Clang.
Change-Id: I3deb266d70e25296c4ae1d58637afbabc3d949c1
2018-06-25 11:52:54 -07:00
Pirama Arumuga Nainar
8e52362e45 Adapt to switch to Clang for Windows host builds
Bug: http://b/69933068

Bug: http://b/91353691: std::chrono_utils is not available in the
libstdc++ in the mingw/gcc prebuilts.  They can be used once we switch
to using libc++ for Windows host.

Test: m native-host-cross with Clang
Change-Id: If9f0f1f201d5e4e445890075ad64c2d6086b0491
2018-06-25 11:47:52 -07:00
Elliott Hughes
11a64eb0e8 libbase: fix libbase_test.logging.StdioLogger.
I don't think the StdioLogger test ever passed. Move GetFileBasename
to where we can use it from StdioLogger, and undo the mix of anonymous
namespace vs static to consistently use static (which is the majority)
while we're touching those lines.

Bug: N/A
Test: ran tests
Change-Id: I95b3966cdb8af642bed71752bd7d4e3a86ac84ca
2018-06-06 12:54:41 -07:00
Elliott Hughes
d580c441ab Merge "libbase: add host properties support." 2018-05-29 23:59:50 +00:00
Elliott Hughes
dc80312628 libbase: add host properties support.
Move init and libprocessgroup away from their existing hacks.

Bug: N/A
Test: ran tests
Change-Id: Ifabdd38e0cc4ab2582f1ea59d32159d386f48eb6
2018-05-24 18:04:31 -07:00
Jiyong Park
a0e75045e6 Build adbd for recovery
adbd (and its dependencies) are marked as recovery_available:true so
that recovery version of the binary is built separately from the one for
system partition. This allows us to stop copying the system version to
the recovery partition and also opens up the way to enable shared
libraries in the recovery partition. Then we can also build adbd as a
dynamic executable.

Bug: 79146551
Test: m -j adbd.recovery
Change-Id: Ib95614c7435f9d0afc02a0c7d5ae1a94e439e32a
2018-05-24 14:11:11 +09:00
Elliott Hughes
1be0d1481b Add StdioLogger for command-line tools.
Bug: N/A
Test: ran tests
Change-Id: If366a4ea25aea1becdd3e443eba225e9bd52ebba
2018-05-23 10:06:20 -07:00
Jiyong Park
612210c75b Mark as recovery_available: true
Libraries that are direct or indirect dependencies of modules installed
to recovery partition (e.g. toybox) are marked as recovery_available:
true. This allows a recovery variant of the lib is created when it is
depended by other recovery or recovery_available modules.

Bug: 67916654
Bug: 64960723
Test: m -j
Change-Id: Ie59155c08890e96ce1893fa3687afcf763d7aea3
2018-05-15 09:47:04 +09:00
Elliott Hughes
40fdf3f4ab Add test_suites lines.
Bug: N/A
Test: builds
Change-Id: Ic5e2b9206bcfcb53c774989013b5db6aab462e42
2018-04-27 16:12:06 -07:00
Elliott Hughes
955b6a4792 Add android::base::ParseByteCount.
Bug: N/A
Test: ran tests
Change-Id: Ib2adcf0a5b9494fcf8259b29974303e8516a9ad9
2018-04-19 19:49:16 -07:00