diff mbox

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

Message ID 1459945907-22090-1-git-send-email-christophe.milard@linaro.org
State Accepted
Commit 55887ead48fa8396098e51b6275d984b8d8b52d0
Headers show

Commit Message

Christophe Milard April 6, 2016, 12:31 p.m. UTC
Fixes: https://bugs.linaro.org/show_bug.cgi?id=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>
---
 platform/linux-generic/test/shmem/shmem_linux.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

Comments

Bill Fischofer April 6, 2016, 6:42 p.m. UTC | #1
On Wed, Apr 6, 2016 at 7:31 AM, Christophe Milard <
christophe.milard@linaro.org> wrote:

> Fixes: https://bugs.linaro.org/show_bug.cgi?id=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>

>


Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>



> ---

>  platform/linux-generic/test/shmem/shmem_linux.c | 15 +++++++++------

>  1 file changed, 9 insertions(+), 6 deletions(-)

>

> diff --git a/platform/linux-generic/test/shmem/shmem_linux.c

> b/platform/linux-generic/test/shmem/shmem_linux.c

> index 12266cc..f9399ab 100644

> --- a/platform/linux-generic/test/shmem/shmem_linux.c

> +++ b/platform/linux-generic/test/shmem/shmem_linux.c

> @@ -50,6 +50,7 @@

>

>  #define ODP_APP_NAME "shmem_odp" /* name of the odp program, in this dir

> */

>  #define DEVNAME_FMT "odp-%d-%s"  /* shm device format: odp-<pid>-<name>

> */

> +#define MAX_FIFO_WAIT 30         /* Max time waiting for the fifo (sec)

> */

>

>  void test_success(char *fifo_name, int fd, pid_t odp_app)

