gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-anastasis] branch master updated: fix child management test


From: gnunet
Subject: [taler-anastasis] branch master updated: fix child management test
Date: Fri, 05 Feb 2021 00:45:20 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository anastasis.

The following commit(s) were added to refs/heads/master by this push:
     new 370c05c  fix child management test
370c05c is described below

commit 370c05ca284d150a23765445221c8cf4f36a94c9
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Feb 5 00:45:16 2021 +0100

    fix child management test
---
 src/util/child_management.c                |  6 +-
 src/util/test_anastasis_child_management.c | 89 +++++++++++++++++-------------
 2 files changed, 53 insertions(+), 42 deletions(-)

diff --git a/src/util/child_management.c b/src/util/child_management.c
index bdff2e4..156daf8 100644
--- a/src/util/child_management.c
+++ b/src/util/child_management.c
@@ -77,6 +77,7 @@ maint_child_death (void *cls)
 {
   char buf[16];
   const struct GNUNET_DISK_FileHandle *pr;
+  struct ANASTASIS_ChildWaitHandle *nxt;
 
   (void) cls;
   sig_task = NULL;
@@ -92,13 +93,12 @@ maint_child_death (void *cls)
   /* find applicable processes that exited */
   for (struct ANASTASIS_ChildWaitHandle *cwh = cwh_head;
        NULL != cwh;
-       cwh = cwh->next)
+       cwh = nxt)
   {
     enum GNUNET_OS_ProcessStatusType type;
     long unsigned int exit_code = 0;
 
-    struct ANASTASIS_ChildWaitHandle *next = cwh->next;
-
+    nxt = cwh->next;
     if (GNUNET_OK ==
         GNUNET_OS_process_status (cwh->proc,
                                   &type,
diff --git a/src/util/test_anastasis_child_management.c 
b/src/util/test_anastasis_child_management.c
index 48edb55..d4f421e 100644
--- a/src/util/test_anastasis_child_management.c
+++ b/src/util/test_anastasis_child_management.c
@@ -32,7 +32,7 @@ static struct ANASTASIS_ChildWaitHandle *cwh;
 
 static int global_ret;
 
-static pid_t pid;
+static struct GNUNET_OS_Process *pid;
 
 
 static void
@@ -45,11 +45,10 @@ child_completed_callback (void *cls,
               "Process extided with code: %lu \n",
               exit_code);
   FILE *file;
-  char *code;
-  code = malloc (sizeof(char) * 9);
-  file = fopen ("child_management_test.txt", "r");
+  char code[9];
 
-  if (file == NULL)
+  file = fopen ("child_management_test.txt", "r");
+  if (NULL == file)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "could not find file: child_management_test.txt in %s:%u\n",
@@ -58,7 +57,9 @@ child_completed_callback (void *cls,
     global_ret = 1;
     return;
   }
-  if (0 == fscanf (file, "%s", code))
+  if (0 == fscanf (file,
+                   "%8s",
+                   code))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "could not read file: child_management_test.txt in %s:%u\n",
@@ -68,15 +69,15 @@ child_completed_callback (void *cls,
     return;
   }
 
-  if (strcmp ("12345678", code) != 0)
+  if (0 != strcmp ("12345678", code))
   {
     global_ret = 1;
     return;
   }
-  pid = -1;
+  GNUNET_OS_process_destroy (pid);
+  pid = NULL;
   GNUNET_SCHEDULER_shutdown ();
   global_ret = 0;
-  return;
 }
 
 
@@ -88,10 +89,15 @@ do_shutdown (void *cls)
     ANASTASIS_wait_child_cancel (cwh);
     cwh = NULL;
   }
-  if (-1 != pid)
+  if (NULL != pid)
   {
-    kill (pid, 9);
-    pid = -1;
+    GNUNET_assert (0 ==
+                   GNUNET_OS_process_kill (pid,
+                                           SIGKILL));
+    GNUNET_assert (GNUNET_OK ==
+                   GNUNET_OS_process_wait (pid));
+    GNUNET_OS_process_destroy (pid);
+    pid = NULL;
   }
 }
 
@@ -100,53 +106,58 @@ static void
 test_child_management (void *cls)
 {
   const char *command = "./child_management_test.sh";
-  int p[2];
-  int ret = pipe (p);
+  struct GNUNET_DISK_PipeHandle *p;
+  struct GNUNET_DISK_FileHandle *out;
 
   (void) cls;
-  if (0 != ret)
+  p = GNUNET_DISK_pipe (GNUNET_DISK_PF_NONE);
+  if (NULL == p)
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
                          "pipe");
     global_ret = 2;
     return;
   }
-  pid = fork ();
-  if (-1 == pid)
+  pid = GNUNET_OS_start_process (0,
+                                 p,
+                                 NULL,
+                                 NULL,
+                                 command,
+                                 command,
+                                 "1234",
+                                 "5678",
+                                 NULL);
+  if (NULL == pid)
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR,
                          "fork");
-    GNUNET_break (0 == close (p[0]));
-    GNUNET_break (0 == close (p[1]));
+    GNUNET_break (GNUNET_OK ==
+                  GNUNET_DISK_pipe_close (p));
     global_ret = 1;
     return;
   }
-  if (0 == pid)
-  {
-    GNUNET_break (0 == close (STDIN_FILENO));
-    GNUNET_break (-1 != dup2 (p[0], STDIN_FILENO));
-    GNUNET_break (0 == close (p[1]));
-    GNUNET_break (0 == close (p[0]));
-    execlp (command,
-            command,
-            "1234",
-            "5678",
-            NULL);
-    GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
-                              "execlp",
-                              command);
-    exit (-1);
-  }
-  GNUNET_break (0 == close (p[0]));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_pipe_close_end (p,
+                                            GNUNET_DISK_PIPE_END_READ));
+  out = GNUNET_DISK_pipe_detach_end (p,
+                                     GNUNET_DISK_PIPE_END_WRITE);
+  GNUNET_assert (NULL != out);
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_pipe_close (p));
+
   GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
                                  NULL);
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Alright");
-  cwh = ANASTASIS_wait_child (&pid,
+  cwh = ANASTASIS_wait_child (pid,
                               &child_completed_callback,
                               cls);
   GNUNET_break (NULL != cwh);
-  GNUNET_assert (5 == write (p[1], "Hello", 5));
-  GNUNET_break (0 == close (p[1]));
+  GNUNET_assert (5 ==
+                 GNUNET_DISK_file_write (out,
+                                         "Hello",
+                                         5));
+  GNUNET_break (GNUNET_OK ==
+                GNUNET_DISK_file_close (out));
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]