diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-28 16:40:02 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-09-28 16:40:02 +0000 |
commit | 4a81fe4173bf5029058253cf0be194c23a5ad369 (patch) | |
tree | 0806d2c3d6df92784c407221d862b9956c9ea115 | |
parent | 3e7eca97b987b351c6f68308c6e0c421541f10c8 (diff) | |
download | busybox-w32-1_11_3.tar.gz busybox-w32-1_11_3.tar.bz2 busybox-w32-1_11_3.zip |
apply post-1.11.2 fixes, bump version to 1.11.31_11_3
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | console-tools/kbd_mode.c | 3 | ||||
-rw-r--r-- | editors/vi.c | 34 | ||||
-rw-r--r-- | include/usage.h | 12 | ||||
-rw-r--r-- | libbb/lineedit.c | 73 | ||||
-rw-r--r-- | miscutils/crontab.c | 19 | ||||
-rw-r--r-- | miscutils/taskset.c | 3 |
7 files changed, 86 insertions, 60 deletions
@@ -1,6 +1,6 @@ | |||
1 | VERSION = 1 | 1 | VERSION = 1 |
2 | PATCHLEVEL = 11 | 2 | PATCHLEVEL = 11 |
3 | SUBLEVEL = 2 | 3 | SUBLEVEL = 3 |
4 | EXTRAVERSION = | 4 | EXTRAVERSION = |
5 | NAME = Unnamed | 5 | NAME = Unnamed |
6 | 6 | ||
diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index f40ee6403..2137d9f47 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c | |||
@@ -2,7 +2,7 @@ | |||
2 | /* | 2 | /* |
3 | * Mini kbd_mode implementation for busybox | 3 | * Mini kbd_mode implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 2007 Loïc Grenié <loic.grenie@gmail.com> | 5 | * Copyright (C) 2007 Loic Grenie <loic.grenie@gmail.com> |
6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from | 6 | * written using Andries Brouwer <aeb@cwi.nl>'s kbd_mode from |
7 | * console-utils v0.2.3, licensed under GNU GPLv2 | 7 | * console-utils v0.2.3, licensed under GNU GPLv2 |
8 | * | 8 | * |
@@ -46,6 +46,7 @@ int kbd_mode_main(int ATTRIBUTE_UNUSED argc, char **argv) | |||
46 | printf("The keyboard is in %s mode\n", mode); | 46 | printf("The keyboard is in %s mode\n", mode); |
47 | } else { | 47 | } else { |
48 | opt = opt & UNICODE ? 3 : opt >> 1; | 48 | opt = opt & UNICODE ? 3 : opt >> 1; |
49 | /* double cast prevents warnings about widening conversion */ | ||
49 | xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt); | 50 | xioctl(fd, KDSKBMODE, (void*)(ptrdiff_t)opt); |
50 | } | 51 | } |
51 | 52 | ||
diff --git a/editors/vi.c b/editors/vi.c index 81baa890f..1985be7db 100644 --- a/editors/vi.c +++ b/editors/vi.c | |||
@@ -147,10 +147,10 @@ struct globals { | |||
147 | #endif | 147 | #endif |
148 | 148 | ||
149 | smallint editing; // >0 while we are editing a file | 149 | smallint editing; // >0 while we are editing a file |
150 | // [code audit says "can be 0 or 1 only"] | 150 | // [code audit says "can be 0, 1 or 2 only"] |
151 | smallint cmd_mode; // 0=command 1=insert 2=replace | 151 | smallint cmd_mode; // 0=command 1=insert 2=replace |
152 | int file_modified; // buffer contents changed (counter, not flag!) | 152 | int file_modified; // buffer contents changed (counter, not flag!) |
153 | int last_file_modified; // = -1; | 153 | int last_file_modified; // = -1; |
154 | int fn_start; // index of first cmd line file name | 154 | int fn_start; // index of first cmd line file name |
155 | int save_argc; // how many file names on cmd line | 155 | int save_argc; // how many file names on cmd line |
156 | int cmdcnt; // repetition count | 156 | int cmdcnt; // repetition count |
@@ -623,7 +623,7 @@ static void edit_file(char *fn) | |||
623 | // These are commands that change text[]. | 623 | // These are commands that change text[]. |
624 | // Remember the input for the "." command | 624 | // Remember the input for the "." command |
625 | if (!adding2q && ioq_start == NULL | 625 | if (!adding2q && ioq_start == NULL |
626 | && strchr(modifying_cmds, c) | 626 | && c != '\0' && strchr(modifying_cmds, c) |
627 | ) { | 627 | ) { |
628 | start_new_cmd_q(c); | 628 | start_new_cmd_q(c); |
629 | } | 629 | } |
@@ -645,8 +645,8 @@ static void edit_file(char *fn) | |||
645 | } | 645 | } |
646 | //------------------------------------------------------------------- | 646 | //------------------------------------------------------------------- |
647 | 647 | ||
648 | place_cursor(rows, 0, FALSE); // go to bottom of screen | 648 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen |
649 | clear_to_eol(); // Erase to end of line | 649 | clear_to_eol(); // erase to end of line |
650 | cookmode(); | 650 | cookmode(); |
651 | #undef cur_line | 651 | #undef cur_line |
652 | } | 652 | } |
@@ -2009,9 +2009,9 @@ static void start_new_cmd_q(char c) | |||
2009 | { | 2009 | { |
2010 | // get buffer for new cmd | 2010 | // get buffer for new cmd |
2011 | // if there is a current cmd count put it in the buffer first | 2011 | // if there is a current cmd count put it in the buffer first |
2012 | if (cmdcnt > 0) | 2012 | if (cmdcnt > 0) { |
2013 | lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); | 2013 | lmc_len = sprintf(last_modifying_cmd, "%d%c", cmdcnt, c); |
2014 | else { // just save char c onto queue | 2014 | } else { // just save char c onto queue |
2015 | last_modifying_cmd[0] = c; | 2015 | last_modifying_cmd[0] = c; |
2016 | lmc_len = 1; | 2016 | lmc_len = 1; |
2017 | } | 2017 | } |
@@ -2247,18 +2247,20 @@ static char readit(void) // read (maybe cursor) key from stdin | |||
2247 | 2247 | ||
2248 | fflush(stdout); | 2248 | fflush(stdout); |
2249 | n = chars_to_parse; | 2249 | n = chars_to_parse; |
2250 | // get input from User- are there already input chars in Q? | 2250 | // get input from User - are there already input chars in Q? |
2251 | if (n <= 0) { | 2251 | if (n <= 0) { |
2252 | // the Q is empty, wait for a typed char | 2252 | // the Q is empty, wait for a typed char |
2253 | again: | ||
2253 | n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer)); | 2254 | n = safe_read(STDIN_FILENO, readbuffer, sizeof(readbuffer)); |
2254 | if (n < 0) { | 2255 | if (n <= 0) { |
2255 | if (errno == EBADF || errno == EFAULT || errno == EINVAL | 2256 | place_cursor(rows - 1, 0, FALSE); // go to bottom of screen |
2256 | || errno == EIO) | 2257 | clear_to_eol(); // erase to end of line |
2257 | editing = 0; // want to exit | 2258 | cookmode(); // terminal to "cooked" |
2258 | errno = 0; | 2259 | bb_error_msg_and_die("can't read user input"); |
2259 | } | 2260 | } |
2260 | if (n <= 0) | 2261 | /* elsewhere we can get very confused by NULs */ |
2261 | return 0; // error | 2262 | if (readbuffer[0] == '\0') |
2263 | goto again; | ||
2262 | if (readbuffer[0] == 27) { | 2264 | if (readbuffer[0] == 27) { |
2263 | // This is an ESC char. Is this Esc sequence? | 2265 | // This is an ESC char. Is this Esc sequence? |
2264 | // Could be bare Esc key. See if there are any | 2266 | // Could be bare Esc key. See if there are any |
diff --git a/include/usage.h b/include/usage.h index dcb6e344e..1165ad615 100644 --- a/include/usage.h +++ b/include/usage.h | |||
@@ -3640,8 +3640,8 @@ | |||
3640 | "[OPTIONS] [-S|-K] ... [-- arguments...]" | 3640 | "[OPTIONS] [-S|-K] ... [-- arguments...]" |
3641 | #define start_stop_daemon_full_usage "\n\n" \ | 3641 | #define start_stop_daemon_full_usage "\n\n" \ |
3642 | "Search for matching processes, and then\n" \ | 3642 | "Search for matching processes, and then\n" \ |
3643 | "-S: stop all matching processes.\n" \ | 3643 | "-S: start a process unless a matching process is found.\n" \ |
3644 | "-K: start a process unless a matching process is found.\n" \ | 3644 | "-K: stop all matching processes.\n" \ |
3645 | USE_GETOPT_LONG( \ | 3645 | USE_GETOPT_LONG( \ |
3646 | "\nProcess matching:" \ | 3646 | "\nProcess matching:" \ |
3647 | "\n -u,--user USERNAME|UID Match only this user's processes" \ | 3647 | "\n -u,--user USERNAME|UID Match only this user's processes" \ |
@@ -3651,7 +3651,7 @@ | |||
3651 | "\n in /proc/PID/cmdline" \ | 3651 | "\n in /proc/PID/cmdline" \ |
3652 | "\n -p,--pidfile FILE Match a process with PID from the file" \ | 3652 | "\n -p,--pidfile FILE Match a process with PID from the file" \ |
3653 | "\n All specified conditions must match" \ | 3653 | "\n All specified conditions must match" \ |
3654 | "\n-K only:" \ | 3654 | "\n-S only:" \ |
3655 | "\n -x,--exec EXECUTABLE Program to run" \ | 3655 | "\n -x,--exec EXECUTABLE Program to run" \ |
3656 | "\n -a,--startas NAME Zeroth argument" \ | 3656 | "\n -a,--startas NAME Zeroth argument" \ |
3657 | "\n -b,--background Background" \ | 3657 | "\n -b,--background Background" \ |
@@ -3660,7 +3660,7 @@ | |||
3660 | ) \ | 3660 | ) \ |
3661 | "\n -c,--chuid USER[:[GRP]] Change to user/group" \ | 3661 | "\n -c,--chuid USER[:[GRP]] Change to user/group" \ |
3662 | "\n -m,--make-pidfile Write PID to the pidfile specified by -p" \ | 3662 | "\n -m,--make-pidfile Write PID to the pidfile specified by -p" \ |
3663 | "\n-S only:" \ | 3663 | "\n-K only:" \ |
3664 | "\n -s,--signal SIG Signal to send" \ | 3664 | "\n -s,--signal SIG Signal to send" \ |
3665 | "\n -t,--test Match only, exit with 0 if a process is found" \ | 3665 | "\n -t,--test Match only, exit with 0 if a process is found" \ |
3666 | "\nOther:" \ | 3666 | "\nOther:" \ |
@@ -3679,7 +3679,7 @@ | |||
3679 | "\n command in /proc/PID/cmdline" \ | 3679 | "\n command in /proc/PID/cmdline" \ |
3680 | "\n -p FILE Match a process with PID from the file" \ | 3680 | "\n -p FILE Match a process with PID from the file" \ |
3681 | "\n All specified conditions must match" \ | 3681 | "\n All specified conditions must match" \ |
3682 | "\n-K only:" \ | 3682 | "\n-S only:" \ |
3683 | "\n -x EXECUTABLE Program to run" \ | 3683 | "\n -x EXECUTABLE Program to run" \ |
3684 | "\n -a NAME Zeroth argument" \ | 3684 | "\n -a NAME Zeroth argument" \ |
3685 | "\n -b Background" \ | 3685 | "\n -b Background" \ |
@@ -3688,7 +3688,7 @@ | |||
3688 | ) \ | 3688 | ) \ |
3689 | "\n -c USER[:[GRP]] Change to user/group" \ | 3689 | "\n -c USER[:[GRP]] Change to user/group" \ |
3690 | "\n -m Write PID to the pidfile specified by -p" \ | 3690 | "\n -m Write PID to the pidfile specified by -p" \ |
3691 | "\n-S only:" \ | 3691 | "\n-K only:" \ |
3692 | "\n -s SIG Signal to send" \ | 3692 | "\n -s SIG Signal to send" \ |
3693 | "\n -t Match only, exit with 0 if a process is found" \ | 3693 | "\n -t Match only, exit with 0 if a process is found" \ |
3694 | "\nOther:" \ | 3694 | "\nOther:" \ |
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index fb595c010..b3f4f5327 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c | |||
@@ -953,24 +953,33 @@ static void input_tab(smallint *lastWasTab) | |||
953 | 953 | ||
954 | #if MAX_HISTORY > 0 | 954 | #if MAX_HISTORY > 0 |
955 | 955 | ||
956 | static void save_command_ps_at_cur_history(void) | ||
957 | { | ||
958 | if (command_ps[0] != '\0') { | ||
959 | int cur = state->cur_history; | ||
960 | free(state->history[cur]); | ||
961 | state->history[cur] = xstrdup(command_ps); | ||
962 | } | ||
963 | } | ||
964 | |||
956 | /* state->flags is already checked to be nonzero */ | 965 | /* state->flags is already checked to be nonzero */ |
957 | static void get_previous_history(void) | 966 | static int get_previous_history(void) |
958 | { | 967 | { |
959 | if (command_ps[0] != '\0' || state->history[state->cur_history] == NULL) { | 968 | if ((state->flags & DO_HISTORY) && state->cur_history) { |
960 | free(state->history[state->cur_history]); | 969 | save_command_ps_at_cur_history(); |
961 | state->history[state->cur_history] = xstrdup(command_ps); | 970 | state->cur_history--; |
971 | return 1; | ||
962 | } | 972 | } |
963 | state->cur_history--; | 973 | beep(); |
974 | return 0; | ||
964 | } | 975 | } |
965 | 976 | ||
966 | static int get_next_history(void) | 977 | static int get_next_history(void) |
967 | { | 978 | { |
968 | if (state->flags & DO_HISTORY) { | 979 | if (state->flags & DO_HISTORY) { |
969 | int ch = state->cur_history; | 980 | if (state->cur_history < state->cnt_history) { |
970 | if (ch < state->cnt_history) { | 981 | save_command_ps_at_cur_history(); /* save the current history line */ |
971 | get_previous_history(); /* save the current history line */ | 982 | return ++state->cur_history; |
972 | state->cur_history = ch + 1; | ||
973 | return state->cur_history; | ||
974 | } | 983 | } |
975 | } | 984 | } |
976 | beep(); | 985 | beep(); |
@@ -992,6 +1001,7 @@ static void load_history(const char *fromfile) | |||
992 | for (hi = state->cnt_history; hi > 0;) { | 1001 | for (hi = state->cnt_history; hi > 0;) { |
993 | hi--; | 1002 | hi--; |
994 | free(state->history[hi]); | 1003 | free(state->history[hi]); |
1004 | state->history[hi] = NULL; | ||
995 | } | 1005 | } |
996 | 1006 | ||
997 | for (hi = 0; hi < MAX_HISTORY;) { | 1007 | for (hi = 0; hi < MAX_HISTORY;) { |
@@ -1003,14 +1013,14 @@ static void load_history(const char *fromfile) | |||
1003 | l = strlen(hl); | 1013 | l = strlen(hl); |
1004 | if (l >= MAX_LINELEN) | 1014 | if (l >= MAX_LINELEN) |
1005 | hl[MAX_LINELEN-1] = '\0'; | 1015 | hl[MAX_LINELEN-1] = '\0'; |
1006 | if (l == 0 || hl[0] == ' ') { | 1016 | if (l == 0) { |
1007 | free(hl); | 1017 | free(hl); |
1008 | continue; | 1018 | continue; |
1009 | } | 1019 | } |
1010 | state->history[hi++] = hl; | 1020 | state->history[hi++] = hl; |
1011 | } | 1021 | } |
1012 | fclose(fp); | 1022 | fclose(fp); |
1013 | state->cur_history = state->cnt_history = hi; | 1023 | state->cnt_history = hi; |
1014 | } | 1024 | } |
1015 | } | 1025 | } |
1016 | 1026 | ||
@@ -1040,19 +1050,27 @@ static void remember_in_history(const char *str) | |||
1040 | 1050 | ||
1041 | if (!(state->flags & DO_HISTORY)) | 1051 | if (!(state->flags & DO_HISTORY)) |
1042 | return; | 1052 | return; |
1043 | 1053 | if (str[0] == '\0') | |
1054 | return; | ||
1044 | i = state->cnt_history; | 1055 | i = state->cnt_history; |
1045 | free(state->history[MAX_HISTORY]); | 1056 | /* Don't save dupes */ |
1046 | state->history[MAX_HISTORY] = NULL; | 1057 | if (i && strcmp(state->history[i-1], str) == 0) |
1047 | /* After max history, remove the oldest command */ | 1058 | return; |
1059 | |||
1060 | free(state->history[MAX_HISTORY]); /* redundant, paranoia */ | ||
1061 | state->history[MAX_HISTORY] = NULL; /* redundant, paranoia */ | ||
1062 | |||
1063 | /* If history[] is full, remove the oldest command */ | ||
1064 | /* we need to keep history[MAX_HISTORY] empty, hence >=, not > */ | ||
1048 | if (i >= MAX_HISTORY) { | 1065 | if (i >= MAX_HISTORY) { |
1049 | free(state->history[0]); | 1066 | free(state->history[0]); |
1050 | for (i = 0; i < MAX_HISTORY-1; i++) | 1067 | for (i = 0; i < MAX_HISTORY-1; i++) |
1051 | state->history[i] = state->history[i+1]; | 1068 | state->history[i] = state->history[i+1]; |
1069 | /* i == MAX_HISTORY-1 */ | ||
1052 | } | 1070 | } |
1053 | // Maybe "if (!i || strcmp(history[i-1], command) != 0) ..." | 1071 | /* i <= MAX_HISTORY-1 */ |
1054 | // (i.e. do not save dups?) | ||
1055 | state->history[i++] = xstrdup(str); | 1072 | state->history[i++] = xstrdup(str); |
1073 | /* i <= MAX_HISTORY */ | ||
1056 | state->cur_history = i; | 1074 | state->cur_history = i; |
1057 | state->cnt_history = i; | 1075 | state->cnt_history = i; |
1058 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY | 1076 | #if ENABLE_FEATURE_EDITING_SAVEHISTORY |
@@ -1394,6 +1412,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t | |||
1394 | if ((state->flags & SAVE_HISTORY) && state->hist_file) | 1412 | if ((state->flags & SAVE_HISTORY) && state->hist_file) |
1395 | load_history(state->hist_file); | 1413 | load_history(state->hist_file); |
1396 | #endif | 1414 | #endif |
1415 | state->cur_history = state->cnt_history; | ||
1397 | 1416 | ||
1398 | /* prepare before init handlers */ | 1417 | /* prepare before init handlers */ |
1399 | cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */ | 1418 | cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */ |
@@ -1429,6 +1448,13 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t | |||
1429 | } | 1448 | } |
1430 | } | 1449 | } |
1431 | #endif | 1450 | #endif |
1451 | |||
1452 | #if 0 | ||
1453 | for (ic = 0; ic <= MAX_HISTORY; ic++) | ||
1454 | bb_error_msg("history[%d]:'%s'", ic, state->history[ic]); | ||
1455 | bb_error_msg("cur_history:%d cnt_history:%d", state->cur_history, state->cnt_history); | ||
1456 | #endif | ||
1457 | |||
1432 | /* Print out the command prompt */ | 1458 | /* Print out the command prompt */ |
1433 | parse_and_put_prompt(prompt); | 1459 | parse_and_put_prompt(prompt); |
1434 | 1460 | ||
@@ -1537,11 +1563,8 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t | |||
1537 | vi_case(CTRL('P')|vbit:) | 1563 | vi_case(CTRL('P')|vbit:) |
1538 | vi_case('k'|vbit:) | 1564 | vi_case('k'|vbit:) |
1539 | /* Control-p -- Get previous command from history */ | 1565 | /* Control-p -- Get previous command from history */ |
1540 | if ((state->flags & DO_HISTORY) && state->cur_history > 0) { | 1566 | if (get_previous_history()) |
1541 | get_previous_history(); | ||
1542 | goto rewrite_line; | 1567 | goto rewrite_line; |
1543 | } | ||
1544 | beep(); | ||
1545 | break; | 1568 | break; |
1546 | #endif | 1569 | #endif |
1547 | 1570 | ||
@@ -1730,10 +1753,8 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t | |||
1730 | #if MAX_HISTORY > 0 | 1753 | #if MAX_HISTORY > 0 |
1731 | case 'A': | 1754 | case 'A': |
1732 | /* Up Arrow -- Get previous command from history */ | 1755 | /* Up Arrow -- Get previous command from history */ |
1733 | if ((state->flags & DO_HISTORY) && state->cur_history > 0) { | 1756 | if (get_previous_history()) |
1734 | get_previous_history(); | ||
1735 | goto rewrite_line; | 1757 | goto rewrite_line; |
1736 | } | ||
1737 | beep(); | 1758 | beep(); |
1738 | break; | 1759 | break; |
1739 | case 'B': | 1760 | case 'B': |
@@ -1743,7 +1764,7 @@ int read_line_input(const char *prompt, char *command, int maxsize, line_input_t | |||
1743 | rewrite_line: | 1764 | rewrite_line: |
1744 | /* Rewrite the line with the selected history item */ | 1765 | /* Rewrite the line with the selected history item */ |
1745 | /* change command */ | 1766 | /* change command */ |
1746 | command_len = strlen(strcpy(command, state->history[state->cur_history])); | 1767 | command_len = strlen(strcpy(command, state->history[state->cur_history] ? : "")); |
1747 | /* redraw and go to eol (bol, in vi */ | 1768 | /* redraw and go to eol (bol, in vi */ |
1748 | redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0); | 1769 | redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0); |
1749 | break; | 1770 | break; |
diff --git a/miscutils/crontab.c b/miscutils/crontab.c index dc3179dac..38933cf4a 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c | |||
@@ -93,6 +93,7 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
93 | char *new_fname; | 93 | char *new_fname; |
94 | char *user_name; /* -u USER */ | 94 | char *user_name; /* -u USER */ |
95 | int fd; | 95 | int fd; |
96 | int src_fd; | ||
96 | int opt_ler; | 97 | int opt_ler; |
97 | 98 | ||
98 | /* file [opts] Replace crontab from file | 99 | /* file [opts] Replace crontab from file |
@@ -144,15 +145,15 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
144 | bb_show_usage(); | 145 | bb_show_usage(); |
145 | 146 | ||
146 | /* Read replacement file under user's UID/GID/group vector */ | 147 | /* Read replacement file under user's UID/GID/group vector */ |
148 | src_fd = STDIN_FILENO; | ||
147 | if (!opt_ler) { /* Replace? */ | 149 | if (!opt_ler) { /* Replace? */ |
148 | if (!argv[0]) | 150 | if (!argv[0]) |
149 | bb_show_usage(); | 151 | bb_show_usage(); |
150 | if (NOT_LONE_DASH(argv[0])) { | 152 | if (NOT_LONE_DASH(argv[0])) { |
151 | fd = open_as_user(pas, argv[0]); | 153 | src_fd = open_as_user(pas, argv[0]); |
152 | if (fd < 0) | 154 | if (src_fd < 0) |
153 | bb_error_msg_and_die("user %s cannot read %s", | 155 | bb_error_msg_and_die("user %s cannot read %s", |
154 | pas->pw_name, argv[0]); | 156 | pas->pw_name, argv[0]); |
155 | xmove_fd(fd, STDIN_FILENO); | ||
156 | } | 157 | } |
157 | } | 158 | } |
158 | 159 | ||
@@ -180,23 +181,23 @@ int crontab_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
180 | tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid()); | 181 | tmp_fname = xasprintf("%s.%u", crontab_dir, (unsigned)getpid()); |
181 | /* No O_EXCL: we don't want to be stuck if earlier crontabs | 182 | /* No O_EXCL: we don't want to be stuck if earlier crontabs |
182 | * were killed, leaving stale temp file behind */ | 183 | * were killed, leaving stale temp file behind */ |
183 | fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600); | 184 | src_fd = xopen3(tmp_fname, O_RDWR|O_CREAT|O_TRUNC, 0600); |
184 | xmove_fd(fd, STDIN_FILENO); | 185 | fchown(src_fd, pas->pw_uid, pas->pw_gid); |
185 | fchown(STDIN_FILENO, pas->pw_uid, pas->pw_gid); | ||
186 | fd = open(pas->pw_name, O_RDONLY); | 186 | fd = open(pas->pw_name, O_RDONLY); |
187 | if (fd >= 0) { | 187 | if (fd >= 0) { |
188 | bb_copyfd_eof(fd, STDIN_FILENO); | 188 | bb_copyfd_eof(fd, src_fd); |
189 | close(fd); | 189 | close(fd); |
190 | xlseek(src_fd, 0, SEEK_SET); | ||
190 | } | 191 | } |
192 | close_on_exec_on(src_fd); /* don't want editor to see this fd */ | ||
191 | edit_file(pas, tmp_fname); | 193 | edit_file(pas, tmp_fname); |
192 | xlseek(STDIN_FILENO, 0, SEEK_SET); | ||
193 | /* fall through */ | 194 | /* fall through */ |
194 | 195 | ||
195 | case 0: /* Replace (no -l, -e, or -r were given) */ | 196 | case 0: /* Replace (no -l, -e, or -r were given) */ |
196 | new_fname = xasprintf("%s.new", pas->pw_name); | 197 | new_fname = xasprintf("%s.new", pas->pw_name); |
197 | fd = open(new_fname, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600); | 198 | fd = open(new_fname, O_WRONLY|O_CREAT|O_TRUNC|O_APPEND, 0600); |
198 | if (fd >= 0) { | 199 | if (fd >= 0) { |
199 | bb_copyfd_eof(STDIN_FILENO, fd); | 200 | bb_copyfd_eof(src_fd, fd); |
200 | close(fd); | 201 | close(fd); |
201 | xrename(new_fname, pas->pw_name); | 202 | xrename(new_fname, pas->pw_name); |
202 | } else { | 203 | } else { |
diff --git a/miscutils/taskset.c b/miscutils/taskset.c index 708abd9f2..973f94ac3 100644 --- a/miscutils/taskset.c +++ b/miscutils/taskset.c | |||
@@ -35,7 +35,8 @@ static char *__from_cpuset(cpu_set_t *mask) | |||
35 | #define TASKSET_PRINTF_MASK "%x" | 35 | #define TASKSET_PRINTF_MASK "%x" |
36 | /* (void*) cast is for battling gcc: */ | 36 | /* (void*) cast is for battling gcc: */ |
37 | /* "dereferencing type-punned pointer will break strict-aliasing rules" */ | 37 | /* "dereferencing type-punned pointer will break strict-aliasing rules" */ |
38 | #define from_cpuset(mask) (*(unsigned*)(void*)&(mask)) | 38 | #define from_cpuset(mask) ({ void *__vp = &(mask); *(unsigned*)__vp; }) |
39 | /* gcc 4.3.0 still complains: #define from_cpuset(mask) (*(unsigned*)(void*)&(mask)) */ | ||
39 | #endif | 40 | #endif |
40 | 41 | ||
41 | 42 | ||