-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshowenv.patch
93 lines (92 loc) · 1.89 KB
/
showenv.patch
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
81
82
83
84
85
86
87
88
89
90
91
92
93
--- /dev/null 2012-02-09 20:31:42.211948750 +0400
+++ kinit/showenv/Makefile 2012-02-09 17:35:01.247496983 +0400
@@ -0,0 +1,3 @@
+prog = showenv
+objs = showenv.o
+include $(CURDIR)/../rules.mk
--- /dev/null 2012-02-09 20:31:42.211948750 +0400
+++ kinit/showenv/showenv.c 2012-02-09 17:56:08.222496887 +0400
@@ -0,0 +1,72 @@
+#include <unistd.h>
+#include <stdio.h>
+#include <ctype.h>
+
+static const char usage[] = "Usage: showenv [-q|-s|-h]\n";
+static unsigned int quote = 0;
+static unsigned int shell = 0;
+
+static void
+write_ch(const char c) {
+ if (write(1, &c, 1) == -1)
+ _exit(1);
+}
+
+static void
+print_ch(const char c) {
+ if (quote && (c == '\\' || c == '"' || c == '$' || c == '`'))
+ write_ch('\\');
+ write_ch(c);
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+ unsigned int i = 0, j;
+
+ if (argc == 2 && argv[1][0] == '-') {
+ if (argv[1][1] == 'h') {
+ if (write(1, usage, sizeof(usage) - 1) == -1)
+ _exit(1);
+ return 0;
+ } else if (argv[1][1] == 'q') {
+ quote = 1;
+ } else if (argv[1][1] == 's') {
+ shell = 1;
+ }
+ }
+
+ while (envp[i]) {
+ j = 0;
+ while(envp[i][j] != '=') j++;
+ envp[i][j] = '\0';
+
+ if (shell) {
+ int k = 0;
+
+ while(envp[i][k] && (isalnum(envp[i][k]) || envp[i][k] == '_')) k++;
+
+ if (j != k) {
+ i++;
+ continue;
+ }
+ }
+ j = 0;
+ while(envp[i][j])
+ print_ch(envp[i][j++]);
+ j++;
+
+ write_ch('=');
+ if (quote)
+ write_ch('"');
+
+ while(envp[i][j])
+ print_ch(envp[i][j++]);
+
+ if (quote)
+ write_ch('"');
+ write_ch('\n');
+ i++;
+ }
+
+ return 0;
+}
--- kinit/Makefile.fix3 2009-11-10 01:31:23 +0300
+++ kinit/Makefile 2009-11-10 01:33:08 +0300
@@ -14,8 +14,9 @@ subdirs += run-init
subdirs += fstype
subdirs += resume
subdirs += md_run
subdirs += replace
+subdirs += showenv
# Additional include paths files
CFLAGS += -I$(srctree)/$(src)/fstype \
-I$(srctree)/$(src)/ipconfig \