>  {

> @@ -89,12 +90,12 @@ int main(int argc __attribute__((unused)), char

> *argv[])

>  {

>         char prg_name[PATH_MAX];

>         char odp_name[PATH_MAX];

> -       int nb_sec = 0;

> +       int nb_sec;

>         int size;

>         pid_t odp_app;

>         char *odp_params = NULL;

>         char fifo_name[PATH_MAX];  /* fifo for linux->odp feedback */

> -       int fifo_fd;

> +       int fifo_fd = -1;

>         char shm_devname[PATH_MAX];/* shared mem device name, under

> /dev/shm */

>         int shm_fd;

>         test_shared_linux_data_t *addr;

> @@ -115,12 +116,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 (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {

> +               fifo_fd = open(fifo_name, O_WRONLY);

> +               if (fifo_fd >= 0)

> +                       break;

>                 sleep(1);

> -               if  (nb_sec++ == 30)

> -                       exit(1);

>         }

> -       fifo_fd = open(fifo_name, O_WRONLY);

> +       if (fifo_fd < 0)

> +               exit(1);

>         printf("pipe found\n");

>

>         /* the linux named pipe has now been found, meaning that the

> --

> 2.1.4

>

> _______________________________________________

> lng-odp mailing list

> lng-odp@lists.linaro.org

> https://lists.linaro.org/mailman/listinfo/lng-odp

>
Maxim Uvarov April 7, 2016, 10:08 a.m. UTC | #2
Merged,
Maxim.

On 04/06/16 21:42, Bill Fischofer wrote:
>
>
> On Wed, Apr 6, 2016 at 7:31 AM, Christophe Milard 
> <christophe.milard@linaro.org <mailto:christophe.milard@linaro.org>> 
> wrote:
>
>     Fixes: https://bugs.linaro.org/show_bug.cgi?id=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
>     <mailto:christophe.milard@linaro.org>>
>
>
> Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org 
> <mailto:bill.fischofer@linaro.org>>
>
>     ---
>      platform/linux-generic/test/shmem/shmem_linux.c | 15 +++++++++------
>      1 file changed, 9 insertions(+), 6 deletions(-)
>
>     diff --git a/platform/linux-generic/test/shmem/shmem_linux.c
>     b/platform/linux-generic/test/shmem/shmem_linux.c
>     index 12266cc..f9399ab 100644
>     --- a/platform/linux-generic/test/shmem/shmem_linux.c
>     +++ b/platform/linux-generic/test/shmem/shmem_linux.c
>     @@ -50,6 +50,7 @@
>
>      #define ODP_APP_NAME "shmem_odp" /* name of the odp program, in
>     this dir */
>      #define DEVNAME_FMT "odp-%d-%s"  /* shm device format:
>     odp-<pid>-<name>  */
>     +#define MAX_FIFO_WAIT 30         /* Max time waiting for the fifo
>     (sec)  */
>
>      void test_success(char *fifo_name, int fd, pid_t odp_app)
>      {
>     @@ -89,12 +90,12 @@ int main(int argc __attribute__((unused)),
>     char *argv[])
>      {
>             char prg_name[PATH_MAX];
>             char odp_name[PATH_MAX];
>     -       int nb_sec = 0;
>     +       int nb_sec;
>             int size;
>             pid_t odp_app;
>             char *odp_params = NULL;
>             char fifo_name[PATH_MAX];  /* fifo for linux->odp feedback */
>     -       int fifo_fd;
>     +       int fifo_fd = -1;
>             char shm_devname[PATH_MAX];/* shared mem device name,
>     under /dev/shm */
>             int shm_fd;
>             test_shared_linux_data_t *addr;
>     @@ -115,12 +116,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 (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {
>     +               fifo_fd = open(fifo_name, O_WRONLY);
>     +               if (fifo_fd >= 0)
>     +                       break;
>                     sleep(1);
>     -               if  (nb_sec++ == 30)
>     -                       exit(1);
>             }
>     -       fifo_fd = open(fifo_name, O_WRONLY);
>     +       if (fifo_fd < 0)
>     +               exit(1);
>             printf("pipe found\n");
>
>             /* the linux named pipe has now been found, meaning that the
>     --
>     2.1.4
>
>     _______________________________________________
>     lng-odp mailing list
>     lng-odp@lists.linaro.org <mailto:lng-odp@lists.linaro.org>
>     https://lists.linaro.org/mailman/listinfo/lng-odp
>
>
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..f9399ab 100644
--- a/platform/linux-generic/test/shmem/shmem_linux.c
+++ b/platform/linux-generic/test/shmem/shmem_linux.c
@@ -50,6 +50,7 @@ 
 
 #define ODP_APP_NAME "shmem_odp" /* name of the odp program, in this dir */
 #define DEVNAME_FMT "odp-%d-%s"  /* shm device format: odp-<pid>-<name>  */
+#define MAX_FIFO_WAIT 30         /* Max time waiting for the fifo (sec)  */
 
 void test_success(char *fifo_name, int fd, pid_t odp_app)
 {
@@ -89,12 +90,12 @@  int main(int argc __attribute__((unused)), char *argv[])
 {
 	char prg_name[PATH_MAX];
 	char odp_name[PATH_MAX];
-	int nb_sec = 0;
+	int nb_sec;
 	int size;
 	pid_t odp_app;
 	char *odp_params = NULL;
 	char fifo_name[PATH_MAX];  /* fifo for linux->odp feedback */
-	int fifo_fd;
+	int fifo_fd = -1;
 	char shm_devname[PATH_MAX];/* shared mem device name, under /dev/shm */
 	int shm_fd;
 	test_shared_linux_data_t *addr;
@@ -115,12 +116,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 (nb_sec = 0; nb_sec < MAX_FIFO_WAIT; nb_sec++) {
+		fifo_fd = open(fifo_name, O_WRONLY);
+		if (fifo_fd >= 0)
+			break;
 		sleep(1);
-		if  (nb_sec++ == 30)
-			exit(1);
 	}
-	fifo_fd = open(fifo_name, O_WRONLY);
+	if (fifo_fd < 0)
+		exit(1);
 	printf("pipe found\n");
 
 	/* the linux named pipe has now been found, meaning that the