diff options
author | Matt Kraai <kraai@debian.org> | 2000-12-15 00:35:22 +0000 |
---|---|---|
committer | Matt Kraai <kraai@debian.org> | 2000-12-15 00:35:22 +0000 |
commit | 8abc78aa84a88c12fca41ae10e84898ad5089cae (patch) | |
tree | a7355d6ab310e8e1ccac7c42cb3c7925790c3314 | |
parent | 1b622ff5ac621305855eacf5886c5bc36790e9ec (diff) | |
download | busybox-w32-8abc78aa84a88c12fca41ae10e84898ad5089cae.tar.gz busybox-w32-8abc78aa84a88c12fca41ae10e84898ad5089cae.tar.bz2 busybox-w32-8abc78aa84a88c12fca41ae10e84898ad5089cae.zip |
Rewrite argv munger.
-rw-r--r-- | applets/busybox.c | 33 | ||||
-rw-r--r-- | busybox.c | 33 |
2 files changed, 22 insertions, 44 deletions
diff --git a/applets/busybox.c b/applets/busybox.c index 8f27dfb8e..e6f25afb5 100644 --- a/applets/busybox.c +++ b/applets/busybox.c | |||
@@ -150,9 +150,7 @@ int main(int argc, char **argv) | |||
150 | 150 | ||
151 | int busybox_main(int argc, char **argv) | 151 | int busybox_main(int argc, char **argv) |
152 | { | 152 | { |
153 | int col = 0; | 153 | int col = 0, len, i; |
154 | int ps_index; | ||
155 | char *index, *index2; | ||
156 | 154 | ||
157 | argc--; | 155 | argc--; |
158 | 156 | ||
@@ -185,25 +183,16 @@ int busybox_main(int argc, char **argv) | |||
185 | /* Flag that we've been here already */ | 183 | /* Flag that we've been here already */ |
186 | been_there_done_that = 1; | 184 | been_there_done_that = 1; |
187 | 185 | ||
188 | /* We do not want the word "busybox" to show up in ps, so we move | 186 | /* Move the command line down a notch */ |
189 | * everything in argv around to fake ps into showing what we want it to | 187 | len = argv[argc] + strlen(argv[argc]) - argv[1]; |
190 | * show. Since we are only shrinking the string, we don't need to move | 188 | memmove(argv[0], argv[1], len); |
191 | * __environ or any of that tedious stuff... */ | 189 | memset(argv[0] + len, 0, argv[1] - argv[0]); |
192 | ps_index = 0; | 190 | |
193 | index=*argv; | 191 | /* Fix up the argv pointers */ |
194 | index2=argv[argc]; | 192 | len = argv[1] - argv[0]; |
195 | index2+=strlen(argv[argc]); | 193 | memmove(argv, argv+1, sizeof(char *) * (argc + 1)); |
196 | while(ps_index < argc) { | 194 | for (i = 0; i < argc; i++) |
197 | argv[ps_index]=index; | 195 | argv[i] -= len; |
198 | memmove(index, argv[ps_index+1], strlen(argv[ps_index+1])+1); | ||
199 | index+=(strlen(index)); | ||
200 | *index='\0'; | ||
201 | index++; | ||
202 | ps_index++; | ||
203 | } | ||
204 | while(index<=index2) | ||
205 | *index++='\0'; | ||
206 | argv[ps_index]=NULL; | ||
207 | 196 | ||
208 | return (main(argc, argv)); | 197 | return (main(argc, argv)); |
209 | } | 198 | } |
@@ -150,9 +150,7 @@ int main(int argc, char **argv) | |||
150 | 150 | ||
151 | int busybox_main(int argc, char **argv) | 151 | int busybox_main(int argc, char **argv) |
152 | { | 152 | { |
153 | int col = 0; | 153 | int col = 0, len, i; |
154 | int ps_index; | ||
155 | char *index, *index2; | ||
156 | 154 | ||
157 | argc--; | 155 | argc--; |
158 | 156 | ||
@@ -185,25 +183,16 @@ int busybox_main(int argc, char **argv) | |||
185 | /* Flag that we've been here already */ | 183 | /* Flag that we've been here already */ |
186 | been_there_done_that = 1; | 184 | been_there_done_that = 1; |
187 | 185 | ||
188 | /* We do not want the word "busybox" to show up in ps, so we move | 186 | /* Move the command line down a notch */ |
189 | * everything in argv around to fake ps into showing what we want it to | 187 | len = argv[argc] + strlen(argv[argc]) - argv[1]; |
190 | * show. Since we are only shrinking the string, we don't need to move | 188 | memmove(argv[0], argv[1], len); |
191 | * __environ or any of that tedious stuff... */ | 189 | memset(argv[0] + len, 0, argv[1] - argv[0]); |
192 | ps_index = 0; | 190 | |
193 | index=*argv; | 191 | /* Fix up the argv pointers */ |
194 | index2=argv[argc]; | 192 | len = argv[1] - argv[0]; |
195 | index2+=strlen(argv[argc]); | 193 | memmove(argv, argv+1, sizeof(char *) * (argc + 1)); |
196 | while(ps_index < argc) { | 194 | for (i = 0; i < argc; i++) |
197 | argv[ps_index]=index; | 195 | argv[i] -= len; |
198 | memmove(index, argv[ps_index+1], strlen(argv[ps_index+1])+1); | ||
199 | index+=(strlen(index)); | ||
200 | *index='\0'; | ||
201 | index++; | ||
202 | ps_index++; | ||
203 | } | ||
204 | while(index<=index2) | ||
205 | *index++='\0'; | ||
206 | argv[ps_index]=NULL; | ||
207 | 196 | ||
208 | return (main(argc, argv)); | 197 | return (main(argc, argv)); |
209 | } | 198 | } |