[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#11991: fakeroot runs commands from the current directory



I was also having problems with fakeroot erroneously running commands
out of the current directory, and I found this bug report from last
summer which is about that.

Here's how you can reproduce the problem:

    $ ls -F
    Makefile  ls*
    $ cat Makefile
    fakeroot-test:
	    ls
    $ cat ls
    #!/bin/sh
    echo "oops, got ./ls"
    $ env - PATH=/bin:/usr/bin fakeroot /usr/bin/make
    ls
    oops, got ./ls
    $ 

What's going on is that the environment passed by fakeroot to the
command it runs is empty except for the two variables fakeroot uses
itself.  If you run bash without a path it will supply a default, but
for simple rules make doesn't call the shell, it runs the command via
execvp() after splitting it apart itself.  The kernel treats a missing
PATH like `:/bin:/usr/bin', so the command found by execvp() is the
one in the current directory.

The bug report says that you've changed your copy of the source to use
execvp() instead of execve(), so that fix for this problem is good.  I
wanted to send this message so you knew that the problem is real and
what is really going on, as there's some confusion about that in the bug
report.

The problem prevents me from using fakeroot to build some of my packages;
please release a new version of fakeroot which has the change you describe.
If you like I'll perform a simple non-maintainer upload which has this
patch (which I cooked up before I read the bug report carefully enough to
realize you'd already done it).

*** fakeroot.cc.~1~	Wed Jan 28 12:24:54 1998
--- fakeroot.cc	Tue Mar 10 21:57:13 1998
***************
*** 561,588 ****
  /***********/
  
  
  int run_command(char *const*cmd){
-   char *envp[]={NULL,"LD_PRELOAD=/usr/lib/fakeroot/libfakeroot.so.0",NULL,NULL};
    char *default_cmd[]={"/bin/sh",NULL};
    char buf[300];
-   char libstr[300];
    int status;
    pid_t child;
  
!   sprintf(buf,FAKEROOTKEY_ENV "=%i",msg_key);
!   envp[0]=buf;
! 
!   if(fakelib!=""){
!     sprintf(libstr,"LD_PRELOAD=%s",&(fakelib[0]));
!     envp[1]=libstr;
!   }
    if(!*cmd)
      cmd=default_cmd;
  
    if(debug)
      fprintf(stderr,"FAKEROOT: running %s\n", cmd[0]);
    if(!(child=fork())){
!     execve(cmd[0],cmd, envp);
      sprintf(buf,"fakeroot, execve %s", cmd[0]);
      perror(buf);
      exit(1);
--- 561,591 ----
  /***********/
  
  
+ void xsetenv(const char *name, const char *val, int over){
+   if(setenv(name,val,over)==-1){
+     fprintf(stderr,"fakeroot: no room for environment variable %s\n",name);
+     exit(1);
+   }
+ }
+ 
  int run_command(char *const*cmd){
    char *default_cmd[]={"/bin/sh",NULL};
    char buf[300];
    int status;
    pid_t child;
  
!   xsetenv("LD_PRELOAD",
! 	  fakelib!=""?&(fakelib[0]):"/usr/lib/fakeroot/libfakeroot.so.0",
! 	  1);
!   sprintf(buf,"%i",msg_key);
!   xsetenv(FAKEROOTKEY_ENV,buf,1);
    if(!*cmd)
      cmd=default_cmd;
  
    if(debug)
      fprintf(stderr,"FAKEROOT: running %s\n", cmd[0]);
    if(!(child=fork())){
!     execvp(cmd[0],cmd);
      sprintf(buf,"fakeroot, execve %s", cmd[0]);
      perror(buf);
      exit(1);

-- 
Roderick Schertler
roderick@argon.org


--
E-mail the word "unsubscribe" to debian-devel-request@lists.debian.org
TO UNSUBSCRIBE FROM THIS MAILING LIST. Trouble?  E-mail to listmaster@debian.org .


Reply to: