From: Eric Andersen Date: Thu, 29 Mar 2001 22:48:33 +0000 (-0000) Subject: Add in a new standalone env applet for fixing up app's environments X-Git-Tag: 0_51~62 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=84e229cfbe00d27ce81dad66c982bec0d50cdfd7;p=oweals%2Fbusybox.git Add in a new standalone env applet for fixing up app's environments -Erik --- diff --git a/Changelog b/Changelog index d90515806..19acbbd5c 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,12 @@ +0.51pre + * Erik Andersen -- added env applet + * Erik Andersen -- Split utility.c into libbb + * + + + -Erik Andersen, not yet released + + 0.50 * Erik Andersen -- added ifconfig interface status reporting * Erik Andersen -- Debian packaging updates diff --git a/Config.h b/Config.h index 423454616..8c7684876 100644 --- a/Config.h +++ b/Config.h @@ -32,6 +32,7 @@ #define BB_DU //#define BB_DUMPKMAP #define BB_ECHO +#define BB_ENV //#define BB_EXPR //#define BB_FBSET //#define BB_FDFLUSH diff --git a/applets.h b/applets.h index 0ab296312..255bd6b44 100644 --- a/applets.h +++ b/applets.h @@ -131,6 +131,9 @@ #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) #endif +#ifdef BB_ENV + APPLET(env, env_main, _BB_DIR_USR_BIN) +#endif #ifdef BB_EXPR APPLET(expr, expr_main, _BB_DIR_USR_BIN) #endif diff --git a/applets/usage.h b/applets/usage.h index dde3dd146..32b34e45f 100644 --- a/applets/usage.h +++ b/applets/usage.h @@ -343,6 +343,15 @@ "$ echo "Erik\nis\ncool"\n" \ "Erik\nis\ncool\n" +#define env_trivial_usage \ + "[-] [-iu] [name=value ...] [command]" +#define env_full_usage \ + "Prints the current environment or runs a program after setting\n" \ + "up the specified environment.\n\n" \ + "Options:\n" \ + "\t-, -i\tstart with an empty environment\n" \ + "\t-u\tremove variable from the environment\n" + #define expr_trivial_usage \ "EXPRESSION" #define expr_full_usage \ diff --git a/coreutils/env.c b/coreutils/env.c new file mode 100644 index 000000000..56577b611 --- /dev/null +++ b/coreutils/env.c @@ -0,0 +1,97 @@ +/* vi: set sw=4 ts=4: */ +/* + * env implementation for busybox + * + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * 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 + * + * Original copyright notice is retained at the end of this file. + * + * Modified for BusyBox by Erik Andersen , + */ + +#include +#include +#include +#include +#include +#include "busybox.h" + +extern int env_main(int argc, char** argv) +{ + char **ep, *p; + char *cleanenv[1]; + int ch; + + while ((ch = getopt(argc, argv, "-iu:")) != -1) + switch(ch) { + case '-': + case 'i': + environ = cleanenv; + cleanenv[0] = NULL; + break; + case 'u': + unsetenv(optarg); + break; + default: + show_usage(); + } + for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) + setenv(*argv, ++p, 1); + if (*argv) { + execvp(*argv, argv); + perror_msg_and_die("%s", *argv); + } + for (ep = environ; *ep; ep++) + printf("%s\n", *ep); + exit(EXIT_SUCCESS); +} + +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. + * + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + diff --git a/env.c b/env.c new file mode 100644 index 000000000..56577b611 --- /dev/null +++ b/env.c @@ -0,0 +1,97 @@ +/* vi: set sw=4 ts=4: */ +/* + * env implementation for busybox + * + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * 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 + * + * Original copyright notice is retained at the end of this file. + * + * Modified for BusyBox by Erik Andersen , + */ + +#include +#include +#include +#include +#include +#include "busybox.h" + +extern int env_main(int argc, char** argv) +{ + char **ep, *p; + char *cleanenv[1]; + int ch; + + while ((ch = getopt(argc, argv, "-iu:")) != -1) + switch(ch) { + case '-': + case 'i': + environ = cleanenv; + cleanenv[0] = NULL; + break; + case 'u': + unsetenv(optarg); + break; + default: + show_usage(); + } + for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) + setenv(*argv, ++p, 1); + if (*argv) { + execvp(*argv, argv); + perror_msg_and_die("%s", *argv); + } + for (ep = environ; *ep; ep++) + printf("%s\n", *ep); + exit(EXIT_SUCCESS); +} + +/* + * Copyright (c) 1988, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * 3. + * + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + + diff --git a/include/applets.h b/include/applets.h index 0ab296312..255bd6b44 100644 --- a/include/applets.h +++ b/include/applets.h @@ -131,6 +131,9 @@ #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) #endif +#ifdef BB_ENV + APPLET(env, env_main, _BB_DIR_USR_BIN) +#endif #ifdef BB_EXPR APPLET(expr, expr_main, _BB_DIR_USR_BIN) #endif diff --git a/include/usage.h b/include/usage.h index dde3dd146..32b34e45f 100644 --- a/include/usage.h +++ b/include/usage.h @@ -343,6 +343,15 @@ "$ echo "Erik\nis\ncool"\n" \ "Erik\nis\ncool\n" +#define env_trivial_usage \ + "[-] [-iu] [name=value ...] [command]" +#define env_full_usage \ + "Prints the current environment or runs a program after setting\n" \ + "up the specified environment.\n\n" \ + "Options:\n" \ + "\t-, -i\tstart with an empty environment\n" \ + "\t-u\tremove variable from the environment\n" + #define expr_trivial_usage \ "EXPRESSION" #define expr_full_usage \ diff --git a/lash.c b/lash.c index 22c56d444..28015cbb3 100644 --- a/lash.c +++ b/lash.c @@ -143,7 +143,6 @@ struct close_me { /* function prototypes for builtins */ static int builtin_cd(struct child_prog *cmd); -static int builtin_env(struct child_prog *dummy); static int builtin_exec(struct child_prog *cmd); static int builtin_exit(struct child_prog *cmd); static int builtin_fg_bg(struct child_prog *cmd); @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { /* 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 built_in_command 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} @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } builtin previous use notes ------ ----------------- --------- cd cmd->progs[0] -env 0 exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins exit cmd->progs[0] fg_bg cmd->progs[0], job_list->head, job_list->fg help 0 jobs job_list->head pwd 0 -export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them +export cmd->progs[0] source cmd->progs[0] unset cmd->progs[0] read cmd->progs[0] @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) return EXIT_SUCCESS; } -/* built-in 'env' handler */ -static int builtin_env(struct child_prog *dummy) -{ - char **e; - - for (e = environ; *e; e++) { - printf( "%s\n", *e); - } - return (0); -} - /* built-in 'exec' handler */ static int builtin_exec(struct child_prog *child) { @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) char *v = child->argv[1]; if (v == NULL) { - return (builtin_env(child)); + char **e; + for (e = environ; *e; e++) { + printf( "%s\n", *e); + } } res = putenv(v); if (res) diff --git a/sh.c b/sh.c index 22c56d444..28015cbb3 100644 --- a/sh.c +++ b/sh.c @@ -143,7 +143,6 @@ struct close_me { /* function prototypes for builtins */ static int builtin_cd(struct child_prog *cmd); -static int builtin_env(struct child_prog *dummy); static int builtin_exec(struct child_prog *cmd); static int builtin_exit(struct child_prog *cmd); static int builtin_fg_bg(struct child_prog *cmd); @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { /* 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 built_in_command 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} @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } builtin previous use notes ------ ----------------- --------- cd cmd->progs[0] -env 0 exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins exit cmd->progs[0] fg_bg cmd->progs[0], job_list->head, job_list->fg help 0 jobs job_list->head pwd 0 -export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them +export cmd->progs[0] source cmd->progs[0] unset cmd->progs[0] read cmd->progs[0] @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) return EXIT_SUCCESS; } -/* built-in 'env' handler */ -static int builtin_env(struct child_prog *dummy) -{ - char **e; - - for (e = environ; *e; e++) { - printf( "%s\n", *e); - } - return (0); -} - /* built-in 'exec' handler */ static int builtin_exec(struct child_prog *child) { @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) char *v = child->argv[1]; if (v == NULL) { - return (builtin_env(child)); + char **e; + for (e = environ; *e; e++) { + printf( "%s\n", *e); + } } res = putenv(v); if (res) diff --git a/shell/lash.c b/shell/lash.c index 22c56d444..28015cbb3 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -143,7 +143,6 @@ struct close_me { /* function prototypes for builtins */ static int builtin_cd(struct child_prog *cmd); -static int builtin_env(struct child_prog *dummy); static int builtin_exec(struct child_prog *cmd); static int builtin_exit(struct child_prog *cmd); static int builtin_fg_bg(struct child_prog *cmd); @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { /* 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 built_in_command 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} @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } builtin previous use notes ------ ----------------- --------- cd cmd->progs[0] -env 0 exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins exit cmd->progs[0] fg_bg cmd->progs[0], job_list->head, job_list->fg help 0 jobs job_list->head pwd 0 -export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them +export cmd->progs[0] source cmd->progs[0] unset cmd->progs[0] read cmd->progs[0] @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) return EXIT_SUCCESS; } -/* built-in 'env' handler */ -static int builtin_env(struct child_prog *dummy) -{ - char **e; - - for (e = environ; *e; e++) { - printf( "%s\n", *e); - } - return (0); -} - /* built-in 'exec' handler */ static int builtin_exec(struct child_prog *child) { @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) char *v = child->argv[1]; if (v == NULL) { - return (builtin_env(child)); + char **e; + for (e = environ; *e; e++) { + printf( "%s\n", *e); + } } res = putenv(v); if (res) diff --git a/usage.h b/usage.h index dde3dd146..32b34e45f 100644 --- a/usage.h +++ b/usage.h @@ -343,6 +343,15 @@ "$ echo "Erik\nis\ncool"\n" \ "Erik\nis\ncool\n" +#define env_trivial_usage \ + "[-] [-iu] [name=value ...] [command]" +#define env_full_usage \ + "Prints the current environment or runs a program after setting\n" \ + "up the specified environment.\n\n" \ + "Options:\n" \ + "\t-, -i\tstart with an empty environment\n" \ + "\t-u\tremove variable from the environment\n" + #define expr_trivial_usage \ "EXPRESSION" #define expr_full_usage \