[CRIU] [PATCH 5/6] parasite: Don't assign error number on logfd
Kir Kolyshkin
kir at openvz.org
Tue Feb 14 09:37:53 EST 2012
On 02/14/2012 05:42 PM, Cyrill Gorcunov wrote:
> In case if recv_fd failed we must not assign error
> number as logfd, it's bloody wrong. Moreover, never
> close descriptors which were not ever used or point
> to standart descriptors.
>
> Signed-off-by: Cyrill Gorcunov<gorcunov at openvz.org>
> ---
> include/types.h | 1 +
> parasite.c | 19 ++++++++++++++-----
> 2 files changed, 15 insertions(+), 5 deletions(-)
>
> diff --git a/include/types.h b/include/types.h
> index b329630..4ae0c88 100644
> --- a/include/types.h
> +++ b/include/types.h
> @@ -10,6 +10,7 @@
> #define STDIN_FILENO 0
> #define STDOUT_FILENO 1
> #define STDERR_FILENO 2
Not really related to this patch, but these defines are there in unistd.h,
and are used only by log.c which already includes unistd.h.
I suggest removing these three from here. A separate patch sent.
> +#define STDFILENO_MAX 2
>
> /* prctl */
> #define ARCH_SET_GS 0x1001
> diff --git a/parasite.c b/parasite.c
> index edda844..3ec0f22 100644
> --- a/parasite.c
> +++ b/parasite.c
> @@ -27,7 +27,7 @@ static void __parasite_data *brk_tail;
>
> static struct page_entry __parasite_data page;
> static struct vma_entry __parasite_data vma;
> -static int __parasite_data logfd = -1;
> +static int __parasite_data logfd = STDOUT_FILENO;
No problem here too, since parasite.c already includes unistd.h
> static int __parasite_data tsock = -1;
>
> static unsigned char __parasite_data hex[] = "0123456789abcdef";
> @@ -391,14 +391,23 @@ static int init(struct parasite_init_args *args)
>
> static int set_logfd()
> {
> - logfd = recv_fd(tsock);
> - return logfd;
> + int ret;
> +
> + ret = recv_fd(tsock);
> + if (ret>= 0)
> + logfd = ret;
> +
> + return ret;
> }
>
> static int fini()
> {
> - sys_close(logfd);
> - sys_close(tsock);
> + if (logfd> STDFILENO_MAX)
> + sys_close(logfd);
> +
> + if (tsock>= 0)
> + sys_close(tsock);
> +
> return 0;
> }
>
More information about the CRIU
mailing list