[CRIU] [PATCH 2/2] service_fd: Close argument fd in install_service_fd()

Dmitry Safonov 0x7f454c46 at gmail.com
Wed Mar 22 04:48:07 PDT 2017


2017-03-22 14:06 GMT+03:00 Kirill Tkhai <ktkhai at virtuozzo.com>:
> We use this function in many places in the way
>
>     sfd = install_service_fd(XXX_OFF, fd);
>     close(fd);
>
> But, in common case, it may happen, that fd is equal to sfd,
> and we close sfd. So, lets be independent of such situations
> and make install_service_fd() close argument fd by itself.
>
> https://travis-ci.org/tkhai/criu/builds/213782750
>
> Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
> ---

Can't we also close fd on error path here, to skip it in callee?
Or there is a place, where we'll need it to be opened in case of
install_service_fd() failure? Should maybe use at that place
do_install_service_fd()?

> +int install_service_fd(enum sfd_type type, int fd)
> +{
> +       int sfd;
> +
> +       sfd = do_install_service_fd(type, fd);
> +       if (sfd < 0)
                close(fd);
> +               return sfd;
> +       if (sfd != fd)
> +               close(fd);
> +       return sfd;
> +}
> +
>  int get_service_fd(enum sfd_type type)
>  {
>         BUG_ON((int)type <= SERVICE_FD_MIN || (int)type >= SERVICE_FD_MAX);
>


-- 
             Dmitry


More information about the CRIU mailing list