2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
24 /******************************************************************************
25 ******************************************************************************
28 ** RCS: $XConsortium: records.c /main/4 1996/05/28 13:34:16 cde-hp $
32 ** (c) Copyright 1995, Hewlett-Packard Company, all rights reserved.
34 ******************************************************************************
35 *****************************************************************************/
42 /********************************************************************
44 * Routines to BLOCK and UNBLOCK the signal SIGCLD.
46 * Use whenever modifying the array of client tracking
47 * records (critical section). If a SIGCLD happens,
48 * dtpdmd.c:handle_SIGCLD() will be called, and it must
49 * be able to work on a stable set of client tracking
52 static void block_SIGCLD( void )
57 sigemptyset( &newset );
58 sigaddset( &newset, SIGCHLD );
59 rtn = sigprocmask( SIG_BLOCK, &newset, (sigset_t *) NULL );
62 static void unblock_SIGCLD( void )
67 sigemptyset( &newset );
68 sigaddset( &newset, SIGCHLD );
69 rtn = sigprocmask( SIG_UNBLOCK, &newset, (sigset_t *) NULL );
72 /********************************************************************
74 * Try to find a service record based on ID. Optionally create a
75 * new service record if one is not found.
77 XpPdmServiceRec *find_rec( Window requestor )
84 return( (XpPdmServiceRec *) NULL );
87 * See if the record already exists.
89 for ( i=0; i < g.serviceRecNum; i++ ) {
90 if ( g.serviceRecs[i]->requestor == requestor )
91 return( g.serviceRecs[i] );
95 * Will need to add - see if we need more room in the child
96 * tracking record array.
100 if ( g.serviceRecNum + 1 > g.maxServiceRecNum ) {
101 g.maxServiceRecNum += 5;
102 if ( g.maxServiceRecNum == 5 ) {
104 (XpPdmServiceRec **) Xmalloc( sizeof(XpPdmServiceRec *) *
105 g.maxServiceRecNum );
109 (XpPdmServiceRec **) Xrealloc( (char *) g.serviceRecs,
110 sizeof(XpPdmServiceRec *) *
111 g.maxServiceRecNum );
116 * Create a new child tracking record and add to array.
118 r = (XpPdmServiceRec *) Xmalloc( sizeof(XpPdmServiceRec) );
120 g.serviceRecs[g.serviceRecNum] = r;
122 memset( (void *) r, 0, sizeof(XpPdmServiceRec) ); /* cheat NULLing */
124 r->mbox_flag = False;
126 r->message_pipe[0] = -1;
127 r->message_pipe[1] = -1;
136 /********************************************************************
138 * Try to find a service record based on previously assigned
141 XpPdmServiceRec *find_rec_by_mbox_win( Window window )
148 return( (XpPdmServiceRec *) NULL );
151 * See if the record already exists.
153 for ( i=0; i < g.serviceRecNum; i++ ) {
154 if ( g.serviceRecs[i]->mbox_window == window )
155 return( g.serviceRecs[i] );
158 return( (XpPdmServiceRec *) NULL );
162 /********************************************************************
164 * Delete the specified service record from global memory.
166 void delete_rec( XpPdmServiceRec *rec )
172 for ( i=0; i< g.serviceRecNum; i++ ) {
173 if ( g.serviceRecs[i] == rec ) {
176 * Delete memory for current rec
178 if (rec->mbox_window)
179 XDestroyWindow( rec->selection_display, rec->mbox_window );
181 unlink( rec->auth_filename );
183 Xfree( g.serviceRecs[i]->video_display_str );
184 Xfree( g.serviceRecs[i]->print_display_str );
185 Xfree( g.serviceRecs[i]->locale_hint );
187 for ( j = 0; g.serviceRecs[i]->pdm_exec_argvs[j]; j++ )
188 Xfree( (char *) g.serviceRecs[i]->pdm_exec_argvs[j] );
189 Xfree( (char *) g.serviceRecs[i]->pdm_exec_argvs );
191 Xfree( g.serviceRecs[i]->pdm_exec_errormessage );
193 Xfree( g.serviceRecs[i]->message_string );
194 Xfree( g.serviceRecs[i]->message_string2 );
196 Xfree( g.serviceRecs[i]->in_buf );
197 for ( j=i; j < g.serviceRecs[i]->cookie_cnt; j++ )
198 Xfree( (char *) g.serviceRecs[i]->cookies[j] );
199 Xfree( (char *) g.serviceRecs[i]->cookies );
201 Xfree( (char *) g.serviceRecs[i] );
204 * Compress list around defunct entry
206 for ( j=i; j < g.serviceRecNum-1; j++ ) {
207 g.serviceRecs[j] = g.serviceRecs[j+1];