109 static CARD32 IAInitTimerCall(OsTimerPtr timer,CARD32 now,pointer arg); |
110 static CARD32 IAInitTimerCall(OsTimerPtr timer,CARD32 now,pointer arg); |
110 |
111 |
111 static iaclass_t IAClass; |
112 static iaclass_t IAClass; |
112 static id_t TScid; |
113 static id_t TScid; |
113 static ClientProcessPtr LastPids = NULL; |
114 static ClientProcessPtr LastPids = NULL; |
114 static int specialIAset = 0; |
|
115 static int ia_nice = IA_BOOST; |
115 static int ia_nice = IA_BOOST; |
116 static Bool InteractiveOS = xTrue; |
116 static Bool InteractiveOS = TRUE; |
117 static ClientPtr wmClientptr = NULL; |
|
118 static unsigned long IAExtensionGeneration = 0; |
117 static unsigned long IAExtensionGeneration = 0; |
119 static OsTimerPtr IAInitTimer = NULL; |
118 static OsTimerPtr IAInitTimer = NULL; |
120 static int (* IASavedProcVector[256]) (ClientPtr client); |
119 static int (* IASavedProcVector[256]) (ClientPtr client); |
121 |
120 |
122 typedef struct { |
121 static int IAPrivKeyIndex; |
123 ClientProcessPtr process; /* Process id information */ |
122 static DevPrivateKey IAPrivKey = &IAPrivKeyIndex; |
124 Bool wmgr; |
123 |
125 } IAClientPrivateRec, *IAClientPrivatePtr; |
124 #define GetIAClient(pClient) \ |
126 |
125 ((IAClientPrivatePtr) dixLookupPrivate(&(pClient)->devPrivates, IAPrivKey)) |
127 static int IAClientPrivateIndex; |
126 |
128 |
127 static inline ClientProcessPtr |
129 #define GetIAClient(pClient) ((IAClientPrivatePtr) (pClient)->devPrivates[IAClientPrivateIndex].ptr) |
128 GetConnectionPids(ClientPtr pClient) |
130 #define GetConnectionPids(pClient) (GetIAClient(pClient)->process) |
129 { |
|
130 IAClientPrivatePtr priv = GetIAClient(pClient); |
|
131 |
|
132 if (priv == NULL) { |
|
133 return NULL; |
|
134 } else { |
|
135 return priv->process; |
|
136 } |
|
137 } |
131 |
138 |
132 /* Set via xorg.conf option in loadable module */ |
139 /* Set via xorg.conf option in loadable module */ |
133 int IADebugLevel = 0; |
140 int IADebugLevel = 0; |
134 |
141 |
135 #define IA_DEBUG(level, func) \ |
142 #define IA_DEBUG(level, func) \ |
139 #define IA_DEBUG_PRIOCNTL 3 |
146 #define IA_DEBUG_PRIOCNTL 3 |
140 |
147 |
141 void |
148 void |
142 IAExtensionInit(void) |
149 IAExtensionInit(void) |
143 { |
150 { |
|
151 ConnectionPidRec myPid = P_MYID; |
|
152 ClientProcessRec myProc = { 1, &myPid, FALSE }; |
|
153 |
144 IA_DEBUG(IA_DEBUG_BASIC, |
154 IA_DEBUG(IA_DEBUG_BASIC, |
145 LogMessage(X_INFO, "SolarisIA: Initializing (generation %ld)\n", |
155 LogMessage(X_INFO, "SolarisIA: Initializing (generation %ld)\n", |
146 IAExtensionGeneration)); |
156 IAExtensionGeneration)); |
147 |
157 |
148 if (IAExtensionGeneration == serverGeneration) |
158 if (IAExtensionGeneration == serverGeneration) |
149 return; |
159 return; |
150 |
160 |
151 InteractiveOS=xFalse; |
161 InteractiveOS = FALSE; |
152 |
162 |
153 if (InitializeClass() != Success) |
163 if (InitializeClass() != Success) |
154 return; |
164 return; |
155 |
165 |
156 if (SetPriority(P_MYID, SET_INTERACTIVE) != Success) |
166 if (SetPriority(&myProc, SET_INTERACTIVE) != Success) |
157 return; |
167 return; |
158 |
168 |
159 if (SetPriority(P_MYID, SET_PRIORITY) != Success) |
169 if (SetPriority(&myProc, SET_PRIORITY) != Success) |
160 return; |
170 return; |
161 |
|
162 IAClientPrivateIndex = AllocateClientPrivateIndex(); |
|
163 if (IAClientPrivateIndex < 0) |
|
164 return; |
|
165 if (!AllocateClientPrivate (IAClientPrivateIndex, |
|
166 sizeof (IAClientPrivateRec))) |
|
167 return; |
|
168 |
171 |
169 if (!AddCallback(&ClientStateCallback, IAClientStateChange, NULL)) |
172 if (!AddCallback(&ClientStateCallback, IAClientStateChange, NULL)) |
170 return; |
173 return; |
171 |
174 |
172 if (IAWrapProcVectors() != 0) |
175 if (IAWrapProcVectors() != 0) |
173 return; |
176 return; |
174 |
177 |
175 if (!AddExtension(IANAME, IANumberEvents, IANumberErrors, |
178 if (!AddExtension(IANAME, IANumberEvents, IANumberErrors, |
176 ProcIADispatch, SProcIADispatch, |
179 ProcIADispatch, SProcIADispatch, |
177 IACloseDown, StandardMinorOpcode)) |
180 IACloseDown, StandardMinorOpcode)) |
178 return; |
181 return; |
179 |
182 |
180 /* InitExtensions is called before InitClientPrivates(serverClient) |
183 /* InitExtensions is called before InitClientPrivates(serverClient) |
181 so we set this timer to callback as soon as we hit WaitForSomething |
184 so we set this timer to callback as soon as we hit WaitForSomething |
182 to initialize the serverClient */ |
185 to initialize the serverClient */ |
183 IAInitTimer = TimerSet(IAInitTimer, 0, 1, IAInitTimerCall, NULL); |
186 IAInitTimer = TimerSet(IAInitTimer, 0, 1, IAInitTimerCall, NULL); |
184 |
187 |
185 specialIAset = 0; |
188 InteractiveOS = TRUE; |
186 InteractiveOS = xTrue; |
|
187 IAExtensionGeneration = serverGeneration; |
189 IAExtensionGeneration = serverGeneration; |
188 |
190 |
189 IA_DEBUG(IA_DEBUG_BASIC, |
191 IA_DEBUG(IA_DEBUG_BASIC, |
190 LogMessage(X_INFO, "SolarisIA: Finished initializing (generation %ld)\n", |
192 LogMessage(X_INFO, |
191 IAExtensionGeneration)); |
193 "SolarisIA: Finished initializing (generation %ld)\n", |
|
194 IAExtensionGeneration)); |
|
195 } |
|
196 |
|
197 /* Allocate client private structure for this client */ |
|
198 static int |
|
199 IAInitClientPrivate(ClientPtr pClient) |
|
200 { |
|
201 IAClientPrivatePtr priv; |
|
202 |
|
203 priv = GetIAClient(pClient); |
|
204 if (priv != NULL) { |
|
205 return Success; |
|
206 } |
|
207 |
|
208 priv = xalloc(sizeof(IAClientPrivateRec)); |
|
209 if (priv == NULL) { |
|
210 return BadAlloc; |
|
211 } |
|
212 |
|
213 priv->process = NULL; |
|
214 priv->wmgr = FALSE; |
|
215 |
|
216 dixSetPrivate(&(pClient)->devPrivates, IAPrivKey, priv); |
|
217 |
|
218 return Success; |
192 } |
219 } |
193 |
220 |
194 /* Called when we first hit WaitForSomething to initialize serverClient */ |
221 /* Called when we first hit WaitForSomething to initialize serverClient */ |
195 static CARD32 |
222 static CARD32 |
196 IAInitTimerCall(OsTimerPtr timer,CARD32 now,pointer arg) |
223 IAInitTimerCall(OsTimerPtr timer,CARD32 now,pointer arg) |
197 { |
224 { |
198 ConnectionPidRec serverPid; |
225 ConnectionPidRec serverPid; |
199 |
226 |
200 if (InteractiveOS != xTrue) |
227 if (InteractiveOS != TRUE) |
201 return 0; |
228 return 0; |
202 |
229 |
203 GetConnectionPids(serverClient) = NULL; |
230 IAInitClientPrivate(serverClient); |
204 GetIAClient(serverClient)->wmgr = FALSE; |
|
205 |
231 |
206 serverPid = getpid(); |
232 serverPid = getpid(); |
207 SetClientPrivate(serverClient, &serverPid, 1); |
233 SetClientPrivate(serverClient, &serverPid, 1); |
208 |
234 |
209 ChangePriority(serverClient); |
235 ChangePriority(serverClient); |
215 IAClientStateChange(CallbackListPtr *pcbl, pointer nulldata, pointer calldata) |
241 IAClientStateChange(CallbackListPtr *pcbl, pointer nulldata, pointer calldata) |
216 { |
242 { |
217 NewClientInfoRec *pci = (NewClientInfoRec *)calldata; |
243 NewClientInfoRec *pci = (NewClientInfoRec *)calldata; |
218 ClientPtr pClient = pci->client; |
244 ClientPtr pClient = pci->client; |
219 ClientProcessPtr CurrentPids; |
245 ClientProcessPtr CurrentPids; |
|
246 IAClientPrivatePtr priv; |
220 |
247 |
221 switch (pClient->clientState) { |
248 switch (pClient->clientState) { |
222 case ClientStateGone: |
249 case ClientStateGone: |
223 case ClientStateRetained: |
250 case ClientStateRetained: |
224 CurrentPids = GetConnectionPids(pClient); |
251 priv = GetIAClient(pClient); |
225 |
252 if (priv == NULL) { |
226 if (pClient==wmClientptr) { |
253 return; |
|
254 } |
|
255 CurrentPids = priv->process; |
|
256 |
|
257 if (priv->wmgr) { |
227 IA_DEBUG(IA_DEBUG_BASIC, |
258 IA_DEBUG(IA_DEBUG_BASIC, |
228 LogMessage(X_INFO, "SolarisIA: WindowManager closed (pid %d)\n", |
259 LogMessage(X_INFO, |
229 (CurrentPids && CurrentPids->pids) ? CurrentPids->pids[0] : -1)); |
260 "SolarisIA: WindowManager closed (pid %d)\n", |
230 wmClientptr=NULL; |
261 (CurrentPids && CurrentPids->pids) ? |
231 } |
262 CurrentPids->pids[0] : -1)); |
232 |
263 } |
233 if (CurrentPids && LastPids && PidSetEqual(CurrentPids, LastPids)) |
264 |
234 LastPids=NULL; |
265 if (CurrentPids && CurrentPids->boosted) { |
235 |
266 SetPriority(CurrentPids, UNSET_PRIORITY); |
236 FreeProcessList(pClient); |
267 } |
237 GetIAClient(pClient)->wmgr = FALSE; |
268 |
|
269 if (CurrentPids && LastPids && PidSetEqual(CurrentPids, LastPids)) { |
|
270 LastPids = NULL; |
|
271 } |
|
272 |
|
273 FreeProcessList(priv); |
|
274 xfree(priv); |
|
275 dixSetPrivate(&(pClient)->devPrivates, IAPrivKey, NULL); |
238 break; |
276 break; |
239 |
277 |
240 case ClientStateInitial: |
278 case ClientStateInitial: |
241 GetConnectionPids(pClient) = NULL; |
279 IAInitClientPrivate(pClient); |
242 GetIAClient(pClient)->wmgr = FALSE; |
|
243 break; |
280 break; |
244 |
281 |
245 default: |
282 default: |
246 break; |
283 break; |
247 } |
284 } |
407 } |
447 } |
408 |
448 |
409 static void |
449 static void |
410 ChangeInteractive(ClientPtr client) |
450 ChangeInteractive(ClientPtr client) |
411 { |
451 { |
412 ClientProcessPtr CurrentPids=GetConnectionPids(client); |
452 ClientProcessPtr CurrentPids = GetConnectionPids(client); |
413 register int count; |
453 |
414 |
454 if (InteractiveOS==FALSE) |
415 if (InteractiveOS==xFalse) |
|
416 return; |
455 return; |
417 |
456 |
418 if (!CurrentPids || !CurrentPids->pids) |
457 if (!CurrentPids || !CurrentPids->pids) |
419 return; |
458 return; |
420 |
459 |
421 count=CurrentPids->count; |
460 SetPriority(CurrentPids, SET_INTERACTIVE); |
422 |
|
423 while(count--) |
|
424 SetPriority(CurrentPids->pids[count], SET_INTERACTIVE); |
|
425 } |
461 } |
426 |
462 |
427 /* |
463 /* |
428 Loop through pids associated with client. Magically make last focus |
464 * Loop through pids associated with client. Magically make last focus |
429 group go non-interactive -IA_BOOST. |
465 * group go non-interactive -IA_BOOST. |
430 */ |
466 */ |
431 static void |
467 static void |
432 ChangePriority(register ClientPtr client) |
468 ChangePriority(register ClientPtr client) |
433 { |
469 { |
434 ClientProcessPtr CurrentPids=GetConnectionPids(client); |
470 IAClientPrivatePtr priv = GetIAClient(client); |
435 register int count; |
471 ClientProcessPtr CurrentPids = (priv == NULL ? NULL : priv->process); |
436 |
472 |
437 /* If no pid info for current client make sure to unset last focus group. */ |
473 if (CurrentPids && LastPids && PidSetEqual(CurrentPids, LastPids)) { |
438 /* This can happen if we have a remote client with focus or if the client */ |
474 /* Shortcut. Focus changed between two windows with same pid */ |
439 /* is statically linked or if it is using a down rev version of libX11. */ |
475 return; |
440 if (!CurrentPids || !CurrentPids->pids) { |
476 } |
441 if (LastPids && LastPids->pids) { |
477 |
442 UnsetLastPriority(LastPids); |
478 /* Remove priority boost for last focus group */ |
443 LastPids=NULL; |
479 if (LastPids) { |
444 } |
480 SetPriority(LastPids, UNSET_PRIORITY); |
445 return; |
481 LastPids = NULL; |
446 } |
482 } |
447 |
483 |
448 /* Make sure server or wmgr isn't unset by testing for them */ |
484 /* If no pid info for current client, then we're done here. |
449 /* this way LastPids is never set to point to the server or */ |
485 * This can happen if we have a remote client with focus or if the client |
450 /* wmgr pid. */ |
486 * is statically linked or if it is using a down rev version of libX11. |
451 if ((client->index==serverClient->index || |
487 */ |
452 GetIAClient(client)->wmgr==xTrue)) { |
488 if ( (CurrentPids == NULL) || (CurrentPids->count == 0) || |
453 |
489 (CurrentPids->pids == NULL) ) { |
454 if ((specialIAset < BOTH) && CurrentPids->pids) { |
490 return; |
455 |
491 } |
456 if (client->index == serverClient->index) { |
492 |
457 specialIAset |= SERVER; |
493 /* Set the priority boost if it isn't already active */ |
458 } |
494 if (!CurrentPids->boosted) { |
459 else { |
495 SetPriority(CurrentPids, SET_PRIORITY); |
460 specialIAset |= WMGR; |
496 } |
461 } |
497 |
462 SetPriority(CurrentPids->pids[0], SET_PRIORITY); |
498 /* Make sure server or wmgr isn't unset by testing for them, so |
463 } |
499 * that LastPids is never set to point to the server or wmgr pid. |
464 return; |
500 */ |
465 } |
501 if ((client->index != serverClient->index) && (priv->wmgr != TRUE)) { |
466 |
502 LastPids = CurrentPids; |
467 if (LastPids && LastPids->pids) { |
503 } |
468 if (CurrentPids && LastPids && PidSetEqual(CurrentPids, LastPids)) |
|
469 return; /*Shortcut. Focus changed |
|
470 between two windows with |
|
471 same pid */ |
|
472 UnsetLastPriority(LastPids); |
|
473 } |
|
474 |
|
475 count=CurrentPids->count; |
|
476 while(count--) |
|
477 SetPriority(CurrentPids->pids[count], SET_PRIORITY); |
|
478 LastPids=CurrentPids; |
|
479 } |
|
480 |
|
481 static void |
|
482 UnsetLastPriority(ClientProcessPtr LastPids) |
|
483 { |
|
484 register int LastPidcount=LastPids->count; |
|
485 |
|
486 while(LastPidcount--) |
|
487 SetPriority(LastPids->pids[LastPidcount], UNSET_PRIORITY); |
|
488 } |
504 } |
489 |
505 |
490 static int |
506 static int |
491 InitializeClass(void) |
507 InitializeClass(void) |
492 { |
508 { |
493 pcinfo_t pcinfo; |
509 pcinfo_t pcinfo; |
494 |
510 |
495 /* Get TS class information */ |
511 /* Get TS class information */ |
496 |
512 strcpy (pcinfo.pc_clname, "TS"); |
497 strcpy (pcinfo.pc_clname, "TS"); |
513 priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo); |
498 priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo); |
514 TScid = pcinfo.pc_cid; |
499 TScid=pcinfo.pc_cid; |
515 |
500 |
516 /* Get IA class information */ |
501 /* Get IA class information */ |
517 strcpy (pcinfo.pc_clname, "IA"); |
502 strcpy (pcinfo.pc_clname, "IA"); |
518 if ((priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo)) == -1) |
503 if ((priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo)) == -1) |
|
504 return ~Success; |
519 return ~Success; |
505 |
520 |
506 IAClass.pc_cid=pcinfo.pc_cid; |
521 IAClass.pc_cid = pcinfo.pc_cid; |
507 ((iaparms_t*)IAClass.pc_clparms)->ia_uprilim=IA_NOCHANGE; |
522 ((iaparms_t*)IAClass.pc_clparms)->ia_uprilim = IA_NOCHANGE; |
508 ((iaparms_t*)IAClass.pc_clparms)->ia_upri=IA_NOCHANGE; |
523 ((iaparms_t*)IAClass.pc_clparms)->ia_upri = IA_NOCHANGE; |
509 |
524 |
510 return Success; |
525 return Success; |
511 } |
526 } |
512 |
527 |
513 static int |
528 static int |
514 SetPriority(int pid, int cmd) |
529 SetPriority(const ClientProcessPtr cpp, int cmd) |
515 { |
530 { |
516 pcparms_t pcinfo; |
531 pcparms_t pcinfo; |
517 long ret; |
532 long ret = Success; |
518 gid_t usr_egid = getegid(); |
533 gid_t usr_egid = getegid(); |
519 |
534 int i; |
520 if ( setegid(0) < 0 ) |
535 |
|
536 if ( (cpp == NULL) || (cpp->pids == NULL) || (cpp->count == 0) ) { |
|
537 return Success; |
|
538 } |
|
539 |
|
540 if ( setegid(0) < 0 ) { |
521 Error("Error in setting egid to 0"); |
541 Error("Error in setting egid to 0"); |
522 |
542 } |
523 |
543 |
524 pcinfo.pc_cid=PC_CLNULL; |
544 for (i = 0; i < cpp->count ; i++) { |
525 if ((priocntl(P_PID, pid, PC_GETPARMS, (caddr_t)&pcinfo)) < 0) { |
545 id_t pid = cpp->pids[i]; |
526 if ( setegid(usr_egid) < 0 ) |
546 |
527 Error("Error in resetting egid"); |
547 pcinfo.pc_cid=PC_CLNULL; |
528 |
548 if ((priocntl(P_PID, pid, PC_GETPARMS, (caddr_t)&pcinfo)) < 0) { |
529 return ~Success; /* Scary time; punt */ |
549 if ( setegid(usr_egid) < 0 ) { |
530 } |
550 Error("Error in resetting egid"); |
531 |
551 } |
532 /* If process is in TS or IA class we can safely set parameters */ |
552 return ~Success; /* Scary time; punt */ |
533 if ((pcinfo.pc_cid == IAClass.pc_cid) || (pcinfo.pc_cid == TScid)) { |
553 } |
534 |
554 |
535 switch (cmd) { |
555 /* If process is in TS or IA class we can safely set parameters */ |
536 case UNSET_PRIORITY: |
556 if ((pcinfo.pc_cid == IAClass.pc_cid) || (pcinfo.pc_cid == TScid)) { |
|
557 |
|
558 switch (cmd) { |
|
559 case UNSET_PRIORITY: |
537 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_INTERACTIVE_OFF; |
560 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_INTERACTIVE_OFF; |
538 break; |
561 break; |
539 case SET_PRIORITY: |
562 case SET_PRIORITY: |
540 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_SET_INTERACTIVE; |
563 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_SET_INTERACTIVE; |
541 break; |
564 break; |
542 case SET_INTERACTIVE: |
565 case SET_INTERACTIVE: |
543 /* If this returns true, the process is already in the IA class */ |
566 /* If this returns true, the process is already in the */ |
544 /* So just return. */ |
567 /* IA class, so we don't need to update it. */ |
545 if ( pcinfo.pc_cid == IAClass.pc_cid) |
568 if ( pcinfo.pc_cid == IAClass.pc_cid) |
546 return Success; |
569 continue; |
547 |
570 |
548 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_INTERACTIVE_OFF; |
571 ((iaparms_t*)IAClass.pc_clparms)->ia_mode=IA_INTERACTIVE_OFF; |
549 break; |
572 break; |
550 } |
573 } |
551 |
574 |
552 if ( priocntl(P_PID, pid, PC_SETPARMS, (caddr_t)&IAClass) == -1 ) |
575 if (priocntl(P_PID, pid, PC_SETPARMS, (caddr_t)&IAClass) == -1) |
553 { |
576 { |
554 ret = ~Success; |
577 ret = ~Success; |
555 } |
578 } |
556 else |
579 |
|
580 IA_DEBUG(IA_DEBUG_PRIOCNTL, |
557 { |
581 { |
558 ret = Success; |
582 const char *cmdmsg; |
559 } |
583 |
560 |
584 switch (cmd) { |
561 |
585 case UNSET_PRIORITY: cmdmsg = "UNSET_PRIORITY"; break; |
562 IA_DEBUG(IA_DEBUG_PRIOCNTL, |
586 case SET_PRIORITY: cmdmsg = "SET_PRIORITY"; break; |
563 { |
587 case SET_INTERACTIVE: cmdmsg = "SET_INTERACTIVE"; break; |
564 const char *cmdmsg; |
588 default: cmdmsg = "UNKNOWN_CMD!!!"; break; |
565 |
589 } |
566 switch (cmd) { |
590 LogMessage(X_INFO, "SolarisIA: SetPriority(%ld, %s): %s\n", |
567 case UNSET_PRIORITY: cmdmsg = "UNSET_PRIORITY"; break; |
591 pid, cmdmsg, |
568 case SET_PRIORITY: cmdmsg = "SET_PRIORITY"; break; |
592 (ret == Success) ? "succeeeded" : "failed"); |
569 case SET_INTERACTIVE: cmdmsg = "SET_INTERACTIVE"; break; |
593 }); |
570 default: cmdmsg = "UNKNOWN_CMD!!!"; break; |
594 } |
571 } |
595 } |
572 LogMessage(X_INFO, "SolarisIA: SetPriority(%d, %s): %s\n", |
596 |
573 pid, cmdmsg, (ret == Success) ? "succeeeded" : "failed"); |
597 if (setegid(usr_egid) < 0) |
574 }); |
598 Error("Error in resetting egid"); |
575 |
599 |
576 |
600 if (ret == Success) { |
577 if ( setegid(usr_egid) < 0 ) |
601 if (cmd == SET_PRIORITY) { |
578 Error("Error in resetting egid"); |
602 cpp->boosted = TRUE; |
579 |
603 } else if (cmd == UNSET_PRIORITY) { |
580 return ret; |
604 cpp->boosted = FALSE; |
581 } |
605 } |
582 |
606 } |
583 return ~Success; |
607 |
|
608 return ret; |
584 } |
609 } |
585 |
610 |
586 static void |
611 static void |
587 SetIAPrivate(int * value) |
612 SetIAPrivate(int * value) |
588 { |
613 { |
589 ia_nice=*value; |
614 ia_nice = *value; |
590 } |
615 } |
591 |
616 |
592 /***************************************************************************** |
617 /***************************************************************************** |
593 * Various utility functions - in Xsun these lived in Xserver/os/process.c |
618 * Various utility functions - in Xsun these lived in Xserver/os/process.c |
594 */ |
619 */ |
595 |
620 |
596 /* In Xsun we used the osPrivate in OsCommPtr, so this was SetOsPrivate. */ |
621 /* In Xsun we used the osPrivate in OsCommPtr, so this was SetOsPrivate. */ |
597 static int |
622 static int |
598 SetClientPrivate(ClientPtr client, ConnectionPidPtr stuff, int length) |
623 SetClientPrivate(ClientPtr client, ConnectionPidPtr stuff, int length) |
599 { |
624 { |
600 ClientProcessPtr cpp; |
625 ClientProcessPtr cpp; |
601 |
626 IAClientPrivatePtr priv; |
602 FreeProcessList(client); |
627 |
603 |
628 priv = GetIAClient(client); |
|
629 if (priv == NULL) { |
|
630 IAInitClientPrivate(client); |
|
631 } else { |
|
632 FreeProcessList(priv); |
|
633 } |
|
634 |
604 cpp = (ClientProcessPtr)xalloc(sizeof(ClientProcessRec)); |
635 cpp = (ClientProcessPtr)xalloc(sizeof(ClientProcessRec)); |
605 |
636 |
606 if (cpp == NULL) |
637 if (cpp == NULL) |
607 return BadAlloc; |
638 return BadAlloc; |
608 |
639 |
611 if (cpp->pids == NULL) { |
642 if (cpp->pids == NULL) { |
612 xfree(cpp); |
643 xfree(cpp); |
613 return BadAlloc; |
644 return BadAlloc; |
614 } |
645 } |
615 |
646 |
616 GetConnectionPids(client) = cpp; |
|
617 cpp->count = length; |
647 cpp->count = length; |
618 memcpy(cpp->pids, stuff, sizeof(ConnectionPidRec)*length); |
648 memcpy(cpp->pids, stuff, sizeof(ConnectionPidRec)*length); |
619 |
649 cpp->boosted = FALSE; |
|
650 |
|
651 priv->process = cpp; |
620 return Success; |
652 return Success; |
621 } |
653 } |
622 |
654 |
623 static void |
655 static void |
624 FreeProcessList(ClientPtr client) |
656 FreeProcessList(IAClientPrivatePtr priv) |
625 { |
657 { |
626 ClientProcessPtr cpp = GetConnectionPids(client); |
658 ClientProcessPtr cpp = priv->process; |
627 |
659 |
628 if (cpp == NULL) |
660 if (cpp == NULL) |
629 return; |
661 return; |
|
662 priv->process = NULL; |
630 |
663 |
631 if ( LastPids == cpp ) |
664 if ( LastPids == cpp ) |
632 LastPids = NULL; |
665 LastPids = NULL; |
633 |
666 |
634 if (cpp->pids != NULL) |
667 if (cpp->pids != NULL) |
635 xfree(cpp->pids); |
668 xfree(cpp->pids); |
636 |
669 |
637 xfree(cpp); |
670 xfree(cpp); |
638 |
|
639 GetConnectionPids(client) = NULL; |
|
640 } |
671 } |
641 |
672 |
642 /* |
673 /* |
643 Check to see that all in current (a) are in |
674 Check to see that all in current (a) are in last (b). |
644 last (b). And that a and b have the same number |
675 And that a and b have the same number of members in the set. |
645 of members in the set. |
|
646 */ |
676 */ |
647 int |
677 static int |
648 PidSetEqual(ClientProcessPtr a, ClientProcessPtr b) |
678 PidSetEqual(ClientProcessPtr a, ClientProcessPtr b) |
649 { |
679 { |
650 register int currentcount=a->count; |
680 int aN, bN; |
651 register int lastcount=b->count; |
681 int count = a->count; |
652 int retval; |
682 int retval = 1; |
653 |
683 |
654 if (currentcount != lastcount) |
684 if (a->count != b->count) { |
655 return 0; /* definately NOT the same set */ |
685 return 0; /* definately NOT the same set */ |
656 |
686 } |
657 while(currentcount--) { |
687 |
658 retval=0; |
688 for (aN = 0; aN < count; aN++) { |
659 while(lastcount--) |
689 retval = 0; |
660 if (a->pids[currentcount]==b->pids[lastcount]) { |
690 for (bN = 0; bN < count ; bN++) { |
661 retval=1; |
691 if (a->pids[aN] == b->pids[bN]) { |
662 break; |
692 retval = 1; |
663 } |
693 break; |
664 if (retval==0) |
694 } |
665 return retval; |
695 } |
666 lastcount=b->count; |
696 if (retval == 0) |
667 } |
697 return retval; |
668 |
698 } |
669 return retval; |
699 |
|
700 return retval; |
670 } |
701 } |
671 |
702 |
672 |
703 |
673 /***************************************************************************** |
704 /***************************************************************************** |
674 * Wrappers for normal procs - in Xsun we modified the original procs directly |
705 * Wrappers for normal procs - in Xsun we modified the original procs directly |