dpylist.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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 <sys/mman.h>
  53. # include "dm.h"
  54. # include "vgmsg.h"
  55. struct display *displays;
  56. int
  57. AnyDisplaysLeft( void )
  58. {
  59. return displays != (struct display *) 0;
  60. }
  61. void
  62. ForEachDisplay( void (*f)() )
  63. {
  64. struct display *d, *next;
  65. for (d = displays; d; d = next) {
  66. next = d->next;
  67. (*f) (d);
  68. }
  69. }
  70. struct display *
  71. FindDisplayByName( char *name )
  72. {
  73. struct display *d;
  74. for (d = displays; d; d = d->next)
  75. if (!strcmp (name, d->name))
  76. return d;
  77. return 0;
  78. }
  79. struct display *
  80. FindDisplayByPid( int pid )
  81. {
  82. struct display *d;
  83. for (d = displays; d; d = d->next)
  84. if (pid == d->pid)
  85. return d;
  86. return 0;
  87. }
  88. struct display *
  89. FindDisplayByServerPid( int serverPid )
  90. {
  91. struct display *d;
  92. for (d = displays; d; d = d->next)
  93. if (serverPid == d->serverPid)
  94. return d;
  95. return 0;
  96. }
  97. struct display *
  98. FindDisplayBySessionID( CARD32 sessionID )
  99. {
  100. struct display *d;
  101. for (d = displays; d; d = d->next)
  102. if (sessionID == d->sessionID)
  103. return d;
  104. return 0;
  105. }
  106. struct display *
  107. FindDisplayByAddress(struct sockaddr *addr, int addrlen,
  108. #if NeedWidePrototypes
  109. int displayNumber )
  110. #else
  111. CARD16 displayNumber )
  112. #endif /* NeedWidePrototypes */
  113. {
  114. struct display *d;
  115. for (d = displays; d; d = d->next)
  116. if (d->displayType.origin == FromXDMCP &&
  117. d->displayNumber == displayNumber &&
  118. addressEqual ((char *)d->from, d->fromlen, (char *)addr, addrlen))
  119. {
  120. return d;
  121. }
  122. return 0;
  123. }
  124. #define IfFree(x) if (x) free ((char *) x)
  125. void
  126. RemoveDisplay( struct display *old )
  127. {
  128. struct display *d, *p;
  129. char **x;
  130. int i;
  131. extern int wakeupTime;
  132. Debug("Removing display %s from display list.\n", old->name);
  133. p = 0;
  134. for (d = displays; d; d = d->next) {
  135. if (d == old) {
  136. if (p)
  137. p->next = d->next;
  138. else
  139. displays = d->next;
  140. IfFree (d->name);
  141. IfFree (d->class);
  142. for (x = d->argv; x && *x; x++)
  143. IfFree (*x);
  144. IfFree (d->argv);
  145. IfFree (d->resources);
  146. IfFree (d->xrdb);
  147. IfFree (d->cpp);
  148. IfFree (d->setup);
  149. IfFree (d->startup);
  150. IfFree (d->reset);
  151. IfFree (d->session);
  152. IfFree (d->userPath);
  153. IfFree (d->systemPath);
  154. IfFree (d->systemShell);
  155. IfFree (d->failsafeClient);
  156. IfFree (d->chooser);
  157. if (d->authorizations)
  158. {
  159. for (i = 0; i < d->authNum; i++)
  160. XauDisposeAuth (d->authorizations[i]);
  161. free ((char *) d->authorizations);
  162. }
  163. IfFree (d->clientAuthFile);
  164. if (d->authFile)
  165. (void) unlink (d->authFile);
  166. IfFree (d->authFile);
  167. IfFree (d->userAuthDir);
  168. IfFree (d->authNames);
  169. IfFree (d->peer);
  170. IfFree (d->from);
  171. XdmcpDisposeARRAY8(&d->clientAddr);
  172. munmap (d->language, LANGUAGESIZE + 1);
  173. IfFree (d->langList);
  174. IfFree (d->utmpId);
  175. IfFree (d->gettyLine);
  176. IfFree (d->gettySpeed);
  177. IfFree (d->environStr);
  178. IfFree (d->verifyName);
  179. /*
  180. * turn off polling if we are removing a suspended display...
  181. */
  182. if ( d->status == suspended )
  183. wakeupTime = -1;
  184. free ((char *) d);
  185. break;
  186. }
  187. p = d;
  188. }
  189. }
  190. struct display *
  191. NewDisplay( char *name, char *class )
  192. {
  193. char *language;
  194. struct display *d;
  195. language = mmap (NULL, LANGUAGESIZE + 1, PROT_READ | PROT_WRITE,
  196. MAP_SHARED | MAP_ANONYMOUS, -1, 0);
  197. if (language == MAP_FAILED) {
  198. LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  199. return 0;
  200. }
  201. d = (struct display *) malloc (sizeof (struct display));
  202. if (!d) {
  203. LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  204. return 0;
  205. }
  206. d->next = displays;
  207. d->name = malloc ((unsigned) (strlen (name) + 1));
  208. if (!d->name) {
  209. LogOutOfMem (ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  210. free ((char *) d);
  211. return 0;
  212. }
  213. strcpy (d->name, name);
  214. if (class)
  215. {
  216. d->class = malloc ((unsigned) (strlen (class) + 1));
  217. if (!d->class) {
  218. LogOutOfMem(
  219. ReadCatalog(MC_LOG_SET,MC_LOG_NEW_DPY,MC_DEF_LOG_NEW_DPY));
  220. free (d->name);
  221. free ((char *) d);
  222. return 0;
  223. }
  224. strcpy (d->class, class);
  225. }
  226. else
  227. {
  228. d->class = (char *) 0;
  229. }
  230. /* initialize every field to avoid possible problems */
  231. d->argv = 0;
  232. d->status = notRunning;
  233. d->pid = -1;
  234. d->serverPid = -1;
  235. d->state = NewEntry;
  236. d->resources = NULL;
  237. d->xrdb = NULL;
  238. d->cpp = NULL;
  239. d->setup = NULL;
  240. d->startup = NULL;
  241. d->reset = NULL;
  242. d->session = NULL;
  243. d->userPath = NULL;
  244. d->systemPath = NULL;
  245. d->systemShell = NULL;
  246. d->failsafeClient = NULL;
  247. d->chooser = NULL;
  248. d->authorize = FALSE;
  249. d->authorizations = NULL;
  250. d->authNum = 0;
  251. d->authNameNum = 0;
  252. d->clientAuthFile = NULL;
  253. d->authFile = NULL;
  254. d->userAuthDir = NULL;
  255. d->authNames = NULL;
  256. d->authNameLens = NULL;
  257. d->openDelay = 0;
  258. d->openRepeat = 0;
  259. d->openTimeout = 0;
  260. d->startAttempts = 0;
  261. d->startTries = 0;
  262. d->terminateServer = 0;
  263. d->grabTimeout = 0;
  264. d->sessionID = 0;
  265. d->peer = 0;
  266. d->peerlen = 0;
  267. d->from = 0;
  268. d->fromlen = 0;
  269. d->displayNumber = 0;
  270. d->useChooser = 0;
  271. d->clientAddr.data = NULL;
  272. d->clientAddr.length = 0;
  273. d->language = language;
  274. d->langList = NULL;
  275. d->utmpId = NULL;
  276. d->gettyLine = NULL;
  277. d->gettySpeed = NULL;
  278. d->environStr = NULL;
  279. d->dtlite = FALSE;
  280. d->verifyName = NULL;
  281. d->pmSearchPath = NULL;
  282. d->bmSearchPath = NULL;
  283. displays = d;
  284. return d;
  285. }