[PATCH 13/23] linux: Add fchroot

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Thu Nov 5 14:02:52 GMT 2026



On 05/11/26 09:26, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> diff --git a/sysdeps/unix/sysv/linux/bits/unistd_ext.h b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> index a541b378d03..6597435ace7 100644
>> --- a/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> +++ b/sysdeps/unix/sysv/linux/bits/unistd_ext.h
>> @@ -47,4 +47,10 @@ extern __pid_t gettid (void) __THROW;
>>  # define CLOSE_RANGE_CLOEXEC (1U << 2)
>>  #endif
>>  
>> +/* Change the root directory of the calling process to the directory
>> +   referred to by the file descriptor FD.  FD can also be FD_FAILFS_ROOT,
>> +   in which case all subsequent absolute file name lookups fail.  FLAGS
>> +   must be zero.  */
>> +extern int fchroot (int __fd, unsigned int __flags) __THROW;
>> +
>>  #endif /* __USE_GNU  */
> 
> CRIU defines _GNU_SOURCE, and it has:
> 
> criu/files.c:#include <unistd.h>
> 
> criu/files.c:static int fchroot(int fd)
> criu/files.c-{
> criu/files.c-   /*
> criu/files.c-    * There's no such thing in syscalls. We can emulate
> criu/files.c-    * it using fchdir()
> criu/files.c-    */
> criu/files.c-
> criu/files.c-   if (fchdir(fd) < 0) {
> criu/files.c-           pr_perror("Can't chdir to proc");
> criu/files.c-           return -1;
> criu/files.c-   }
> criu/files.c-
> criu/files.c-   pr_debug("Going to chroot into /proc/self/fd/%d\n", fd);
> criu/files.c-   return chroot(".");
> criu/files.c-}
> 
> So it breaks the build.  I think that's true for

I think you ended the sentence here.

> 
> I wonder if we should start defining macros like
> 
> #define _LIBC_HAS_FUNCTION_fchroot
> 
> in some header file as part of a general push for more system call
> wrappers.

Please no, this adds another set of defines we will need to keep tracking
of.

For the CRIU, it would require to add a configure check. I don't think it
should be a blocked for this wrapper.

> Thanks,
> Florian



More information about the Libc-alpha mailing list