dpylist.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* (c) Copyright 1997 The Open Group */
  24. /* *
  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. *
  29. */
  30. /*
  31. * xdm - display manager daemon
  32. *
  33. * $TOG: dpylist.c /main/5 1997/03/14 13:44:46 barstow $
  34. *
  35. * Copyright 1988 Massachusetts Institute of Technology
  36. *
  37. * Permission to use, copy, modify, and distribute this software and its
  38. * documentation for any purpose and without fee is hereby granted, provided
  39. * that the above copyright notice appear in all copies and that both that
  40. * copyright notice and this permission notice appear in supporting
  41. * documentation, and that the name of M.I.T. not be used in advertising or
  42. * publicity pertaining to distribution of the software without specific,
  43. * written prior permission. M.I.T. makes no representations about the
  44. * suitability of this software for any purpose. It is provided "as is"
  45. * without express or implied warranty.
  46. *
  47. * Author: Keith Packard, MIT X Consortium
  48. */
  49. /*
  50. * a simple linked list of known displays
  51. */
  52. # include "dm.h"
  53. # include "vgmsg.h"
  54. struct display *displays;
  55. int
  56. AnyDisplaysLeft( void )
  57. {
  58. return displays != (struct display *) 0;
  59. }
  60. void
  61. ForEachDisplay( void (*f)() )
  62. {
  63. struct display *d, *next;
  64. for (d = displays; d; d = next) {
  65. next = d->next;
  66. (*f) (d);
  67. }
  68. }
  69. struct display *
  70. FindDisplayByName( char *name )
  71. {
  72. struct display *d;
  73. for (d = displays; d; d = d->next)
  74. if (!strcmp (name, d->name))
  75. return d;
  76. return 0;
  77. }
  78. struct display *
  79. FindDisplayByPid( int pid )
  80. {
  81. struct display *d;
  82. for (d = displays; d; d = d->next)
  83. if (pid == d->pid)
  84. return d;
  85. return 0;
  86. }
  87. struct display *
  88. FindDisplayByServerPid( int serverPid )
  89. {
  90. struct display *d;
  91. for (d = displays; d; d = d->next)
  92. if (serverPid == d->serverPid)
  93. return d;
  94. return 0;
  95. }
  96. struct display *
  97. FindDisplayBySessionID( CARD32 sessionID )
  98. {
  99. struct display *d;
  100. for (d = displays; d; d = d->next)
  101. if (sessionID == d->sessionID)
  102. return d;
  103. return 0;
  104. }
  105. struct display *
  106. FindDisplayByAddress(struct sockaddr *addr, int addrlen,
  107. #if NeedWidePrototypes
  108. int displayNumber )
  109. #else
  110. CARD16 displayNumber )
  111. #endif /* NeedWidePrototypes */
  112. {
  113. struct display *d;
  114. for (d = displays; d; d = d->next)
  115. if (d->displayType.origin == FromXDMCP &&
  116. d->displayNumber == displayNumber &&
  117. addressEqual ((char *)d->from, d->fromlen, (char *)addr, addrlen))
  118. {
  119. return d;
  120. }
  121. return 0;
  122. }
  123. #define IfFree(x) if (x) free ((char *) x)
  124. void
  125. RemoveDisplay( struct display *old )
  126. {
  127. struct display *d, *p;
  128. char **x;
  129. int i;
  130. extern int wakeupTime;
  131. Debug("Removing display %s from display list.\n", old->name);
  132. p = 0;
  133. for (d = displays; d; d = d->next) {
  134. if (d == old) {
  135. if (p)
  136. p->next = d->next;
  137. else
  138. displays = d->next;
  139. IfFree (d->name);
  140. IfFree (d->class);
  141. for (x = d->argv; x && *x; x++)
  142. IfFree (*x);
  143. IfFree (d->argv);
  144. IfFree (d->resources);
  145. IfFree (d->xrdb);
  146. IfFree (d->cpp);
  147. IfFree (d->setup);
  148. IfFree (d->startup);
  149. IfFree (d->reset);
  150. IfFree (d->session);
  151. IfFree (d->userPath);
  152. IfFree (d->systemPath);
  153. IfFree (d->systemShell);
  154. IfFree (d->failsafeClient);
  155. IfFree (d->chooser);
  156. if (d->authorizations)
  157. {
  158. for (i = 0; i < d->authNum; i++)
  159. XauDisposeAuth (d->authorizations[i]);
  160. free ((char *) d->authorizations);
  161. }
  162. IfFree (d->clientAuthFile);
  163. if (d->authFile)
  164. (void) unlink (d->authFile);
  165. IfFree (d->authFile);
  166. IfFree (d->userAuthDir);
  167. IfFree (d->authNames);
  168. IfFree (d->peer);
  169. IfFree (d->from);
  170. XdmcpDisposeARRAY8(&d->clientAddr);
  171. IfFree (d->language);
  172. IfFree (d->langList);
  173. IfFree (d->utmpId);
  174. IfFree (d->gettyLine);
  175. IfFree (d->gettySpeed);
  176. IfFree (d->environStr);
  177. IfFree (d->verifyName);
  178. /*
  179. * turn off polling if we are removing a suspended display...
  180. */
  181. if ( d->status == suspended )
  182. wakeupTime = -1;
  183. free ((char *) d);
  184. break;
  185. }
  186. p = d;
  187. }
  188. }
  189. struct display *
  190. NewDisplay( char *name, char *class )
  191. {
  192. struct display *d;
  193. d = (struct display *) malloc (sizeof (struct display));
  194. if (!d) {
  195. LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  196. return 0;
  197. }
  198. d->next = displays;
  199. d->name = malloc ((unsigned) (strlen (name) + 1));
  200. if (!d->name) {
  201. LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  202. free ((char *) d);
  203. return 0;
  204. }
  205. strcpy (d->name, name);
  206. if (class)
  207. {
  208. d->class = malloc ((unsigned) (strlen (class) + 1));
  209. if (!d->class) {
  210. LogOutOfMem(
  211. ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  212. free (d->name);
  213. free ((char *) d);
  214. return 0;
  215. }
  216. strcpy (d->class, class);
  217. }
  218. else
  219. {
  220. d->class = (char *) 0;
  221. }
  222. /* initialize every field to avoid possible problems */
  223. d->argv = 0;
  224. d->status = notRunning;
  225. d->pid = -1;
  226. d->serverPid = -1;
  227. d->state = NewEntry;
  228. d->resources = NULL;
  229. d->xrdb = NULL;
  230. d->cpp = NULL;
  231. d->setup = NULL;
  232. d->startup = NULL;
  233. d->reset = NULL;
  234. d->session = NULL;
  235. d->userPath = NULL;
  236. d->systemPath = NULL;
  237. d->systemShell = NULL;
  238. d->failsafeClient = NULL;
  239. d->chooser = NULL;
  240. d->authorize = FALSE;
  241. d->authorizations = NULL;
  242. d->authNum = 0;
  243. d->authNameNum = 0;
  244. d->clientAuthFile = NULL;
  245. d->authFile = NULL;
  246. d->userAuthDir = NULL;
  247. d->authNames = NULL;
  248. d->authNameLens = NULL;
  249. d->openDelay = 0;
  250. d->openRepeat = 0;
  251. d->openTimeout = 0;
  252. d->startAttempts = 0;
  253. d->startTries = 0;
  254. d->terminateServer = 0;
  255. d->grabTimeout = 0;
  256. d->sessionID = 0;
  257. d->peer = 0;
  258. d->peerlen = 0;
  259. d->from = 0;
  260. d->fromlen = 0;
  261. d->displayNumber = 0;
  262. d->useChooser = 0;
  263. d->clientAddr.data = NULL;
  264. d->clientAddr.length = 0;
  265. d->language = NULL;
  266. d->langList = NULL;
  267. d->utmpId = NULL;
  268. d->gettyLine = NULL;
  269. d->gettySpeed = NULL;
  270. d->environStr = NULL;
  271. d->dtlite = FALSE;
  272. d->verifyName = NULL;
  273. d->pmSearchPath = NULL;
  274. d->bmSearchPath = NULL;
  275. displays = d;
  276. return d;
  277. }