[CRIU] [PATCH 2/2] service_fd: Close argument fd in install_service_fd()
Kirill Tkhai
ktkhai at virtuozzo.com
Wed Mar 22 05:06:37 PDT 2017
On 22.03.2017 14:48, Dmitry Safonov wrote:
> 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()?
I decided do not take out (sfd != fd) comparison in any case, which looks
ugly for me. So, the patch is so.
>> +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);
>>
>
>
More information about the CRIU
mailing list