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
23 /* $TOG: SmConMgmt.c /main/6 1998/04/06 14:35:42 mgreess $ */
25 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
26 * (c) Copyright 1993, 1994 International Business Machines Corp. *
27 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
28 * (c) Copyright 1993, 1994 Novell, Inc. *
31 /*************************************<+>*************************************
32 *****************************************************************************
36 ** Project: HP DT Session Manager (dtsession)
40 ** Contains all code which performs contention management functionality
43 *******************************************************************
44 ** (c) Copyright Hewlett-Packard Company, 1990. All rights are
45 ** reserved. Copying or other reproduction of this program
46 ** except for archival purposes is prohibited without prior
47 ** written consent of Hewlett-Packard Company.
48 ********************************************************************
52 *****************************************************************************
53 *************************************<+>*************************************/
58 #if !defined(__linux__)
61 #include <X11/Intrinsic.h>
63 #include "SmProtocol.h"
64 #include "SmConMgmt.h"
72 #include <sys/fixpoint.h>
76 #define KMEM_FILE "/dev/kmem"
81 # define KERNEL_FILE "/vmunix"
83 # define KERNEL_FILE "/hp-ux"
88 #define GPGSLIM "gpgslim"
89 #define FREEMEM "freemem"
93 # define GPGSLIM "gpgslim"
94 # define FREEMEM "freemem"
95 # endif /* __hp9000s800 */
100 #define GPGSLIM "_gpgslim"
101 #endif /* not defined GPGSLIM */
104 #define FREEMEM "_freemem"
105 #endif /* not defined FREEMEM */
110 * Variables global to this module only
112 #if !defined(__linux__)
113 static struct nlist namelist[3];
115 static int freemem_loc, gpgslim_loc, gpgslim, freemem;
116 static int clientTimeout;
119 * Functions local to this module
122 static void HandleClientMessage(Widget smWidget, XtPointer dummy,
124 static void WaitClientTimeout(XtPointer, XtIntervalId *);
128 /*************************************<->*************************************
130 * GetMemoryUtilization ()
135 * Returns 1 of 3 values. Tells the calling program that memory is not
136 * available, that it is full (paging has started), or that it is not
146 * An integer value representing the current memory utilization of the
152 * WARNING: This routine, by its very nature is non-portable. It depends
153 * on an OS having some kind of access to its memory utilization.
155 * DOUBLE WARNING: The mips architecture code has never been tested.
158 *************************************<->***********************************/
161 GetMemoryUtilization(void)
163 #if !defined(__linux__)
166 #if !defined(SVR4) && !defined(hpV4) && !defined(_POWER) && !defined(CSRG_BASED)
173 setresgid(-1, smGD.conMgmtGID, -1);
176 setregid(smGD.runningGID, smGD.conMgmtGID);
178 setgid(smGD.runningGID);
179 setegid(smGD.conMgmtGID);
185 namelist[0].n_name = FREEMEM;
186 namelist[1].n_name = GPGSLIM;
187 namelist[2].n_name = (char *) NULL;
188 nlist( KERNEL_FILE, namelist);
189 for(i = 0; i < 2; i++)
191 if (namelist[i].n_type == 0 ||
192 namelist[i].n_value == 0)
195 setresgid(-1, smGD.runningGID, -1);
198 setregid(smGD.conMgmtGID, smGD.runningGID);
200 setgid(smGD.conMgmtGID);
201 setegid(smGD.runningGID);
204 return(MEM_NOT_AVAILABLE);
208 freemem_loc = namelist[0].n_value;
209 gpgslim_loc = namelist[1].n_value;
211 kmem = open(KMEM_FILE, O_RDONLY);
215 setresgid(-1, smGD.runningGID, -1);
218 setregid(smGD.conMgmtGID, smGD.runningGID);
220 setgid(smGD.conMgmtGID);
221 setegid(smGD.runningGID);
224 return(MEM_NOT_AVAILABLE);
226 (void) lseek(kmem, gpgslim_loc, 0);
230 (void) read(kmem, (char *)&temp, sizeof(fix));
231 gpgslim = FIX_TO_DBL(temp);
234 (void) read(kmem, (char *)&gpgslim, sizeof(int));
239 (void) lseek(kmem, freemem_loc, 0);
243 (void) read(kmem, (char *)&temp, sizeof(fix));
244 freemem = FIX_TO_DBL(temp);
247 (void) read(kmem, (char *)&freemem, sizeof(int));
251 setresgid(-1, smGD.runningGID, -1);
254 setregid(smGD.conMgmtGID, smGD.runningGID);
256 setgid(smGD.conMgmtGID);
257 setegid(smGD.runningGID);
261 if(freemem >= gpgslim)
263 return(MEM_NOT_FULL);
270 return(MEM_NOT_FULL);
276 /*************************************<->*************************************
278 * WaitForClientMap ()
283 * This routine waits for the workspace manager to send it information
284 * about a client being mapped, before returning to start the next client
297 *************************************<->***********************************/
299 WaitForClientMap( void )
303 XClientMessageEvent *cEvent = (XClientMessageEvent *) &event;
304 XtIntervalId clientTimerId;
306 XtAddEventHandler(smGD.topLevelWid,
309 (XtEventHandler)HandleClientMessage,
313 * Set a timer which stops the block on waiting for the
314 * client to start. This value is fetched from the
315 * waitClientTimeout resource.
317 clientRunning = False;
318 clientTimeout = False;
319 clientTimerId = XtAppAddTimeOut(smGD.appCon,
320 smRes.waitClientTimeout,
321 WaitClientTimeout, NULL);
323 while((clientRunning == False) && (clientTimeout == False))
325 XtAppProcessEvent(smGD.appCon, XtIMAll);
328 XtRemoveTimeOut(clientTimerId);
329 XtRemoveEventHandler(smGD.topLevelWid,
332 (XtEventHandler)HandleClientMessage,
338 /*************************************<->*************************************
345 * Timeout procedure the WaitForClientMap routine. It stops a loop waiting
346 * for the last started app to get mapped.
355 * clientTimeout = (global) flag that stops the loop
360 *************************************<->***********************************/
363 XtPointer client_data,
366 clientTimeout = True;
371 /*************************************<->*************************************
373 * HandleClientMessage
378 * This is the event handler registered to receive the client message
379 * from dtwm when a client has beem managed
382 *************************************<->***********************************/
384 HandleClientMessage( Widget smWidget,
388 if (event->type == ClientMessage)
390 ProcessClientMessage(event);
393 } /* END OF FUNCTION HandleClientMessage */