aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2015-05-18 09:36:27 +0100
committerRon Yorston <rmy@pobox.com>2015-05-18 09:36:27 +0100
commit60063627a6d540871061854a362047e6517f821c (patch)
tree0de228630450c64e085f2e3f5141b5ba17eccab3 /libbb
parentec39cb770ddd5c0e085d5c4ee10be65bab5e7a44 (diff)
parent9a595bb36ded308e6d4336aef2c1cd3ac738a398 (diff)
downloadbusybox-w32-60063627a6d540871061854a362047e6517f821c.tar.gz
busybox-w32-60063627a6d540871061854a362047e6517f821c.tar.bz2
busybox-w32-60063627a6d540871061854a362047e6517f821c.zip
Merge branch 'busybox' into mergeFRP
Diffstat (limited to 'libbb')
-rw-r--r--libbb/appletlib.c24
-rw-r--r--libbb/change_identity.c23
-rw-r--r--libbb/missing_syscalls.c5
-rw-r--r--libbb/platform.c19
-rw-r--r--libbb/read_printf.c8
-rw-r--r--libbb/utmp.c44
6 files changed, 84 insertions, 39 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index 3f51ecef6..683d10b20 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -635,7 +635,7 @@ static int busybox_main(char **argv)
635 full_write2_str(bb_banner); /* reuse const string */ 635 full_write2_str(bb_banner); /* reuse const string */
636 full_write2_str(" multi-call binary.\n"); /* reuse */ 636 full_write2_str(" multi-call binary.\n"); /* reuse */
637 full_write2_str( 637 full_write2_str(
638 "BusyBox is copyrighted by many authors between 1998-2012.\n" 638 "BusyBox is copyrighted by many authors between 1998-2015.\n"
639 "Licensed under GPLv2. See source distribution for detailed\n" 639 "Licensed under GPLv2. See source distribution for detailed\n"
640 "copyright notices.\n" 640 "copyright notices.\n"
641 "\n" 641 "\n"
@@ -761,23 +761,25 @@ void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
761 xfunc_error_retval = EXIT_FAILURE; 761 xfunc_error_retval = EXIT_FAILURE;
762 applet_name = APPLET_NAME(applet_no); 762 applet_name = APPLET_NAME(applet_no);
763 763
764#if defined APPLET_NO_test
765 /* Special case. POSIX says "test --help" 764 /* Special case. POSIX says "test --help"
766 * should be no different from e.g. "test --foo". 765 * should be no different from e.g. "test --foo".
767 * Thus for "test", we skip --help check. 766 * Thus for "test", we skip --help check.
767 * "true" and "false" are also special.
768 */ 768 */
769 if (applet_no != APPLET_NO_test) 769 if (1
770#if defined APPLET_NO_test
771 && applet_no != APPLET_NO_test
772#endif
773#if defined APPLET_NO_true
774 && applet_no != APPLET_NO_true
770#endif 775#endif
771 {
772 if (argc == 2 && strcmp(argv[1], "--help") == 0) {
773#if defined APPLET_NO_false 776#if defined APPLET_NO_false
774 /* Someone insisted that "false --help" must exit 1. Sigh */ 777 && applet_no != APPLET_NO_false
775 if (applet_no != APPLET_NO_false)
776#endif 778#endif
777 { 779 ) {
778 /* Make "foo --help" exit with 0: */ 780 if (argc == 2 && strcmp(argv[1], "--help") == 0) {
779 xfunc_error_retval = 0; 781 /* Make "foo --help" exit with 0: */
780 } 782 xfunc_error_retval = 0;
781 bb_show_usage(); 783 bb_show_usage();
782 } 784 }
783 } 785 }
diff --git a/libbb/change_identity.c b/libbb/change_identity.c
index 619db09a8..d48d86326 100644
--- a/libbb/change_identity.c
+++ b/libbb/change_identity.c
@@ -33,9 +33,28 @@
33/* Become the user and group(s) specified by PW. */ 33/* Become the user and group(s) specified by PW. */
34void FAST_FUNC change_identity(const struct passwd *pw) 34void FAST_FUNC change_identity(const struct passwd *pw)
35{ 35{
36 if (initgroups(pw->pw_name, pw->pw_gid) == -1) 36 int res;
37 bb_perror_msg_and_die("can't set groups"); 37
38 res = initgroups(pw->pw_name, pw->pw_gid);
38 endgrent(); /* helps to close a fd used internally by libc */ 39 endgrent(); /* helps to close a fd used internally by libc */
40
41 if (res != 0) {
42 /*
43 * If initgroups() fails because a system call is unimplemented
44 * then we are running on a Linux kernel compiled without multiuser
45 * support (CONFIG_MULTIUSER is not defined).
46 *
47 * If we are running without multiuser support *and* the target uid
48 * already matches the current uid then we can skip the change of
49 * identity.
50 */
51 if (errno == ENOSYS && pw->pw_uid == getuid()) {
52 return;
53 }
54
55 bb_perror_msg_and_die("can't set groups");
56 }
57
39 xsetgid(pw->pw_gid); 58 xsetgid(pw->pw_gid);
40 xsetuid(pw->pw_uid); 59 xsetuid(pw->pw_uid);
41} 60}
diff --git a/libbb/missing_syscalls.c b/libbb/missing_syscalls.c
index dd430e3e2..e3c1e924b 100644
--- a/libbb/missing_syscalls.c
+++ b/libbb/missing_syscalls.c
@@ -39,4 +39,9 @@ int pivot_root(const char *new_root, const char *put_old)
39{ 39{
40 return syscall(__NR_pivot_root, new_root, put_old); 40 return syscall(__NR_pivot_root, new_root, put_old);
41} 41}
42
43int tcdrain(int fd)
44{
45 return ioctl(fd, TCSBRK, 1);
46}
42#endif 47#endif
diff --git a/libbb/platform.c b/libbb/platform.c
index 8d90ca4e9..03bbb798b 100644
--- a/libbb/platform.c
+++ b/libbb/platform.c
@@ -194,3 +194,22 @@ ssize_t FAST_FUNC getline(char **lineptr, size_t *n, FILE *stream)
194 return len; 194 return len;
195} 195}
196#endif 196#endif
197
198#ifndef HAVE_TTYNAME_R
199int ttyname_r(int fd, char *buf, size_t buflen)
200{
201 int r;
202 char path[sizeof("/proc/self/fd/%d") + sizeof(int)*3];
203
204 if (!isatty(fd))
205 return errno == EINVAL ? ENOTTY : errno;
206 sprintf(path, "/proc/self/fd/%d", fd);
207 r = readlink(path, buf, buflen);
208 if (r < 0)
209 return errno;
210 if (r >= buflen)
211 return ERANGE;
212 buf[r] = '\0';
213 return 0;
214}
215#endif
diff --git a/libbb/read_printf.c b/libbb/read_printf.c
index ef4911cd5..e47ac7afe 100644
--- a/libbb/read_printf.c
+++ b/libbb/read_printf.c
@@ -45,20 +45,20 @@
45 * which detects EAGAIN and uses poll() to wait on the fd. 45 * which detects EAGAIN and uses poll() to wait on the fd.
46 * Thankfully, poll() doesn't care about O_NONBLOCK flag. 46 * Thankfully, poll() doesn't care about O_NONBLOCK flag.
47 */ 47 */
48ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count, int loop_on_EINTR) 48ssize_t FAST_FUNC nonblock_immune_read(int fd, void *buf, size_t count)
49{ 49{
50 struct pollfd pfd[1]; 50 struct pollfd pfd[1];
51 ssize_t n; 51 ssize_t n;
52 52
53 while (1) { 53 while (1) {
54 n = loop_on_EINTR ? safe_read(fd, buf, count) : read(fd, buf, count); 54 n = safe_read(fd, buf, count);
55 if (n >= 0 || errno != EAGAIN) 55 if (n >= 0 || errno != EAGAIN)
56 return n; 56 return n;
57 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */ 57 /* fd is in O_NONBLOCK mode. Wait using poll and repeat */
58 pfd[0].fd = fd; 58 pfd[0].fd = fd;
59 pfd[0].events = POLLIN; 59 pfd[0].events = POLLIN;
60 /* note: safe_poll pulls in printf */ 60 /* note: safe_poll pulls in printf */
61 loop_on_EINTR ? safe_poll(pfd, 1, -1) : poll(pfd, 1, -1); 61 safe_poll(pfd, 1, -1);
62 } 62 }
63} 63}
64 64
@@ -81,7 +81,7 @@ char* FAST_FUNC xmalloc_reads(int fd, size_t *maxsz_p)
81 p = buf + sz; 81 p = buf + sz;
82 sz += 128; 82 sz += 128;
83 } 83 }
84 if (nonblock_immune_read(fd, p, 1, /*loop_on_EINTR:*/ 1) != 1) { 84 if (nonblock_immune_read(fd, p, 1) != 1) {
85 /* EOF/error */ 85 /* EOF/error */
86 if (p == buf) { /* we read nothing */ 86 if (p == buf) { /* we read nothing */
87 free(buf); 87 free(buf);
diff --git a/libbb/utmp.c b/libbb/utmp.c
index 8ad9ba27e..bd07670db 100644
--- a/libbb/utmp.c
+++ b/libbb/utmp.c
@@ -16,7 +16,7 @@ static void touch(const char *filename)
16 16
17void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname) 17void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname)
18{ 18{
19 struct utmp utent; 19 struct utmpx utent;
20 char *id; 20 char *id;
21 unsigned width; 21 unsigned width;
22 22
@@ -45,17 +45,17 @@ void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, con
45 tty_name += 3; 45 tty_name += 3;
46 strncpy(id, tty_name, width); 46 strncpy(id, tty_name, width);
47 47
48 touch(_PATH_UTMP); 48 touch(_PATH_UTMPX);
49 //utmpname(_PATH_UTMP); 49 //utmpxname(_PATH_UTMPX);
50 setutent(); 50 setutxent();
51 /* Append new one (hopefully, unless we collide on ut_id) */ 51 /* Append new one (hopefully, unless we collide on ut_id) */
52 pututline(&utent); 52 pututxline(&utent);
53 endutent(); 53 endutxent();
54 54
55#if ENABLE_FEATURE_WTMP 55#if ENABLE_FEATURE_WTMP
56 /* "man utmp" says wtmp file should *not* be created automagically */ 56 /* "man utmp" says wtmp file should *not* be created automagically */
57 /*touch(bb_path_wtmp_file);*/ 57 /*touch(bb_path_wtmp_file);*/
58 updwtmp(bb_path_wtmp_file, &utent); 58 updwtmpx(bb_path_wtmp_file, &utent);
59#endif 59#endif
60} 60}
61 61
@@ -64,17 +64,17 @@ void FAST_FUNC write_new_utmp(pid_t pid, int new_type, const char *tty_name, con
64 */ 64 */
65void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname) 65void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const char *username, const char *hostname)
66{ 66{
67 struct utmp utent; 67 struct utmpx utent;
68 struct utmp *utp; 68 struct utmpx *utp;
69 69
70 touch(_PATH_UTMP); 70 touch(_PATH_UTMPX);
71 //utmpname(_PATH_UTMP); 71 //utmpxname(_PATH_UTMPX);
72 setutent(); 72 setutxent();
73 73
74 /* Did init/getty/telnetd/sshd/... create an entry for us? 74 /* Did init/getty/telnetd/sshd/... create an entry for us?
75 * It should be (new_type-1), but we'd also reuse 75 * It should be (new_type-1), but we'd also reuse
76 * any other potentially stale xxx_PROCESS entry */ 76 * any other potentially stale xxx_PROCESS entry */
77 while ((utp = getutent()) != NULL) { 77 while ((utp = getutxent()) != NULL) {
78 if (utp->ut_pid == pid 78 if (utp->ut_pid == pid
79 // && ut->ut_line[0] 79 // && ut->ut_line[0]
80 && utp->ut_id[0] /* must have nonzero id */ 80 && utp->ut_id[0] /* must have nonzero id */
@@ -88,25 +88,25 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
88 /* Stale record. Nuke hostname */ 88 /* Stale record. Nuke hostname */
89 memset(utp->ut_host, 0, sizeof(utp->ut_host)); 89 memset(utp->ut_host, 0, sizeof(utp->ut_host));
90 } 90 }
91 /* NB: pututline (see later) searches for matching utent 91 /* NB: pututxline (see later) searches for matching utxent
92 * using getutid(utent) - we must not change ut_id 92 * using getutxid(utent) - we must not change ut_id
93 * if we want *exactly this* record to be overwritten! 93 * if we want *exactly this* record to be overwritten!
94 */ 94 */
95 break; 95 break;
96 } 96 }
97 } 97 }
98 //endutent(); - no need, pututline can deal with (and actually likes) 98 //endutxent(); - no need, pututxline can deal with (and actually likes)
99 //the situation when utmp file is positioned on found record 99 //the situation when utmp file is positioned on found record
100 100
101 if (!utp) { 101 if (!utp) {
102 if (new_type != DEAD_PROCESS) 102 if (new_type != DEAD_PROCESS)
103 write_new_utmp(pid, new_type, tty_name, username, hostname); 103 write_new_utmp(pid, new_type, tty_name, username, hostname);
104 else 104 else
105 endutent(); 105 endutxent();
106 return; 106 return;
107 } 107 }
108 108
109 /* Make a copy. We can't use *utp, pututline's internal getutid 109 /* Make a copy. We can't use *utp, pututxline's internal getutxid
110 * will overwrite it before it is used! */ 110 * will overwrite it before it is used! */
111 utent = *utp; 111 utent = *utp;
112 112
@@ -120,14 +120,14 @@ void FAST_FUNC update_utmp(pid_t pid, int new_type, const char *tty_name, const
120 utent.ut_tv.tv_sec = time(NULL); 120 utent.ut_tv.tv_sec = time(NULL);
121 121
122 /* Update, or append new one */ 122 /* Update, or append new one */
123 //setutent(); 123 //setutxent();
124 pututline(&utent); 124 pututxline(&utent);
125 endutent(); 125 endutxent();
126 126
127#if ENABLE_FEATURE_WTMP 127#if ENABLE_FEATURE_WTMP
128 /* "man utmp" says wtmp file should *not* be created automagically */ 128 /* "man utmp" says wtmp file should *not* be created automagically */
129 /*touch(bb_path_wtmp_file);*/ 129 /*touch(bb_path_wtmp_file);*/
130 updwtmp(bb_path_wtmp_file, &utent); 130 updwtmpx(bb_path_wtmp_file, &utent);
131#endif 131#endif
132} 132}
133 133