reset.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. /* *
  24. * (c) Copyright 1993, 1994 Hewlett-Packard Company *
  25. * (c) Copyright 1993, 1994 International Business Machines Corp. *
  26. * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
  27. * (c) Copyright 1993, 1994 Novell, Inc. *
  28. */
  29. /*
  30. * xdm - display manager daemon
  31. *
  32. * $XConsortium: reset.c /main/4 1995/10/27 16:14:40 rswiston $
  33. *
  34. * Copyright 1988 Massachusetts Institute of Technology
  35. *
  36. * Permission to use, copy, modify, and distribute this software and its
  37. * documentation for any purpose and without fee is hereby granted, provided
  38. * that the above copyright notice appear in all copies and that both that
  39. * copyright notice and this permission notice appear in supporting
  40. * documentation, and that the name of M.I.T. not be used in advertising or
  41. * publicity pertaining to distribution of the software without specific,
  42. * written prior permission. M.I.T. makes no representations about the
  43. * suitability of this software for any purpose. It is provided "as is"
  44. * without express or implied warranty.
  45. *
  46. * Author: Keith Packard, MIT X Consortium
  47. */
  48. /*
  49. * pseudoReset -- pretend to reset the server by killing all clients
  50. * with windows. It will reset the server most of the time, unless
  51. * a client remains connected with no windows.
  52. */
  53. # include <setjmp.h>
  54. # include <sys/types.h>
  55. # include <sys/signal.h>
  56. # include "dm.h"
  57. # include "vgmsg.h"
  58. /***************************************************************************
  59. *
  60. * Local procedure declarations
  61. *
  62. ***************************************************************************/
  63. static SIGVAL abortReset( int arg ) ;
  64. static int ignoreErrors( Display *dpy, XErrorEvent *event) ;
  65. static void killWindows( Display *dpy, Window window) ;
  66. /***************************************************************************
  67. *
  68. *
  69. *
  70. ***************************************************************************/
  71. /*ARGSUSED*/
  72. static int
  73. ignoreErrors( Display *dpy, XErrorEvent *event )
  74. {
  75. Debug ("Ignoring error...\n");
  76. return 1;
  77. }
  78. /*
  79. * this is mostly bogus -- but quite useful. I wish the protocol
  80. * had some way of enumerating and identifying clients, that way
  81. * this code wouldn't have to be this kludgy.
  82. */
  83. static void
  84. killWindows( Display *dpy, Window window )
  85. {
  86. Window root, parent, *children;
  87. int child;
  88. unsigned int nchildren = 0;
  89. while (XQueryTree (dpy, window, &root, &parent, &children, &nchildren)
  90. && nchildren > 0)
  91. {
  92. for (child = 0; child < nchildren; child++) {
  93. Debug ("Calling XKillClient() for window 0x%x\n",
  94. children[child]);
  95. XKillClient (dpy, children[child]);
  96. }
  97. XFree ((char *)children);
  98. }
  99. }
  100. static sigjmp_buf resetJmp;
  101. static SIGVAL
  102. abortReset( int arg )
  103. {
  104. siglongjmp (resetJmp, 1);
  105. }
  106. /*
  107. * this display connection better not have any windows...
  108. */
  109. void
  110. pseudoReset( Display *dpy )
  111. {
  112. Window root;
  113. int screen;
  114. if (sigsetjmp (resetJmp, 1)) {
  115. LogError(
  116. ReadCatalog(MC_LOG_SET,MC_LOG_PSEUDO,MC_DEF_LOG_PSEUDO));
  117. } else {
  118. signal (SIGALRM, abortReset);
  119. alarm (30);
  120. XSetErrorHandler (ignoreErrors);
  121. for (screen = 0; screen < ScreenCount (dpy); screen++) {
  122. Debug ("Pseudo reset screen %d\n", screen);
  123. root = RootWindow (dpy, screen);
  124. killWindows (dpy, root);
  125. }
  126. Debug ("Before XSync\n");
  127. XSync (dpy, False);
  128. (void) alarm (0);
  129. }
  130. signal (SIGALRM, SIG_DFL);
  131. XSetErrorHandler ((int (*)()) 0);
  132. Debug ("pseudoReset() done\n");
  133. }