[BusyBox] Sed/Sh/Env/Ifconfig
Tim Robbins
fyre at box3n.gumbynet.org
Wed Nov 15 15:04:11 UTC 2000
I did end up finding my patch. I've attached it to this message. The first
revision of this patch was rejected because it did not remove the shell
builtin env; I'm not sure what happened to the second one (attached), but
if there is something about it that needs to be changed, let me know and
I'll try my best to fix it.
Tim
--
Tim J. Robbins <fyre at eryf.net>
-------------- next part --------------
diff -ruN busybox.old/Config.h busybox/Config.h
--- busybox.old/Config.h Tue Oct 10 05:56:47 2000
+++ busybox/Config.h Thu Oct 19 13:46:01 2000
@@ -29,6 +29,7 @@
#define BB_DU
#define BB_DUMPKMAP
#define BB_ECHO
+#define BB_ENV
#define BB_EXPR
#define BB_FBSET
#define BB_FDFLUSH
Binary files busybox.old/busybox and busybox/busybox differ
diff -ruN busybox.old/busybox.c busybox/busybox.c
--- busybox.old/busybox.c Tue Oct 10 05:56:47 2000
+++ busybox/busybox.c Thu Oct 19 13:46:01 2000
@@ -82,6 +82,9 @@
#ifdef BB_ECHO
{"echo", echo_main, _BB_DIR_BIN, echo_usage},
#endif
+#ifdef BB_ENV
+ {"env", env_main, _BB_DIR_USR_BIN, env_usage},
+#endif
#ifdef BB_EXPR
{"expr", expr_main, _BB_DIR_USR_BIN, expr_usage},
#endif
diff -ruN busybox.old/busybox.h busybox/busybox.h
--- busybox.old/busybox.h Tue Oct 10 05:56:47 2000
+++ busybox/busybox.h Thu Oct 19 13:46:01 2000
@@ -132,6 +132,7 @@
extern int dumpkmap_main(int argc, char** argv);
extern int dutmp_main(int argc, char** argv);
extern int echo_main(int argc, char** argv);
+extern int env_main(int argc, char** argv);
extern int expr_main(int argc, char** argv);
extern int false_main(int argc, char** argv);
extern int fbset_main(int argc, char** argv);
@@ -250,6 +251,7 @@
extern const char dumpkmap_usage[];
extern const char dutmp_usage[];
extern const char echo_usage[];
+extern const char env_usage[];
extern const char expr_usage[];
extern const char false_usage[];
extern const char fdflush_usage[];
diff -ruN busybox.old/env.c busybox/env.c
--- busybox.old/env.c Thu Jan 1 10:00:00 1970
+++ busybox/env.c Thu Oct 19 13:46:01 2000
@@ -0,0 +1,101 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * env - Set environment for command invocation
+ *
+ * Copyright (c) 2000 Tim J. Robbins.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ */
+
+#include "busybox.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+
+extern char **environ;
+
+int env_main (int argc, char *argv[])
+{
+ int ch;
+ int zap = 0;
+
+ if ((argc > 1) && (strcmp (argv[1], "-") == 0)) {
+ zap = 1;
+ argc -= 2;
+ argv += 2;
+ } else {
+ while ((ch = getopt (argc, argv, "iu:")) != -1) {
+ switch (ch) {
+ case 'i':
+ zap = 1;
+ break;
+ case 'u':
+ /*
+ * This is an extension to P1003.2.
+ */
+ unsetenv (optarg);
+ break;
+ default:
+ usage (env_usage);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+ }
+
+ if (zap != 0) *environ = NULL;
+
+ while (*argv != NULL) {
+ if (strchr (*argv, '=') == NULL)
+ break;
+ if (putenv (*argv) < 0) {
+ errorMsg ("%s\n", strerror (errno));
+ exit (1);
+ }
+ argc--;
+ argv++;
+ }
+
+ if (*argv == NULL) {
+ char **e;
+
+ for (e = environ; *e != NULL; e++)
+ printf ("%s\n", *e);
+ } else {
+ int saverrno;
+ execvp (argv[0], argv);
+ saverrno = errno;
+ /*
+ * XXX Can't use fatalError() here otherwise we can't
+ * control exit status (defined by P1003.2).
+ */
+ errorMsg ("%s: %s\n", argv[0], strerror (errno));
+ if (saverrno == ENOENT) exit (127);
+ else exit (126);
+ }
+
+ return 0;
+}
+
+/*
+Local Variables:
+c-file-style: "linux"
+c-basic-offset: 4
+tab-width: 4
+End:
+*/
diff -ruN busybox.old/sh.c busybox/sh.c
--- busybox.old/sh.c Wed Sep 27 13:43:35 2000
+++ busybox/sh.c Thu Oct 19 13:46:10 2000
@@ -107,7 +107,6 @@
/* function prototypes for builtins */
static int builtin_cd(struct job *cmd, struct jobSet *junk);
-static int builtin_env(struct job *dummy, struct jobSet *junk);
static int builtin_exec(struct job *cmd, struct jobSet *junk);
static int builtin_exit(struct job *cmd, struct jobSet *junk);
static int builtin_fg_bg(struct job *cmd, struct jobSet *jobList);
@@ -160,7 +159,6 @@
/* Table of forking built-in functions (things that fork cannot change global
* variables in the parent process, such as the current working directory) */
static struct builtInCommand bltins_forking[] = {
- {"env", "Print all environment variables", builtin_env},
{"pwd", "Print current directory", builtin_pwd},
{"help", "List shell built-in commands", builtin_help},
{NULL, NULL, NULL}
@@ -210,17 +208,6 @@
return TRUE;
}
-/* built-in 'env' handler */
-static int builtin_env(struct job *dummy, struct jobSet *junk)
-{
- char **e;
-
- for (e = environ; *e; e++) {
- fprintf(stdout, "%s\n", *e);
- }
- return (0);
-}
-
/* built-in 'exec' handler */
static int builtin_exec(struct job *cmd, struct jobSet *junk)
{
@@ -347,7 +334,11 @@
int res;
if (!cmd->progs[0].argv[1] == 1) {
- return (builtin_env(cmd, junk));
+ char **e;
+
+ for (e = environ; *e; e++) {
+ fprintf(stdout, "%s\n", *e);
+ }
}
res = putenv(cmd->progs[0].argv[1]);
if (res)
diff -ruN busybox.old/usage.c busybox/usage.c
--- busybox.old/usage.c Fri Oct 13 09:30:31 2000
+++ busybox/usage.c Thu Oct 19 13:46:01 2000
@@ -270,6 +270,17 @@
;
#endif
+#if defined BB_ENV
+const char env_usage[] =
+ "env [-i] [name=value] ... [utility [argument ...]]\n"
+#ifndef BB_FEATURE_TRIVIAL_HELP
+ "\nExecute utility with modified argument\n\n"
+ "Options:\n"
+ "\t-i\tdo not inherit environment\n"
+#endif
+ ;
+#endif
+
#if defined BB_EXPR
const char expr_usage[] =
"expr EXPRESSION\n"
More information about the busybox
mailing list