# HG changeset patch # User Isaac Dunham # Date 1416436726 21600 # Node ID 685a0da6ca5960a72e999b087156b4261e448361 # Parent 3d32f9523584cdf768b6f4568a30020a4cf02d85 probe for getspnam(), forkpty(), utmpx, replace sethostname() Android is missing all of these; we need to probe for some so we have a config symbol to depend on. sethostname() is easily replaced. We got termios.h via pty.h; now it's not included in configure-step tools, so we need termios.h to generate globals. diff -r 3d32f9523584 -r 685a0da6ca59 lib/portability.c --- a/lib/portability.c Wed Nov 19 14:29:53 2014 -0600 +++ b/lib/portability.c Wed Nov 19 16:38:46 2014 -0600 @@ -5,6 +5,9 @@ */ #include "toys.h" +#if defined(__ANDROID__) +#include +#endif #if defined(__APPLE__) || defined(__ANDROID__) ssize_t getdelim(char **linep, size_t *np, int delim, FILE *stream) @@ -61,6 +64,13 @@ } #endif +#if defined(__ANDROID__) +int sethostname(const char *name, size_t len) +{ + return syscall(__NR_sethostname, name, len); +} +#endif + #if defined(__APPLE__) extern char **environ; diff -r 3d32f9523584 -r 685a0da6ca59 lib/portability.h --- a/lib/portability.h Wed Nov 19 14:29:53 2014 -0600 +++ b/lib/portability.h Wed Nov 19 16:38:46 2014 -0600 @@ -180,10 +180,25 @@ #endif // Linux headers not listed by POSIX or LSB -#include #include #include +// Android is missing some headers and functions +#if defined(__ANDROID__) +int sethostname(const char *name, size_t len); +#endif +// "generated/config.h" is included first +#if defined(CFG_TOYBOX_SHADOW) && CFG_TOYBOX_SHADOW +#include +#endif +#if defined(CFG_TOYBOX_UTMPX) && CFG_TOYBOX_UTMPX +#include +#endif +#if defined(CFG_TOYBOX_PTY) && CFG_TOYBOX_PTY +#include +#endif + + // Some systems don't define O_NOFOLLOW, and it varies by architecture, so... #include #ifndef O_NOFOLLOW diff -r 3d32f9523584 -r 685a0da6ca59 scripts/genconfig.sh --- a/scripts/genconfig.sh Wed Nov 19 14:29:53 2014 -0600 +++ b/scripts/genconfig.sh Wed Nov 19 16:38:46 2014 -0600 @@ -44,6 +44,34 @@ int main(int argc, char *argv[]) { return posix_fallocate(0,0,0); } EOF + + # Android and some other platforms miss utmpx + probesymbol TOYBOX_UTMPX -c << EOF + #include + #ifndef BOOT_TIME + #error nope + #endif + int main(int argc, char *argv[]) { + struct utmpx *a; + if (0 != (a = getutxent())) return 0; + return 1; + } +EOF + + # Android is missing shadow.h and pty.h + probesymbol TOYBOX_PTY -c << EOF + #include + int main(int argc, char *argv[]) { + int master; return forkpty(&master, NULL, NULL, NULL); + } +EOF + + probesymbol TOYBOX_SHADOW -c << EOF + #include + int main(int argc, char *argv[]) { + struct spwd *a = getspnam("root"); return 0; + } +EOF } genconfig() diff -r 3d32f9523584 -r 685a0da6ca59 toys.h --- a/toys.h Wed Nov 19 14:29:53 2014 -0600 +++ b/toys.h Wed Nov 19 16:38:46 2014 -0600 @@ -41,10 +41,10 @@ #include #include #include +#include #include #include #include -#include // Posix networking @@ -64,7 +64,6 @@ #include // LSB 4.1 headers -#include #include #include #include diff -r 3d32f9523584 -r 685a0da6ca59 toys/lsb/passwd.c --- a/toys/lsb/passwd.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/lsb/passwd.c Wed Nov 19 16:38:46 2014 -0600 @@ -10,6 +10,7 @@ config PASSWD bool "passwd" default y + depends on TOYBOX_SHADOW help usage: passwd [-a ALGO] [-dlu] diff -r 3d32f9523584 -r 685a0da6ca59 toys/lsb/su.c --- a/toys/lsb/su.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/lsb/su.c Wed Nov 19 16:38:46 2014 -0600 @@ -10,6 +10,7 @@ config SU bool "su" default y + depends on TOYBOX_SHADOW help usage: su [-lmp] [-c CMD] [-s SHELL] [USER [ARGS...]] diff -r 3d32f9523584 -r 685a0da6ca59 toys/other/login.c --- a/toys/other/login.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/other/login.c Wed Nov 19 16:38:46 2014 -0600 @@ -10,6 +10,7 @@ config LOGIN bool "login" default y + depends on TOYBOX_SHADOW help usage: login [-p] [-h host] [[-f] username] diff -r 3d32f9523584 -r 685a0da6ca59 toys/other/netcat.c --- a/toys/other/netcat.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/other/netcat.c Wed Nov 19 16:38:46 2014 -0600 @@ -26,6 +26,7 @@ bool "netcat server options (-let)" default y depends on NETCAT + depends on TOYBOX_PTY help usage: netcat [-t] [-lL COMMAND...] diff -r 3d32f9523584 -r 685a0da6ca59 toys/other/uptime.c --- a/toys/other/uptime.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/other/uptime.c Wed Nov 19 16:38:46 2014 -0600 @@ -25,17 +25,18 @@ time_t tmptime; struct tm * now; unsigned int days, hours, minutes; - struct utmpx *entry; - int users = 0; + USE_TOYBOX_UTMPX(struct utmpx *entry;) + USE_TOYBOX_UTMPX(int users = 0;) // Obtain the data we need. sysinfo(&info); time(&tmptime); now = localtime(&tmptime); + // Obtain info about logged on users - setutxent(); - while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++; - endutxent(); + USE_TOYBOX_UTMPX(setutxent();) + USE_TOYBOX_UTMPX(while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++;) + USE_TOYBOX_UTMPX(endutxent();) // Time xprintf(" %02d:%02d:%02d up ", now->tm_hour, now->tm_min, now->tm_sec); @@ -48,7 +49,7 @@ if (days) xprintf("%d day%s, ", days, (days!=1)?"s":""); if (hours) xprintf("%2d:%02d, ", hours, minutes); else printf("%d min, ", minutes); - printf(" %d user%s, ", users, (users!=1) ? "s" : ""); + USE_TOYBOX_UTMPX(printf(" %d user%s, ", users, (users!=1) ? "s" : "");) printf(" load average: %.02f, %.02f, %.02f\n", info.loads[0]/65536.0, info.loads[1]/65536.0, info.loads[2]/65536.0); } diff -r 3d32f9523584 -r 685a0da6ca59 toys/other/w.c --- a/toys/other/w.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/other/w.c Wed Nov 19 16:38:46 2014 -0600 @@ -7,6 +7,7 @@ config W bool "w" default y + depends on TOYBOX_UTMPX help usage: w diff -r 3d32f9523584 -r 685a0da6ca59 toys/pending/sulogin.c --- a/toys/pending/sulogin.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/pending/sulogin.c Wed Nov 19 16:38:46 2014 -0600 @@ -13,6 +13,7 @@ config SULOGIN bool "sulogin" default n + depends on TOYBOX_SHADOW help usage: sulogin [-t time] [tty] diff -r 3d32f9523584 -r 685a0da6ca59 toys/pending/telnetd.c --- a/toys/pending/telnetd.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/pending/telnetd.c Wed Nov 19 16:38:46 2014 -0600 @@ -8,6 +8,7 @@ config TELNETD bool "telnetd" default n + depends on TOYBOX_PTY help Handle incoming telnet connections diff -r 3d32f9523584 -r 685a0da6ca59 toys/posix/who.c --- a/toys/posix/who.c Wed Nov 19 14:29:53 2014 -0600 +++ b/toys/posix/who.c Wed Nov 19 16:38:46 2014 -0600 @@ -14,6 +14,7 @@ config WHO bool "who" default y + depends on TOYBOX_UTMPX help usage: who