File: SIGCHLD_handler.C

package info (click to toggle)
peruser 4b33-6
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,952 kB
  • ctags: 1,064
  • sloc: cpp: 22,367; perl: 2,733; makefile: 345; sh: 335
file content (78 lines) | stat: -rw-r--r-- 1,886 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>

#include <gtk/gtk.h>

#include "npfile.h"
#include "npstringarray.h"
#include "npgroup.h"
#include "npnode.h"
#include "nptree.h"
#include "npcollections.h"

extern NP_Collections *collections_p;

void SIGCHLD_handler( int signo )
{
   pid_t pid;
   while(( pid = waitpid( -1, NULL, WNOHANG )) > 0 )
   {
      int total = collections_p->children.get_total();
      if ( total < 0 )
      {
         collections_p->children.print_error();
         return;
      }

      if ( total )
         for( int i = 0; i < total; ++i )
         {
            char *text = ( char *)collections_p->children[ i ];
            if ( text == NULL )
               continue;
            
            if ( pid == atoi( text ))
            {
               int result;
               while(( result = collections_p->children.remove_item( i ))
                     == 3 );
               if ( result )
                  collections_p->children.print_error();

               break;
            }
         }

      if ( pid == collections_p->launcher_pid )
         collections_p->launcher_pid = 0;

      if ( pid == collections_p->child_pid )
         collections_p->child_pid = 0;

      if ( pid == collections_p->compose_pid )
         collections_p->compose_pid = 0;
      
      if ( pid == collections_p->summary_pid )
      {
         collections_p->summary_pid = 0;
         if ( collections_p->summary_file != NULL )
         {
            fclose( collections_p->summary_file );
            collections_p->summary_file = NULL;
         }
         
         if ( collections_p->feedback_file != NULL )
         {
            fclose( collections_p->feedback_file );
            collections_p->feedback_file = NULL;
         }
      }
   }

   signal( SIGCHLD, SIGCHLD_handler );

   return;
}