Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/coreutils/env.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 815 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 29  Line 29 
29   * - use xfunc_error_retval   * - use xfunc_error_retval
30   */   */
31    
32  #include "busybox.h"  /* This is a NOEXEC applet. Be very careful! */
33  #include <errno.h>  
34  #include <getopt.h> /* struct option */  #include "libbb.h"
35    
36  #if ENABLE_FEATURE_ENV_LONG_OPTIONS  #if ENABLE_FEATURE_ENV_LONG_OPTIONS
37  static const struct option env_long_options[] = {  static const char env_longopts[] ALIGN1 =
38   { "ignore-environment", 0, NULL, 'i' },   "ignore-environment\0" No_argument       "i"
39   { "unset", 1, NULL, 'u' },   "unset\0"              Required_argument "u"
40   { 0, 0, 0, 0 }   ;
 };  
41  #endif  #endif
42    
43  int env_main(int argc, char** argv)  int env_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
44    int env_main(int argc UNUSED_PARAM, char **argv)
45  {  {
46   static char *cleanenv[1] = { NULL };   /* cleanenv was static - why? */
47     char *cleanenv[1];
48   char **ep;   char **ep;
49   unsigned opt;   unsigned opt;
50   llist_t *unset_env = NULL;   llist_t *unset_env = NULL;
  extern char **environ;  
51    
52   opt_complementary = "u::";   opt_complementary = "u::";
53  #if ENABLE_FEATURE_ENV_LONG_OPTIONS  #if ENABLE_FEATURE_ENV_LONG_OPTIONS
54   applet_long_options = env_long_options;   applet_long_options = env_longopts;
55  #endif  #endif
56     opt = getopt32(argv, "+iu:", &unset_env);
  opt = getopt32(argc, argv, "+iu:", &unset_env);  
   
57   argv += optind;   argv += optind;
58   if (*argv && LONE_DASH(argv[0])) {   if (*argv && LONE_DASH(argv[0])) {
59   opt |= 1;   opt |= 1;
60   ++argv;   ++argv;
61   }   }
62     if (opt & 1) {
63   if (opt & 1)   cleanenv[0] = NULL;
64   environ = cleanenv;   environ = cleanenv;
65   else if (opt & 2) {   } else {
66   while (unset_env) {   while (unset_env) {
67   unsetenv(unset_env->data);   unsetenv(llist_pop(&unset_env));
  unset_env = unset_env->link;  
68   }   }
69   }   }
70    
# Line 80  int env_main(int argc, char** argv) Line 76  int env_main(int argc, char** argv)
76   }   }
77    
78   if (*argv) {   if (*argv) {
79   execvp(*argv, argv);   BB_EXECVP(*argv, argv);
80   /* SUSv3-mandated exit codes. */   /* SUSv3-mandated exit codes. */
81   xfunc_error_retval = (errno == ENOENT) ? 127 : 126;   xfunc_error_retval = (errno == ENOENT) ? 127 : 126;
82   bb_perror_msg_and_die("%s", *argv);   bb_simple_perror_msg_and_die(*argv);
83   }   }
84    
85   for (ep = environ; *ep; ep++) {   for (ep = environ; *ep; ep++) {
86   puts(*ep);   puts(*ep);
87   }   }
88    
89   fflush_stdout_and_exit(0);   fflush_stdout_and_exit(EXIT_SUCCESS);
90  }  }
91    
92  /*  /*
# Line 125  int env_main(int argc, char** argv) Line 121  int env_main(int argc, char** argv)
121   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
122   * SUCH DAMAGE.   * SUCH DAMAGE.
123   */   */
   
   

Legend:
Removed from v.815  
changed lines
  Added in v.816