[CRIU] [PATCH 2/3] sfd: Make sure we're not overwriting existing files
Cyrill Gorcunov
gorcunov at gmail.com
Mon Apr 1 18:52:56 MSK 2019
On Mon, Apr 01, 2019 at 03:35:43PM +0000, Pavel Emelianov wrote:
...
> >
> > +#define sfd_verify_targtet(_type, _old_fd, _new_fd) \
> > + do { \
> > + char self_path[64]; \
> > + \
> > + snprintf(self_path, sizeof(self_path), "/proc/self/fd/%d", _new_fd); \
> > + if (access(self_path, F_OK)) { \
>
> Calling fcntl(fd, F_GETFL) is much faster to check whether the fd in question is busy or not.
> We even have(d) a reopen_fd_safe() for it.
fcntl is faster but a way less flexible. i thought of using it at first place
but though desided to switch to 'access' helper so that we might need to use
this macro for testing other pid's fds, not just for self. but I tend
to agree that this looks like overkill. Will switch back to fcntl later.
More information about the CRIU
mailing list