diff mbox

[PATCHv2] linux-generic: test: shmem: atomic check+open fifo

Message ID 1459324484-1100-1-git-send-email-christophe.milard@linaro.org
State Superseded
Headers show

Commit Message

Christophe Milard March 30, 2016, 7:54 a.m. UTC
Fix for bug 2146, CID 159395:
The open system call is directely used to check the presence of the fifo
and open it at the same time.

Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
---
 since v1: changed loop to avoid open() line duplication (Maxim)

 platform/linux-generic/test/shmem/shmem_linux.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Maxim Uvarov April 1, 2016, 3:32 p.m. UTC | #1
On 03/30/16 10:54, Christophe Milard wrote:
> Fix for bug 2146, CID 159395:
> The open system call is directely used to check the presence of the fifo
> and open it at the same time.
>
> Signed-off-by: Christophe Milard <christophe.milard@linaro.org>
> ---
>   since v1: changed loop to avoid open() line duplication (Maxim)
>
>   platform/linux-generic/test/shmem/shmem_linux.c | 8 +++++---
>   1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/platform/linux-generic/test/shmem/shmem_linux.c b/platform/linux-generic/test/shmem/shmem_linux.c
> index 12266cc..0f15c9e 100644
> --- a/platform/linux-generic/test/shmem/shmem_linux.c
> +++ b/platform/linux-generic/test/shmem/shmem_linux.c
> @@ -115,12 +115,14 @@ int main(int argc __attribute__((unused)), char *argv[])
>   	 * Just die if time expire as there is no fifo to communicate
>   	 * through... */
>   	sprintf(fifo_name, FIFO_NAME_FMT, odp_app);
> -	while (access(fifo_name, W_OK) != 0) {
> +	for (;;) {
> +		fifo_fd = open(fifo_name, O_WRONLY);
> +		if (fifo_fd >= 0)
> +			break;
>   		sleep(1);
> -		if  (nb_sec++ == 30)
> +		if (nb_sec++ == 30)
>   			exit(1);
>   	}

that is very strange using on nb_sec. You use it only in that loop. Set 
up to zero at the variable declaration.
Have for loop without increment and increment it down in the loop. 
Please move setting to 0 and increment
inside for.

Maxim.


> -	fifo_fd = open(fifo_name, O_WRONLY);
>   	printf("pipe found\n");
>   
>   	/* the linux named pipe has now been found, meaning that the
diff mbox

Patch

diff --git a/platform/linux-generic/test/shmem/shmem_linux.c b/platform/linux-generic/test/shmem/shmem_linux.c
index 12266cc..0f15c9e 100644
--- a/platform/linux-generic/test/shmem/shmem_linux.c
+++ b/platform/linux-generic/test/shmem/shmem_linux.c
@@ -115,12 +115,14 @@  int main(int argc __attribute__((unused)), char *argv[])
 	 * Just die if time expire as there is no fifo to communicate
 	 * through... */
 	sprintf(fifo_name, FIFO_NAME_FMT, odp_app);
-	while (access(fifo_name, W_OK) != 0) {
+	for (;;) {
+		fifo_fd = open(fifo_name, O_WRONLY);
+		if (fifo_fd >= 0)
+			break;
 		sleep(1);
-		if  (nb_sec++ == 30)
+		if (nb_sec++ == 30)
 			exit(1);
 	}
-	fifo_fd = open(fifo_name, O_WRONLY);
 	printf("pipe found\n");
 
 	/* the linux named pipe has now been found, meaning that the