Hurd: Implement chdir support in posix_spawn

Message ID 87h8gtjezi.fsf@oldenburg.str.redhat.com
State Superseded
Headers

Commit Message

Florian Weimer Nov. 7, 2018, 11:37 a.m. UTC
  This fixes build-many-glibcs.py on i686-gnu.

Note that I don't really know what I'm doing here, and I don't have a
way to check this code.

Thanks,
Florian

2018-11-07  Florian Weimer  <fweimer@redhat.com>

	* sysdeps/mach/hurd/spawni.c (__spawni): Add nested function
	child_chdir.  Handle spawn_do_chdir.
  

Comments

Samuel Thibault Nov. 7, 2018, 1:25 p.m. UTC | #1
Florian Weimer, le mer. 07 nov. 2018 12:37:05 +0100, a ecrit:
> This fixes build-many-glibcs.py on i686-gnu.
> 
> Note that I don't really know what I'm doing here, and I don't have a
> way to check this code.

No problem, I'll have a look and test :)

Thanks!
Samuel
  

Patch

diff --git a/sysdeps/mach/hurd/spawni.c b/sysdeps/mach/hurd/spawni.c
index 9351c13e56..b554ccc646 100644
--- a/sysdeps/mach/hurd/spawni.c
+++ b/sysdeps/mach/hurd/spawni.c
@@ -205,6 +205,38 @@  __spawni (pid_t *pid, const char *file,
       return __hurd_file_name_lookup (&child_init_port, &child_fd, 0,
 				      file, oflag, mode, result);
     }
+  auto error_t child_chdir (const char *name)
+    {
+      if (rcwdir != MACH_PORT_NULL)
+	{
+	  __mach_port_deallocate (__mach_task_self (), rcwdir);
+	  rcwdir = MACH_PORT_NULL;
+	}
+
+      /* See _hurd_change_directory_port_from_name.  */
+
+      /* Append trailing "/." to directory name to force ENOTDIR if
+	 it's not a directory and EACCES if we don't have search
+	 permission.  */
+      len = strlen (name);
+      const char *lookup = name;
+      if (len >= 2 && name[len - 2] == '/' && name[len - 1] == '.')
+	lookup = name;
+      else if (len == 0)
+	/* Special-case empty file name according to POSIX.  */
+	return __hurd_fail (ENOENT);
+      else
+	{
+	  char *n = alloca (len + 3);
+	  memcpy (n, name, len);
+	  n[len] = '/';
+	  n[len + 1] = '.';
+	  n[len + 2] = '\0';
+	  lookup = n;
+	}
+
+      return child_lookup (lookup, 0, 0, &rcwdir);
+    }
 
 
   /* Do this once.  */
@@ -485,6 +517,10 @@  __spawni (pid_t *pid, const char *file,
 	      dtable_cells[fd] = NULL;
 	      break;
 	    }
+
+	  case spawn_do_chdir:
+	    err = child_chdir (action->action.chdir_action.path);
+	    break;
 	  }
 
 	if (err)