• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • dcop
 

dcop

  • dcop
dcopserver_shutdown_win.cpp
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 1999 Waldo Bastian <bastian@kde.org>
4  (c) 1999 Mario Weilguni <mweilguni@sime.com>
5  (c) 2001 Lubos Lunak <l.lunak@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License version 2 as published by the Free Software Foundation.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #ifdef HAVE_CONFIG_H
23 #include <config.h>
24 #endif
25 
26 #ifdef HAVE_SYS_TYPES_H
27 #include <sys/types.h>
28 #endif
29 
30 #include <sys/socket.h>
31 #include <stdlib.h>
32 #if 0
33 #include <sys/select.h>
34 #include <sys/time.h>
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/time.h>
38 #include <sys/stat.h>
39 #include <sys/un.h>
40 
41 #include <errno.h>
42 #include <string.h>
43 #include <stdio.h>
44 #include <stdlib.h>
45 #include <unistd.h>
46 #include <pwd.h>
47 #include <signal.h>
48 #endif
49 
50 #define QT_CLEAN_NAMESPACE 1
51 #include <tqfile.h>
52 
53 #include <dcopclient.h>
54 
55 #define BUFFER_SIZE 4096
56 
57 extern TQCString dcopServerFile(const TQCString &hostname, bool old);
58 
59 static char *getDisplay()
60 {
61  const char *display;
62  char *result;
63  char *screen;
64  char *colon;
65 /*
66  don't test for a value from tqglobal.h but instead distinguish
67  Qt/X11 from Qt/Embedded by the fact that Qt/E apps have -DQWS
68  on the commandline (which in tqglobal.h however triggers Q_WS_QWS,
69  but we don't want to include that here) (Simon)
70 #ifdef Q_WS_X11
71  */
72 #if !defined(QWS)
73  display = getenv("DISPLAY");
74 #else
75  display = getenv("QWS_DISPLAY");
76 #endif
77  if (!display || !*display)
78  {
79  display = "NODISPLAY";
80  }
81  result = (char*)malloc(strlen(display)+1);
82  if (result == NULL)
83  return NULL;
84  strcpy(result, display);
85  screen = strrchr(result, '.');
86  colon = strrchr(result, ':');
87  if (screen && (screen > colon))
88  *screen = '\0';
89  return result;
90 }
91 
92 static void cleanupDCOPsocket(const char *socketfile)
93 {
94  char cmd[BUFFER_SIZE];
95  char buffer[BUFFER_SIZE];
96  const char *socket_file;
97  int l;
98 
99  l = strlen(socketfile);
100  if (!l)
101  return;
102  strncpy(buffer,socketfile,l);
103  buffer[l-1] = '\0'; /* strip LF */
104 
105  socket_file = strchr(buffer, ':');
106  if (socket_file)
107  socket_file++;
108 
109  if (socket_file)
110  unlink(socket_file);
111 
112  snprintf(cmd, BUFFER_SIZE, "iceauth remove netid='%s'", buffer);
113  system(cmd);
114 }
115 
116 #ifdef Q_OS_WIN
117 static void killDCOPWin(pid_t pid)
118 {
119  char sz[256];
120  sprintf(sz,"dcopserver%i",pid);
121  HANDLE hEvent = CreateEventA(NULL,TRUE,FALSE,(LPCSTR)sz);
122  DWORD dwError = GetLastError();
123  printf("Signal event %s %p, %i\n",sz,hEvent,dwError);
124  if(hEvent != NULL)
125  {
126  SetEvent(hEvent);
127  CloseHandle(hEvent);
128  }
129 }
130 #endif
131 
132 static void cleanupDCOP(int dont_kill_dcop, int wait_for_exit)
133 {
134  TQCString host;
135  TQCString strDCOPServer = DCOPClient::dcopServerFile(host);
136 
137  if(strDCOPServer.isEmpty())
138  {
139  printf("no server file\n");
140  return;
141  }
142  printf("server file %s\n",(const char *)strDCOPServer);
143 
144  pid_t pid = 0;
145  TQFile f(strDCOPServer);
146  if(f.open(IO_ReadOnly))
147  {
148  TQString str;
149  while(f.readLine(str,2048))
150  {
151  pid = str.toULong();
152  if (pid)
153  break;
154  cleanupDCOPsocket(str.ascii());
155  }
156  }
157  f.close();
158  /* Clean up .DCOPserver file */
159  TQFile::remove(strDCOPServer);
160  printf("remove server file %s\n",(const char *)strDCOPServer);
161 
162  if(pid)
163  {
164  if(!dont_kill_dcop)
165  {
166 #ifdef Q_OS_WIN
167  killDCOPWin(pid);
168 #else
169  kill(pid, SIGTERM);
170 #endif
171  }
172  else
173  {
174 #ifdef Q_OS_WIN
175  killDCOPWin(pid);
176 #endif
177  }
178  }
179 
180 #ifdef Q_OS_WIN
181  if(wait_for_exit)
182  {
183  HANDLE hProcess = OpenProcess(SYNCHRONIZE,FALSE,(DWORD)pid);
184  if(hProcess)
185  {
186  WaitForSingleObject(hProcess,INFINITE);
187  CloseHandle(hProcess);
188  }
189  }
190 #else
191  while(wait_for_exit && (kill(pid, 0) == 0))
192  {
193  struct timeval tv;
194  tv.tv_sec = 0;
195  tv.tv_usec = 100000;
196  select(0,0,0,0,&tv);
197  }
198 #endif
199 }
200 
201 int main(int argc, char **argv)
202 {
203  TQCString host;
204 
205  int dont_kill_dcop = (argc == 2) && (strcmp(argv[1], "--nokill") == 0);
206  int wait_for_exit = (argc == 2) && (strcmp(argv[1], "--wait") == 0);
207 
208  cleanupDCOP(dont_kill_dcop, wait_for_exit);
209  return 0;
210 }
DCOPClient::dcopServerFile
static TQCString dcopServerFile(const TQCString &hostname=0)
File with information how to reach the dcopserver.
Definition: dcopclient.cpp:316

dcop

Skip menu "dcop"
  • Main Page
  • Modules
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

dcop

Skip menu "dcop"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dcop by doxygen 1.8.8
This website is maintained by Timothy Pearson.