Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/libbb/run_shell.c

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

revision 532 by niro, Sat Sep 1 22:45:15 2007 UTC revision 816 by niro, Fri Apr 24 18:33:46 2009 UTC
# Line 28  Line 28 
28   * SUCH DAMAGE.   * SUCH DAMAGE.
29   */   */
30    
 #include <stdio.h>  
 #include <errno.h>  
 #include <unistd.h>  
 #include <string.h>  
 #include <stdlib.h>  
 #include <syslog.h>  
 #include <ctype.h>  
31  #include "libbb.h"  #include "libbb.h"
32  #ifdef CONFIG_SELINUX  #if ENABLE_SELINUX
33  #include <selinux/selinux.h>  /* for setexeccon  */  #include <selinux/selinux.h>  /* for setexeccon  */
34  #endif  #endif
35    
36  #ifdef CONFIG_SELINUX  #if ENABLE_SELINUX
37  static security_context_t current_sid;  static security_context_t current_sid;
38    
39  void  void FAST_FUNC renew_current_security_context(void)
 renew_current_security_context(void)  
40  {  {
41   if (current_sid)   freecon(current_sid);  /* Release old context  */
  freecon(current_sid);  /* Release old context  */  
42   getcon(&current_sid);  /* update */   getcon(&current_sid);  /* update */
43  }  }
44  void  void FAST_FUNC set_current_security_context(security_context_t sid)
 set_current_security_context(security_context_t sid)  
45  {  {
46   if (current_sid)   freecon(current_sid);  /* Release old context  */
  freecon(current_sid);  /* Release old context  */  
47   current_sid = sid;   current_sid = sid;
48  }  }
49    
# Line 65  set_current_security_context(security_co Line 54  set_current_security_context(security_co
54     If ADDITIONAL_ARGS is nonzero, pass it to the shell as more     If ADDITIONAL_ARGS is nonzero, pass it to the shell as more
55     arguments.  */     arguments.  */
56    
57  void run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)  void FAST_FUNC run_shell(const char *shell, int loginshell, const char *command, const char **additional_args)
58  {  {
59   const char **args;   const char **args;
60   int argno = 1;   int argno = 1;
# Line 76  void run_shell(const char *shell, int lo Line 65  void run_shell(const char *shell, int lo
65    
66   args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));   args = xmalloc(sizeof(char*) * (4 + additional_args_cnt));
67    
68   args[0] = bb_get_last_path_component(xstrdup(shell));   args[0] = bb_get_last_path_component_nostrip(xstrdup(shell));
69    
70   if (loginshell)   if (loginshell)
71   args[0] = xasprintf("-%s", args[0]);   args[0] = xasprintf("-%s", args[0]);
# Line 90  void run_shell(const char *shell, int lo Line 79  void run_shell(const char *shell, int lo
79   args[argno++] = *additional_args;   args[argno++] = *additional_args;
80   }   }
81   args[argno] = NULL;   args[argno] = NULL;
82  #ifdef CONFIG_SELINUX  #if ENABLE_SELINUX
83   if (current_sid && !setexeccon(current_sid)) {   if (current_sid)
84     setexeccon(current_sid);
85     if (ENABLE_FEATURE_CLEAN_UP)
86   freecon(current_sid);   freecon(current_sid);
  execve(shell, (char **) args, environ);  
  } else  
87  #endif  #endif
88   execv(shell, (char **) args);   execv(shell, (char **) args);
89   bb_perror_msg_and_die("cannot run %s", shell);   bb_perror_msg_and_die("cannot run %s", shell);

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