diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-20 20:21:31 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2017-08-20 20:21:31 +0200 |
commit | ec2482e966c505d9076cf8581dabc4925c4c8bfe (patch) | |
tree | 1f6d7f1bded5446cbb5324fa5db28ff73efed437 | |
parent | 20c0d07e952ab764b6d8d46bfe30c30efcba005c (diff) | |
download | busybox-w32-ec2482e966c505d9076cf8581dabc4925c4c8bfe.tar.gz busybox-w32-ec2482e966c505d9076cf8581dabc4925c4c8bfe.tar.bz2 busybox-w32-ec2482e966c505d9076cf8581dabc4925c4c8bfe.zip |
setpriv: code shrink
function old new delta
parse_cap 125 117 -8
setpriv_main 949 933 -16
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-24) Total: -24 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | util-linux/setpriv.c | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index 76fb62c22..c549bcaf8 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c | |||
@@ -211,7 +211,7 @@ static void getcaps(struct caps *caps) | |||
211 | bb_simple_perror_msg_and_die("capget"); | 211 | bb_simple_perror_msg_and_die("capget"); |
212 | } | 212 | } |
213 | 213 | ||
214 | static void parse_cap(unsigned long *index, const char *cap) | 214 | static unsigned long parse_cap(const char *cap) |
215 | { | 215 | { |
216 | unsigned long i; | 216 | unsigned long i; |
217 | 217 | ||
@@ -229,8 +229,7 @@ static void parse_cap(unsigned long *index, const char *cap) | |||
229 | if ((sscanf(cap, "cap_%lu", &i)) == 1) { | 229 | if ((sscanf(cap, "cap_%lu", &i)) == 1) { |
230 | if (!cap_valid(i)) | 230 | if (!cap_valid(i)) |
231 | bb_error_msg_and_die("unsupported capability '%s'", cap); | 231 | bb_error_msg_and_die("unsupported capability '%s'", cap); |
232 | *index = i; | 232 | return i; |
233 | return; | ||
234 | } | 233 | } |
235 | 234 | ||
236 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES | 235 | # if ENABLE_FEATURE_SETPRIV_CAPABILITY_NAMES |
@@ -240,8 +239,7 @@ static void parse_cap(unsigned long *index, const char *cap) | |||
240 | 239 | ||
241 | if (!cap_valid(i)) | 240 | if (!cap_valid(i)) |
242 | bb_error_msg_and_die("unsupported capability '%s'", cap); | 241 | bb_error_msg_and_die("unsupported capability '%s'", cap); |
243 | *index = i; | 242 | return i; |
244 | return; | ||
245 | } | 243 | } |
246 | # endif | 244 | # endif |
247 | 245 | ||
@@ -258,7 +256,7 @@ static void set_inh_caps(char *capstring) | |||
258 | while (capstring) { | 256 | while (capstring) { |
259 | unsigned long cap; | 257 | unsigned long cap; |
260 | 258 | ||
261 | parse_cap(&cap, capstring); | 259 | cap = parse_cap(capstring); |
262 | if (CAP_TO_INDEX(cap) >= caps.u32s) | 260 | if (CAP_TO_INDEX(cap) >= caps.u32s) |
263 | bb_error_msg_and_die("invalid capability cap"); | 261 | bb_error_msg_and_die("invalid capability cap"); |
264 | 262 | ||
@@ -284,7 +282,7 @@ static void set_ambient_caps(char *string) | |||
284 | while (cap) { | 282 | while (cap) { |
285 | unsigned long index; | 283 | unsigned long index; |
286 | 284 | ||
287 | parse_cap(&index, cap); | 285 | index = parse_cap(cap); |
288 | if (cap[0] == '+') { | 286 | if (cap[0] == '+') { |
289 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, index, 0, 0) < 0) | 287 | if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, index, 0, 0) < 0) |
290 | bb_perror_msg("cap_ambient_raise"); | 288 | bb_perror_msg("cap_ambient_raise"); |
@@ -421,8 +419,8 @@ int setpriv_main(int argc UNUSED_PARAM, char **argv) | |||
421 | int opts; | 419 | int opts; |
422 | IF_FEATURE_SETPRIV_CAPABILITIES(char *inh_caps, *ambient_caps;) | 420 | IF_FEATURE_SETPRIV_CAPABILITIES(char *inh_caps, *ambient_caps;) |
423 | 421 | ||
424 | opts = getopt32long(argv, | 422 | opts = getopt32long(argv, "+" |
425 | "+"IF_FEATURE_SETPRIV_DUMP("d") | 423 | IF_FEATURE_SETPRIV_DUMP("d") |
426 | IF_FEATURE_SETPRIV_CAPABILITIES("\xfe:\xfd:"), | 424 | IF_FEATURE_SETPRIV_CAPABILITIES("\xfe:\xfd:"), |
427 | setpriv_longopts | 425 | setpriv_longopts |
428 | IF_FEATURE_SETPRIV_CAPABILITIES(, &inh_caps, &ambient_caps) | 426 | IF_FEATURE_SETPRIV_CAPABILITIES(, &inh_caps, &ambient_caps) |