This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v2] Remove signal handling for nanosleep (bug 16364)
- From: Andreas Schwab <schwab at suse dot de>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>
- Cc: libc-alpha at sourceware dot org, Adhemerval Zanella <adhemerval dot zanella at linaro dot com>
- Date: Tue, 10 Nov 2015 14:16:44 +0100
- Subject: Re: [PATCH v2] Remove signal handling for nanosleep (bug 16364)
- Authentication-results: sourceware.org; auth=none
- References: <1447160038-11754-1-git-send-email-adhemerval dot zanella at linaro dot org>
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> +/* Fork and terminate the child in 0.25s while parent waits on a nanosleep
> + for 0.5s. */
> +static int
> +check_nanosleep_base (void)
> +{
> + int ret = 0;
> + pid_t f = fork ();
> + if (f == 0)
> + {
> + // child
> + struct timespec tv = { .tv_sec = 0, .tv_nsec = 250000000UL };
> + nanosleep (&tv, &tv);
> + _exit (EXIT_SUCCESS);
> + }
> + else if (f > 0)
> + {
> + // parent
> + struct timespec tv = { .tv_sec = 0, .tv_nsec = 500000000UL };
> + ret = nanosleep (&tv, &tv);
> + }
> + else if (f == -1)
> + {
> + puts ("error: fork failed");
> + _exit (EXIT_FAILURE);
> + }
> + return ret;
> +}
You should wait for the child before returning.
How do you avoid the race between the parent and the child?
Andreas.
--
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE 1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."