diff options
author | Denys Vlasenko | 2009-10-08 03:06:04 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-10-08 03:06:04 +0200 |
commit | 4ac9819263114edb9b5b638ffa6d2e41a4bb46e7 (patch) | |
tree | f0c5bc9c7a2bf3a384b85350bfe4c9ca5ec4858f /libbb | |
parent | 5b807cd5acd1f27b3e7aa36aac2728be27c5907c (diff) | |
download | busybox-4ac9819263114edb9b5b638ffa6d2e41a4bb46e7.zip busybox-4ac9819263114edb9b5b638ffa6d2e41a4bb46e7.tar.gz |
apply post-1.15.1 fixes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/lineedit.c | 49 | ||||
-rw-r--r-- | libbb/procps.c | 133 | ||||
-rw-r--r-- | libbb/recursive_action.c | 17 |
3 files changed, 111 insertions, 88 deletions
diff --git a/libbb/lineedit.c b/libbb/lineedit.c index 9a773b4..071fc5b 100644 --- a/libbb/lineedit.c +++ b/libbb/lineedit.c @@ -114,8 +114,8 @@ struct lineedit_statics { unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */ unsigned cursor; - unsigned command_len; - /* *int* maxsize: we want x in "if (x > S.maxsize)" + int command_len; /* must be signed (^D returns -1 len) */ + /* signed maxsize: we want x in "if (x > S.maxsize)" * to _not_ be promoted to unsigned */ int maxsize; CHAR_T *command_ps; @@ -1095,15 +1095,15 @@ static void save_command_ps_at_cur_history(void) int cur = state->cur_history; free(state->history[cur]); -#if ENABLE_FEATURE_ASSUME_UNICODE +# if ENABLE_FEATURE_ASSUME_UNICODE { char tbuf[MAX_LINELEN]; save_string(tbuf, sizeof(tbuf)); state->history[cur] = xstrdup(tbuf); } -#else +# else state->history[cur] = xstrdup(command_ps); -#endif +# endif } } @@ -1131,7 +1131,7 @@ static int get_next_history(void) return 0; } -#if ENABLE_FEATURE_EDITING_SAVEHISTORY +# if ENABLE_FEATURE_EDITING_SAVEHISTORY /* We try to ensure that concurrent additions to the history * do not overwrite each other. * Otherwise shell users get unhappy. @@ -1256,10 +1256,10 @@ static void save_history(char *str) free_line_input_t(st_temp); } } -#else -#define load_history(a) ((void)0) -#define save_history(a) ((void)0) -#endif /* FEATURE_COMMAND_SAVEHISTORY */ +# else +# define load_history(a) ((void)0) +# define save_history(a) ((void)0) +# endif /* FEATURE_COMMAND_SAVEHISTORY */ static void remember_in_history(char *str) { @@ -1290,15 +1290,15 @@ static void remember_in_history(char *str) /* i <= MAX_HISTORY */ state->cur_history = i; state->cnt_history = i; -#if ENABLE_FEATURE_EDITING_SAVEHISTORY +# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY if ((state->flags & SAVE_HISTORY) && state->hist_file) save_history(str); -#endif +# endif IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;) } #else /* MAX_HISTORY == 0 */ -#define remember_in_history(a) ((void)0) +# define remember_in_history(a) ((void)0) #endif /* MAX_HISTORY */ @@ -1476,11 +1476,11 @@ static void parse_and_put_prompt(const char *prmt_ptr) c = *prmt_ptr++; switch (c) { -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR case 'u': pbuf = user_buf ? user_buf : (char*)""; break; -#endif +# endif case 'h': pbuf = free_me = safe_gethostname(); *strchrnul(pbuf, '.') = '\0'; @@ -1488,7 +1488,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) case '$': c = (geteuid() == 0 ? '#' : '$'); break; -#if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR +# if ENABLE_FEATURE_GETUSERNAME_AND_HOMEDIR case 'w': /* /home/user[/something] -> ~[/something] */ pbuf = cwd_buf; @@ -1501,7 +1501,7 @@ static void parse_and_put_prompt(const char *prmt_ptr) pbuf = free_me = xasprintf("~%s", cwd_buf + l); } break; -#endif +# endif case 'W': pbuf = cwd_buf; cp = strrchr(pbuf, '/'); @@ -1688,13 +1688,15 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li /* With null flags, no other fields are ever used */ state = st ? st : (line_input_t*) &const_int_0; -#if ENABLE_FEATURE_EDITING_SAVEHISTORY +#if MAX_HISTORY > 0 +# if ENABLE_FEATURE_EDITING_SAVEHISTORY if ((state->flags & SAVE_HISTORY) && state->hist_file) if (state->cnt_history == 0) load_history(state); -#endif +# endif if (state->flags & DO_HISTORY) state->cur_history = state->cnt_history; +#endif /* prepare before init handlers */ cmdedit_y = 0; /* quasireal y, not true if line > xt*yt */ @@ -1716,7 +1718,7 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li new_settings.c_cc[VTIME] = 0; /* Turn off CTRL-C, so we can trap it */ #ifndef _POSIX_VDISABLE -#define _POSIX_VDISABLE '\0' +# define _POSIX_VDISABLE '\0' #endif new_settings.c_cc[VINTR] = _POSIX_VDISABLE; tcsetattr_stdin_TCSANOW(&new_settings); @@ -2037,7 +2039,8 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li rewrite_line: /* Rewrite the line with the selected history item */ /* change command */ - command_len = load_string(state->history[state->cur_history] ? : "", maxsize); + command_len = load_string(state->history[state->cur_history] ? + state->history[state->cur_history] : "", maxsize); /* redraw and go to eol (bol, in vi) */ redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0); break; @@ -2121,7 +2124,9 @@ int FAST_FUNC read_line_input(const char *prompt, char *command, int maxsize, li #undef command #if ENABLE_FEATURE_ASSUME_UNICODE - command_len = save_string(command, maxsize - 1); + command[0] = '\0'; + if (command_len > 0) + command_len = save_string(command, maxsize - 1); free(command_ps); #endif diff --git a/libbb/procps.c b/libbb/procps.c index 307d8d6..7276f60 100644 --- a/libbb/procps.c +++ b/libbb/procps.c @@ -134,8 +134,8 @@ static unsigned long fast_strtoul_16(char **endptr) return n; } /* TOPMEM uses fast_strtoul_10, so... */ -#undef ENABLE_FEATURE_FAST_TOP -#define ENABLE_FEATURE_FAST_TOP 1 +# undef ENABLE_FEATURE_FAST_TOP +# define ENABLE_FEATURE_FAST_TOP 1 #endif #if ENABLE_FEATURE_FAST_TOP @@ -198,14 +198,16 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) if (errno) continue; - /* After this point we have to break, not continue - * ("continue" would mean that current /proc/NNN - * is not a valid process info) */ + /* After this point we can: + * "break": stop parsing, return the data + * "continue": try next /proc/XXX + */ memset(&sp->vsz, 0, sizeof(*sp) - offsetof(procps_status_t, vsz)); sp->pid = pid; - if (!(flags & ~PSSCAN_PID)) break; + if (!(flags & ~PSSCAN_PID)) + break; /* we needed only pid, we got it */ #if ENABLE_SELINUX if (flags & PSSCAN_CONTEXT) { @@ -218,7 +220,7 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) if (flags & PSSCAN_UIDGID) { if (stat(filename, &sb)) - break; + continue; /* process probably exited */ /* Effective UID/GID, not real */ sp->uid = sb.st_uid; sp->gid = sb.st_gid; @@ -234,10 +236,10 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) strcpy(filename_tail, "stat"); n = read_to_buf(filename, buf); if (n < 0) - break; + continue; /* process probably exited */ cp = strrchr(buf, ')'); /* split into "PID (cmd" and "<rest>" */ /*if (!cp || cp[1] != ' ') - break;*/ + continue;*/ cp[0] = '\0'; if (sizeof(sp->comm) < 16) BUG_comm_size(); @@ -257,12 +259,12 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) "%lu " /* start_time */ "%lu " /* vsize */ "%lu " /* rss */ -#if ENABLE_FEATURE_TOP_SMP_PROCESS +# if ENABLE_FEATURE_TOP_SMP_PROCESS "%*s %*s %*s %*s %*s %*s " /*rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */ "%*s %*s %*s %*s " /*signal, blocked, sigignore, sigcatch */ "%*s %*s %*s %*s " /*wchan, nswap, cnswap, exit_signal */ "%d" /*cpu last seen on*/ -#endif +# endif , sp->state, &sp->ppid, &sp->pgid, &sp->sid, &tty, @@ -271,17 +273,17 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) &sp->start_time, &vsz, &rss -#if ENABLE_FEATURE_TOP_SMP_PROCESS +# if ENABLE_FEATURE_TOP_SMP_PROCESS , &sp->last_seen_on_cpu -#endif +# endif ); if (n < 11) - break; -#if ENABLE_FEATURE_TOP_SMP_PROCESS + continue; /* bogus data, get next /proc/XXX */ +# if ENABLE_FEATURE_TOP_SMP_PROCESS if (n < 11+15) sp->last_seen_on_cpu = 0; -#endif +# endif /* vsz is in bytes and we want kb */ sp->vsz = vsz >> 10; @@ -311,14 +313,14 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) sp->vsz = fast_strtoul_10(&cp) >> 10; /* vsz is in bytes but rss is in *PAGES*! Can you believe that? */ sp->rss = fast_strtoul_10(&cp) << sp->shift_pages_to_kb; -#if ENABLE_FEATURE_TOP_SMP_PROCESS +# if ENABLE_FEATURE_TOP_SMP_PROCESS /* (6): rss_rlim, start_code, end_code, start_stack, kstk_esp, kstk_eip */ /* (4): signal, blocked, sigignore, sigcatch */ /* (4): wchan, nswap, cnswap, exit_signal */ cp = skip_fields(cp, 14); //FIXME: is it safe to assume this field exists? sp->last_seen_on_cpu = fast_strtoul_10(&cp); -#endif +# endif #endif /* end of !ENABLE_FEATURE_TOP_SMP_PROCESS */ #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS @@ -343,48 +345,48 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) strcpy(filename_tail, "smaps"); file = fopen_for_read(filename); - if (!file) - break; - while (fgets(buf, sizeof(buf), file)) { - unsigned long sz; - char *tp; - char w; + if (file) { + while (fgets(buf, sizeof(buf), file)) { + unsigned long sz; + char *tp; + char w; #define SCAN(str, name) \ if (strncmp(buf, str, sizeof(str)-1) == 0) { \ tp = skip_whitespace(buf + sizeof(str)-1); \ sp->name += fast_strtoul_10(&tp); \ continue; \ } - SCAN("Shared_Clean:" , shared_clean ); - SCAN("Shared_Dirty:" , shared_dirty ); - SCAN("Private_Clean:", private_clean); - SCAN("Private_Dirty:", private_dirty); + SCAN("Shared_Clean:" , shared_clean ); + SCAN("Shared_Dirty:" , shared_dirty ); + SCAN("Private_Clean:", private_clean); + SCAN("Private_Dirty:", private_dirty); #undef SCAN - // f7d29000-f7d39000 rw-s ADR M:m OFS FILE - tp = strchr(buf, '-'); - if (tp) { - *tp = ' '; - tp = buf; - sz = fast_strtoul_16(&tp); /* start */ - sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */ - // tp -> "rw-s" string - w = tp[1]; - // skipping "rw-s ADR M:m OFS " - tp = skip_whitespace(skip_fields(tp, 4)); - // filter out /dev/something (something != zero) - if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { - if (w == 'w') { - sp->mapped_rw += sz; - } else if (w == '-') { - sp->mapped_ro += sz; + // f7d29000-f7d39000 rw-s ADR M:m OFS FILE + tp = strchr(buf, '-'); + if (tp) { + *tp = ' '; + tp = buf; + sz = fast_strtoul_16(&tp); /* start */ + sz = (fast_strtoul_16(&tp) - sz) >> 10; /* end - start */ + // tp -> "rw-s" string + w = tp[1]; + // skipping "rw-s ADR M:m OFS " + tp = skip_whitespace(skip_fields(tp, 4)); + // filter out /dev/something (something != zero) + if (strncmp(tp, "/dev/", 5) != 0 || strcmp(tp, "/dev/zero\n") == 0) { + if (w == 'w') { + sp->mapped_rw += sz; + } else if (w == '-') { + sp->mapped_ro += sz; + } } - } //else printf("DROPPING %s (%s)\n", buf, tp); - if (strcmp(tp, "[stack]\n") == 0) - sp->stack += sz; + if (strcmp(tp, "[stack]\n") == 0) + sp->stack += sz; + } } + fclose(file); } - fclose(file); } #endif /* TOPMEM */ #if ENABLE_FEATURE_PS_ADDITIONAL_COLUMNS @@ -393,23 +395,34 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) strcpy(filename_tail, "status"); file = fopen_for_read(filename); - if (!file) - break; - while (fgets(buf, sizeof(buf), file)) { - char *tp; + if (file) { + while (fgets(buf, sizeof(buf), file)) { + char *tp; #define SCAN_TWO(str, name, statement) \ if (strncmp(buf, str, sizeof(str)-1) == 0) { \ tp = skip_whitespace(buf + sizeof(str)-1); \ sscanf(tp, "%u", &sp->name); \ statement; \ } - SCAN_TWO("Uid:", ruid, continue); - SCAN_TWO("Gid:", rgid, break); + SCAN_TWO("Uid:", ruid, continue); + SCAN_TWO("Gid:", rgid, break); #undef SCAN_TWO + } + fclose(file); } - fclose(file); } #endif /* PS_ADDITIONAL_COLUMNS */ + if (flags & PSSCAN_EXE) { + strcpy(filename_tail, "exe"); + free(sp->exe); + sp->exe = xmalloc_readlink(filename); + } + /* Note: if /proc/PID/cmdline is empty, + * code below "breaks". Therefore it must be + * the last code to parse /proc/PID/xxx data + * (we used to have /proc/PID/exe parsing after it + * and were getting stale sp->exe). + */ #if 0 /* PSSCAN_CMD is not used */ if (flags & (PSSCAN_CMD|PSSCAN_ARGV0)) { free(sp->argv0); @@ -452,13 +465,9 @@ procps_status_t* FAST_FUNC procps_scan(procps_status_t* sp, int flags) } } #endif - if (flags & PSSCAN_EXE) { - strcpy(filename_tail, "exe"); - free(sp->exe); - sp->exe = xmalloc_readlink(filename); - } break; - } + } /* for (;;) */ + return sp; } diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index 3ec596a..3a4eb28 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c @@ -61,6 +61,7 @@ int FAST_FUNC recursive_action(const char *fileName, unsigned depth) { struct stat statbuf; + unsigned follow; int status; DIR *dir; struct dirent *next; @@ -68,14 +69,22 @@ int FAST_FUNC recursive_action(const char *fileName, if (!fileAction) fileAction = true_action; if (!dirAction) dirAction = true_action; - status = ACTION_FOLLOWLINKS; /* hijack a variable for bitmask... */ - if (!depth) - status = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; - status = ((flags & status) ? stat : lstat)(fileName, &statbuf); + follow = ACTION_FOLLOWLINKS; + if (depth == 0) + follow = ACTION_FOLLOWLINKS | ACTION_FOLLOWLINKS_L0; + follow &= flags; + status = (follow ? stat : lstat)(fileName, &statbuf); if (status < 0) { #ifdef DEBUG_RECURS_ACTION bb_error_msg("status=%d flags=%x", status, flags); #endif + if ((flags & ACTION_DANGLING_OK) + && errno == ENOENT + && lstat(fileName, &statbuf) == 0 + ) { + /* Dangling link */ + return fileAction(fileName, &statbuf, userData, depth); + } goto done_nak_warn; } |