2 /******************************************************************************
3 ******************************************************************************
6 ** RCS: $XConsortium: records.c /main/4 1996/05/28 13:34:16 cde-hp $
10 ** (c) Copyright 1995, Hewlett-Packard Company, all rights reserved.
12 ******************************************************************************
13 *****************************************************************************/
20 /********************************************************************
22 * Routines to BLOCK and UNBLOCK the signal SIGCLD.
24 * Use whenever modifying the array of client tracking
25 * records (critical section). If a SIGCLD happens,
26 * dtpdmd.c:handle_SIGCLD() will be called, and it must
27 * be able to work on a stable set of client tracking
30 static void block_SIGCLD( void )
35 sigemptyset( &newset );
36 sigaddset( &newset, SIGCLD );
37 rtn = sigprocmask( SIG_BLOCK, &newset, (sigset_t *) NULL );
40 static void unblock_SIGCLD( void )
45 sigemptyset( &newset );
46 sigaddset( &newset, SIGCLD );
47 rtn = sigprocmask( SIG_UNBLOCK, &newset, (sigset_t *) NULL );
50 /********************************************************************
52 * Try to find a service record based on ID. Optionally create a
53 * new service record if one is not found.
55 XpPdmServiceRec *find_rec( Window requestor )
62 return( (XpPdmServiceRec *) NULL );
65 * See if the record already exists.
67 for ( i=0; i < g.serviceRecNum; i++ ) {
68 if ( g.serviceRecs[i]->requestor == requestor )
69 return( g.serviceRecs[i] );
73 * Will need to add - see if we need more room in the child
74 * tracking record array.
78 if ( g.serviceRecNum + 1 > g.maxServiceRecNum ) {
79 g.maxServiceRecNum += 5;
80 if ( g.maxServiceRecNum == 5 ) {
82 (XpPdmServiceRec **) Xmalloc( sizeof(XpPdmServiceRec *) *
87 (XpPdmServiceRec **) Xrealloc( (char *) g.serviceRecs,
88 sizeof(XpPdmServiceRec *) *
94 * Create a new child tracking record and add to array.
96 r = (XpPdmServiceRec *) Xmalloc( sizeof(XpPdmServiceRec) );
98 g.serviceRecs[g.serviceRecNum] = r;
100 memset( (void *) r, NULL, sizeof(XpPdmServiceRec) ); /* cheat NULLing */
102 r->mbox_flag = False;
104 r->message_pipe[0] = -1;
105 r->message_pipe[1] = -1;
114 /********************************************************************
116 * Try to find a service record based on previously assigned
119 XpPdmServiceRec *find_rec_by_mbox_win( Window window )
126 return( (XpPdmServiceRec *) NULL );
129 * See if the record already exists.
131 for ( i=0; i < g.serviceRecNum; i++ ) {
132 if ( g.serviceRecs[i]->mbox_window == window )
133 return( g.serviceRecs[i] );
136 return( (XpPdmServiceRec *) NULL );
140 /********************************************************************
142 * Delete the specified service record from global memory.
144 void delete_rec( XpPdmServiceRec *rec )
150 for ( i=0; i< g.serviceRecNum; i++ ) {
151 if ( g.serviceRecs[i] == rec ) {
154 * Delete memory for current rec
156 if (rec->mbox_window)
157 XDestroyWindow( rec->selection_display, rec->mbox_window );
159 unlink( rec->auth_filename );
161 Xfree( g.serviceRecs[i]->video_display_str );
162 Xfree( g.serviceRecs[i]->print_display_str );
163 Xfree( g.serviceRecs[i]->locale_hint );
165 for ( j = 0; g.serviceRecs[i]->pdm_exec_argvs[j]; j++ )
166 Xfree( (char *) g.serviceRecs[i]->pdm_exec_argvs[j] );
167 Xfree( (char *) g.serviceRecs[i]->pdm_exec_argvs );
169 Xfree( g.serviceRecs[i]->pdm_exec_errormessage );
171 Xfree( g.serviceRecs[i]->message_string );
172 Xfree( g.serviceRecs[i]->message_string2 );
174 Xfree( g.serviceRecs[i]->in_buf );
175 for ( j=i; j < g.serviceRecs[i]->cookie_cnt; j++ )
176 Xfree( (char *) g.serviceRecs[i]->cookies[j] );
177 Xfree( (char *) g.serviceRecs[i]->cookies );
179 Xfree( (char *) g.serviceRecs[i] );
182 * Compress list around defunct entry
184 for ( j=i; j < g.serviceRecNum-1; j++ ) {
185 g.serviceRecs[j] = g.serviceRecs[j+1];