1 /* $TOG: SmConMgmt.c /main/6 1998/04/06 14:35:42 mgreess $ */
3 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
4 * (c) Copyright 1993, 1994 International Business Machines Corp. *
5 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
6 * (c) Copyright 1993, 1994 Novell, Inc. *
9 /*************************************<+>*************************************
10 *****************************************************************************
14 ** Project: HP DT Session Manager (dtsession)
18 ** Contains all code which performs contention management functionality
21 *******************************************************************
22 ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
23 ** reserved. Copying or other reproduction of this program
24 ** except for archival purposes is prohibited without prior
25 ** written consent of Hewlett-Packard Company.
26 ********************************************************************
30 *****************************************************************************
31 *************************************<+>*************************************/
39 #include <X11/Intrinsic.h>
41 #include "SmProtocol.h"
42 #include "SmConMgmt.h"
50 #include <sys/fixpoint.h>
54 #define KMEM_FILE "/dev/kmem"
59 # define KERNEL_FILE "/vmunix"
61 # define KERNEL_FILE "/hp-ux"
66 #define GPGSLIM "gpgslim"
67 #define FREEMEM "freemem"
71 # define GPGSLIM "gpgslim"
72 # define FREEMEM "freemem"
73 # endif /* __hp9000s800 */
78 #define GPGSLIM "_gpgslim"
79 #endif /* not defined GPGSLIM */
82 #define FREEMEM "_freemem"
83 #endif /* not defined FREEMEM */
88 * Variables global to this module only
91 static struct nlist namelist[3];
93 static int freemem_loc, gpgslim_loc, gpgslim, freemem;
94 static int clientTimeout;
97 * Functions local to this module
100 static void HandleClientMessage(Widget smWidget, XtPointer dummy,
102 static void WaitClientTimeout(XtPointer, XtIntervalId *);
106 /*************************************<->*************************************
108 * GetMemoryUtilization ()
113 * Returns 1 of 3 values. Tells the calling program that memory is not
114 * available, that it is full (paging has started), or that it is not
124 * An integer value representing the current memory utilization of the
130 * WARNING: This routine, by its very nature is non-portable. It depends
131 * on an OS having some kind of access to its memory utilization.
133 * DOUBLE WARNING: The mips architecture code has never been tested.
136 *************************************<->***********************************/
139 GetMemoryUtilization(void)
144 #if !defined(SVR4) && !defined(sco) && !defined(hpV4) && !defined(_POWER) && !defined (__osf__)
151 setresgid(-1, smGD.conMgmtGID, -1);
154 setregid(smGD.runningGID, smGD.conMgmtGID);
156 setgid(smGD.runningGID);
157 setegid(smGD.conMgmtGID);
163 namelist[0].n_name = FREEMEM;
164 namelist[1].n_name = GPGSLIM;
165 namelist[2].n_name = (char *) NULL;
166 nlist( KERNEL_FILE, namelist);
167 for(i = 0; i < 2; i++)
169 if (namelist[i].n_type == 0 ||
170 namelist[i].n_value == 0)
173 setresgid(-1, smGD.runningGID, -1);
176 setregid(smGD.conMgmtGID, smGD.runningGID);
178 setgid(smGD.conMgmtGID);
179 setegid(smGD.runningGID);
182 return(MEM_NOT_AVAILABLE);
186 freemem_loc = namelist[0].n_value;
187 gpgslim_loc = namelist[1].n_value;
189 kmem = open(KMEM_FILE, O_RDONLY);
193 setresgid(-1, smGD.runningGID, -1);
196 setregid(smGD.conMgmtGID, smGD.runningGID);
198 setgid(smGD.conMgmtGID);
199 setegid(smGD.runningGID);
202 return(MEM_NOT_AVAILABLE);
204 (void) lseek(kmem, gpgslim_loc, 0);
208 (void) read(kmem, (char *)&temp, sizeof(fix));
209 gpgslim = FIX_TO_DBL(temp);
212 (void) read(kmem, (char *)&gpgslim, sizeof(int));
217 (void) lseek(kmem, freemem_loc, 0);
221 (void) read(kmem, (char *)&temp, sizeof(fix));
222 freemem = FIX_TO_DBL(temp);
225 (void) read(kmem, (char *)&freemem, sizeof(int));
229 setresgid(-1, smGD.runningGID, -1);
232 setregid(smGD.conMgmtGID, smGD.runningGID);
234 setgid(smGD.conMgmtGID);
235 setegid(smGD.runningGID);
239 if(freemem >= gpgslim)
241 return(MEM_NOT_FULL);
248 return(MEM_NOT_FULL);
254 /*************************************<->*************************************
256 * WaitForClientMap ()
261 * This routine waits for the workspace manager to send it information
262 * about a client being mapped, before returning to start the next client
275 *************************************<->***********************************/
277 WaitForClientMap( void )
281 XClientMessageEvent *cEvent = (XClientMessageEvent *) &event;
282 XtIntervalId clientTimerId;
284 XtAddEventHandler(smGD.topLevelWid,
287 (XtEventHandler)HandleClientMessage,
291 * Set a timer which stops the block on waiting for the
292 * client to start. This value is fetched from the
293 * waitClientTimeout resource.
295 clientRunning = False;
296 clientTimeout = False;
297 clientTimerId = XtAppAddTimeOut(smGD.appCon,
298 smRes.waitClientTimeout,
299 WaitClientTimeout, NULL);
301 while((clientRunning == False) && (clientTimeout == False))
303 XtAppProcessEvent(smGD.appCon, XtIMAll);
306 XtRemoveTimeOut(clientTimerId);
307 XtRemoveEventHandler(smGD.topLevelWid,
310 (XtEventHandler)HandleClientMessage,
316 /*************************************<->*************************************
323 * Timeout procedure the WaitForClientMap routine. It stops a loop waiting
324 * for the last started app to get mapped.
333 * clientTimeout = (global) flag that stops the loop
338 *************************************<->***********************************/
341 XtPointer client_data,
344 clientTimeout = True;
349 /*************************************<->*************************************
351 * HandleClientMessage
356 * This is the event handler registered to recieve the client message
357 * from dtwm when a client has beem managed
360 *************************************<->***********************************/
362 HandleClientMessage( Widget smWidget,
366 if (event->type == ClientMessage)
368 ProcessClientMessage(event);
371 } /* END OF FUNCTION HandleClientMessage */