[Libguestfs] [PATCH 2/2] daemon: Change chdir to use openat/fdopendir.
Jim Meyering
jim at meyering.net
Mon Oct 26 14:07:17 UTC 2009
Richard W.M. Jones wrote:
> Subject: [PATCH 2/2] daemon: Change chdir to use openat/fdopendir.
To make this work on older Linux kernels and on systems
without openat, you can use gnulib's openat module.
...
> +#ifndef _ATFILE_SOURCE
> +#define _ATFILE_SOURCE
> +#endif
In which case, you won't need to do the above.
...
> + int fd;
I like to call this sort of variable "fd_cwd"
or something similar, so that it's easier to see
that it's more than a "normal" open-on-some-file fd.
Other than that, it looks fine.
> - /* MUST chdir ("/") before leaving this function. */
> - if (chdir (sysroot) == -1) {
> + /* 'fd' here is a surrogate for the current working directory, so
> + * that we don't have to actually call chdir(2).
> + */
> + fd = open (sysroot, O_RDONLY | O_DIRECTORY);
...
More information about the Libguestfs
mailing list