diff mbox

[v2] sunrpc: Properly clean up if tst-udp-timeout fails

Message ID 20200212141102.30848-1-msc@linux.ibm.com
State Committed
Delegated to: Tulio Magno Quites Machado Filho
Headers show

Commit Message

Matheus Castanho Feb. 12, 2020, 2:11 p.m. UTC
Nits fixed.

Thanks,
Matheus Castanho

--- 8< ---

The macro TEST_VERIFY_EXIT is used several times on
sunrpc/tst-udp-timeout to exit the test if a condition evaluates to
false. The side effect is that the code to terminate the RPC server
process is not executed when the program calls exit, so that
sub-process stays alive.

This commit registers a clean up function with atexit to kill the
server process before exiting the main program.
---
Changes from v1:
    - Rename pid variable and make it static
    - Fix styling issues

 sunrpc/tst-udp-timeout.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Comments

Florian Weimer Feb. 12, 2020, 2:14 p.m. UTC | #1
* Matheus Castanho:

> Nits fixed.

This version is fine.  Do you need someone to commit it for you?

Thanks,
Florian
Matheus Castanho Feb. 12, 2020, 2:25 p.m. UTC | #2
On 2/12/20 11:14 AM, Florian Weimer wrote:
> * Matheus Castanho:
> 
>> Nits fixed.
> 
> This version is fine.  Do you need someone to commit it for you?

Yes, I do. But Tulio (cc) will do it for me. Thanks!

> 
> Thanks,
> Florian
>
Andreas Schwab Feb. 12, 2020, 2:27 p.m. UTC | #3
On Feb 12 2020, Matheus Castanho wrote:

> @@ -177,6 +180,14 @@ server_dispatch (struct svc_req *request, SVCXPRT *transport)
>      }
>  }
>  
> +/* Function to be called before exit to make sure the
> +   server process is properly killed.  */
> +static void
> +kill_server (void)
> +{
> +  kill(server_pid, SIGTERM);

Style: space before paren.

> @@ -381,16 +392,17 @@ do_test (void)
>    TEST_VERIFY_EXIT (transport != NULL);
>    TEST_VERIFY (svc_register (transport, PROGNUM, VERSNUM, server_dispatch, 0));
>  
> -  pid_t pid = xfork ();
> -  if (pid == 0)
> +  server_pid = xfork ();
> +  if (server_pid == 0)
>      {
>        svc_run ();
>        FAIL_EXIT1 ("supposed to be unreachable");
>      }
> +  atexit(kill_server);

Likewise.

Andreas.
Florian Weimer Feb. 12, 2020, 2:38 p.m. UTC | #4
* Matheus Castanho:

> On 2/12/20 11:14 AM, Florian Weimer wrote:
>> * Matheus Castanho:
>> 
>>> Nits fixed.
>> 
>> This version is fine.  Do you need someone to commit it for you?
>
> Yes, I do. But Tulio (cc) will do it for me. Thanks!

Okay, please also incorporate Andreas' feedback.  No need to post a new
version of the patch.

Thanks,
Florian
Matheus Castanho Feb. 12, 2020, 4:06 p.m. UTC | #5
On 2/12/20 11:38 AM, Florian Weimer wrote:
> * Matheus Castanho:
> 
>> On 2/12/20 11:14 AM, Florian Weimer wrote:
>>> * Matheus Castanho:
>>>
>>>> Nits fixed.
>>>
>>> This version is fine.  Do you need someone to commit it for you?
>>
>> Yes, I do. But Tulio (cc) will do it for me. Thanks!
> 
> Okay, please also incorporate Andreas' feedback.  No need to post a new
> version of the patch.

Ok, no problem.

--
Matheus Castanho
> 
> Thanks,
> Florian
>
Tulio Magno Quites Machado Filho Feb. 12, 2020, 7:28 p.m. UTC | #6
Andreas Schwab <schwab@suse.de> writes:

> On Feb 12 2020, Matheus Castanho wrote:
>
>> @@ -177,6 +180,14 @@ server_dispatch (struct svc_req *request, SVCXPRT *transport)
>>      }
>>  }
>>  
>> +/* Function to be called before exit to make sure the
>> +   server process is properly killed.  */
>> +static void
>> +kill_server (void)
>> +{
>> +  kill(server_pid, SIGTERM);
>
> Style: space before paren.

Fixed.

>> @@ -381,16 +392,17 @@ do_test (void)
>>    TEST_VERIFY_EXIT (transport != NULL);
>>    TEST_VERIFY (svc_register (transport, PROGNUM, VERSNUM, server_dispatch, 0));
>>  
>> -  pid_t pid = xfork ();
>> -  if (pid == 0)
>> +  server_pid = xfork ();
>> +  if (server_pid == 0)
>>      {
>>        svc_run ();
>>        FAIL_EXIT1 ("supposed to be unreachable");
>>      }
>> +  atexit(kill_server);
>
> Likewise.

Fixed.

Pushed as f34c4d0f10ed09500d5f0ebd473c3f37ce4989d7.

Thanks!
diff mbox

Patch

diff --git a/sunrpc/tst-udp-timeout.c b/sunrpc/tst-udp-timeout.c
index 8d45365b23..36752447c0 100644
--- a/sunrpc/tst-udp-timeout.c
+++ b/sunrpc/tst-udp-timeout.c
@@ -29,6 +29,9 @@ 
 #include <sys/socket.h>
 #include <time.h>
 #include <unistd.h>
+#include <stdlib.h>
+
+static pid_t server_pid;
 
 /* Test data serialization and deserialization.   */
 
@@ -177,6 +180,14 @@  server_dispatch (struct svc_req *request, SVCXPRT *transport)
     }
 }
 
+/* Function to be called before exit to make sure the
+   server process is properly killed.  */
+static void
+kill_server (void)
+{
+  kill(server_pid, SIGTERM);
+}
+
 /* Implementation of the test client.  */
 
 static struct test_response
@@ -381,16 +392,17 @@  do_test (void)
   TEST_VERIFY_EXIT (transport != NULL);
   TEST_VERIFY (svc_register (transport, PROGNUM, VERSNUM, server_dispatch, 0));
 
-  pid_t pid = xfork ();
-  if (pid == 0)
+  server_pid = xfork ();
+  if (server_pid == 0)
     {
       svc_run ();
       FAIL_EXIT1 ("supposed to be unreachable");
     }
+  atexit(kill_server);
   test_udp_server (transport->xp_port);
 
   int status;
-  xwaitpid (pid, &status, 0);
+  xwaitpid (server_pid, &status, 0);
   TEST_VERIFY (WIFEXITED (status) && WEXITSTATUS (status) == EXIT_MARKER);
 
   SVC_DESTROY (transport);