+++ /dev/null
-Allows the user to specify a location at compile time for temporarily storing ash's history file until the shell is closed.
-NB This is only useful if ASH_HIST_BUFFER_PATH points to an in-memory filesystem.
-By Dennis Groenen <tj.groenen@gmail.com> - 2011-08-20
----
-
---- a/shell/ash.c
-+++ b/shell/ash.c
-@@ -184,6 +184,24 @@
- //config: This option recreates the prompt string from the environment
- //config: variable each time it is displayed.
- //config:
-+//config:config ASH_HIST_BUFFER
-+//config: bool "History buffer"
-+//config: default n
-+//config: depends on ASH && FEATURE_EDITING_SAVEHISTORY
-+//config: help
-+//config: Allows you to set a temporary location for .ash_history.
-+//config: History is saved to this custom location, and written out to
-+//config: its default location (~/.ash_history) upon shell exit.
-+//config: Useful to prevent wear on flash-based storage devices.
-+//config:
-+//config:config ASH_HIST_BUFFER_PATH
-+//config: string "History buffer location"
-+//config: default "/tmp"
-+//config: depends on ASH && ASH_HIST_BUFFER
-+//config: help
-+//config: Directory which will be used to save the shell history until
-+//config: ash is exited.
-+//config:
-
- //applet:IF_ASH(APPLET(ash, BB_DIR_BIN, BB_SUID_DROP))
- //applet:IF_FEATURE_SH_IS_ASH(APPLET_ODDNAME(sh, ash, BB_DIR_BIN, BB_SUID_DROP, sh))
-@@ -12888,6 +12906,14 @@ exitshell(void)
- char *p;
- int status;
-
-+#if ENABLE_ASH_HIST_BUFFER
-+ const char *tmphistory = lookupvar("HISTFILE");
-+ const char *storedhistory = lookupvar("STOREDHISTFILE");
-+
-+ if (storedhistory) /* is NULL when setting up the history buffer failed; check for this before copying */
-+ copy_file(tmphistory, storedhistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS);
-+#endif
-+
- status = exitstatus;
- TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
- if (setjmp(loc.loc)) {
-@@ -13151,9 +13177,59 @@ int ash_main(int argc UNUSED_PARAM, char
- if (!hp) {
- hp = lookupvar("HOME");
- if (hp) {
-+#if ENABLE_ASH_HIST_BUFFER
-+ char *tmppath;
-+ char *tmphistory;
-+ char *storedhistory;
-+ const char *user = lookupvar("USER");
-+
-+ tmppath = concat_path_file(CONFIG_ASH_HIST_BUFFER_PATH, user);
-+ tmphistory = concat_path_file(tmppath, ".ash_history");
-+ storedhistory = concat_path_file(hp, ".ash_history");
-+
-+ if (access(CONFIG_ASH_HIST_BUFFER_PATH, R_OK == -1)) {
-+ bb_simple_perror_msg("could not access history buffer path");
-+ goto bail;
-+ }
-+
-+ if (bb_make_directory(tmppath, S_IRWXU, FILEUTILS_RECUR)) {
-+ /* bb_make_directory is noisy, no need for an additional error message */
-+ goto bail;
-+ } else {
-+ struct stat stat_tmppath;
-+ stat(tmppath, &stat_tmppath);
-+ if (stat_tmppath.st_uid != geteuid() || stat_tmppath.st_mode & (S_IRWXG | S_IRWXO)) {
-+ errno = 0;
-+ bb_simple_perror_msg("history buffer is not exclusive to the shell user");
-+ goto bail;
-+ }
-+ }
-+
-+ if (access(tmphistory, R_OK | W_OK) == -1) {
-+ if (access(storedhistory, R_OK) != -1) {
-+ if (copy_file(storedhistory, tmphistory, FILEUTILS_FORCE | FILEUTILS_DEREFERENCE | FILEUTILS_PRESERVE_STATUS) == -1) {
-+ /* copy_file is noisy too, no need for an additional error message */
-+ goto bail;
-+ }
-+ }
-+ }
-+ setvar("STOREDHISTFILE", storedhistory, 0);
-+ goto out;
-+
-+ bail:
-+ errno = 0;
-+ bb_simple_perror_msg("shell history will not be saved");
-+ tmphistory = xasprintf("/dev/null");
-+ out:
-+ setvar("HISTFILE", tmphistory, 0);
-+ free(storedhistory);
-+ free(tmphistory);
-+ free(tmppath);
-+#else
- char *defhp = concat_path_file(hp, ".ash_history");
- setvar("HISTFILE", defhp, 0);
- free(defhp);
-+#endif
- }
- }
- }
+++ /dev/null
-libbb/lineedit: implement optional Ctrl-R history search
-Source: http://git.busybox.net/busybox/commit/?id=a669eca3a230e35e4a6894a30168a047000f3b75
----
-
---- a/libbb/Config.src
-+++ b/libbb/Config.src
-@@ -93,6 +93,14 @@ config FEATURE_EDITING_SAVEHISTORY
- help
- Enable history saving in shells.
-
-+config FEATURE_REVERSE_SEARCH
-+ bool "Reverse history search"
-+ default y
-+ depends on FEATURE_EDITING_SAVEHISTORY
-+ help
-+ Enable readline-like Ctrl-R combination for reverse history search.
-+ Increases code by about 0.5k.
-+
- config FEATURE_TAB_COMPLETION
- bool "Tab completion"
- default y
---- a/libbb/lineedit.c
-+++ b/libbb/lineedit.c
-@@ -202,9 +202,9 @@ static void deinit_S(void)
-
-
- #if ENABLE_UNICODE_SUPPORT
--static size_t load_string(const char *src, int maxsize)
-+static size_t load_string(const char *src)
- {
-- ssize_t len = mbstowcs(command_ps, src, maxsize - 1);
-+ ssize_t len = mbstowcs(command_ps, src, S.maxsize - 1);
- if (len < 0)
- len = 0;
- command_ps[len] = BB_NUL;
-@@ -297,9 +297,9 @@ static wchar_t adjust_width_and_validate
- return wc;
- }
- #else /* !UNICODE */
--static size_t load_string(const char *src, int maxsize)
-+static size_t load_string(const char *src)
- {
-- safe_strncpy(command_ps, src, maxsize);
-+ safe_strncpy(command_ps, src, S.maxsize);
- return strlen(command_ps);
- }
- # if ENABLE_FEATURE_TAB_COMPLETION
-@@ -1202,10 +1202,10 @@ static NOINLINE void input_tab(smallint
- strcpy(match_buf, &command[cursor_mb]);
- /* where do we want to have cursor after all? */
- strcpy(&command[cursor_mb], chosen_match + match_pfx_len);
-- len = load_string(command, S.maxsize);
-+ len = load_string(command);
- /* add match and tail */
- sprintf(&command[cursor_mb], "%s%s", chosen_match + match_pfx_len, match_buf);
-- command_len = load_string(command, S.maxsize);
-+ command_len = load_string(command);
- /* write out the matched command */
- /* paranoia: load_string can return 0 on conv error,
- * prevent passing pos = (0 - 12) to redraw */
-@@ -1911,6 +1911,140 @@ static int isrtl_str(void)
- #undef CTRL
- #define CTRL(a) ((a) & ~0x40)
-
-+enum {
-+ VI_CMDMODE_BIT = 0x40000000,
-+ /* 0x80000000 bit flags KEYCODE_xxx */
-+};
-+
-+#if ENABLE_FEATURE_REVERSE_SEARCH
-+/* Mimic readline Ctrl-R reverse history search.
-+ * When invoked, it shows the following prompt:
-+ * (reverse-i-search)'': user_input [cursor pos unchanged by Ctrl-R]
-+ * and typing results in search being performed:
-+ * (reverse-i-search)'tmp': cd /tmp [cursor under t in /tmp]
-+ * Search is performed by looking at progressively older lines in history.
-+ * Ctrl-R again searches for the next match in history.
-+ * Backspace deletes last matched char.
-+ * Control keys exit search and return to normal editing (at current history line).
-+ */
-+static int32_t reverse_i_search(void)
-+{
-+ char match_buf[128]; /* for user input */
-+ char read_key_buffer[KEYCODE_BUFFER_SIZE];
-+ const char *matched_history_line;
-+ const char *saved_prompt;
-+ int32_t ic;
-+
-+ matched_history_line = NULL;
-+ read_key_buffer[0] = 0;
-+ match_buf[0] = '\0';
-+
-+ /* Save and replace the prompt */
-+ saved_prompt = cmdedit_prompt;
-+ goto set_prompt;
-+
-+ while (1) {
-+ int h;
-+ unsigned match_buf_len = strlen(match_buf);
-+
-+ fflush_all();
-+//FIXME: correct timeout?
-+ ic = lineedit_read_key(read_key_buffer);
-+
-+ switch (ic) {
-+ case CTRL('R'): /* searching for the next match */
-+ break;
-+
-+ case '\b':
-+ case '\x7f':
-+ /* Backspace */
-+ if (unicode_status == UNICODE_ON) {
-+ while (match_buf_len != 0) {
-+ uint8_t c = match_buf[--match_buf_len];
-+ if ((c & 0xc0) != 0x80) /* start of UTF-8 char? */
-+ break; /* yes */
-+ }
-+ } else {
-+ if (match_buf_len != 0)
-+ match_buf_len--;
-+ }
-+ match_buf[match_buf_len] = '\0';
-+ break;
-+
-+ default:
-+ if (ic < ' '
-+ || (!ENABLE_UNICODE_SUPPORT && ic >= 256)
-+ || (ENABLE_UNICODE_SUPPORT && ic >= VI_CMDMODE_BIT)
-+ ) {
-+ goto ret;
-+ }
-+
-+ /* Append this char */
-+#if ENABLE_UNICODE_SUPPORT
-+ if (unicode_status == UNICODE_ON) {
-+ mbstate_t mbstate = { 0 };
-+ char buf[MB_CUR_MAX + 1];
-+ int len = wcrtomb(buf, ic, &mbstate);
-+ if (len > 0) {
-+ buf[len] = '\0';
-+ if (match_buf_len + len < sizeof(match_buf))
-+ strcpy(match_buf + match_buf_len, buf);
-+ }
-+ } else
-+#endif
-+ if (match_buf_len < sizeof(match_buf) - 1) {
-+ match_buf[match_buf_len] = ic;
-+ match_buf[match_buf_len + 1] = '\0';
-+ }
-+ break;
-+ } /* switch (ic) */
-+
-+ /* Search in history for match_buf */
-+ h = state->cur_history;
-+ if (ic == CTRL('R'))
-+ h--;
-+ while (h >= 0) {
-+ if (state->history[h]) {
-+ char *match = strstr(state->history[h], match_buf);
-+ if (match) {
-+ state->cur_history = h;
-+ matched_history_line = state->history[h];
-+ command_len = load_string(matched_history_line);
-+ cursor = match - matched_history_line;
-+//FIXME: cursor position for Unicode case
-+
-+ free((char*)cmdedit_prompt);
-+ set_prompt:
-+ cmdedit_prompt = xasprintf("(reverse-i-search)'%s': ", match_buf);
-+ cmdedit_prmt_len = strlen(cmdedit_prompt);
-+ goto do_redraw;
-+ }
-+ }
-+ h--;
-+ }
-+
-+ /* Not found */
-+ match_buf[match_buf_len] = '\0';
-+ beep();
-+ continue;
-+
-+ do_redraw:
-+ redraw(cmdedit_y, command_len - cursor);
-+ } /* while (1) */
-+
-+ ret:
-+ if (matched_history_line)
-+ command_len = load_string(matched_history_line);
-+
-+ free((char*)cmdedit_prompt);
-+ cmdedit_prompt = saved_prompt;
-+ cmdedit_prmt_len = strlen(cmdedit_prompt);
-+ redraw(cmdedit_y, command_len - cursor);
-+
-+ return ic;
-+}
-+#endif
-+
- /* maxsize must be >= 2.
- * Returns:
- * -1 on read errors or EOF, or on bare Ctrl-D,
-@@ -2026,15 +2160,14 @@ int FAST_FUNC read_line_input(const char
- * clutters the big switch a bit, but keeps all the code
- * in one place.
- */
-- enum {
-- VI_CMDMODE_BIT = 0x40000000,
-- /* 0x80000000 bit flags KEYCODE_xxx */
-- };
- int32_t ic, ic_raw;
-
- fflush_all();
- ic = ic_raw = lineedit_read_key(read_key_buffer);
-
-+#if ENABLE_FEATURE_REVERSE_SEARCH
-+ again:
-+#endif
- #if ENABLE_FEATURE_EDITING_VI
- newdelflag = 1;
- if (vi_cmdmode) {
-@@ -2138,6 +2271,11 @@ int FAST_FUNC read_line_input(const char
- while (cursor > 0 && !BB_isspace(command_ps[cursor-1]))
- input_backspace();
- break;
-+#if ENABLE_FEATURE_REVERSE_SEARCH
-+ case CTRL('R'):
-+ ic = ic_raw = reverse_i_search();
-+ goto again;
-+#endif
-
- #if ENABLE_FEATURE_EDITING_VI
- case 'i'|VI_CMDMODE_BIT:
-@@ -2291,7 +2429,7 @@ int FAST_FUNC read_line_input(const char
- /* Rewrite the line with the selected history item */
- /* change command */
- command_len = load_string(state->history[state->cur_history] ?
-- state->history[state->cur_history] : "", maxsize);
-+ state->history[state->cur_history] : "");
- /* redraw and go to eol (bol, in vi) */
- redraw(cmdedit_y, (state->flags & VI_MODE) ? 9999 : 0);
- break;
+++ /dev/null
-Index: busybox/coreutils/fsync.c
-===================================================================
---- busybox/coreutils/fsync.c (revision 0)
-+++ busybox/coreutils/fsync.c (revision 0)
-@@ -0,0 +1,46 @@
-+/* vi: set sw=4 ts=4: */
-+/*
-+ * Mini fsync implementation for busybox
-+ *
-+ * Copyright (C) 2008 Nokia Corporation. All rights reserved.
-+ *
-+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
-+ */
-+
-+#include "libbb.h"
-+
-+/* This is a NOFORK applet. Be very careful! */
-+
-+int fsync_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-+int fsync_main(int argc, char **argv)
-+{
-+ int status = EXIT_SUCCESS;
-+ int flags;
-+ int fd;
-+ char *path;
-+
-+ flags = getopt32(argv, "d"); /* fdatasync */
-+ argv += optind;
-+
-+ if (!*argv) {
-+ bb_show_usage();
-+ }
-+
-+ for (path = *argv++; path; path = *argv++) {
-+ fd = open(path, O_NOATIME | O_NOCTTY | O_RDONLY);
-+
-+ if (fd == -1) {
-+ bb_simple_perror_msg(path);
-+ status = EXIT_FAILURE;
-+ continue;
-+ }
-+
-+ if ((flags ? fdatasync(fd) : fsync(fd)) == -1) {
-+ bb_simple_perror_msg(path);
-+ }
-+
-+ close(fd);
-+ }
-+
-+ return status;
-+}
-Index: busybox/coreutils/Kbuild
-===================================================================
---- busybox/coreutils/Kbuild (revision 23238)
-+++ busybox/coreutils/Kbuild (working copy)
-@@ -36,6 +36,7 @@
- lib-$(CONFIG_EXPAND) += expand.o
- lib-$(CONFIG_FALSE) += false.o
- lib-$(CONFIG_FOLD) += fold.o
-+lib-$(CONFIG_FSYNC) += fsync.o
- lib-$(CONFIG_HEAD) += head.o
- lib-$(CONFIG_HOSTID) += hostid.o
- lib-$(CONFIG_ID) += id.o
-Index: busybox/coreutils/Config.in
-===================================================================
---- busybox/coreutils/Config.in (revision 23238)
-+++ busybox/coreutils/Config.in (working copy)
-@@ -249,6 +249,12 @@
- help
- Wrap text to fit a specific width.
-
-+config FSYNC
-+ bool "fsync"
-+ default n
-+ help
-+ fsync is used to flush file-related cached blocks to disk.
-+
- config HEAD
- bool "head"
- default n
-Index: busybox/include/usage.h
-===================================================================
---- busybox/include/usage.h (revision 23238)
-+++ busybox/include/usage.h (working copy)
-@@ -3905,6 +3905,13 @@
- #define sync_full_usage "\n\n" \
- "Write all buffered filesystem blocks to disk"
-
-+#define fsync_trivial_usage \
-+ "[OPTION]... FILE..."
-+#define fsync_full_usage \
-+ "Write files' buffered blocks to disk\n" \
-+ "\nOptions:" \
-+ "\n -d Avoid syncing metadata (like access time)"
-+
- #define sysctl_trivial_usage \
- "[OPTIONS]... [VALUE]..."
- #define sysctl_full_usage "\n\n" \
-Index: busybox/include/applets.h
-===================================================================
---- busybox/include/applets.h (revision 23238)
-+++ busybox/include/applets.h (working copy)
-@@ -160,6 +160,7 @@
- //USE_E2FSCK(APPLET_ODDNAME(fsck.ext2, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_ext2))
- //USE_E2FSCK(APPLET_ODDNAME(fsck.ext3, e2fsck, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_ext3))
- USE_FSCK_MINIX(APPLET_ODDNAME(fsck.minix, fsck_minix, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix))
-+USE_FSYNC(APPLET_NOFORK(fsync, fsync, _BB_DIR_BIN, _BB_SUID_NEVER, fsync))
- USE_FTPGET(APPLET_ODDNAME(ftpget, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER, ftpget))
- USE_FTPPUT(APPLET_ODDNAME(ftpput, ftpgetput, _BB_DIR_USR_BIN, _BB_SUID_NEVER, ftpput))
- USE_FUSER(APPLET(fuser, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
+++ /dev/null
-From 2089b4bf5880f49e8185b2e07966714a9ce9dcd5 Mon Sep 17 00:00:00 2001
-From: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
-Date: Fri, 12 Jun 2009 14:43:26 +0300
-Subject: [PATCH] Don't follow symlinks for -l or -s in ls. Fixes: NB#120999.
-
-Signed-off-by: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
----
- coreutils/ls.c | 4 ++--
- 1 files changed, 2 insertions(+), 2 deletions(-)
-
-diff --git a/coreutils/ls.c b/coreutils/ls.c
-index 9e5c6de..e06f0eb 100644
---- a/coreutils/ls.c
-+++ b/coreutils/ls.c
-@@ -908,8 +908,8 @@ int ls_main(int argc, char **argv)
- /* stuff the command line file names into a dnode array */
- dn = NULL;
- for (oi = 0; oi < ac; oi++) {
-- /* ls w/o -l follows links on command line */
-- cur = my_stat(av[oi], av[oi], !(all_fmt & STYLE_LONG));
-+ /* NB: follow links on command line unless -l or -s */
-+ cur = my_stat(av[oi], av[oi], !(all_fmt & (STYLE_LONG|LIST_BLOCKS)));
- if (!cur)
- continue;
- cur->allocated = 0;
---
-1.6.3.1
-
+++ /dev/null
---- busybox.orig/util-linux/mount.c
-+++ busybox/util-linux/mount.c
-@@ -26,6 +26,9 @@
- /* For FEATURE_MOUNT_LABEL only */
- #include "volume_id.h"
- #endif
-+#ifndef MS_RELATIME
-+#define MS_RELATIME (1 << 21)
-+#endif
-
- /* Needed for nfs support only */
- #include <sys/utsname.h>
-@@ -136,6 +139,8 @@
- /* "noatime" */ MS_NOATIME,
- /* "diratime" */ ~MS_NODIRATIME,
- /* "nodiratime" */ MS_NODIRATIME,
-+ /* "relatime" */ MS_RELATIME,
-+ /* "norelatime" */ ~MS_RELATIME,
- /* "loud" */ ~MS_SILENT,
-
- // action flags
-@@ -186,6 +191,8 @@
- "noatime" "\0"
- "diratime" "\0"
- "nodiratime" "\0"
-+ "relatime" "\0"
-+ "norelatime" "\0"
- "loud" "\0"
-
- // action flags
+++ /dev/null
-From 02d849739e15552046128abb8dba79c584266f61 Mon Sep 17 00:00:00 2001
-From: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
-Date: Fri, 6 Mar 2009 15:24:52 +0200
-Subject: [PATCH] pidof/killall5: fix DNA problems of hald children and the like
-
-Children of hal daemon make a perfect example of why reading
-/proc/$pid/exe symlink is about the only reliable way to figure
-if the process is what we're actually looking for: they clobber
-their argv[0] and argv[1].
-
-Signed-off-by: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
----
- include/libbb.h | 4 +++-
- libbb/find_pid_by_name.c | 6 +++++-
- libbb/procps.c | 6 ++++++
- 3 files changed, 14 insertions(+), 2 deletions(-)
-
-diff --git a/include/libbb.h b/include/libbb.h
-index 859b3bc..4f75d96 100644
---- a/include/libbb.h
-+++ b/include/libbb.h
-@@ -1101,6 +1101,8 @@ typedef struct procps_status_t {
- * (if executable is symlink or script, it is NOT replaced
- * by link target or interpreter name) */
- char comm[COMM_LEN];
-+ /* where /proc/$PID/exe points to */
-+ char *exe;
- /* user/group? - use passwd/group parsing functions */
- } procps_status_t;
- enum {
-@@ -1112,7 +1114,7 @@ enum {
- PSSCAN_COMM = 1 << 5,
- /* PSSCAN_CMD = 1 << 6, - use read_cmdline instead */
- PSSCAN_ARGV0 = 1 << 7,
-- /* PSSCAN_EXE = 1 << 8, - not implemented */
-+ PSSCAN_EXE = 1 << 8, /* almost implemented */
- PSSCAN_STATE = 1 << 9,
- PSSCAN_VSZ = 1 << 10,
- PSSCAN_RSS = 1 << 11,
-diff --git a/libbb/find_pid_by_name.c b/libbb/find_pid_by_name.c
-index 8dcdb13..832116d 100644
---- a/libbb/find_pid_by_name.c
-+++ b/libbb/find_pid_by_name.c
-@@ -55,7 +55,7 @@ pid_t* find_pid_by_name(const char* procName)
- procps_status_t* p = NULL;
-
- pidList = xmalloc(sizeof(*pidList));
-- while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGV0))) {
-+ while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_COMM|PSSCAN_ARGV0|PSSCAN_EXE))) {
- if (
- /* we require comm to match and to not be truncated */
- /* in Linux, if comm is 15 chars, it may be a truncated
-@@ -63,11 +63,15 @@ pid_t* find_pid_by_name(const char* procName)
- (!p->comm[sizeof(p->comm)-2] && strcmp(p->comm, procName) == 0)
- /* or we require argv0 to match (essential for matching reexeced /proc/self/exe)*/
- || (p->argv0 && strcmp(bb_basename(p->argv0), procName) == 0)
-+ || (p->exe && strcmp(bb_basename(p->exe), procName) == 0)
- /* TOOD: we can also try /proc/NUM/exe link, do we want that? */
- ) {
- pidList = xrealloc(pidList, sizeof(*pidList) * (i+2));
- pidList[i++] = p->pid;
- }
-+
-+ if (p->exe)
-+ free(p->exe);
- }
-
- pidList[i] = 0;
-diff --git a/libbb/procps.c b/libbb/procps.c
-index 8946917..f33c64e 100644
---- a/libbb/procps.c
-+++ b/libbb/procps.c
-@@ -378,6 +378,12 @@ procps_status_t *procps_scan(procps_status_t* sp, int flags)
- }
- }
- #else
-+ if (flags & (PSSCAN_EXE)) {
-+ strcpy(filename_tail, "/exe");
-+
-+ sp->exe = xmalloc_readlink(filename);
-+ }
-+
- if (flags & (PSSCAN_ARGV0|PSSCAN_ARGVN)) {
- free(sp->argv0);
- sp->argv0 = NULL;
---
-1.6.1.3
-
+++ /dev/null
-Patch to only update history upon shell exit.
-Should prevent unnecessary wear on the flash and save some power.
-By Alexander Shishkin <ext-alexander.shishkin@nokia.com>
-
-Ported to BusyBox 1.18.4 by Dennis Groenen <dennis_groenen@hotmail.com> - 2011-04-29
----
-
---- a/libbb/lineedit.c
-+++ b/libbb/lineedit.c
-@@ -1275,130 +1275,52 @@ static int get_next_history(void)
- }
-
- # 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.
-- *
-- * History file is trimmed lazily, when it grows several times longer
-- * than configured MAX_HISTORY lines.
-- */
--
--static void free_line_input_t(line_input_t *n)
--{
-- int i = n->cnt_history;
-- while (i > 0)
-- free(n->history[--i]);
-- free(n);
--}
--
- /* state->flags is already checked to be nonzero */
--static void load_history(line_input_t *st_parm)
-+static void load_history(const char *fromfile)
- {
-- char *temp_h[MAX_HISTORY];
-- char *line;
- FILE *fp;
-- unsigned idx, i, line_len;
-+ int hi = 0;
-
-- /* NB: do not trash old history if file can't be opened */
-+ if (!state->cnt_history) {
-+ fp = fopen(fromfile, "r");
-+ if (fp) {
-+ for (hi = 0; hi < MAX_HISTORY;) {
-+ char *hl = xmalloc_fgetline(fp);
-+ int l;
-
-- fp = fopen_for_read(st_parm->hist_file);
-- if (fp) {
-- /* clean up old history */
-- for (idx = st_parm->cnt_history; idx > 0;) {
-- idx--;
-- free(st_parm->history[idx]);
-- st_parm->history[idx] = NULL;
-- }
--
-- /* fill temp_h[], retaining only last MAX_HISTORY lines */
-- memset(temp_h, 0, sizeof(temp_h));
-- st_parm->cnt_history_in_file = idx = 0;
-- while ((line = xmalloc_fgetline(fp)) != NULL) {
-- if (line[0] == '\0') {
-- free(line);
-- continue;
-- }
-- free(temp_h[idx]);
-- temp_h[idx] = line;
-- st_parm->cnt_history_in_file++;
-- idx++;
-- if (idx == MAX_HISTORY)
-- idx = 0;
-- }
-- fclose(fp);
--
-- /* find first non-NULL temp_h[], if any */
-- if (st_parm->cnt_history_in_file) {
-- while (temp_h[idx] == NULL) {
-- idx++;
-- if (idx == MAX_HISTORY)
-- idx = 0;
-+ if (!hl)
-+ break;
-+ l = strlen(hl);
-+ if (l >= MAX_LINELEN)
-+ hl[MAX_LINELEN-1] = '\0';
-+ if (l == 0 || hl[0] == ' ') {
-+ free(hl);
-+ continue;
-+ }
-+ state->history[hi++] = hl;
- }
-+ fclose(fp);
- }
--
-- /* copy temp_h[] to st_parm->history[] */
-- for (i = 0; i < MAX_HISTORY;) {
-- line = temp_h[idx];
-- if (!line)
-- break;
-- idx++;
-- if (idx == MAX_HISTORY)
-- idx = 0;
-- line_len = strlen(line);
-- if (line_len >= MAX_LINELEN)
-- line[MAX_LINELEN-1] = '\0';
-- st_parm->history[i++] = line;
-- }
-- st_parm->cnt_history = i;
-+ state->cur_history = state->cnt_history = hi;
- }
- }
-
- /* state->flags is already checked to be nonzero */
--static void save_history(char *str)
-+void save_history(line_input_t *);
-+void save_history(line_input_t *st)
- {
-- int fd;
-- int len, len2;
-+ FILE *fp;
-
-- fd = open(state->hist_file, O_WRONLY | O_CREAT | O_APPEND, 0600);
-- if (fd < 0)
-- return;
-- xlseek(fd, 0, SEEK_END); /* paranoia */
-- len = strlen(str);
-- str[len] = '\n'; /* we (try to) do atomic write */
-- len2 = full_write(fd, str, len + 1);
-- str[len] = '\0';
-- close(fd);
-- if (len2 != len + 1)
-- return; /* "wtf?" */
--
-- /* did we write so much that history file needs trimming? */
-- state->cnt_history_in_file++;
-- if (state->cnt_history_in_file > MAX_HISTORY * 4) {
-- char *new_name;
-- line_input_t *st_temp;
--
-- /* we may have concurrently written entries from others.
-- * load them */
-- st_temp = new_line_input_t(state->flags);
-- st_temp->hist_file = state->hist_file;
-- load_history(st_temp);
--
-- /* write out temp file and replace hist_file atomically */
-- new_name = xasprintf("%s.%u.new", state->hist_file, (int) getpid());
-- fd = open(state->hist_file, O_WRONLY | O_CREAT | O_TRUNC, 0600);
-- if (fd >= 0) {
-- FILE *fp;
-+ if (st->cnt_history) {
-+ fp = fopen(st->hist_file, "w");
-+ if (fp) {
- int i;
-
-- fp = xfdopen_for_write(fd);
-- for (i = 0; i < st_temp->cnt_history; i++)
-- fprintf(fp, "%s\n", st_temp->history[i]);
-+ for (i = 0; i < st->cnt_history; i++) {
-+ fprintf(fp, "%s\n", st->history[i]);
-+ }
- fclose(fp);
-- if (rename(new_name, state->hist_file) == 0)
-- state->cnt_history_in_file = st_temp->cnt_history;
- }
-- free(new_name);
-- free_line_input_t(st_temp);
- }
- }
- # else
-@@ -1435,10 +1357,6 @@ static void remember_in_history(char *st
- /* i <= MAX_HISTORY */
- state->cur_history = i;
- state->cnt_history = i;
--# if MAX_HISTORY > 0 && ENABLE_FEATURE_EDITING_SAVEHISTORY
-- if ((state->flags & SAVE_HISTORY) && state->hist_file)
-- save_history(str);
--# endif
- IF_FEATURE_EDITING_FANCY_PROMPT(num_ok_lines++;)
- }
-
-@@ -1960,7 +1878,7 @@ int FAST_FUNC read_line_input(const char
- # if ENABLE_FEATURE_EDITING_SAVEHISTORY
- if ((state->flags & SAVE_HISTORY) && state->hist_file)
- if (state->cnt_history == 0)
-- load_history(state);
-+ load_history(state->hist_file);
- # endif
- if (state->flags & DO_HISTORY)
- state->cur_history = state->cnt_history;
-diff -urpN a/shell/ash.c b/shell/ash.c
---- a/shell/ash.c
-+++ b/shell/ash.c
-@@ -51,6 +51,9 @@
- #else
- # define CLEAR_RANDOM_T(rnd) ((void)0)
- #endif
-+#if ENABLE_FEATURE_EDITING_SAVEHISTORY
-+void save_history(line_input_t *);
-+#endif
-
- #include "NUM_APPLETS.h"
- #if NUM_APPLETS == 1
-@@ -12810,6 +12813,10 @@ exitshell(void)
- char *p;
- int status;
-
-+ if (iflag && (line_input_state->flags & SAVE_HISTORY)
-+ && line_input_state->hist_file && !shlvl) {
-+ save_history(line_input_state);
-+ }
- status = exitstatus;
- TRACE(("pid %d, exitshell(%d)\n", getpid(), status));
- if (setjmp(loc.loc)) {
+++ /dev/null
-Pull patch from BusyBox' git repo to make "showkey -a" work on any stdin
-Source: http://git.busybox.net/busybox/commit/?id=9beb68e3e2dc1c6f457acfb307cfed73cce65cd9
----
-
---- a/console-tools/showkey.c
-+++ b/console-tools/showkey.c
-@@ -56,37 +56,45 @@ int showkey_main(int argc UNUSED_PARAM,
- // FIXME: aks are all mutually exclusive
- getopt32(argv, "aks");
-
-- // get keyboard settings
-- xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
-- printf("kb mode was %s\n\nPress any keys. Program terminates %s\n\n",
-- kbmode == K_RAW ? "RAW" :
-- (kbmode == K_XLATE ? "XLATE" :
-- (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
-- (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN")))
-- , (option_mask32 & OPT_a) ? "on EOF (ctrl-D)" : "10s after last keypress"
-- );
--
- // prepare for raw mode
- xget1(&tio, &tio0);
- // put stdin in raw mode
- xset1(&tio);
-
-+#define press_keys "Press any keys, program terminates %s:\r\n\n"
-+
- if (option_mask32 & OPT_a) {
-+ // just read stdin char by char
- unsigned char c;
-
-- // just read stdin char by char
-+ printf(press_keys, "on EOF (ctrl-D)");
-+
-+ // read and show byte values
- while (1 == read(STDIN_FILENO, &c, 1)) {
- printf("%3u 0%03o 0x%02x\r\n", c, c, c);
- if (04 /*CTRL-D*/ == c)
- break;
- }
-+
- } else {
-+ // we assume a PC keyboard
-+ xioctl(STDIN_FILENO, KDGKBMODE, &kbmode);
-+ printf("Keyboard mode was %s.\r\n\n",
-+ kbmode == K_RAW ? "RAW" :
-+ (kbmode == K_XLATE ? "XLATE" :
-+ (kbmode == K_MEDIUMRAW ? "MEDIUMRAW" :
-+ (kbmode == K_UNICODE ? "UNICODE" : "UNKNOWN")))
-+ );
-+
- // set raw keyboard mode
- xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)((option_mask32 & OPT_k) ? K_MEDIUMRAW : K_RAW));
-
- // we should exit on any signal; signals should interrupt read
- bb_signals_recursive_norestart(BB_FATAL_SIGS, record_signo);
-
-+ // inform user that program ends after time of inactivity
-+ printf(press_keys, "10s after last keypress");
-+
- // read and show scancodes
- while (!bb_got_signal) {
- char buf[18];
-@@ -94,6 +102,7 @@ int showkey_main(int argc UNUSED_PARAM,
-
- // setup 10s watchdog
- alarm(10);
-+
- // read scancodes
- n = read(STDIN_FILENO, buf, sizeof(buf));
- i = 0;
-@@ -121,11 +130,13 @@ int showkey_main(int argc UNUSED_PARAM,
- }
- puts("\r");
- }
-+
-+ // restore keyboard mode
-+ xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
- }
-
-- // restore keyboard and console settings
-+ // restore console settings
- xset1(&tio0);
-- xioctl(STDIN_FILENO, KDSKBMODE, (void *)(ptrdiff_t)kbmode);
-
- return EXIT_SUCCESS;
- }
+++ /dev/null
-From 04522f492dc25d650c22e2d4a11296e72fa40e32 Mon Sep 17 00:00:00 2001
-From: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
-Date: Wed, 17 Jun 2009 16:01:31 +0300
-Subject: [PATCH] Call telinit for normal reboot/shutdown.
-
-Signed-off-by: Alexander Shishkin <ext-alexander.shishkin@nokia.com>
----
- init/Config.in | 14 ++++++++++++++
- init/halt.c | 12 ++++++++++++
- 2 files changed, 26 insertions(+), 0 deletions(-)
-
-diff --git a/init/Config.in b/init/Config.in
-index 25f4390..ea91b45 100644
---- a/init/Config.in
-+++ b/init/Config.in
-@@ -12,6 +12,20 @@ config INIT
- help
- init is the first program run when the system boots.
-
-+config CALL_TELINIT
-+ bool "Call telinit on shutdown and reboot"
-+ help
-+ What I just said
-+
-+config TELINIT_PATH
-+ string "Path to telinit executable"
-+ default "/sbin/telinit"
-+ depends on CALL_TELINIT
-+ help
-+ When busybox halt and friends have to call external telinit
-+ to facilitate proper shutdown, this path is to be used when
-+ locating telinit executable.
-+
- config DEBUG_INIT
- bool "Debugging aid"
- default n
-diff --git a/init/halt.c b/init/halt.c
-index c14f0f2..b877be1 100644
---- a/init/halt.c
-+++ b/init/halt.c
-@@ -84,6 +84,18 @@ RB_AUTOBOOT
- }
- if (rc)
- rc = kill(1, signals[which]);
-+ } else if (ENABLE_CALL_TELINIT && !(flags & 4)) {
-+ /* runlevels:
-+ * 0 == shutdown
-+ * 6 == reboot */
-+ const char *telinit_argv[] = {
-+ "telinit",
-+ which == 2 ? "6" : "0",
-+ NULL
-+ };
-+
-+ forkexit_or_rexec();
-+ execve(CONFIG_TELINIT_PATH, telinit_argv, environ);
- } else
- rc = reboot(magic[which]);
-
---
-1.6.3.1
-