aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--archival/libarchive/decompress_uncompress.c13
-rw-r--r--editors/sed.c79
-rw-r--r--findutils/find.c5
-rw-r--r--findutils/grep.c22
-rw-r--r--include/platform.h2
-rw-r--r--libbb/getpty.c18
-rw-r--r--libbb/match_fstype.c4
-rw-r--r--libbb/procps.c34
-rw-r--r--libbb/udp_io.c2
-rw-r--r--miscutils/less.c7
-rw-r--r--shell/cttyhack.c8
-rwxr-xr-xtestsuite/sed.tests10
-rw-r--r--util-linux/swaponoff.c3
14 files changed, 131 insertions, 78 deletions
diff --git a/Makefile b/Makefile
index 7a1abda1b..138d1d425 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
1VERSION = 1 1VERSION = 1
2PATCHLEVEL = 19 2PATCHLEVEL = 19
3SUBLEVEL = 0 3SUBLEVEL = 1
4EXTRAVERSION = 4EXTRAVERSION =
5NAME = Unnamed 5NAME = Unnamed
6 6
diff --git a/archival/libarchive/decompress_uncompress.c b/archival/libarchive/decompress_uncompress.c
index 44d894244..d1061a2bb 100644
--- a/archival/libarchive/decompress_uncompress.c
+++ b/archival/libarchive/decompress_uncompress.c
@@ -163,7 +163,8 @@ unpack_Z_stream(int fd_in, int fd_out)
163 163
164 if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) { 164 if (insize < (int) (IBUFSIZ + 64) - IBUFSIZ) {
165 rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ); 165 rsize = safe_read(fd_in, inbuf + insize, IBUFSIZ);
166//error check?? 166 if (rsize < 0)
167 bb_error_msg_and_die(bb_msg_read_error);
167 insize += rsize; 168 insize += rsize;
168 } 169 }
169 170
@@ -195,6 +196,8 @@ unpack_Z_stream(int fd_in, int fd_out)
195 196
196 197
197 if (oldcode == -1) { 198 if (oldcode == -1) {
199 if (code >= 256)
200 bb_error_msg_and_die("corrupted data"); /* %ld", code); */
198 oldcode = code; 201 oldcode = code;
199 finchar = (int) oldcode; 202 finchar = (int) oldcode;
200 outbuf[outpos++] = (unsigned char) finchar; 203 outbuf[outpos++] = (unsigned char) finchar;
@@ -239,6 +242,8 @@ unpack_Z_stream(int fd_in, int fd_out)
239 242
240 /* Generate output characters in reverse order */ 243 /* Generate output characters in reverse order */
241 while ((long) code >= (long) 256) { 244 while ((long) code >= (long) 256) {
245 if (stackp <= &htabof(0))
246 bb_error_msg_and_die("corrupted data");
242 *--stackp = tab_suffixof(code); 247 *--stackp = tab_suffixof(code);
243 code = tab_prefixof(code); 248 code = tab_prefixof(code);
244 } 249 }
@@ -263,8 +268,7 @@ unpack_Z_stream(int fd_in, int fd_out)
263 } 268 }
264 269
265 if (outpos >= OBUFSIZ) { 270 if (outpos >= OBUFSIZ) {
266 full_write(fd_out, outbuf, outpos); 271 xwrite(fd_out, outbuf, outpos);
267//error check??
268 IF_DESKTOP(total_written += outpos;) 272 IF_DESKTOP(total_written += outpos;)
269 outpos = 0; 273 outpos = 0;
270 } 274 }
@@ -292,8 +296,7 @@ unpack_Z_stream(int fd_in, int fd_out)
292 } while (rsize > 0); 296 } while (rsize > 0);
293 297
294 if (outpos > 0) { 298 if (outpos > 0) {
295 full_write(fd_out, outbuf, outpos); 299 xwrite(fd_out, outbuf, outpos);
296//error check??
297 IF_DESKTOP(total_written += outpos;) 300 IF_DESKTOP(total_written += outpos;)
298 } 301 }
299 302
diff --git a/editors/sed.c b/editors/sed.c
index 5c4e9cc3b..1552cf370 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -75,6 +75,13 @@
75#include "libbb.h" 75#include "libbb.h"
76#include "xregex.h" 76#include "xregex.h"
77 77
78#if 0
79# define dbg(...) bb_error_msg(__VA_ARGS__)
80#else
81# define dbg(...) ((void)0)
82#endif
83
84
78enum { 85enum {
79 OPT_in_place = 1 << 0, 86 OPT_in_place = 1 << 0,
80}; 87};
@@ -89,6 +96,7 @@ typedef struct sed_cmd_s {
89 regex_t *end_match; /* sed -e '/match/,/end_match/cmd' */ 96 regex_t *end_match; /* sed -e '/match/,/end_match/cmd' */
90 regex_t *sub_match; /* For 's/sub_match/string/' */ 97 regex_t *sub_match; /* For 's/sub_match/string/' */
91 int beg_line; /* 'sed 1p' 0 == apply commands to all lines */ 98 int beg_line; /* 'sed 1p' 0 == apply commands to all lines */
99 int beg_line_orig; /* copy of the above, needed for -i */
92 int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($) */ 100 int end_line; /* 'sed 1,3p' 0 == one line only. -1 = last line ($) */
93 101
94 FILE *sw_file; /* File (sw) command writes to, -1 for none. */ 102 FILE *sw_file; /* File (sw) command writes to, -1 for none. */
@@ -123,7 +131,7 @@ struct globals {
123 regex_t *previous_regex_ptr; 131 regex_t *previous_regex_ptr;
124 132
125 /* linked list of sed commands */ 133 /* linked list of sed commands */
126 sed_cmd_t sed_cmd_head, *sed_cmd_tail; 134 sed_cmd_t *sed_cmd_head, **sed_cmd_tail;
127 135
128 /* Linked list of append lines */ 136 /* Linked list of append lines */
129 llist_t *append_head; 137 llist_t *append_head;
@@ -148,7 +156,7 @@ struct BUG_G_too_big {
148#if ENABLE_FEATURE_CLEAN_UP 156#if ENABLE_FEATURE_CLEAN_UP
149static void sed_free_and_close_stuff(void) 157static void sed_free_and_close_stuff(void)
150{ 158{
151 sed_cmd_t *sed_cmd = G.sed_cmd_head.next; 159 sed_cmd_t *sed_cmd = G.sed_cmd_head;
152 160
153 llist_free(G.append_head, free); 161 llist_free(G.append_head, free);
154 162
@@ -599,6 +607,7 @@ static void add_cmd(const char *cmdstr)
599 607
600 /* first part (if present) is an address: either a '$', a number or a /regex/ */ 608 /* first part (if present) is an address: either a '$', a number or a /regex/ */
601 cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); 609 cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
610 sed_cmd->beg_line_orig = sed_cmd->beg_line;
602 611
603 /* second part (if present) will begin with a comma */ 612 /* second part (if present) will begin with a comma */
604 if (*cmdstr == ',') { 613 if (*cmdstr == ',') {
@@ -630,8 +639,8 @@ static void add_cmd(const char *cmdstr)
630 cmdstr = parse_cmd_args(sed_cmd, cmdstr); 639 cmdstr = parse_cmd_args(sed_cmd, cmdstr);
631 640
632 /* Add the command to the command array */ 641 /* Add the command to the command array */
633 G.sed_cmd_tail->next = sed_cmd; 642 *G.sed_cmd_tail = sed_cmd;
634 G.sed_cmd_tail = G.sed_cmd_tail->next; 643 G.sed_cmd_tail = &sed_cmd->next;
635 } 644 }
636 645
637 /* If we glued multiple lines together, free the memory. */ 646 /* If we glued multiple lines together, free the memory. */
@@ -777,7 +786,7 @@ static sed_cmd_t *branch_to(char *label)
777{ 786{
778 sed_cmd_t *sed_cmd; 787 sed_cmd_t *sed_cmd;
779 788
780 for (sed_cmd = G.sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) { 789 for (sed_cmd = G.sed_cmd_head; sed_cmd; sed_cmd = sed_cmd->next) {
781 if (sed_cmd->cmd == ':' && sed_cmd->string && !strcmp(sed_cmd->string, label)) { 790 if (sed_cmd->cmd == ':' && sed_cmd->string && !strcmp(sed_cmd->string, label)) {
782 return sed_cmd; 791 return sed_cmd;
783 } 792 }
@@ -953,24 +962,24 @@ static void process_files(void)
953 962
954 /* For every line, go through all the commands */ 963 /* For every line, go through all the commands */
955 restart: 964 restart:
956 for (sed_cmd = G.sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) { 965 for (sed_cmd = G.sed_cmd_head; sed_cmd; sed_cmd = sed_cmd->next) {
957 int old_matched, matched; 966 int old_matched, matched;
958 967
959 old_matched = sed_cmd->in_match; 968 old_matched = sed_cmd->in_match;
960 969
961 /* Determine if this command matches this line: */ 970 /* Determine if this command matches this line: */
962 971
963 //bb_error_msg("match1:%d", sed_cmd->in_match); 972 dbg("match1:%d", sed_cmd->in_match);
964 //bb_error_msg("match2:%d", (!sed_cmd->beg_line && !sed_cmd->end_line 973 dbg("match2:%d", (!sed_cmd->beg_line && !sed_cmd->end_line
965 // && !sed_cmd->beg_match && !sed_cmd->end_match)); 974 && !sed_cmd->beg_match && !sed_cmd->end_match));
966 //bb_error_msg("match3:%d", (sed_cmd->beg_line > 0 975 dbg("match3:%d", (sed_cmd->beg_line > 0
967 // && (sed_cmd->end_line || sed_cmd->end_match 976 && (sed_cmd->end_line || sed_cmd->end_match
968 // ? (sed_cmd->beg_line <= linenum) 977 ? (sed_cmd->beg_line <= linenum)
969 // : (sed_cmd->beg_line == linenum) 978 : (sed_cmd->beg_line == linenum)
970 // ) 979 )
971 // ) 980 ));
972 //bb_error_msg("match4:%d", (beg_match(sed_cmd, pattern_space))); 981 dbg("match4:%d", (beg_match(sed_cmd, pattern_space)));
973 //bb_error_msg("match5:%d", (sed_cmd->beg_line == -1 && next_line == NULL)); 982 dbg("match5:%d", (sed_cmd->beg_line == -1 && next_line == NULL));
974 983
975 /* Are we continuing a previous multi-line match? */ 984 /* Are we continuing a previous multi-line match? */
976 sed_cmd->in_match = sed_cmd->in_match 985 sed_cmd->in_match = sed_cmd->in_match
@@ -981,7 +990,14 @@ static void process_files(void)
981 || (sed_cmd->beg_line > 0 990 || (sed_cmd->beg_line > 0
982 && (sed_cmd->end_line || sed_cmd->end_match 991 && (sed_cmd->end_line || sed_cmd->end_match
983 /* note: even if end is numeric and is < linenum too, 992 /* note: even if end is numeric and is < linenum too,
984 * GNU sed matches! We match too */ 993 * GNU sed matches! We match too, therefore we don't
994 * check here that linenum <= end.
995 * Example:
996 * printf '1\n2\n3\n4\n' | sed -n '1{N;N;d};1p;2,3p;3p;4p'
997 * first three input lines are deleted;
998 * 4th line is matched and printed
999 * by "2,3" (!) and by "4" ranges
1000 */
985 ? (sed_cmd->beg_line <= linenum) /* N,end */ 1001 ? (sed_cmd->beg_line <= linenum) /* N,end */
986 : (sed_cmd->beg_line == linenum) /* N */ 1002 : (sed_cmd->beg_line == linenum) /* N */
987 ) 1003 )
@@ -994,16 +1010,14 @@ static void process_files(void)
994 /* Snapshot the value */ 1010 /* Snapshot the value */
995 matched = sed_cmd->in_match; 1011 matched = sed_cmd->in_match;
996 1012
997 //bb_error_msg("cmd:'%c' matched:%d beg_line:%d end_line:%d linenum:%d", 1013 dbg("cmd:'%c' matched:%d beg_line:%d end_line:%d linenum:%d",
998 //sed_cmd->cmd, matched, sed_cmd->beg_line, sed_cmd->end_line, linenum); 1014 sed_cmd->cmd, matched, sed_cmd->beg_line, sed_cmd->end_line, linenum);
999 1015
1000 /* Is this line the end of the current match? */ 1016 /* Is this line the end of the current match? */
1001 1017
1002 if (matched) { 1018 if (matched) {
1003 /* once matched, "n,xxx" range is dead, disabling it */ 1019 /* once matched, "n,xxx" range is dead, disabling it */
1004 if (sed_cmd->beg_line > 0 1020 if (sed_cmd->beg_line > 0) {
1005 && !(option_mask32 & OPT_in_place) /* but not for -i */
1006 ) {
1007 sed_cmd->beg_line = -2; 1021 sed_cmd->beg_line = -2;
1008 } 1022 }
1009 sed_cmd->in_match = !( 1023 sed_cmd->in_match = !(
@@ -1017,7 +1031,8 @@ static void process_files(void)
1017 /* or does this line matches our last address regex */ 1031 /* or does this line matches our last address regex */
1018 || (sed_cmd->end_match && old_matched 1032 || (sed_cmd->end_match && old_matched
1019 && (regexec(sed_cmd->end_match, 1033 && (regexec(sed_cmd->end_match,
1020 pattern_space, 0, NULL, 0) == 0)) 1034 pattern_space, 0, NULL, 0) == 0)
1035 )
1021 ); 1036 );
1022 } 1037 }
1023 1038
@@ -1407,11 +1422,12 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1407 add_input_file(stdin); 1422 add_input_file(stdin);
1408 } else { 1423 } else {
1409 int i; 1424 int i;
1410 FILE *file;
1411 1425
1412 for (i = 0; argv[i]; i++) { 1426 for (i = 0; argv[i]; i++) {
1413 struct stat statbuf; 1427 struct stat statbuf;
1414 int nonstdoutfd; 1428 int nonstdoutfd;
1429 FILE *file;
1430 sed_cmd_t *sed_cmd;
1415 1431
1416 if (LONE_DASH(argv[i]) && !(opt & OPT_in_place)) { 1432 if (LONE_DASH(argv[i]) && !(opt & OPT_in_place)) {
1417 add_input_file(stdin); 1433 add_input_file(stdin);
@@ -1423,11 +1439,13 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1423 status = EXIT_FAILURE; 1439 status = EXIT_FAILURE;
1424 continue; 1440 continue;
1425 } 1441 }
1442 add_input_file(file);
1426 if (!(opt & OPT_in_place)) { 1443 if (!(opt & OPT_in_place)) {
1427 add_input_file(file);
1428 continue; 1444 continue;
1429 } 1445 }
1430 1446
1447 /* -i: process each FILE separately: */
1448
1431 G.outname = xasprintf("%sXXXXXX", argv[i]); 1449 G.outname = xasprintf("%sXXXXXX", argv[i]);
1432 nonstdoutfd = xmkstemp(G.outname); 1450 nonstdoutfd = xmkstemp(G.outname);
1433 G.nonstdout = xfdopen_for_write(nonstdoutfd); 1451 G.nonstdout = xfdopen_for_write(nonstdoutfd);
@@ -1438,15 +1456,20 @@ int sed_main(int argc UNUSED_PARAM, char **argv)
1438 * but GNU sed 4.2.1 does not preserve them either */ 1456 * but GNU sed 4.2.1 does not preserve them either */
1439 fchmod(nonstdoutfd, statbuf.st_mode); 1457 fchmod(nonstdoutfd, statbuf.st_mode);
1440 fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid); 1458 fchown(nonstdoutfd, statbuf.st_uid, statbuf.st_gid);
1441 add_input_file(file); 1459
1442 process_files(); 1460 process_files();
1443 fclose(G.nonstdout); 1461 fclose(G.nonstdout);
1444
1445 G.nonstdout = stdout; 1462 G.nonstdout = stdout;
1463
1446 /* unlink(argv[i]); */ 1464 /* unlink(argv[i]); */
1447 xrename(G.outname, argv[i]); 1465 xrename(G.outname, argv[i]);
1448 free(G.outname); 1466 free(G.outname);
1449 G.outname = NULL; 1467 G.outname = NULL;
1468
1469 /* Re-enable disabled range matches */
1470 for (sed_cmd = G.sed_cmd_head; sed_cmd; sed_cmd = sed_cmd->next) {
1471 sed_cmd->beg_line = sed_cmd->beg_line_orig;
1472 }
1450 } 1473 }
1451 /* Here, to handle "sed 'cmds' nonexistent_file" case we did: 1474 /* Here, to handle "sed 'cmds' nonexistent_file" case we did:
1452 * if (G.current_input_file >= G.input_file_count) 1475 * if (G.current_input_file >= G.input_file_count)
diff --git a/findutils/find.c b/findutils/find.c
index 05f88d2f0..fc0fc5c9f 100644
--- a/findutils/find.c
+++ b/findutils/find.c
@@ -932,7 +932,10 @@ static action*** parse_params(char **argv)
932 * expression is reached. 932 * expression is reached.
933 */ 933 */
934 /* Options */ 934 /* Options */
935 if (0) { } 935 if (parm == OPT_FOLLOW) {
936 dbg("follow enabled: %d", __LINE__);
937 G.recurse_flags |= ACTION_FOLLOWLINKS | ACTION_DANGLING_OK;
938 }
936#if ENABLE_FEATURE_FIND_XDEV 939#if ENABLE_FEATURE_FIND_XDEV
937 else if (parm == OPT_XDEV) { 940 else if (parm == OPT_XDEV) {
938 dbg("%d", __LINE__); 941 dbg("%d", __LINE__);
diff --git a/findutils/grep.c b/findutils/grep.c
index 3acfa9197..5f4224203 100644
--- a/findutils/grep.c
+++ b/findutils/grep.c
@@ -562,20 +562,20 @@ static char *add_grep_list_data(char *pattern)
562 562
563static void load_regexes_from_file(llist_t *fopt) 563static void load_regexes_from_file(llist_t *fopt)
564{ 564{
565 char *line;
566 FILE *f;
567
568 while (fopt) { 565 while (fopt) {
566 char *line;
567 FILE *fp;
569 llist_t *cur = fopt; 568 llist_t *cur = fopt;
570 char *ffile = cur->data; 569 char *ffile = cur->data;
571 570
572 fopt = cur->link; 571 fopt = cur->link;
573 free(cur); 572 free(cur);
574 f = xfopen_stdin(ffile); 573 fp = xfopen_stdin(ffile);
575 while ((line = xmalloc_fgetline(f)) != NULL) { 574 while ((line = xmalloc_fgetline(fp)) != NULL) {
576 llist_add_to(&pattern_head, 575 llist_add_to(&pattern_head,
577 new_grep_list_data(line, ALLOCATED)); 576 new_grep_list_data(line, ALLOCATED));
578 } 577 }
578 fclose_if_not_stdin(fp);
579 } 579 }
580} 580}
581 581
@@ -659,15 +659,19 @@ int grep_main(int argc UNUSED_PARAM, char **argv)
659#endif 659#endif
660 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */ 660 invert_search = ((option_mask32 & OPT_v) != 0); /* 0 | 1 */
661 661
662 if (pattern_head != NULL) { 662 { /* convert char **argv to grep_list_data_t */
663 /* convert char **argv to grep_list_data_t */
664 llist_t *cur; 663 llist_t *cur;
665
666 for (cur = pattern_head; cur; cur = cur->link) 664 for (cur = pattern_head; cur; cur = cur->link)
667 cur->data = new_grep_list_data(cur->data, 0); 665 cur->data = new_grep_list_data(cur->data, 0);
668 } 666 }
669 if (option_mask32 & OPT_f) 667 if (option_mask32 & OPT_f) {
670 load_regexes_from_file(fopt); 668 load_regexes_from_file(fopt);
669 if (!pattern_head) { /* -f EMPTY_FILE? */
670 /* GNU grep treats it as "nothing matches" */
671 llist_add_to(&pattern_head, new_grep_list_data((char*) "", 0));
672 invert_search ^= 1;
673 }
674 }
671 675
672 if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f') 676 if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f')
673 option_mask32 |= OPT_F; 677 option_mask32 |= OPT_F;
diff --git a/include/platform.h b/include/platform.h
index e22dbdb4a..826a4c497 100644
--- a/include/platform.h
+++ b/include/platform.h
@@ -417,6 +417,8 @@ typedef unsigned smalluint;
417# undef HAVE_STRVERSCMP 417# undef HAVE_STRVERSCMP
418# undef HAVE_XTABS 418# undef HAVE_XTABS
419# undef HAVE_DPRINTF 419# undef HAVE_DPRINTF
420# undef HAVE_UNLOCKED_STDIO
421# undef HAVE_UNLOCKED_LINE_OPS
420#endif 422#endif
421 423
422#if defined(__FreeBSD__) 424#if defined(__FreeBSD__)
diff --git a/libbb/getpty.c b/libbb/getpty.c
index 6a15cff2f..435e4d09f 100644
--- a/libbb/getpty.c
+++ b/libbb/getpty.c
@@ -19,20 +19,22 @@ 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#ifndef HAVE_PTSNAME_R 22# ifndef HAVE_PTSNAME_R
23 const char *name; 23 {
24 name = ptsname(p); /* find out the name of slave pty */ 24 const char *name;
25 if (!name) { 25 name = ptsname(p); /* find out the name of slave pty */
26 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); 26 if (!name) {
27 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
28 }
29 safe_strncpy(line, name, GETPTY_BUFSIZE);
27 } 30 }
28 safe_strncpy(line, name, GETPTY_BUFSIZE); 31# else
29#else
30 /* find out the name of slave pty */ 32 /* find out the name of slave pty */
31 if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) { 33 if (ptsname_r(p, line, GETPTY_BUFSIZE-1) != 0) {
32 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)"); 34 bb_perror_msg_and_die("ptsname error (is /dev/pts mounted?)");
33 } 35 }
34 line[GETPTY_BUFSIZE-1] = '\0'; 36 line[GETPTY_BUFSIZE-1] = '\0';
35#endif 37# endif
36 return p; 38 return p;
37 } 39 }
38#else 40#else
diff --git a/libbb/match_fstype.c b/libbb/match_fstype.c
index 83d6e6770..c792d13b3 100644
--- a/libbb/match_fstype.c
+++ b/libbb/match_fstype.c
@@ -10,6 +10,8 @@
10 * Licensed under GPLv2 or later, see file LICENSE in this source tree. 10 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
11 */ 11 */
12 12
13#ifdef HAVE_MNTENT_H
14
13#include "libbb.h" 15#include "libbb.h"
14 16
15int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype) 17int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
@@ -40,3 +42,5 @@ int FAST_FUNC match_fstype(const struct mntent *mt, const char *t_fstype)
40 42
41 return !match; 43 return !match;
42} 44}
45
46#endif /* HAVE_MNTENT_H */
diff --git a/libbb/procps.c b/libbb/procps.c
index 1dea61518..e15ddd1e5 100644
--- a/libbb/procps.c
+++ b/libbb/procps.c
@@ -284,27 +284,25 @@ int FAST_FUNC procps_read_smaps(pid_t pid, struct smaprec *total,
284void BUG_comm_size(void); 284void BUG_comm_size(void);
285procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) 285procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
286{ 286{
287 struct dirent *entry;
288 char buf[PROCPS_BUFSIZE];
289 char filename[sizeof("/proc//cmdline") + sizeof(int)*3];
290 char *filename_tail;
291 long tasknice;
292 unsigned pid;
293 int n;
294 struct stat sb;
295
296 if (!sp) 287 if (!sp)
297 sp = alloc_procps_scan(); 288 sp = alloc_procps_scan();
298 289
299 for (;;) { 290 for (;;) {
291 struct dirent *entry;
292 char buf[PROCPS_BUFSIZE];
293 long tasknice;
294 unsigned pid;
295 int n;
296 char filename[sizeof("/proc/%u/task/%u/cmdline") + sizeof(int)*3 * 2];
297 char *filename_tail;
298
300#if ENABLE_FEATURE_SHOW_THREADS 299#if ENABLE_FEATURE_SHOW_THREADS
301 if ((flags & PSSCAN_TASKS) && sp->task_dir) { 300 if (sp->task_dir) {
302 entry = readdir(sp->task_dir); 301 entry = readdir(sp->task_dir);
303 if (entry) 302 if (entry)
304 goto got_entry; 303 goto got_entry;
305 closedir(sp->task_dir); 304 closedir(sp->task_dir);
306 sp->task_dir = NULL; 305 sp->task_dir = NULL;
307 sp->main_thread_pid = 0;
308 } 306 }
309#endif 307#endif
310 entry = readdir(sp->dir); 308 entry = readdir(sp->dir);
@@ -321,9 +319,9 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
321 /* We found another /proc/PID. Do not use it, 319 /* We found another /proc/PID. Do not use it,
322 * there will be /proc/PID/task/PID (same PID!), 320 * there will be /proc/PID/task/PID (same PID!),
323 * so just go ahead and dive into /proc/PID/task. */ 321 * so just go ahead and dive into /proc/PID/task. */
324 char task_dir[sizeof("/proc/%u/task") + sizeof(int)*3]; 322 sprintf(filename, "/proc/%u/task", pid);
325 sprintf(task_dir, "/proc/%u/task", pid); 323 /* Note: if opendir fails, we just go to next /proc/XXX */
326 sp->task_dir = xopendir(task_dir); 324 sp->task_dir = opendir(filename);
327 sp->main_thread_pid = pid; 325 sp->main_thread_pid = pid;
328 continue; 326 continue;
329 } 327 }
@@ -347,9 +345,15 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags)
347 } 345 }
348#endif 346#endif
349 347
350 filename_tail = filename + sprintf(filename, "/proc/%u/", pid); 348#if ENABLE_FEATURE_SHOW_THREADS
349 if (sp->task_dir)
350 filename_tail = filename + sprintf(filename, "/proc/%u/task/%u/", sp->main_thread_pid, pid);
351 else
352#endif
353 filename_tail = filename + sprintf(filename, "/proc/%u/", pid);
351 354
352 if (flags & PSSCAN_UIDGID) { 355 if (flags & PSSCAN_UIDGID) {
356 struct stat sb;
353 if (stat(filename, &sb)) 357 if (stat(filename, &sb))
354 continue; /* process probably exited */ 358 continue; /* process probably exited */
355 /* Effective UID/GID, not real */ 359 /* Effective UID/GID, not real */
diff --git a/libbb/udp_io.c b/libbb/udp_io.c
index b8fb6755d..7985a9723 100644
--- a/libbb/udp_io.c
+++ b/libbb/udp_io.c
@@ -13,7 +13,7 @@
13 * We don't check for errors here. Not supported == won't be used 13 * We don't check for errors here. Not supported == won't be used
14 */ 14 */
15void FAST_FUNC 15void FAST_FUNC
16socket_want_pktinfo(int fd) 16socket_want_pktinfo(int fd UNUSED_PARAM)
17{ 17{
18#ifdef IP_PKTINFO 18#ifdef IP_PKTINFO
19 setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &const_int_1, sizeof(int)); 19 setsockopt(fd, IPPROTO_IP, IP_PKTINFO, &const_int_1, sizeof(int));
diff --git a/miscutils/less.c b/miscutils/less.c
index 9543fb9f9..045fd2db3 100644
--- a/miscutils/less.c
+++ b/miscutils/less.c
@@ -721,8 +721,8 @@ static void print_found(const char *line)
721 while (match_status == 0) { 721 while (match_status == 0) {
722 char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL, 722 char *new = xasprintf("%s%.*s"HIGHLIGHT"%.*s"NORMAL,
723 growline ? growline : "", 723 growline ? growline : "",
724 match_structs.rm_so, str, 724 (int)match_structs.rm_so, str,
725 match_structs.rm_eo - match_structs.rm_so, 725 (int)(match_structs.rm_eo - match_structs.rm_so),
726 str + match_structs.rm_so); 726 str + match_structs.rm_so);
727 free(growline); 727 free(growline);
728 growline = new; 728 growline = new;
@@ -990,7 +990,8 @@ static int64_t less_getch(int pos)
990 */ 990 */
991 if (key >= 0 && key < ' ' && key != 0x0d && key != 8) 991 if (key >= 0 && key < ' ' && key != 0x0d && key != 8)
992 goto again; 992 goto again;
993 return key; 993
994 return key64;
994} 995}
995 996
996static char* less_gets(int sz) 997static char* less_gets(int sz)
diff --git a/shell/cttyhack.c b/shell/cttyhack.c
index 4261289b4..37ea13723 100644
--- a/shell/cttyhack.c
+++ b/shell/cttyhack.c
@@ -122,10 +122,12 @@ int cttyhack_main(int argc UNUSED_PARAM, char **argv)
122 do { 122 do {
123#ifdef __linux__ 123#ifdef __linux__
124 int s = open_read_close("/sys/class/tty/console/active", 124 int s = open_read_close("/sys/class/tty/console/active",
125 console + 5, sizeof(console) - 5 - 1); 125 console + 5, sizeof(console) - 5);
126 if (s > 0) { 126 if (s > 0) {
127 /* found active console via sysfs (Linux 2.6.38+) */ 127 /* found active console via sysfs (Linux 2.6.38+)
128 console[5 + s] = '\0'; 128 * sysfs string looks like "ttyS0\n" so zap the newline:
129 */
130 console[4 + s] = '\0';
129 break; 131 break;
130 } 132 }
131 133
diff --git a/testsuite/sed.tests b/testsuite/sed.tests
index e9d0ed601..ba163e9e9 100755
--- a/testsuite/sed.tests
+++ b/testsuite/sed.tests
@@ -6,7 +6,7 @@
6 6
7. ./testing.sh 7. ./testing.sh
8 8
9# testing "description" "arguments" "result" "infile" "stdin" 9# testing "description" "commands" "result" "infile" "stdin"
10 10
11# Corner cases 11# Corner cases
12testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n" 12testing "sed no files (stdin)" 'sed ""' "hello\n" "" "hello\n"
@@ -225,7 +225,7 @@ testing "sed s/xxx/[/" "sed -e 's/xxx/[/'" "[\n" "" "xxx\n"
225#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \ 225#testing "sed -g (exhaustive)" "sed -e 's/[[:space:]]*/,/g'" ",1,2,3,4,5," \
226# "" "12345" 226# "" "12345"
227 227
228# testing "description" "arguments" "result" "infile" "stdin" 228# testing "description" "commands" "result" "infile" "stdin"
229 229
230testing "sed n command must reset 'substituted' bit" \ 230testing "sed n command must reset 'substituted' bit" \
231 "sed 's/1/x/;T;n;: next;s/3/y/;t quit;n;b next;: quit;q'" \ 231 "sed 's/1/x/;T;n;: next;s/3/y/;t quit;n;b next;: quit;q'" \
@@ -291,6 +291,10 @@ testing "sed understands \r" \
291 "sed 's/r/\r/'" \ 291 "sed 's/r/\r/'" \
292 "\rrr\n" "" "rrr\n" 292 "\rrr\n" "" "rrr\n"
293 293
294# testing "description" "arguments" "result" "infile" "stdin" 294testing "sed -i finishes ranges correctly" \
295 "sed '1,2d' -i input; echo \$?; cat input" \
296 "0\n3\n4\n" "1\n2\n3\n4\n" ""
297
298# testing "description" "commands" "result" "infile" "stdin"
295 299
296exit $FAILCOUNT 300exit $FAILCOUNT
diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c
index 43ddb4031..e53e24c71 100644
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -114,7 +114,8 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
114#if !ENABLE_FEATURE_SWAPON_PRI 114#if !ENABLE_FEATURE_SWAPON_PRI
115 ret = getopt32(argv, "a"); 115 ret = getopt32(argv, "a");
116#else 116#else
117 opt_complementary = "p+"; 117 if (applet_name[5] == 'n')
118 opt_complementary = "p+";
118 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags); 119 ret = getopt32(argv, (applet_name[5] == 'n') ? "ap:" : "a", &g_flags);
119 120
120 if (ret & 2) { // -p 121 if (ret & 2) { // -p