summaryrefslogtreecommitdiff
path: root/package/busybox/patches/190-ash_performance.patch
blob: 09319314194e6403b171aadd14d62be28a1a7f04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80

	Copyright (C) 2006 OpenWrt.org

diff -urN busybox.old/shell/ash.c busybox.dev/shell/ash.c
--- busybox.old/shell/ash.c	2005-11-12 22:39:19.853826250 +0100
+++ busybox.dev/shell/ash.c	2005-11-12 22:39:42.771258500 +0100
@@ -1414,6 +1414,13 @@
 
 #define NUMBUILTINS  (sizeof (builtincmd) / sizeof (struct builtincmd) )
 
+static const char *safe_applets[] = { 
+	"[", "test", "echo", "cat",
+	"ln", "cp", "touch", "mkdir", "rm",
+	"cut", "hexdump", "awk", "sort",
+	"find", "xargs", "ls", "dd",
+	"chown", "chmod"
+};
 
 
 struct cmdentry {
@@ -2050,6 +2057,19 @@
 static void exitshell(void) __attribute__((__noreturn__));
 static int decode_signal(const char *, int);
 
+
+static int is_safe_applet(char *name)
+{
+	int n = sizeof(safe_applets) / sizeof(char *);
+	int i;
+	for (i = 0; i < n; i++)
+		if (strcmp(safe_applets[i], name) == 0)
+			return 1;
+
+	return 0;
+}
+
+
 /*
  * This routine is called when an error or an interrupt occurs in an
  * interactive shell and control is returned to the main command loop.
@@ -3680,6 +3700,7 @@
 	clearredir(1);
 	envp = environment();
 	if (strchr(argv[0], '/') != NULL
+		|| is_safe_applet(argv[0])
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
 		|| find_applet_by_name(argv[0])
 #endif
@@ -3721,6 +3742,18 @@
 tryexec(char *cmd, char **argv, char **envp)
 {
 	int repeated = 0;
+	struct BB_applet *a;
+	int argc = 0;
+	char **c;
+	
+	if(strchr(cmd, '/') == NULL && is_safe_applet(cmd) && (a = find_applet_by_name(cmd)) != NULL) {
+		c = argv;
+		while (*c != NULL) {
+			c++; argc++;
+		}
+		bb_applet_name = cmd;
+		exit(a->main(argc, argv));
+	}
 #ifdef CONFIG_FEATURE_SH_STANDALONE_SHELL
 	int flg_bb = 0;
 	char *name = cmd;
@@ -3919,6 +3952,12 @@
 	}
 #endif
 
+	if (is_safe_applet(name)) {
+		entry->cmdtype = CMDNORMAL;
+		entry->u.index = -1;
+		return;
+	}
+
 	updatetbl = (path == pathval());
 	if (!updatetbl) {
 		act |= DO_ALTPATH;