Ignore:
Timestamp:
Nov 4, 2007, 3:16:40 AM (16 years ago)
Author:
Bruno Cornec
Message:

Update to busybox 1.7.2

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.5/mindi-busybox/libbb/setup_environment.c

    r821 r1765  
    2929 */
    3030
    31 #include <stdio.h>
    32 #include <errno.h>
    33 #include <unistd.h>
    34 #include <string.h>
    35 #include <stdlib.h>
    36 #include <syslog.h>
    37 #include <ctype.h>
    3831#include "libbb.h"
    3932
    40 
    41 
    42 #define DEFAULT_LOGIN_PATH      "/bin:/usr/bin"
    43 #define DEFAULT_ROOT_LOGIN_PATH "/usr/sbin:/bin:/usr/bin:/sbin"
    44 
    45 static void xsetenv ( const char *key, const char *value )
     33void setup_environment(const char *shell, int loginshell, int changeenv, const struct passwd *pw)
    4634{
    47         if ( setenv ( key, value, 1 ))
    48                 bb_error_msg_and_die (bb_msg_memory_exhausted);
    49 }
    50 
    51 void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw )
    52 {
    53     if ( loginshell ) {
     35    if (loginshell) {
    5436        const char *term;
    5537
     
    6042         * Some systems default to HOME=/
    6143         */
    62         if ( chdir ( pw-> pw_dir )) {
    63             if ( chdir ( "/" )) {
    64                 syslog ( LOG_WARNING, "unable to cd to %s' for user %s'\n", pw-> pw_dir, pw-> pw_name );
    65                 bb_error_msg_and_die ( "cannot cd to home directory or /" );
    66             }
    67             fputs ( "warning: cannot change to home directory\n", stderr );
     44        if (chdir(pw->pw_dir)) {
     45            xchdir("/");
     46            fputs("warning: cannot change to home directory\n", stderr);
    6847        }
    6948
    7049        /* Leave TERM unchanged.  Set HOME, SHELL, USER, LOGNAME, PATH.
    7150           Unset all other environment variables.  */
    72         term = getenv ("TERM");
    73         clearenv ( );
    74         if ( term )
    75             xsetenv ( "TERM", term );
    76         xsetenv ( "HOME",    pw-> pw_dir );
    77         xsetenv ( "SHELL",   shell );
    78         xsetenv ( "USER",    pw-> pw_name );
    79         xsetenv ( "LOGNAME", pw-> pw_name );
    80         xsetenv ( "PATH",    ( pw-> pw_uid ? DEFAULT_LOGIN_PATH : DEFAULT_ROOT_LOGIN_PATH ));
     51        term = getenv("TERM");
     52        clearenv();
     53        if (term)
     54            xsetenv("TERM", term);
     55        xsetenv("HOME",    pw->pw_dir);
     56        xsetenv("SHELL",   shell);
     57        xsetenv("USER",    pw->pw_name);
     58        xsetenv("LOGNAME", pw->pw_name);
     59        xsetenv("PATH",   (pw->pw_uid ? bb_default_path : bb_default_root_path));
    8160    }
    82     else if ( changeenv ) {
     61    else if (changeenv) {
    8362        /* Set HOME, SHELL, and if not becoming a super-user,
    8463           USER and LOGNAME.  */
    85         xsetenv ( "HOME",  pw-> pw_dir );
    86         xsetenv ( "SHELL", shell );
    87         if  ( pw-> pw_uid ) {
    88             xsetenv ( "USER",    pw-> pw_name );
    89             xsetenv ( "LOGNAME", pw-> pw_name );
     64        xsetenv("HOME",  pw->pw_dir);
     65        xsetenv("SHELL", shell);
     66        if (pw->pw_uid) {
     67            xsetenv("USER",    pw->pw_name);
     68            xsetenv("LOGNAME", pw->pw_name);
    9069        }
    9170    }
    9271}
    93 
Note: See TracChangeset for help on using the changeset viewer.