diff options
author | Ron Yorston <rmy@pobox.com> | 2019-08-16 09:42:39 +0100 |
---|---|---|
committer | Ron Yorston <rmy@pobox.com> | 2019-08-16 09:45:21 +0100 |
commit | 517cf74f6265ec4308b790b637b3f9778cbdc6e0 (patch) | |
tree | be9337069b60ca1bb03565d8575bacfc71181003 /libbb | |
parent | ae65dc37bcc9b1d9cef0b111131c79dc4ba1bf51 (diff) | |
parent | ac78f2ac96b3efd6551a08e7dc609efa1fb69481 (diff) | |
download | busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.gz busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.tar.bz2 busybox-w32-517cf74f6265ec4308b790b637b3f9778cbdc6e0.zip |
Merge branch 'busybox' into merge
Diffstat (limited to 'libbb')
35 files changed, 209 insertions, 73 deletions
diff --git a/libbb/appletlib.c b/libbb/appletlib.c index 1f1a18aab..ef7d1ccd9 100644 --- a/libbb/appletlib.c +++ b/libbb/appletlib.c | |||
@@ -650,7 +650,7 @@ static void check_suid(int applet_no) | |||
650 | /* same group / in group */ | 650 | /* same group / in group */ |
651 | m >>= 3; | 651 | m >>= 3; |
652 | if (!(m & S_IXOTH)) /* is x bit not set? */ | 652 | if (!(m & S_IXOTH)) /* is x bit not set? */ |
653 | bb_error_msg_and_die("you have no permission to run this applet"); | 653 | bb_simple_error_msg_and_die("you have no permission to run this applet"); |
654 | 654 | ||
655 | /* We set effective AND saved ids. If saved-id is not set | 655 | /* We set effective AND saved ids. If saved-id is not set |
656 | * like we do below, seteuid(0) can still later succeed! */ | 656 | * like we do below, seteuid(0) can still later succeed! */ |
@@ -662,7 +662,7 @@ static void check_suid(int applet_no) | |||
662 | rgid = sct->m_ugid.gid; | 662 | rgid = sct->m_ugid.gid; |
663 | /* else: we will set egid = rgid, thus dropping sgid effect */ | 663 | /* else: we will set egid = rgid, thus dropping sgid effect */ |
664 | if (setresgid(-1, rgid, rgid)) | 664 | if (setresgid(-1, rgid, rgid)) |
665 | bb_perror_msg_and_die("setresgid"); | 665 | bb_simple_perror_msg_and_die("setresgid"); |
666 | 666 | ||
667 | /* Are we directed to change uid | 667 | /* Are we directed to change uid |
668 | * (APPLET = s** USER.GROUP or APPLET = S** USER.GROUP)? | 668 | * (APPLET = s** USER.GROUP or APPLET = S** USER.GROUP)? |
@@ -672,7 +672,7 @@ static void check_suid(int applet_no) | |||
672 | uid = sct->m_ugid.uid; | 672 | uid = sct->m_ugid.uid; |
673 | /* else: we will set euid = ruid, thus dropping suid effect */ | 673 | /* else: we will set euid = ruid, thus dropping suid effect */ |
674 | if (setresuid(-1, uid, uid)) | 674 | if (setresuid(-1, uid, uid)) |
675 | bb_perror_msg_and_die("setresuid"); | 675 | bb_simple_perror_msg_and_die("setresuid"); |
676 | 676 | ||
677 | goto ret; | 677 | goto ret; |
678 | } | 678 | } |
@@ -682,7 +682,7 @@ static void check_suid(int applet_no) | |||
682 | 682 | ||
683 | if (!onetime) { | 683 | if (!onetime) { |
684 | onetime = 1; | 684 | onetime = 1; |
685 | bb_error_msg("using fallback suid method"); | 685 | bb_simple_error_msg("using fallback suid method"); |
686 | } | 686 | } |
687 | } | 687 | } |
688 | # endif | 688 | # endif |
@@ -692,7 +692,7 @@ static void check_suid(int applet_no) | |||
692 | /* Real uid is not 0. If euid isn't 0 too, suid bit | 692 | /* Real uid is not 0. If euid isn't 0 too, suid bit |
693 | * is most probably not set on our executable */ | 693 | * is most probably not set on our executable */ |
694 | if (geteuid()) | 694 | if (geteuid()) |
695 | bb_error_msg_and_die("must be suid to work properly"); | 695 | bb_simple_error_msg_and_die("must be suid to work properly"); |
696 | } else if (APPLET_SUID(applet_no) == BB_SUID_DROP) { | 696 | } else if (APPLET_SUID(applet_no) == BB_SUID_DROP) { |
697 | /* | 697 | /* |
698 | * Drop all privileges. | 698 | * Drop all privileges. |
diff --git a/libbb/bb_getgroups.c b/libbb/bb_getgroups.c index 59ae53738..5d83c729a 100644 --- a/libbb/bb_getgroups.c +++ b/libbb/bb_getgroups.c | |||
@@ -38,7 +38,7 @@ gid_t* FAST_FUNC bb_getgroups(int *ngroups, gid_t *group_array) | |||
38 | continue; | 38 | continue; |
39 | } | 39 | } |
40 | /* Some other error (should never happen on Linux) */ | 40 | /* Some other error (should never happen on Linux) */ |
41 | bb_perror_msg_and_die("getgroups"); | 41 | bb_simple_perror_msg_and_die("getgroups"); |
42 | } | 42 | } |
43 | 43 | ||
44 | if (ngroups) | 44 | if (ngroups) |
diff --git a/libbb/bbunit.c b/libbb/bbunit.c index 5f8d980a3..ccd909d78 100644 --- a/libbb/bbunit.c +++ b/libbb/bbunit.c | |||
@@ -60,6 +60,6 @@ int unit_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) | |||
60 | return EXIT_FAILURE; | 60 | return EXIT_FAILURE; |
61 | } | 61 | } |
62 | 62 | ||
63 | bb_error_msg("All tests passed"); | 63 | bb_simple_error_msg("All tests passed"); |
64 | return EXIT_SUCCESS; | 64 | return EXIT_SUCCESS; |
65 | } | 65 | } |
diff --git a/libbb/capability.c b/libbb/capability.c index d0ae78b91..23afd8eb9 100644 --- a/libbb/capability.c +++ b/libbb/capability.c | |||
@@ -119,7 +119,7 @@ void FAST_FUNC getcaps(void *arg) | |||
119 | caps->u32s = _LINUX_CAPABILITY_U32S_3; | 119 | caps->u32s = _LINUX_CAPABILITY_U32S_3; |
120 | break; | 120 | break; |
121 | default: | 121 | default: |
122 | bb_error_msg_and_die("unsupported capability version"); | 122 | bb_simple_error_msg_and_die("unsupported capability version"); |
123 | } | 123 | } |
124 | 124 | ||
125 | if (capget(&caps->header, caps->data) != 0) | 125 | if (capget(&caps->header, caps->data) != 0) |
diff --git a/libbb/change_identity.c b/libbb/change_identity.c index 20d7c5f2d..9ff741234 100644 --- a/libbb/change_identity.c +++ b/libbb/change_identity.c | |||
@@ -51,7 +51,7 @@ void FAST_FUNC change_identity(const struct passwd *pw) | |||
51 | return; | 51 | return; |
52 | } | 52 | } |
53 | 53 | ||
54 | bb_perror_msg_and_die("can't set groups"); | 54 | bb_simple_perror_msg_and_die("can't set groups"); |
55 | } | 55 | } |
56 | 56 | ||
57 | xsetgid(pw->pw_gid); | 57 | xsetgid(pw->pw_gid); |
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 1dc515b07..9b10dda1f 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -333,7 +333,7 @@ int FAST_FUNC copy_file(const char *source, const char *dest, int flags) | |||
333 | ) { | 333 | ) { |
334 | security_context_t con; | 334 | security_context_t con; |
335 | if (getfscreatecon(&con) == -1) { | 335 | if (getfscreatecon(&con) == -1) { |
336 | bb_perror_msg("getfscreatecon"); | 336 | bb_simple_perror_msg("getfscreatecon"); |
337 | return -1; | 337 | return -1; |
338 | } | 338 | } |
339 | if (con) { | 339 | if (con) { |
diff --git a/libbb/copyfd.c b/libbb/copyfd.c index dd0517cd6..ae5c26999 100644 --- a/libbb/copyfd.c +++ b/libbb/copyfd.c | |||
@@ -87,7 +87,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) | |||
87 | rd = safe_read(src_fd, buffer, | 87 | rd = safe_read(src_fd, buffer, |
88 | size > buffer_size ? buffer_size : size); | 88 | size > buffer_size ? buffer_size : size); |
89 | if (rd < 0) { | 89 | if (rd < 0) { |
90 | bb_perror_msg(bb_msg_read_error); | 90 | bb_simple_perror_msg(bb_msg_read_error); |
91 | break; | 91 | break; |
92 | } | 92 | } |
93 | read_ok: | 93 | read_ok: |
@@ -100,7 +100,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size) | |||
100 | ssize_t wr = full_write(dst_fd, buffer, rd); | 100 | ssize_t wr = full_write(dst_fd, buffer, rd); |
101 | if (wr < rd) { | 101 | if (wr < rd) { |
102 | if (!continue_on_write_error) { | 102 | if (!continue_on_write_error) { |
103 | bb_perror_msg(bb_msg_write_error); | 103 | bb_simple_perror_msg(bb_msg_write_error); |
104 | break; | 104 | break; |
105 | } | 105 | } |
106 | dst_fd = -1; | 106 | dst_fd = -1; |
@@ -151,7 +151,7 @@ void FAST_FUNC bb_copyfd_exact_size(int fd1, int fd2, off_t size) | |||
151 | if (sz == (size >= 0 ? size : -size)) | 151 | if (sz == (size >= 0 ? size : -size)) |
152 | return; | 152 | return; |
153 | if (sz != -1) | 153 | if (sz != -1) |
154 | bb_error_msg_and_die("short read"); | 154 | bb_simple_error_msg_and_die("short read"); |
155 | /* if sz == -1, bb_copyfd_XX already complained */ | 155 | /* if sz == -1, bb_copyfd_XX already complained */ |
156 | xfunc_die(); | 156 | xfunc_die(); |
157 | } | 157 | } |
diff --git a/libbb/die_if_bad_username.c b/libbb/die_if_bad_username.c index 46f103340..e5e1160c4 100644 --- a/libbb/die_if_bad_username.c +++ b/libbb/die_if_bad_username.c | |||
@@ -57,5 +57,5 @@ void FAST_FUNC die_if_bad_username(const char *name) | |||
57 | * including the terminating null byte. | 57 | * including the terminating null byte. |
58 | */ | 58 | */ |
59 | if (name - start >= LOGIN_NAME_MAX) | 59 | if (name - start >= LOGIN_NAME_MAX) |
60 | bb_error_msg_and_die("name is too long"); | 60 | bb_simple_error_msg_and_die("name is too long"); |
61 | } | 61 | } |
diff --git a/libbb/dump.c b/libbb/dump.c index b4b49d709..8029cca0e 100644 --- a/libbb/dump.c +++ b/libbb/dump.c | |||
@@ -199,7 +199,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) | |||
199 | pr->bcnt = fu->bcnt; | 199 | pr->bcnt = fu->bcnt; |
200 | if (fu->bcnt == 0) { | 200 | if (fu->bcnt == 0) { |
201 | if (!prec) | 201 | if (!prec) |
202 | bb_error_msg_and_die("%%s needs precision or byte count"); | 202 | bb_simple_error_msg_and_die("%%s needs precision or byte count"); |
203 | pr->bcnt = atoi(prec); | 203 | pr->bcnt = atoi(prec); |
204 | } | 204 | } |
205 | } else | 205 | } else |
@@ -266,7 +266,7 @@ static NOINLINE void rewrite(priv_dumper_t *dumper, FS *fs) | |||
266 | 266 | ||
267 | /* only one conversion character if byte count */ | 267 | /* only one conversion character if byte count */ |
268 | if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { | 268 | if (!(pr->flags & F_ADDRESS) && fu->bcnt && nconv++) { |
269 | bb_error_msg_and_die("byte count with multiple conversion characters"); | 269 | bb_simple_error_msg_and_die("byte count with multiple conversion characters"); |
270 | } | 270 | } |
271 | } | 271 | } |
272 | /* | 272 | /* |
diff --git a/libbb/fflush_stdout_and_exit.c b/libbb/fflush_stdout_and_exit.c index 4c689c0fb..5df74170e 100644 --- a/libbb/fflush_stdout_and_exit.c +++ b/libbb/fflush_stdout_and_exit.c | |||
@@ -15,7 +15,7 @@ void FAST_FUNC fflush_stdout_and_exit(int retval) | |||
15 | { | 15 | { |
16 | xfunc_error_retval = retval; | 16 | xfunc_error_retval = retval; |
17 | if (fflush(stdout)) | 17 | if (fflush(stdout)) |
18 | bb_perror_msg_and_die(bb_msg_standard_output); | 18 | bb_simple_perror_msg_and_die(bb_msg_standard_output); |
19 | /* In case we are in NOFORK applet. Do not exit() directly, | 19 | /* In case we are in NOFORK applet. Do not exit() directly, |
20 | * but use xfunc_die() */ | 20 | * but use xfunc_die() */ |
21 | xfunc_die(); | 21 | xfunc_die(); |
diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c index 52debb171..0b6d5a206 100644 --- a/libbb/find_pid_by_name.c +++ b/libbb/find_pid_by_name.c | |||
@@ -95,7 +95,11 @@ pid_t* FAST_FUNC find_pid_by_name(const char *procName) | |||
95 | /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/ | 95 | /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/ |
96 | || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0) | 96 | || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0) |
97 | /* or we require /proc/PID/exe link to match */ | 97 | /* or we require /proc/PID/exe link to match */ |
98 | || (p->exe && strcmp(bb_basename(p->exe), procName) == 0) | 98 | || (p->exe && strcmp( |
99 | procName[0] == '/' ? p->exe /* support "pidof /path/to/binary" case too */ | ||
100 | : bb_basename(p->exe), | ||
101 | procName | ||
102 | ) == 0) | ||
99 | #endif | 103 | #endif |
100 | ) { | 104 | ) { |
101 | pidList = xrealloc_vector(pidList, 2, i); | 105 | pidList = xrealloc_vector(pidList, 2, i); |
diff --git a/libbb/get_console.c b/libbb/get_console.c index 0b53524aa..7f2c75332 100644 --- a/libbb/get_console.c +++ b/libbb/get_console.c | |||
@@ -62,7 +62,7 @@ int FAST_FUNC get_console_fd_or_die(void) | |||
62 | } | 62 | } |
63 | } | 63 | } |
64 | 64 | ||
65 | bb_error_msg_and_die("can't open console"); | 65 | bb_simple_error_msg_and_die("can't open console"); |
66 | } | 66 | } |
67 | 67 | ||
68 | /* From <linux/vt.h> */ | 68 | /* From <linux/vt.h> */ |
diff --git a/libbb/get_volsize.c b/libbb/get_volsize.c index 241ceda9b..087efb3c7 100644 --- a/libbb/get_volsize.c +++ b/libbb/get_volsize.c | |||
@@ -18,7 +18,7 @@ uoff_t FAST_FUNC get_volume_size_in_bytes(int fd, | |||
18 | if (override) { | 18 | if (override) { |
19 | result = XATOOFF(override); | 19 | result = XATOOFF(override); |
20 | if (result >= (uoff_t)(MAXINT(off_t)) / override_units) | 20 | if (result >= (uoff_t)(MAXINT(off_t)) / override_units) |
21 | bb_error_msg_and_die("image size is too big"); | 21 | bb_simple_error_msg_and_die("image size is too big"); |
22 | result *= override_units; | 22 | result *= override_units; |
23 | /* seek past end fails on block devices but works on files */ | 23 | /* seek past end fails on block devices but works on files */ |
24 | if (lseek(fd, result - 1, SEEK_SET) != (off_t)-1) { | 24 | if (lseek(fd, result - 1, SEEK_SET) != (off_t)-1) { |
@@ -42,7 +42,7 @@ uoff_t FAST_FUNC get_volume_size_in_bytes(int fd, | |||
42 | * | 42 | * |
43 | * Picked 16k arbitrarily: */ | 43 | * Picked 16k arbitrarily: */ |
44 | if (result < 16*1024) | 44 | if (result < 16*1024) |
45 | bb_error_msg_and_die("image is too small"); | 45 | bb_simple_error_msg_and_die("image is too small"); |
46 | 46 | ||
47 | return result; | 47 | return result; |
48 | } | 48 | } |
diff --git a/libbb/getpty.c b/libbb/getpty.c index 5d24ca930..9ec6265ad 100644 --- a/libbb/getpty.c +++ b/libbb/getpty.c | |||
@@ -23,14 +23,14 @@ int FAST_FUNC xgetpty(char *line) | |||
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) { |
26 | bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); | 26 | bb_simple_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); |
27 | } | 27 | } |
28 | safe_strncpy(line, name, GETPTY_BUFSIZE); | 28 | safe_strncpy(line, name, GETPTY_BUFSIZE); |
29 | } | 29 | } |
30 | # else | 30 | # else |
31 | /* find out the name of slave pty */ | 31 | /* find out the name of slave pty */ |
32 | if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) { | 32 | if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) { |
33 | bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); | 33 | bb_simple_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); |
34 | } | 34 | } |
35 | line[GETPTY_BUFSIZE-1] = '\0'; | 35 | line[GETPTY_BUFSIZE-1] = '\0'; |
36 | # endif | 36 | # endif |
@@ -61,5 +61,5 @@ int FAST_FUNC xgetpty(char *line) | |||
61 | } | 61 | } |
62 | } | 62 | } |
63 | #endif /* FEATURE_DEVPTS */ | 63 | #endif /* FEATURE_DEVPTS */ |
64 | bb_error_msg_and_die("can't find free pty"); | 64 | bb_simple_error_msg_and_die("can't find free pty"); |
65 | } | 65 | } |
diff --git a/libbb/herror_msg.c b/libbb/herror_msg.c index d041076e0..a7dd98679 100644 --- a/libbb/herror_msg.c +++ b/libbb/herror_msg.c | |||
@@ -26,3 +26,13 @@ void FAST_FUNC bb_herror_msg_and_die(const char *s, ...) | |||
26 | va_end(p); | 26 | va_end(p); |
27 | xfunc_die(); | 27 | xfunc_die(); |
28 | } | 28 | } |
29 | |||
30 | void FAST_FUNC bb_simple_herror_msg(const char *s) | ||
31 | { | ||
32 | bb_herror_msg("%s", s); | ||
33 | } | ||
34 | |||
35 | void FAST_FUNC bb_simple_herror_msg_and_die(const char *s) | ||
36 | { | ||
37 | bb_herror_msg_and_die("%s", s); | ||
38 | } | ||
diff --git a/libbb/loop.c b/libbb/loop.c index c78535a20..ada0c7638 100644 --- a/libbb/loop.c +++ b/libbb/loop.c | |||
@@ -78,6 +78,24 @@ int FAST_FUNC del_loop(const char *device) | |||
78 | return rc; | 78 | return rc; |
79 | } | 79 | } |
80 | 80 | ||
81 | /* Obtain an unused loop device number */ | ||
82 | int FAST_FUNC get_free_loop(void) | ||
83 | { | ||
84 | int fd; | ||
85 | int loopdevno; | ||
86 | |||
87 | fd = open("/dev/loop-control", O_RDWR | O_CLOEXEC); | ||
88 | if (fd == -1) | ||
89 | return fd - 1; /* -2: "no /dev/loop-control" */ | ||
90 | |||
91 | #ifndef LOOP_CTL_GET_FREE | ||
92 | # define LOOP_CTL_GET_FREE 0x4C82 | ||
93 | #endif | ||
94 | loopdevno = ioctl(fd, LOOP_CTL_GET_FREE); | ||
95 | close(fd); | ||
96 | return loopdevno; /* can be -1 if error */ | ||
97 | } | ||
98 | |||
81 | /* Returns opened fd to the loop device, <0 on error. | 99 | /* Returns opened fd to the loop device, <0 on error. |
82 | * *device is loop device to use, or if *device==NULL finds a loop device to | 100 | * *device is loop device to use, or if *device==NULL finds a loop device to |
83 | * mount it on and sets *device to a strdup of that loop device name. This | 101 | * mount it on and sets *device to a strdup of that loop device name. This |
@@ -106,12 +124,24 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
106 | return -errno; | 124 | return -errno; |
107 | } | 125 | } |
108 | 126 | ||
109 | //TODO: use LOOP_CTL_GET_FREE instead of trying every loopN in sequence? a-la: | 127 | try = *device; |
110 | // fd = open("/dev/loop-control", O_RDWR); | 128 | if (!try) { |
111 | // loopN = ioctl(fd, LOOP_CTL_GET_FREE); | 129 | i = get_free_loop(); |
112 | // | 130 | if (i == -2) { /* no /dev/loop-control */ |
131 | i = 0; | ||
132 | try = dev; | ||
133 | goto old_style; | ||
134 | } | ||
135 | if (i == -1) { | ||
136 | close(ffd); | ||
137 | return -1; /* no free loop devices */ | ||
138 | } | ||
139 | try = *device = xasprintf(LOOP_FORMAT, i); | ||
140 | goto try_to_open; | ||
141 | } | ||
142 | |||
143 | old_style: | ||
113 | /* Find a loop device. */ | 144 | /* Find a loop device. */ |
114 | try = *device ? *device : dev; | ||
115 | /* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */ | 145 | /* 1048575 (0xfffff) is a max possible minor number in Linux circa 2010 */ |
116 | for (i = 0; rc && i < 1048576; i++) { | 146 | for (i = 0; rc && i < 1048576; i++) { |
117 | sprintf(dev, LOOP_FORMAT, i); | 147 | sprintf(dev, LOOP_FORMAT, i); |
@@ -170,7 +200,7 @@ int FAST_FUNC set_loop(char **device, const char *file, unsigned long long offse | |||
170 | rc = ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo); | 200 | rc = ioctl(dfd, BB_LOOP_SET_STATUS, &loopinfo); |
171 | } | 201 | } |
172 | if (rc != 0) { | 202 | if (rc != 0) { |
173 | ioctl(dfd, LOOP_CLR_FD, 0); | 203 | ioctl(dfd, LOOP_CLR_FD, 0); // actually, 0 param is unnecessary |
174 | } | 204 | } |
175 | } | 205 | } |
176 | } else { | 206 | } else { |
diff --git a/libbb/mtab.c b/libbb/mtab.c index 131705ddb..aa1a2a103 100644 --- a/libbb/mtab.c +++ b/libbb/mtab.c | |||
@@ -21,7 +21,7 @@ void FAST_FUNC erase_mtab(const char *name) | |||
21 | /* Bummer. Fall back on trying the /proc filesystem */ | 21 | /* Bummer. Fall back on trying the /proc filesystem */ |
22 | if (!mountTable) mountTable = setmntent("/proc/mounts", "r"); | 22 | if (!mountTable) mountTable = setmntent("/proc/mounts", "r"); |
23 | if (!mountTable) { | 23 | if (!mountTable) { |
24 | bb_perror_msg(bb_path_mtab_file); | 24 | bb_simple_perror_msg(bb_path_mtab_file); |
25 | return; | 25 | return; |
26 | } | 26 | } |
27 | 27 | ||
@@ -49,6 +49,6 @@ void FAST_FUNC erase_mtab(const char *name) | |||
49 | } | 49 | } |
50 | endmntent(mountTable); | 50 | endmntent(mountTable); |
51 | } else if (errno != EROFS) | 51 | } else if (errno != EROFS) |
52 | bb_perror_msg(bb_path_mtab_file); | 52 | bb_simple_perror_msg(bb_path_mtab_file); |
53 | } | 53 | } |
54 | #endif | 54 | #endif |
diff --git a/libbb/perror_nomsg.c b/libbb/perror_nomsg.c index a2a11cc8e..d7d53de44 100644 --- a/libbb/perror_nomsg.c +++ b/libbb/perror_nomsg.c | |||
@@ -12,11 +12,11 @@ | |||
12 | * instead of including libbb.h */ | 12 | * instead of including libbb.h */ |
13 | //#include "libbb.h" | 13 | //#include "libbb.h" |
14 | #include "platform.h" | 14 | #include "platform.h" |
15 | extern void bb_perror_msg(const char *s, ...) FAST_FUNC; | 15 | extern void bb_simple_perror_msg(const char *s) FAST_FUNC; |
16 | 16 | ||
17 | /* suppress gcc "no previous prototype" warning */ | 17 | /* suppress gcc "no previous prototype" warning */ |
18 | void FAST_FUNC bb_perror_nomsg(void); | 18 | void FAST_FUNC bb_perror_nomsg(void); |
19 | void FAST_FUNC bb_perror_nomsg(void) | 19 | void FAST_FUNC bb_perror_nomsg(void) |
20 | { | 20 | { |
21 | bb_perror_msg(0); | 21 | bb_simple_perror_msg(0); |
22 | } | 22 | } |
diff --git a/libbb/perror_nomsg_and_die.c b/libbb/perror_nomsg_and_die.c index 543ff5178..bea5f25a5 100644 --- a/libbb/perror_nomsg_and_die.c +++ b/libbb/perror_nomsg_and_die.c | |||
@@ -12,11 +12,11 @@ | |||
12 | * instead of including libbb.h */ | 12 | * instead of including libbb.h */ |
13 | //#include "libbb.h" | 13 | //#include "libbb.h" |
14 | #include "platform.h" | 14 | #include "platform.h" |
15 | extern void bb_perror_msg_and_die(const char *s, ...) FAST_FUNC; | 15 | extern void bb_simple_perror_msg_and_die(const char *s) FAST_FUNC; |
16 | 16 | ||
17 | /* suppress gcc "no previous prototype" warning */ | 17 | /* suppress gcc "no previous prototype" warning */ |
18 | void FAST_FUNC bb_perror_nomsg_and_die(void); | 18 | void FAST_FUNC bb_perror_nomsg_and_die(void); |
19 | void FAST_FUNC bb_perror_nomsg_and_die(void) | 19 | void FAST_FUNC bb_perror_nomsg_and_die(void) |
20 | { | 20 | { |
21 | bb_perror_msg_and_die(0); | 21 | bb_simple_perror_msg_and_die(0); |
22 | } | 22 | } |
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index 86455cd0d..47c20690f 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -6,7 +6,9 @@ | |||
6 | * | 6 | * |
7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. | 7 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
8 | */ | 8 | */ |
9 | #if !ENABLE_USE_BB_CRYPT | ||
9 | #include <crypt.h> | 10 | #include <crypt.h> |
11 | #endif | ||
10 | #include "libbb.h" | 12 | #include "libbb.h" |
11 | 13 | ||
12 | /* static const uint8_t ascii64[] ALIGN1 = | 14 | /* static const uint8_t ascii64[] ALIGN1 = |
diff --git a/libbb/read_printf.c b/libbb/read_printf.c index 1e67d6542..379dd2448 100644 --- a/libbb/read_printf.c +++ b/libbb/read_printf.c | |||
@@ -222,7 +222,7 @@ void FAST_FUNC xread(int fd, void *buf, size_t count) | |||
222 | if (count) { | 222 | if (count) { |
223 | ssize_t size = full_read(fd, buf, count); | 223 | ssize_t size = full_read(fd, buf, count); |
224 | if ((size_t)size != count) | 224 | if ((size_t)size != count) |
225 | bb_error_msg_and_die("short read"); | 225 | bb_simple_error_msg_and_die("short read"); |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
diff --git a/libbb/safe_poll.c b/libbb/safe_poll.c index cf93a9774..a07e785f3 100644 --- a/libbb/safe_poll.c +++ b/libbb/safe_poll.c | |||
@@ -27,7 +27,7 @@ int FAST_FUNC safe_poll(struct pollfd *ufds, nfds_t nfds, int timeout) | |||
27 | /* I doubt many callers would handle this correctly! */ | 27 | /* I doubt many callers would handle this correctly! */ |
28 | if (errno == ENOMEM) | 28 | if (errno == ENOMEM) |
29 | continue; | 29 | continue; |
30 | bb_perror_msg("poll"); | 30 | bb_simple_perror_msg("poll"); |
31 | return n; | 31 | return n; |
32 | } | 32 | } |
33 | } | 33 | } |
diff --git a/libbb/selinux_common.c b/libbb/selinux_common.c index c2585557f..f917a1c6a 100644 --- a/libbb/selinux_common.c +++ b/libbb/selinux_common.c | |||
@@ -48,7 +48,7 @@ void FAST_FUNC selinux_preserve_fcontext(int fdesc) | |||
48 | if (fgetfilecon(fdesc, &context) < 0) { | 48 | if (fgetfilecon(fdesc, &context) < 0) { |
49 | if (errno == ENODATA || errno == ENOTSUP) | 49 | if (errno == ENODATA || errno == ENOTSUP) |
50 | return; | 50 | return; |
51 | bb_perror_msg_and_die("fgetfilecon failed"); | 51 | bb_simple_perror_msg_and_die("fgetfilecon failed"); |
52 | } | 52 | } |
53 | setfscreatecon_or_die(context); | 53 | setfscreatecon_or_die(context); |
54 | freecon(context); | 54 | freecon(context); |
diff --git a/libbb/time.c b/libbb/time.c index f9b8da0b3..cab0ad602 100644 --- a/libbb/time.c +++ b/libbb/time.c | |||
@@ -258,7 +258,7 @@ char* FAST_FUNC strftime_YYYYMMDDHHMMSS(char *buf, unsigned len, time_t *tp) | |||
258 | static void get_mono(struct timespec *ts) | 258 | static void get_mono(struct timespec *ts) |
259 | { | 259 | { |
260 | if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts)) | 260 | if (syscall(__NR_clock_gettime, CLOCK_MONOTONIC, ts)) |
261 | bb_error_msg_and_die("clock_gettime(MONOTONIC) failed"); | 261 | bb_simple_error_msg_and_die("clock_gettime(MONOTONIC) failed"); |
262 | } | 262 | } |
263 | unsigned long long FAST_FUNC monotonic_ns(void) | 263 | unsigned long long FAST_FUNC monotonic_ns(void) |
264 | { | 264 | { |
diff --git a/libbb/unicode.c b/libbb/unicode.c index 89d42179b..79481f159 100644 --- a/libbb/unicode.c +++ b/libbb/unicode.c | |||
@@ -674,14 +674,20 @@ int FAST_FUNC wcwidth(unsigned ucs) | |||
674 | ( (/*ucs >= 0x1100 &&*/ ucs <= 0x115f) /* Hangul Jamo init. consonants */ | 674 | ( (/*ucs >= 0x1100 &&*/ ucs <= 0x115f) /* Hangul Jamo init. consonants */ |
675 | || ucs == 0x2329 /* left-pointing angle bracket; also CJK punct. char */ | 675 | || ucs == 0x2329 /* left-pointing angle bracket; also CJK punct. char */ |
676 | || ucs == 0x232a /* right-pointing angle bracket; also CJK punct. char */ | 676 | || ucs == 0x232a /* right-pointing angle bracket; also CJK punct. char */ |
677 | # if CONFIG_LAST_SUPPORTED_WCHAR >= 0x2e80 | ||
677 | || (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) /* CJK ... Yi */ | 678 | || (ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f) /* CJK ... Yi */ |
679 | # endif | ||
678 | # if CONFIG_LAST_SUPPORTED_WCHAR >= 0xac00 | 680 | # if CONFIG_LAST_SUPPORTED_WCHAR >= 0xac00 |
679 | || (ucs >= 0xac00 && ucs <= 0xd7a3) /* Hangul Syllables */ | 681 | || (ucs >= 0xac00 && ucs <= 0xd7a3) /* Hangul Syllables */ |
682 | # endif | ||
683 | # if CONFIG_LAST_SUPPORTED_WCHAR >= 0xf900 | ||
680 | || (ucs >= 0xf900 && ucs <= 0xfaff) /* CJK Compatibility Ideographs */ | 684 | || (ucs >= 0xf900 && ucs <= 0xfaff) /* CJK Compatibility Ideographs */ |
681 | || (ucs >= 0xfe10 && ucs <= 0xfe19) /* Vertical forms */ | 685 | || (ucs >= 0xfe10 && ucs <= 0xfe19) /* Vertical forms */ |
682 | || (ucs >= 0xfe30 && ucs <= 0xfe6f) /* CJK Compatibility Forms */ | 686 | || (ucs >= 0xfe30 && ucs <= 0xfe6f) /* CJK Compatibility Forms */ |
683 | || (ucs >= 0xff00 && ucs <= 0xff60) /* Fullwidth Forms */ | 687 | || (ucs >= 0xff00 && ucs <= 0xff60) /* Fullwidth Forms */ |
684 | || (ucs >= 0xffe0 && ucs <= 0xffe6) | 688 | || (ucs >= 0xffe0 && ucs <= 0xffe6) |
689 | # endif | ||
690 | # if CONFIG_LAST_SUPPORTED_WCHAR >= 0x20000 | ||
685 | || ((ucs >> 17) == (2 >> 1)) /* 20000..3ffff: Supplementary and Tertiary Ideographic Planes */ | 691 | || ((ucs >> 17) == (2 >> 1)) /* 20000..3ffff: Supplementary and Tertiary Ideographic Planes */ |
686 | # endif | 692 | # endif |
687 | ); | 693 | ); |
diff --git a/libbb/update_passwd.c b/libbb/update_passwd.c index 95423d19b..c605c4c64 100644 --- a/libbb/update_passwd.c +++ b/libbb/update_passwd.c | |||
@@ -25,7 +25,7 @@ static void check_selinux_update_passwd(const char *username) | |||
25 | return; /* No need to check */ | 25 | return; /* No need to check */ |
26 | 26 | ||
27 | if (getprevcon_raw(&context) < 0) | 27 | if (getprevcon_raw(&context) < 0) |
28 | bb_perror_msg_and_die("getprevcon failed"); | 28 | bb_simple_perror_msg_and_die("getprevcon failed"); |
29 | seuser = strtok(context, ":"); | 29 | seuser = strtok(context, ":"); |
30 | if (!seuser) | 30 | if (!seuser) |
31 | bb_error_msg_and_die("invalid context '%s'", context); | 31 | bb_error_msg_and_die("invalid context '%s'", context); |
@@ -42,7 +42,7 @@ static void check_selinux_update_passwd(const char *username) | |||
42 | 42 | ||
43 | if (selinux_check_passwd_access(av) != 0) | 43 | if (selinux_check_passwd_access(av) != 0) |
44 | die: | 44 | die: |
45 | bb_error_msg_and_die("SELinux: access denied"); | 45 | bb_simple_error_msg_and_die("SELinux: access denied"); |
46 | } | 46 | } |
47 | if (ENABLE_FEATURE_CLEAN_UP) | 47 | if (ENABLE_FEATURE_CLEAN_UP) |
48 | freecon(context); | 48 | freecon(context); |
@@ -270,10 +270,16 @@ int FAST_FUNC update_passwd(const char *filename, | |||
270 | if (shadow && *cp == ':') { | 270 | if (shadow && *cp == ':') { |
271 | /* /etc/shadow's field 3 (passwd change date) needs updating */ | 271 | /* /etc/shadow's field 3 (passwd change date) needs updating */ |
272 | /* move past old change date */ | 272 | /* move past old change date */ |
273 | unsigned time_days = (unsigned long)(time(NULL)) / (24*60*60); | ||
274 | |||
275 | if (time_days == 0) { | ||
276 | /* 0 as change date has special meaning, avoid it */ | ||
277 | time_days = 1; | ||
278 | } | ||
273 | cp = strchrnul(cp + 1, ':'); | 279 | cp = strchrnul(cp + 1, ':'); |
274 | /* "name:" + "new_passwd" + ":" + "change date" + ":rest of line" */ | 280 | /* "name:" + "new_passwd" + ":" + "change date" + ":rest of line" */ |
275 | fprintf(new_fp, "%s%s:%u%s\n", name_colon, new_passwd, | 281 | fprintf(new_fp, "%s%s:%u%s\n", name_colon, new_passwd, |
276 | (unsigned)(time(NULL)) / (24*60*60), cp); | 282 | time_days, cp); |
277 | } else { | 283 | } else { |
278 | /* "name:" + "new_passwd" + ":rest of line" */ | 284 | /* "name:" + "new_passwd" + ":rest of line" */ |
279 | fprintf(new_fp, "%s%s%s\n", name_colon, new_passwd, cp); | 285 | fprintf(new_fp, "%s%s%s\n", name_colon, new_passwd, cp); |
diff --git a/libbb/uuencode.c b/libbb/uuencode.c index f32a3da7d..d36b34f63 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c | |||
@@ -213,7 +213,7 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags) | |||
213 | if (*in_tail == '\0') | 213 | if (*in_tail == '\0') |
214 | return; | 214 | return; |
215 | /* No */ | 215 | /* No */ |
216 | bb_error_msg_and_die("truncated base64 input"); | 216 | bb_simple_error_msg_and_die("truncated base64 input"); |
217 | } | 217 | } |
218 | 218 | ||
219 | /* It was partial decode */ | 219 | /* It was partial decode */ |
diff --git a/libbb/verror_msg.c b/libbb/verror_msg.c index 6d3459905..71512aee2 100644 --- a/libbb/verror_msg.c +++ b/libbb/verror_msg.c | |||
@@ -197,4 +197,19 @@ void FAST_FUNC bb_info_msg(const char *s, ...) | |||
197 | bb_vinfo_msg(s, p); | 197 | bb_vinfo_msg(s, p); |
198 | va_end(p); | 198 | va_end(p); |
199 | } | 199 | } |
200 | |||
201 | void FAST_FUNC bb_simple_info_msg(const char *s) | ||
202 | { | ||
203 | bb_info_msg("%s", s); | ||
204 | } | ||
200 | #endif | 205 | #endif |
206 | |||
207 | void FAST_FUNC bb_simple_error_msg(const char *s) | ||
208 | { | ||
209 | bb_error_msg("%s", s); | ||
210 | } | ||
211 | |||
212 | void FAST_FUNC bb_simple_error_msg_and_die(const char *s) | ||
213 | { | ||
214 | bb_error_msg_and_die("%s", s); | ||
215 | } | ||
diff --git a/libbb/warn_ignoring_args.c b/libbb/warn_ignoring_args.c index 3f3025c03..b24546e41 100644 --- a/libbb/warn_ignoring_args.c +++ b/libbb/warn_ignoring_args.c | |||
@@ -12,7 +12,7 @@ | |||
12 | void FAST_FUNC bb_warn_ignoring_args(char *arg) | 12 | void FAST_FUNC bb_warn_ignoring_args(char *arg) |
13 | { | 13 | { |
14 | if (arg) { | 14 | if (arg) { |
15 | bb_error_msg("ignoring all arguments"); | 15 | bb_simple_error_msg("ignoring all arguments"); |
16 | } | 16 | } |
17 | } | 17 | } |
18 | #endif | 18 | #endif |
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index a6127508b..38faef38e 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -11,6 +11,9 @@ | |||
11 | #include <netinet/in.h> | 11 | #include <netinet/in.h> |
12 | #include <net/if.h> | 12 | #include <net/if.h> |
13 | #include <sys/un.h> | 13 | #include <sys/un.h> |
14 | #if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT | ||
15 | # include <linux/netlink.h> | ||
16 | #endif | ||
14 | #include "libbb.h" | 17 | #include "libbb.h" |
15 | 18 | ||
16 | int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval) | 19 | int FAST_FUNC setsockopt_int(int fd, int level, int optname, int optval) |
@@ -63,7 +66,7 @@ int FAST_FUNC setsockopt_bindtodevice(int fd, const char *iface) | |||
63 | int FAST_FUNC setsockopt_bindtodevice(int fd UNUSED_PARAM, | 66 | int FAST_FUNC setsockopt_bindtodevice(int fd UNUSED_PARAM, |
64 | const char *iface UNUSED_PARAM) | 67 | const char *iface UNUSED_PARAM) |
65 | { | 68 | { |
66 | bb_error_msg("SO_BINDTODEVICE is not supported on this system"); | 69 | bb_simple_error_msg("SO_BINDTODEVICE is not supported on this system"); |
67 | return -1; | 70 | return -1; |
68 | } | 71 | } |
69 | #endif | 72 | #endif |
@@ -108,7 +111,7 @@ void FAST_FUNC xconnect(int s, const struct sockaddr *saddr, socklen_t addrlen) | |||
108 | bb_perror_msg_and_die("%s (%s)", | 111 | bb_perror_msg_and_die("%s (%s)", |
109 | "can't connect to remote host", | 112 | "can't connect to remote host", |
110 | inet_ntoa(((struct sockaddr_in *)saddr)->sin_addr)); | 113 | inet_ntoa(((struct sockaddr_in *)saddr)->sin_addr)); |
111 | bb_perror_msg_and_die("can't connect to remote host"); | 114 | bb_simple_perror_msg_and_die("can't connect to remote host"); |
112 | } | 115 | } |
113 | } | 116 | } |
114 | 117 | ||
@@ -132,6 +135,7 @@ unsigned FAST_FUNC bb_lookup_port(const char *port, const char *protocol, unsign | |||
132 | port_nr = default_port; | 135 | port_nr = default_port; |
133 | if (tserv) | 136 | if (tserv) |
134 | port_nr = ntohs(tserv->s_port); | 137 | port_nr = ntohs(tserv->s_port); |
138 | //FIXME: else: port string was garbage, but we don't report that??? | ||
135 | } | 139 | } |
136 | errno = old_errno; | 140 | errno = old_errno; |
137 | } | 141 | } |
@@ -418,6 +422,38 @@ int FAST_FUNC create_and_bind_dgram_or_die(const char *bindaddr, int port) | |||
418 | } | 422 | } |
419 | 423 | ||
420 | 424 | ||
425 | #if ENABLE_IFPLUGD || ENABLE_FEATURE_MDEV_DAEMON || ENABLE_UEVENT | ||
426 | int FAST_FUNC create_and_bind_to_netlink(int proto, int grp, unsigned rcvbuf) | ||
427 | { | ||
428 | struct sockaddr_nl sa; | ||
429 | int fd; | ||
430 | |||
431 | memset(&sa, 0, sizeof(sa)); | ||
432 | sa.nl_family = AF_NETLINK; | ||
433 | sa.nl_pid = getpid(); | ||
434 | sa.nl_groups = grp; | ||
435 | fd = xsocket(AF_NETLINK, SOCK_DGRAM, proto); | ||
436 | xbind(fd, (struct sockaddr *) &sa, sizeof(sa)); | ||
437 | close_on_exec_on(fd); | ||
438 | |||
439 | if (rcvbuf != 0) { | ||
440 | // SO_RCVBUFFORCE (root only) can go above net.core.rmem_max sysctl | ||
441 | setsockopt_SOL_SOCKET_int(fd, SO_RCVBUF, rcvbuf); | ||
442 | setsockopt_SOL_SOCKET_int(fd, SO_RCVBUFFORCE, rcvbuf); | ||
443 | # if 0 | ||
444 | { | ||
445 | int z; | ||
446 | socklen_t zl = sizeof(z); | ||
447 | getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &z, &zl); | ||
448 | bb_error_msg("SO_RCVBUF:%d", z); | ||
449 | } | ||
450 | # endif | ||
451 | } | ||
452 | |||
453 | return fd; | ||
454 | } | ||
455 | #endif | ||
456 | |||
421 | int FAST_FUNC create_and_connect_stream_or_die(const char *peer, int port) | 457 | int FAST_FUNC create_and_connect_stream_or_die(const char *peer, int port) |
422 | { | 458 | { |
423 | int fd; | 459 | int fd; |
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c index 57bda6204..c92436683 100644 --- a/libbb/xfuncs.c +++ b/libbb/xfuncs.c | |||
@@ -430,6 +430,6 @@ int FAST_FUNC wait_for_exitstatus(pid_t pid) | |||
430 | 430 | ||
431 | n = safe_waitpid(pid, &exit_status, 0); | 431 | n = safe_waitpid(pid, &exit_status, 0); |
432 | if (n < 0) | 432 | if (n < 0) |
433 | bb_perror_msg_and_die("waitpid"); | 433 | bb_simple_perror_msg_and_die("waitpid"); |
434 | return exit_status; | 434 | return exit_status; |
435 | } | 435 | } |
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index a0db2b86e..cfe062a47 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -27,7 +27,7 @@ | |||
27 | 27 | ||
28 | void FAST_FUNC bb_die_memory_exhausted(void) | 28 | void FAST_FUNC bb_die_memory_exhausted(void) |
29 | { | 29 | { |
30 | bb_error_msg_and_die(bb_msg_memory_exhausted); | 30 | bb_simple_error_msg_and_die(bb_msg_memory_exhausted); |
31 | } | 31 | } |
32 | 32 | ||
33 | #ifndef DMALLOC | 33 | #ifndef DMALLOC |
@@ -40,7 +40,7 @@ void* FAST_FUNC malloc_or_warn(size_t size) | |||
40 | { | 40 | { |
41 | void *ptr = malloc(size); | 41 | void *ptr = malloc(size); |
42 | if (ptr == NULL && size != 0) | 42 | if (ptr == NULL && size != 0) |
43 | bb_error_msg(bb_msg_memory_exhausted); | 43 | bb_simple_error_msg(bb_msg_memory_exhausted); |
44 | return ptr; | 44 | return ptr; |
45 | } | 45 | } |
46 | 46 | ||
@@ -97,7 +97,7 @@ char* FAST_FUNC xstrndup(const char *s, int n) | |||
97 | char *t; | 97 | char *t; |
98 | 98 | ||
99 | if (ENABLE_DEBUG && s == NULL) | 99 | if (ENABLE_DEBUG && s == NULL) |
100 | bb_error_msg_and_die("xstrndup bug"); | 100 | bb_simple_error_msg_and_die("xstrndup bug"); |
101 | 101 | ||
102 | /* We can just xmalloc(n+1) and strncpy into it, */ | 102 | /* We can just xmalloc(n+1) and strncpy into it, */ |
103 | /* but think about xstrndup("abc", 10000) wastage! */ | 103 | /* but think about xstrndup("abc", 10000) wastage! */ |
@@ -215,13 +215,13 @@ int FAST_FUNC rename_or_warn(const char *oldpath, const char *newpath) | |||
215 | void FAST_FUNC xpipe(int filedes[2]) | 215 | void FAST_FUNC xpipe(int filedes[2]) |
216 | { | 216 | { |
217 | if (pipe(filedes)) | 217 | if (pipe(filedes)) |
218 | bb_perror_msg_and_die("can't create pipe"); | 218 | bb_simple_perror_msg_and_die("can't create pipe"); |
219 | } | 219 | } |
220 | 220 | ||
221 | void FAST_FUNC xdup2(int from, int to) | 221 | void FAST_FUNC xdup2(int from, int to) |
222 | { | 222 | { |
223 | if (dup2(from, to) != to) | 223 | if (dup2(from, to) != to) |
224 | bb_perror_msg_and_die("can't duplicate file descriptor"); | 224 | bb_simple_perror_msg_and_die("can't duplicate file descriptor"); |
225 | // " %d to %d", from, to); | 225 | // " %d to %d", from, to); |
226 | } | 226 | } |
227 | 227 | ||
@@ -245,7 +245,7 @@ void FAST_FUNC xwrite(int fd, const void *buf, size_t count) | |||
245 | * or some writes succeeded, then we hit an error. | 245 | * or some writes succeeded, then we hit an error. |
246 | * In either case, errno is set. | 246 | * In either case, errno is set. |
247 | */ | 247 | */ |
248 | bb_perror_msg_and_die( | 248 | bb_simple_perror_msg_and_die( |
249 | size >= 0 ? "short write" : "write error" | 249 | size >= 0 ? "short write" : "write error" |
250 | ); | 250 | ); |
251 | } | 251 | } |
@@ -259,7 +259,7 @@ void FAST_FUNC xwrite_str(int fd, const char *str) | |||
259 | void FAST_FUNC xclose(int fd) | 259 | void FAST_FUNC xclose(int fd) |
260 | { | 260 | { |
261 | if (close(fd)) | 261 | if (close(fd)) |
262 | bb_perror_msg_and_die("close failed"); | 262 | bb_simple_perror_msg_and_die("close failed"); |
263 | } | 263 | } |
264 | 264 | ||
265 | // Die with an error message if we can't lseek to the right spot. | 265 | // Die with an error message if we can't lseek to the right spot. |
@@ -267,9 +267,7 @@ off_t FAST_FUNC xlseek(int fd, off_t offset, int whence) | |||
267 | { | 267 | { |
268 | off_t off = lseek(fd, offset, whence); | 268 | off_t off = lseek(fd, offset, whence); |
269 | if (off == (off_t)-1) { | 269 | if (off == (off_t)-1) { |
270 | if (whence == SEEK_SET) | 270 | bb_perror_msg_and_die("lseek(%"OFF_FMT"u, %d)", offset, whence); |
271 | bb_perror_msg_and_die("lseek(%"OFF_FMT"u)", offset); | ||
272 | bb_perror_msg_and_die("lseek"); | ||
273 | } | 271 | } |
274 | return off; | 272 | return off; |
275 | } | 273 | } |
@@ -384,23 +382,23 @@ void FAST_FUNC bb_unsetenv_and_free(char *var) | |||
384 | // setgid() will fail and we'll _still_be_root_, which is bad.) | 382 | // setgid() will fail and we'll _still_be_root_, which is bad.) |
385 | void FAST_FUNC xsetgid(gid_t gid) | 383 | void FAST_FUNC xsetgid(gid_t gid) |
386 | { | 384 | { |
387 | if (setgid(gid)) bb_perror_msg_and_die("setgid"); | 385 | if (setgid(gid)) bb_simple_perror_msg_and_die("setgid"); |
388 | } | 386 | } |
389 | 387 | ||
390 | // Die with an error message if we can't set uid. (See xsetgid() for why.) | 388 | // Die with an error message if we can't set uid. (See xsetgid() for why.) |
391 | void FAST_FUNC xsetuid(uid_t uid) | 389 | void FAST_FUNC xsetuid(uid_t uid) |
392 | { | 390 | { |
393 | if (setuid(uid)) bb_perror_msg_and_die("setuid"); | 391 | if (setuid(uid)) bb_simple_perror_msg_and_die("setuid"); |
394 | } | 392 | } |
395 | 393 | ||
396 | void FAST_FUNC xsetegid(gid_t egid) | 394 | void FAST_FUNC xsetegid(gid_t egid) |
397 | { | 395 | { |
398 | if (setegid(egid)) bb_perror_msg_and_die("setegid"); | 396 | if (setegid(egid)) bb_simple_perror_msg_and_die("setegid"); |
399 | } | 397 | } |
400 | 398 | ||
401 | void FAST_FUNC xseteuid(uid_t euid) | 399 | void FAST_FUNC xseteuid(uid_t euid) |
402 | { | 400 | { |
403 | if (seteuid(euid)) bb_perror_msg_and_die("seteuid"); | 401 | if (seteuid(euid)) bb_simple_perror_msg_and_die("seteuid"); |
404 | } | 402 | } |
405 | 403 | ||
406 | // Die if we can't chdir to a new path. | 404 | // Die if we can't chdir to a new path. |
@@ -413,7 +411,7 @@ void FAST_FUNC xchdir(const char *path) | |||
413 | void FAST_FUNC xfchdir(int fd) | 411 | void FAST_FUNC xfchdir(int fd) |
414 | { | 412 | { |
415 | if (fchdir(fd)) | 413 | if (fchdir(fd)) |
416 | bb_perror_msg_and_die("fchdir"); | 414 | bb_simple_perror_msg_and_die("fchdir"); |
417 | } | 415 | } |
418 | 416 | ||
419 | void FAST_FUNC xchroot(const char *path) | 417 | void FAST_FUNC xchroot(const char *path) |
@@ -463,7 +461,7 @@ int FAST_FUNC xsocket(int domain, int type, int protocol) | |||
463 | IF_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";) | 461 | IF_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";) |
464 | bb_perror_msg_and_die("socket(AF_%s,%d,%d)", s, type, protocol); | 462 | bb_perror_msg_and_die("socket(AF_%s,%d,%d)", s, type, protocol); |
465 | #else | 463 | #else |
466 | bb_perror_msg_and_die("socket"); | 464 | bb_simple_perror_msg_and_die("socket"); |
467 | #endif | 465 | #endif |
468 | } | 466 | } |
469 | 467 | ||
@@ -473,13 +471,13 @@ IF_FEATURE_IPV6(if (domain == AF_INET6) s = "INET6";) | |||
473 | // Die with an error message if we can't bind a socket to an address. | 471 | // Die with an error message if we can't bind a socket to an address. |
474 | void FAST_FUNC xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) | 472 | void FAST_FUNC xbind(int sockfd, struct sockaddr *my_addr, socklen_t addrlen) |
475 | { | 473 | { |
476 | if (bind(sockfd, my_addr, addrlen)) bb_perror_msg_and_die("bind"); | 474 | if (bind(sockfd, my_addr, addrlen)) bb_simple_perror_msg_and_die("bind"); |
477 | } | 475 | } |
478 | 476 | ||
479 | // Die with an error message if we can't listen for connections on a socket. | 477 | // Die with an error message if we can't listen for connections on a socket. |
480 | void FAST_FUNC xlisten(int s, int backlog) | 478 | void FAST_FUNC xlisten(int s, int backlog) |
481 | { | 479 | { |
482 | if (listen(s, backlog)) bb_perror_msg_and_die("listen"); | 480 | if (listen(s, backlog)) bb_simple_perror_msg_and_die("listen"); |
483 | } | 481 | } |
484 | 482 | ||
485 | /* Die with an error message if sendto failed. | 483 | /* Die with an error message if sendto failed. |
@@ -491,7 +489,7 @@ ssize_t FAST_FUNC xsendto(int s, const void *buf, size_t len, const struct socka | |||
491 | if (ret < 0) { | 489 | if (ret < 0) { |
492 | if (ENABLE_FEATURE_CLEAN_UP) | 490 | if (ENABLE_FEATURE_CLEAN_UP) |
493 | close(s); | 491 | close(s); |
494 | bb_perror_msg_and_die("sendto"); | 492 | bb_simple_perror_msg_and_die("sendto"); |
495 | } | 493 | } |
496 | return ret; | 494 | return ret; |
497 | } | 495 | } |
@@ -520,12 +518,12 @@ void FAST_FUNC selinux_or_die(void) | |||
520 | #if ENABLE_SELINUX | 518 | #if ENABLE_SELINUX |
521 | int rc = is_selinux_enabled(); | 519 | int rc = is_selinux_enabled(); |
522 | if (rc == 0) { | 520 | if (rc == 0) { |
523 | bb_error_msg_and_die("SELinux is disabled"); | 521 | bb_simple_error_msg_and_die("SELinux is disabled"); |
524 | } else if (rc < 0) { | 522 | } else if (rc < 0) { |
525 | bb_error_msg_and_die("is_selinux_enabled() failed"); | 523 | bb_simple_error_msg_and_die("is_selinux_enabled() failed"); |
526 | } | 524 | } |
527 | #else | 525 | #else |
528 | bb_error_msg_and_die("SELinux support is disabled"); | 526 | bb_simple_error_msg_and_die("SELinux support is disabled"); |
529 | #endif | 527 | #endif |
530 | } | 528 | } |
531 | 529 | ||
@@ -676,7 +674,7 @@ pid_t FAST_FUNC xfork(void) | |||
676 | pid_t pid; | 674 | pid_t pid; |
677 | pid = fork(); | 675 | pid = fork(); |
678 | if (pid < 0) /* wtf? */ | 676 | if (pid < 0) /* wtf? */ |
679 | bb_perror_msg_and_die("vfork"+1); | 677 | bb_simple_perror_msg_and_die("vfork"+1); |
680 | return pid; | 678 | return pid; |
681 | } | 679 | } |
682 | #endif | 680 | #endif |
diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c index 7f9088bda..f4e768982 100644 --- a/libbb/xgetcwd.c +++ b/libbb/xgetcwd.c | |||
@@ -33,7 +33,7 @@ xrealloc_getcwd_or_warn(char *cwd) | |||
33 | if (errno == ERANGE) | 33 | if (errno == ERANGE) |
34 | continue; | 34 | continue; |
35 | free(cwd); | 35 | free(cwd); |
36 | bb_perror_msg("getcwd"); | 36 | bb_simple_perror_msg("getcwd"); |
37 | return NULL; | 37 | return NULL; |
38 | } | 38 | } |
39 | cwd = xrealloc(cwd, strlen(cwd) + 1); | 39 | cwd = xrealloc(cwd, strlen(cwd) + 1); |
diff --git a/libbb/xgethostbyname.c b/libbb/xgethostbyname.c index 89d0329cc..9446daba7 100644 --- a/libbb/xgethostbyname.c +++ b/libbb/xgethostbyname.c | |||
@@ -12,6 +12,6 @@ struct hostent* FAST_FUNC xgethostbyname(const char *name) | |||
12 | { | 12 | { |
13 | struct hostent *retval = gethostbyname(name); | 13 | struct hostent *retval = gethostbyname(name); |
14 | if (!retval) | 14 | if (!retval) |
15 | bb_herror_msg_and_die("%s", name); | 15 | bb_simple_herror_msg_and_die(name); |
16 | return retval; | 16 | return retval; |
17 | } | 17 | } |
diff --git a/libbb/xreadlink.c b/libbb/xreadlink.c index 9ae70de99..ca53e12d3 100644 --- a/libbb/xreadlink.c +++ b/libbb/xreadlink.c | |||
@@ -147,6 +147,35 @@ char* FAST_FUNC xmalloc_realpath_coreutils(const char *path) | |||
147 | buf[len++] = '/'; | 147 | buf[len++] = '/'; |
148 | strcpy(buf + len, last_slash); | 148 | strcpy(buf + len, last_slash); |
149 | } | 149 | } |
150 | } else { | ||
151 | char *target = xmalloc_readlink(path); | ||
152 | if (target) { | ||
153 | char *cwd; | ||
154 | if (target[0] == '/') { | ||
155 | /* | ||
156 | * $ ln -s /bin/qwe symlink # note: /bin is a link to /usr/bin | ||
157 | * $ readlink -f symlink | ||
158 | * /usr/bin/qwe/target_does_not_exist | ||
159 | * $ realpath symlink | ||
160 | * /usr/bin/qwe/target_does_not_exist | ||
161 | */ | ||
162 | buf = xmalloc_realpath_coreutils(target); | ||
163 | free(target); | ||
164 | return buf; | ||
165 | } | ||
166 | /* | ||
167 | * $ ln -s target_does_not_exist symlink | ||
168 | * $ readlink -f symlink | ||
169 | * /CURDIR/target_does_not_exist | ||
170 | * $ realpath symlink | ||
171 | * /CURDIR/target_does_not_exist | ||
172 | */ | ||
173 | cwd = xrealloc_getcwd_or_warn(NULL); | ||
174 | buf = concat_path_file(cwd, target); | ||
175 | free(cwd); | ||
176 | free(target); | ||
177 | return buf; | ||
178 | } | ||
150 | } | 179 | } |
151 | } | 180 | } |
152 | 181 | ||