LCOV - code coverage report
Current view: top level - tests - t-fork.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 13 15 86.7 %
Date: 2016-12-01 18:29:05 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* t-fork.c
       2             :  * Copyright 2016 g10 Code GmbH
       3             :  *
       4             :  * This file is free software; as a special exception the author gives
       5             :  * unlimited permission to copy and/or distribute it, with or without
       6             :  * modifications, as long as this notice is preserved.
       7             :  *
       8             :  * This file is distributed in the hope that it will be useful, but
       9             :  * WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
      10             :  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
      11             :  */
      12             : 
      13             : #include <sys/types.h>
      14             : #include <sys/wait.h>
      15             : #include <unistd.h>
      16             : #include "t-support.h"
      17             : 
      18             : /* This is a test if nPth can allow daemon-like applications
      19             :    initializing earlier.
      20             : 
      21             :    For daemon-like applications, ideally, it is expected to call
      22             :    npth_init after fork.  This condition is not satisfied sometimes.
      23             : 
      24             :    Failure of this test means nPth implementation doesn't allow
      25             :    npth_init after fork.  In such a case, application should be
      26             :    modified.
      27             :  */
      28             : 
      29             : int
      30           1 : main (int argc, const char *argv[])
      31             : {
      32             :   int rc;
      33             :   pid_t pid;
      34             : 
      35           1 :   if (argc >= 2 && !strcmp (argv[1], "--verbose"))
      36           0 :     opt_verbose = 1;
      37             : 
      38           1 :   rc = npth_init ();
      39           1 :   fail_if_err (rc);
      40             : 
      41           1 :   pid = fork ();
      42           2 :   if (pid == (pid_t)-1)
      43           0 :     fail_msg ("fork failed");
      44           2 :   else if (pid)
      45             :    {
      46             :      int status;
      47             : 
      48           1 :      info_msg ("forked");
      49           1 :      wait (&status);
      50           1 :      fail_if_err (status);
      51             :    }
      52             :   else
      53             :     {
      54           1 :       info_msg ("child exit");
      55           1 :       npth_usleep (1000);     /* Let NPTH enter, sleep, and leave.  */
      56             :     }
      57             : 
      58           2 :   return 0;
      59             : }

Generated by: LCOV version 1.11