aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
authorRon Yorston <rmy@pobox.com>2012-03-21 20:53:50 +0000
committerRon Yorston <rmy@pobox.com>2012-03-21 20:53:50 +0000
commitf6bad5ef766b0447158e3de2f55c35f1f6cecb58 (patch)
treef5ec7ac45234c25794c97f87e9a6daa8a551e57c /libbb
parent72394258b6509b40e0fa08594ac86215a558dfd8 (diff)
parent8d0e0cdadf726beab28ccdc7d69738c1534e1f74 (diff)
downloadbusybox-w32-f6bad5ef766b0447158e3de2f55c35f1f6cecb58.tar.gz
busybox-w32-f6bad5ef766b0447158e3de2f55c35f1f6cecb58.tar.bz2
busybox-w32-f6bad5ef766b0447158e3de2f55c35f1f6cecb58.zip
Merge commit '8d0e0cdadf726beab28ccdc7d69738c1534e1f74' into merge
Conflicts: include/platform.h libbb/Kbuild.src libbb/messages.c
Diffstat (limited to 'libbb')
-rw-r--r--libbb/Kbuild.src3
-rw-r--r--libbb/appletlib.c4
-rw-r--r--libbb/getpty.c2
-rw-r--r--libbb/makedev.c19
-rw-r--r--libbb/messages.c13
-rw-r--r--libbb/procps.c4
-rw-r--r--libbb/progress.c22
-rw-r--r--libbb/systemd_support.c62
-rw-r--r--libbb/time.c8
-rw-r--r--libbb/unicode.c11
-rw-r--r--libbb/utmp.c1
-rw-r--r--libbb/xfuncs.c18
12 files changed, 119 insertions, 48 deletions
diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src
index f815c6dbc..3c9493f7e 100644
--- a/libbb/Kbuild.src
+++ b/libbb/Kbuild.src
@@ -115,12 +115,13 @@ lib-$(CONFIG_PLATFORM_POSIX) += inet_common.o
115lib-$(CONFIG_PLATFORM_POSIX) += kernel_version.o 115lib-$(CONFIG_PLATFORM_POSIX) += kernel_version.o
116lib-$(CONFIG_PLATFORM_POSIX) += login.o 116lib-$(CONFIG_PLATFORM_POSIX) += login.o
117lib-$(CONFIG_PLATFORM_POSIX) += makedev.o 117lib-$(CONFIG_PLATFORM_POSIX) += makedev.o
118lib-$(CONFIG_PLATFORM_POSIX) += match_fstype.o
119lib-$(CONFIG_PLATFORM_POSIX) += read_key.o 118lib-$(CONFIG_PLATFORM_POSIX) += read_key.o
120lib-$(CONFIG_PLATFORM_POSIX) += signals.o 119lib-$(CONFIG_PLATFORM_POSIX) += signals.o
121lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o 120lib-$(CONFIG_PLATFORM_POSIX) += udp_io.o
122lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o 121lib-$(CONFIG_PLATFORM_POSIX) += xgethostbyname.o
123 122
123lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o
124
124lib-$(CONFIG_FEATURE_UTMP) += utmp.o 125lib-$(CONFIG_FEATURE_UTMP) += utmp.o
125 126
126# A mix of optimizations (why build stuff we know won't be used) 127# A mix of optimizations (why build stuff we know won't be used)
diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index b1c772cf3..4e32414b4 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
@@ -574,12 +574,12 @@ static void check_suid(int applet_no)
574# endif 574# endif
575 check_need_suid: 575 check_need_suid:
576# endif 576# endif
577 if (APPLET_SUID(applet_no) == _BB_SUID_REQUIRE) { 577 if (APPLET_SUID(applet_no) == BB_SUID_REQUIRE) {
578 /* Real uid is not 0. If euid isn't 0 too, suid bit 578 /* Real uid is not 0. If euid isn't 0 too, suid bit
579 * is most probably not set on our executable */ 579 * is most probably not set on our executable */
580 if (geteuid()) 580 if (geteuid())
581 bb_error_msg_and_die("must be suid to work properly"); 581 bb_error_msg_and_die("must be suid to work properly");
582 } else if (APPLET_SUID(applet_no) == _BB_SUID_DROP) { 582 } else if (APPLET_SUID(applet_no) == BB_SUID_DROP) {
583 xsetgid(rgid); /* drop all privileges */ 583 xsetgid(rgid); /* drop all privileges */
584 xsetuid(ruid); 584 xsetuid(ruid);
585 } 585 }
diff --git a/libbb/getpty.c b/libbb/getpty.c
index ea653b0b6..6a15cff2f 100644
--- a/libbb/getpty.c
+++ b/libbb/getpty.c
@@ -19,7 +19,7 @@ int FAST_FUNC xgetpty(char *line)
19 if (p > 0) { 19 if (p > 0) {
20 grantpt(p); /* chmod+chown corresponding slave pty */ 20 grantpt(p); /* chmod+chown corresponding slave pty */
21 unlockpt(p); /* (what does this do?) */ 21 unlockpt(p); /* (what does this do?) */
22#if 0 /* if ptsname_r is not available... */ 22#ifndef HAVE_PTSNAME_R
23 const char *name; 23 const char *name;
24 name = ptsname(p); /* find out the name of slave pty */ 24 name = ptsname(p); /* find out the name of slave pty */
25 if (!name) { 25 if (!name) {
diff --git a/libbb/makedev.c b/libbb/makedev.c
index cf59e616b..06c4039a3 100644
--- a/libbb/makedev.c
+++ b/libbb/makedev.c
@@ -8,16 +8,23 @@
8 8
9/* We do not include libbb.h - #define makedev() is there! */ 9/* We do not include libbb.h - #define makedev() is there! */
10#include "platform.h" 10#include "platform.h"
11#include <features.h> 11
12#include <sys/sysmacros.h> 12/* Different Unixes want different headers for makedev */
13#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
14 || defined(__APPLE__)
15# include <sys/types.h>
16#else
17# include <features.h>
18# include <sys/sysmacros.h>
19#endif
13 20
14#ifdef __GLIBC__ 21#ifdef __GLIBC__
15/* At least glibc has horrendously large inline for this, so wrap it */ 22/* At least glibc has horrendously large inline for this, so wrap it. */
16/* uclibc people please check - do we need "&& !__UCLIBC__" above? */ 23/* uclibc people please check - do we need "&& !__UCLIBC__" above? */
17 24
18/* suppress gcc "no previous prototype" warning */ 25/* Suppress gcc "no previous prototype" warning */
19unsigned long long FAST_FUNC bb_makedev(unsigned int major, unsigned int minor); 26unsigned long long FAST_FUNC bb_makedev(unsigned major, unsigned minor);
20unsigned long long FAST_FUNC bb_makedev(unsigned int major, unsigned int minor) 27unsigned long long FAST_FUNC bb_makedev(unsigned major, unsigned minor)
21{ 28{
22 return makedev(major, minor); 29 return makedev(major, minor);
23} 30}
diff --git a/libbb/messages.c b/libbb/messages.c
index 3c3ec3519..9e7bd0fef 100644
--- a/libbb/messages.c
+++ b/libbb/messages.c
@@ -50,17 +50,16 @@ const int const_int_1 = 1;
50 * and it will end up in bss */ 50 * and it will end up in bss */
51const int const_int_0 = 0; 51const int const_int_0 = 0;
52 52
53#if !ENABLE_PLATFORM_MINGW32 /* No wtmp on Windows */ 53#if ENABLE_FEATURE_WTMP
54#include <utmp.h>
55/* This is usually something like "/var/adm/wtmp" or "/var/log/wtmp" */ 54/* This is usually something like "/var/adm/wtmp" or "/var/log/wtmp" */
56const char bb_path_wtmp_file[] ALIGN1 = 55const char bb_path_wtmp_file[] ALIGN1 =
57#if defined _PATH_WTMP 56# if defined _PATH_WTMP
58 _PATH_WTMP; 57 _PATH_WTMP;
59#elif defined WTMP_FILE 58# elif defined WTMP_FILE
60 WTMP_FILE; 59 WTMP_FILE;
61#else 60# else
62#error unknown path to wtmp file 61# error unknown path to wtmp file
63#endif 62# endif
64#endif 63#endif
65 64
66/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1. 65/* We use it for "global" data via *(struct global*)&bb_common_bufsiz1.
diff --git a/libbb/procps.c b/libbb/procps.c
index fcf86d9bb..c68d3e655 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -155,6 +155,7 @@ static unsigned long fast_strtoul_10(char **endptr)
155 return n; 155 return n;
156} 156}
157 157
158# if ENABLE_FEATURE_FAST_TOP
158static long fast_strtol_10(char **endptr) 159static long fast_strtol_10(char **endptr)
159{ 160{
160 if (**endptr != '-') 161 if (**endptr != '-')
@@ -163,6 +164,7 @@ static long fast_strtol_10(char **endptr)
163 (*endptr)++; 164 (*endptr)++;
164 return - (long)fast_strtoul_10(endptr); 165 return - (long)fast_strtoul_10(endptr);
165} 166}
167# endif
166 168
167static char *skip_fields(char *str, int count) 169static char *skip_fields(char *str, int count)
168{ 170{
@@ -451,7 +453,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
451//FIXME: is it safe to assume this field exists? 453//FIXME: is it safe to assume this field exists?
452 sp->last_seen_on_cpu = fast_strtoul_10(&cp); 454 sp->last_seen_on_cpu = fast_strtoul_10(&cp);
453# endif 455# endif
454#endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */ 456#endif /* FEATURE_FAST_TOP */
455 457
456#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS 458#if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS
457 sp->niceness = tasknice; 459 sp->niceness = tasknice;
diff --git a/libbb/progress.c b/libbb/progress.c
index 4c2763c53..40608b047 100644
--- a/libbb/progress.c
+++ b/libbb/progress.c
@@ -78,7 +78,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
78 /* Do not update on every call 78 /* Do not update on every call
79 * (we can be called on every network read!) */ 79 * (we can be called on every network read!) */
80 if (since_last_update == 0 && !totalsize) 80 if (since_last_update == 0 && !totalsize)
81 return; 81 return;
82 82
83 beg_and_transferred = beg_range + transferred; 83 beg_and_transferred = beg_range + transferred;
84 ratio = 100; 84 ratio = 100;
@@ -93,22 +93,9 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
93 93
94#if ENABLE_UNICODE_SUPPORT 94#if ENABLE_UNICODE_SUPPORT
95 init_unicode(); 95 init_unicode();
96 /* libbb candidate? */
97 { 96 {
98 wchar_t wbuf21[21]; 97 char *buf = unicode_conv_to_printable_fixedwidth(/*NULL,*/ curfile, 20);
99 char *buf = xstrdup(curfile); 98 fprintf(stderr, "\r%s%4u%% ", buf, ratio);
100 unsigned len;
101
102 /* trim to 20 wide chars max (sets wbuf21[20] to 0)
103 * also, in case mbstowcs fails, we at least
104 * dont get garbage */
105 memset(wbuf21, 0, sizeof(wbuf21));
106 /* convert to wide chars, no more than 20 */
107 len = mbstowcs(wbuf21, curfile, 20); /* NB: may return -1 */
108 /* back to multibyte; cant overflow */
109 wcstombs(buf, wbuf21, INT_MAX);
110 len = (len > 20) ? 0 : 20 - len;
111 fprintf(stderr, "\r%s%*s%4u%% ", buf, len, "", ratio);
112 free(buf); 99 free(buf);
113 } 100 }
114#else 101#else
@@ -158,7 +145,8 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
158 /* (long long helps to have working ETA even if !LFS) */ 145 /* (long long helps to have working ETA even if !LFS) */
159 unsigned eta = (unsigned long long)to_download*elapsed/(uoff_t)transferred - elapsed; 146 unsigned eta = (unsigned long long)to_download*elapsed/(uoff_t)transferred - elapsed;
160 unsigned secs = eta % 3600; 147 unsigned secs = eta % 3600;
161 fprintf(stderr, "%02u:%02u:%02u ETA", eta / 3600, secs / 60, secs % 60); 148 unsigned hours = eta / 3600;
149 fprintf(stderr, "%02u:%02u:%02u ETA", hours, secs / 60, secs % 60);
162 } 150 }
163 } 151 }
164} 152}
diff --git a/libbb/systemd_support.c b/libbb/systemd_support.c
new file mode 100644
index 000000000..981296dbb
--- /dev/null
+++ b/libbb/systemd_support.c
@@ -0,0 +1,62 @@
1/*
2 * Copyright (C) 2011 Davide Cavalca <davide@geexbox.org>
3 *
4 * Based on http://cgit.freedesktop.org/systemd/tree/src/sd-daemon.c
5 * Copyright 2010 Lennart Poettering
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation files
9 * (the "Software"), to deal in the Software without restriction,
10 * including without limitation the rights to use, copy, modify, merge,
11 * publish, distribute, sublicense, and/or sell copies of the Software,
12 * and to permit persons to whom the Software is furnished to do so,
13 * subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27#include "libbb.h"
28
29//config:config FEATURE_SYSTEMD
30//config: bool "Enable systemd support"
31//config: default y
32//config: help
33//config: If you plan to use busybox daemons on a system where daemons
34//config: are controlled by systemd, enable this option.
35//config: If you don't use systemd, it is still safe to enable it,
36//config: but yhe downside is increased code size.
37
38//kbuild:lib-$(CONFIG_FEATURE_SYSTEMD) += systemd_support.o
39
40int sd_listen_fds(void)
41{
42 const char *e;
43 int n;
44 int fd;
45
46 e = getenv("LISTEN_PID");
47 if (!e)
48 return 0;
49 n = xatoi_positive(e);
50 /* Is this for us? */
51 if (getpid() != (pid_t) n)
52 return 0;
53
54 e = getenv("LISTEN_FDS");
55 if (!e)
56 return 0;
57 n = xatoi_positive(e);
58 for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++)
59 close_on_exec_on(fd);
60
61 return n;
62}
diff --git a/libbb/time.c b/libbb/time.c
index 1eb2d75c2..e2b938471 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -91,7 +91,13 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
91 * .SS Seconds, a number from 0 to 61 (with leap seconds) 91 * .SS Seconds, a number from 0 to 61 (with leap seconds)
92 * Everything but the minutes is optional 92 * Everything but the minutes is optional
93 * 93 *
94 * This coincides with the format of "touch -t TIME" 94 * "touch -t DATETIME" format: [[[[[YY]YY]MM]DD]hh]mm[.ss]
95 * Some, but not all, Unix "date DATETIME" commands
96 * move [[YY]YY] past minutes mm field (!).
97 * Coreutils date does it, and SUS mandates it.
98 * (date -s DATETIME does not support this format. lovely!)
99 * In bbox, this format is special-cased in date applet
100 * (IOW: this function assumes "touch -t" format).
95 */ 101 */
96 unsigned cur_year = ptm->tm_year; 102 unsigned cur_year = ptm->tm_year;
97 int len = strchrnul(date_str, '.') - date_str; 103 int len = strchrnul(date_str, '.') - date_str;
diff --git a/libbb/unicode.c b/libbb/unicode.c
index cf0c6bed9..08a4c7427 100644
--- a/libbb/unicode.c
+++ b/libbb/unicode.c
@@ -1107,16 +1107,17 @@ char* FAST_FUNC unicode_conv_to_printable(uni_stat_t *stats, const char *src)
1107{ 1107{
1108 return unicode_conv_to_printable2(stats, src, INT_MAX, 0); 1108 return unicode_conv_to_printable2(stats, src, INT_MAX, 0);
1109} 1109}
1110char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth) 1110char* FAST_FUNC unicode_conv_to_printable_fixedwidth(/*uni_stat_t *stats,*/ const char *src, unsigned width)
1111{ 1111{
1112 return unicode_conv_to_printable2(stats, src, maxwidth, 0); 1112 return unicode_conv_to_printable2(/*stats:*/ NULL, src, width, UNI_FLAG_PAD);
1113} 1113}
1114char* FAST_FUNC unicode_conv_to_printable_fixedwidth(uni_stat_t *stats, const char *src, unsigned width) 1114
1115#ifdef UNUSED
1116char* FAST_FUNC unicode_conv_to_printable_maxwidth(uni_stat_t *stats, const char *src, unsigned maxwidth)
1115{ 1117{
1116 return unicode_conv_to_printable2(stats, src, width, UNI_FLAG_PAD); 1118 return unicode_conv_to_printable2(stats, src, maxwidth, 0);
1117} 1119}
1118 1120
1119#ifdef UNUSED
1120unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src) 1121unsigned FAST_FUNC unicode_padding_to_width(unsigned width, const char *src)
1121{ 1122{
1122 if (unicode_status != UNICODE_ON) { 1123 if (unicode_status != UNICODE_ON) {
diff --git a/libbb/utmp.c b/libbb/utmp.c
index 2bf9c11f2..09443fb6c 100644
--- a/libbb/utmp.c
+++ b/libbb/utmp.c
@@ -7,7 +7,6 @@
7 * Licensed under GPLv2, see file LICENSE in this source tree. 7 * Licensed under GPLv2, see file LICENSE in this source tree.
8 */ 8 */
9#include "libbb.h" 9#include "libbb.h"
10#include <utmp.h>
11 10
12static void touch(const char *filename) 11static void touch(const char *filename)
13{ 12{
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index 53c48557d..e657820f3 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -25,19 +25,25 @@
25#include "libbb.h" 25#include "libbb.h"
26 26
27/* Turn on nonblocking I/O on a fd */ 27/* Turn on nonblocking I/O on a fd */
28int FAST_FUNC ndelay_on(int fd) 28void FAST_FUNC ndelay_on(int fd)
29{ 29{
30 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK); 30 int flags = fcntl(fd, F_GETFL);
31 if (flags & O_NONBLOCK)
32 return;
33 fcntl(fd, F_SETFL, flags | O_NONBLOCK);
31} 34}
32 35
33int FAST_FUNC ndelay_off(int fd) 36void FAST_FUNC ndelay_off(int fd)
34{ 37{
35 return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) & ~O_NONBLOCK); 38 int flags = fcntl(fd, F_GETFL);
39 if (!(flags & O_NONBLOCK))
40 return;
41 fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
36} 42}
37 43
38int FAST_FUNC close_on_exec_on(int fd) 44void FAST_FUNC close_on_exec_on(int fd)
39{ 45{
40 return fcntl(fd, F_SETFD, FD_CLOEXEC); 46 fcntl(fd, F_SETFD, FD_CLOEXEC);
41} 47}
42 48
43char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src) 49char* FAST_FUNC strncpy_IFNAMSIZ(char *dst, const char *src)