mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-11-27 13:40:22 +00:00
Add in a new standalone env applet for fixing up app's environments
-Erik
This commit is contained in:
parent
e5c24dfd01
commit
84e229cfbe
@ -1,3 +1,12 @@
|
||||
0.51pre
|
||||
* Erik Andersen -- added env applet
|
||||
* Erik Andersen -- Split utility.c into libbb
|
||||
* <fixme>
|
||||
|
||||
|
||||
-Erik Andersen, not yet released
|
||||
|
||||
|
||||
0.50
|
||||
* Erik Andersen -- added ifconfig interface status reporting
|
||||
* Erik Andersen -- Debian packaging updates
|
||||
|
1
Config.h
1
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
|
||||
|
@ -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
|
||||
|
@ -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 \
|
||||
|
97
coreutils/env.c
Normal file
97
coreutils/env.c
Normal file
@ -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 <andersen@lineo.com>, <andersee@debian.org>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#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. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
97
env.c
Normal file
97
env.c
Normal file
@ -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 <andersen@lineo.com>, <andersee@debian.org>
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#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. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
|
||||
* ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
@ -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
|
||||
|
@ -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 \
|
||||
|
21
lash.c
21
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)
|
||||
|
21
sh.c
21
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)
|
||||
|
21
shell/lash.c
21
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)
|
||||
|
9
usage.h
9
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 \
|
||||
|
Loading…
Reference in New Issue
Block a user