Commit graph

267 commits

Author SHA1 Message Date
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
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
Elliott Hughes
1b86d41c78 Add SIZEOF_MEMBER.
Bug: N/A
Test: ran tests
Change-Id: Icb7e8ae83d242c867b71a990b08eb1a62ed1482c
2018-04-11 12:29:50 -07:00
Mark Salyzyn
2507a048ab base: kernel logging get pre-opened /dev/kmsg from environment
If the environment has an instance of /dev/kmsg pre-opened, pick up.
This happens when an init script has 'file w /dev/kmsg' in the
daemon's recipe.

libcutils android_get_control_file operations are open-coded to
prevent a dependency on libcutils itself.  Also check that /dev/kmsg
file descriptor is valid and open'd for write only.

Test: check to make sure init() kernel logging still works
Bug: 77541952
Bug: 77661605
Change-Id: I007553acd594ef0815d23f32f8aa2867518570ba
2018-04-09 07:19:33 -07:00
Treehugger Robot
3b279aa5c7 Merge "Allow android::base::ScopeGuard in STL containers" 2018-03-26 23:05:25 +00:00
Luis Hector Chavez
b77035b89a Allow android::base::ScopeGuard in STL containers
This change lets android::base::ScopeGuard be useful in STL containers
(e.g. std::vector<android::base::ScopeGuard<std::function<void()>>>). It
also provides perfect forwarding for android::base::make_scope_guard.

Bug: 34764308
Test: libbase_test

Change-Id: I7d1e5494b0f0695763cff0700efdb9ec18ae85c8
2018-03-26 13:30:09 -07:00
Josh Gao
5791e21697 base: export GetThreadId.
and stop using the incorrect (on Mac) version in adb..

Test: mma
Change-Id: If28f6c8d73b03db863be13ed88df81422c3aef87
2018-03-16 15:35:52 -07:00
Yabin Cui
ef58cef982 base: Add TemporaryFile::DoNotRemove().
Bug: http://b/73127105
Test: none.
Change-Id: I563c12bfb629ddd630568dda4817fb10cc9940a8
2018-03-08 17:59:36 -08:00
Andreas Gampe
1923e768ef Base: Add default tag manipulation
Allow the default tag (the program name) to be overwritten.

Bug: 34867873
Test: m
Test: logging_test
Test: manual
Change-Id: I4ef32bad413a7cc82e46ce16a2f26212925964b1
2018-03-06 14:45:11 -08:00
Erik Kline
b154d18d11 EndsWith *suffix*
Possibly an old copy and paste error.

Test: built
Change-Id: Ie86203d65b4021ed4b787d2330729ab0b1d73e9d
2018-02-27 16:12:55 +09:00
Andreas Gampe
af05f3b761 Base: Add an NDK-compiled version of libbase
To support building libraries for CTS.

Bug: 73206894
Bug: 73659009
Test: mmma system/core/base
Change-Id: I630be88f44cf5cefcb13be7959fc1a710686e29b
2018-02-21 01:59:24 +00:00
Elliott Hughes
dc699a269f bpfmt.
Bug: N/A
Test: builds
Change-Id: I89ad00e1c4c7e0767bc80a7ac7935a4d55e090ac
2018-02-16 17:58:14 -08:00
yusukes
d3b9404241 Prevent WaitForProperty() from using ~100% of CPU time on 32bit builds
Since 'struct timespec' members (time_t and long) are both 32bit on
32bit systems, and std::chrono::{seconds,nanoseconds}::rep are both
>32bit, timespec members assigned in DurationToTimeSpec() can have a
negative value, especially when WaitForProperty() is called with the
default timeout value which is std::chrono::milliseconds::max().

Regarding functionality, passing a negative value to
__system_property_wait() is okay because WaitForProperty() still
waits for the property value (so unit tests are passing), but while
WaitForProperty() does that, the function, to be more exact,
SystemProperties::Wait() in bionic/, consumes ~100% of CPU time. This
happens because SystemProperties::Wait() which implements
__system_property_wait() has a tight while-loop with a __futex_wait()
call, and the futex call immediately returns EINVAL when the timespec
passed in has a negative value.

With this CL, WaitForProperty() will never pass a negative timespec
to __system_property_wait(), and therefore the __futex_wait() call
in bionic works as expected without consuming too much CPU time even
on 32bit systems.

Bug: None
Test: libbase_test32 still passes
Test: strace no longer shows repeated EINVALs from __futex_wait
Change-Id: Id1834fac8cd2876b02dbe4479bf3d3eda2fa7da1
2018-02-14 10:07:54 -08:00
Mark Salyzyn
0c071c9de7 base: adb.exe build error
Windows build of adb is broken because of the lack of
std::chrono_literals and for an implementation of
android::boot_clock::now().

Test: make -j vts
Bug: 72941624
Change-Id: Ie65fed098633eb45a94ea553de6903f8d55fc5b2
2018-02-05 09:33:10 -08:00