Merge "POSIX getlogin_r/LOGIN_NAME_MAX/TTY_NAME_MAX."

am: 8aa4bc7c55

Change-Id: I578d3e5c096401b0447f9ed7223d3e20ffb5b19e
This commit is contained in:
Elliott Hughes 2017-07-29 14:59:15 +00:00 committed by android-build-merger
commit b82a2d0bd5
12 changed files with 71 additions and 17 deletions

View file

@ -467,7 +467,16 @@ int getgrouplist(const char* /*user*/, gid_t group, gid_t* groups, int* ngroups)
char* getlogin() { // NOLINT: implementing bad function.
passwd *pw = getpwuid(getuid()); // NOLINT: implementing bad function in terms of bad function.
return (pw != NULL) ? pw->pw_name : NULL;
return pw ? pw->pw_name : nullptr;
}
int getlogin_r(char* buf, size_t size) {
char* login = getlogin();
if (login == nullptr) return errno;
size_t login_length = strlen(login) + 1;
if (login_length > size) return ERANGE;
memcpy(buf, login, login_length);
return 0;
}
void setpwent() {

View file

@ -135,12 +135,12 @@ long sysconf(int name) {
case _SC_TIMERS: return _POSIX_TIMERS;
case _SC_GETGR_R_SIZE_MAX: return 1024;
case _SC_GETPW_R_SIZE_MAX: return 1024;
case _SC_LOGIN_NAME_MAX: return 256; // Seems default on linux.
case _SC_LOGIN_NAME_MAX: return LOGIN_NAME_MAX;
case _SC_THREAD_DESTRUCTOR_ITERATIONS: return PTHREAD_DESTRUCTOR_ITERATIONS;
case _SC_THREAD_KEYS_MAX: return PTHREAD_KEYS_MAX;
case _SC_THREAD_STACK_MIN: return PTHREAD_STACK_MIN;
case _SC_THREAD_THREADS_MAX: return -1; // No specific limit.
case _SC_TTY_NAME_MAX: return 32; // Seems default on linux.
case _SC_TTY_NAME_MAX: return TTY_NAME_MAX;
case _SC_THREADS: return _POSIX_THREADS;
case _SC_THREAD_ATTR_STACKADDR: return _POSIX_THREAD_ATTR_STACKADDR;
case _SC_THREAD_ATTR_STACKSIZE: return _POSIX_THREAD_ATTR_STACKSIZE;

View file

@ -137,6 +137,8 @@
#include <bits/posix_limits.h>
#define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
#define LOGIN_NAME_MAX 256
#define TTY_NAME_MAX 32
#define _POSIX_VERSION 200809L
#define _POSIX2_VERSION _POSIX_VERSION

View file

@ -118,6 +118,7 @@ int setresgid(gid_t __rgid, gid_t __egid, gid_t __sgid);
int getresuid(uid_t* __ruid, uid_t* __euid, uid_t* __suid);
int getresgid(gid_t* __rgid, gid_t* __egid, gid_t* __sgid);
char* getlogin(void);
int getlogin_r(char* __buffer, size_t __buffer_size) __INTRODUCED_IN_FUTURE;
long fpathconf(int __fd, int __name);
long pathconf(const char* __path, int __name);

View file

@ -1316,6 +1316,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
___Unwind_Backtrace; # arm
@ -1532,7 +1537,7 @@ LIBC_PRIVATE {
vfdprintf; # arm x86 mips
wait3; # arm x86 mips
wcswcs; # arm x86 mips
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1554,4 +1559,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1238,6 +1238,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
android_getaddrinfofornet;
@ -1249,7 +1254,7 @@ LIBC_PRIVATE {
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1271,4 +1276,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1341,6 +1341,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
___Unwind_Backtrace; # arm
@ -1558,7 +1563,7 @@ LIBC_PRIVATE {
vfdprintf; # arm x86 mips
wait3; # arm x86 mips
wcswcs; # arm x86 mips
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1580,4 +1585,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1300,6 +1300,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
__accept4; # arm x86 mips
@ -1373,7 +1378,7 @@ LIBC_PRIVATE {
vfdprintf; # arm x86 mips
wait3; # arm x86 mips
wcswcs; # arm x86 mips
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1395,4 +1400,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1238,6 +1238,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
android_getaddrinfofornet;
@ -1249,7 +1254,7 @@ LIBC_PRIVATE {
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1271,4 +1276,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1298,6 +1298,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
__accept4; # arm x86 mips
@ -1372,7 +1377,7 @@ LIBC_PRIVATE {
vfdprintf; # arm x86 mips
wait3; # arm x86 mips
wcswcs; # arm x86 mips
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1394,4 +1399,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1238,6 +1238,11 @@ LIBC_O {
wctrans_l; # introduced=26
} LIBC_N;
LIBC_P {
global:
getlogin_r; # future
} LIBC_O;
LIBC_PRIVATE {
global:
android_getaddrinfofornet;
@ -1249,7 +1254,7 @@ LIBC_PRIVATE {
free_malloc_leak_info;
get_malloc_leak_info;
gMallocLeakZygoteChild;
} LIBC_O;
} LIBC_P;
LIBC_DEPRECATED {
global:
@ -1271,4 +1276,4 @@ LIBC_PLATFORM {
malloc_disable;
malloc_enable;
malloc_iterate;
} LIBC_O;
} LIBC_P;

View file

@ -1372,3 +1372,10 @@ TEST(UNISTD_TEST, exec_argv0_null) {
ASSERT_EXIT(execve("/system/bin/run-as", args, envs), testing::ExitedWithCode(1),
"<unknown>: usage: run-as");
}
TEST(UNISTD_TEST, getlogin_r) {
char buf[LOGIN_NAME_MAX] = {};
EXPECT_EQ(ERANGE, getlogin_r(buf, 0));
EXPECT_EQ(0, getlogin_r(buf, sizeof(buf)));
EXPECT_STREQ(getlogin(), buf);
}