• 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 #include <tqfile.h>
51 
52 #include <dcopclient.h>
53 
54 #define BUFFER_SIZE 4096
55 
56 extern TQCString dcopServerFile(const TQCString &hostname, bool old);
57 
58 static char *getDisplay()
59 {
60  const char *display;
61  char *result;
62  char *screen;
63  char *colon;
64 /*
65  don't test for a value from tqglobal.h but instead distinguish
66  Qt/X11 from Qt/Embedded by the fact that Qt/E apps have -DQWS
67  on the commandline (which in tqglobal.h however triggers TQ_WS_QWS,
68  but we don't want to include that here) (Simon)
69 #ifdef TQ_WS_X11
70  */
71 #if !defined(QWS)
72  display = getenv("DISPLAY");
73 #else
74  display = getenv("QWS_DISPLAY");
75 #endif
76  if (!display || !*display)
77  {
78  display = "NODISPLAY";
79  }
80  result = (char*)malloc(strlen(display)+1);
81  if (result == NULL)
82  return NULL;
83  strcpy(result, display);
84  screen = strrchr(result, '.');
85  colon = strrchr(result, ':');
86  if (screen && (screen > colon))
87  *screen = '\0';
88  return result;
89 }
90 
91 static void cleanupDCOPsocket(const char *socketfile)
92 {
93  char cmd[BUFFER_SIZE];
94  char buffer[BUFFER_SIZE];
95  const char *socket_file;
96  int l;
97 
98  l = strlen(socketfile);
99  if (!l)
100  return;
101  strncpy(buffer,socketfile,l);
102  buffer[l-1] = '\0'; /* strip LF */
103 
104  socket_file = strchr(buffer, ':');
105  if (socket_file)
106  socket_file++;
107 
108  if (socket_file)
109  unlink(socket_file);
110 
111  snprintf(cmd, BUFFER_SIZE, "iceauth remove netid='%s'", buffer);
112  system(cmd);
113 }
114 
115 #ifdef Q_OS_WIN
116 static void killDCOPWin(pid_t pid)
117 {
118  char sz[256];
119  sprintf(sz,"dcopserver%i",pid);
120  HANDLE hEvent = CreateEventA(NULL,TRUE,FALSE,(LPCSTR)sz);
121  DWORD dwError = GetLastError();
122  printf("Signal event %s %p, %i\n",sz,hEvent,dwError);
123  if(hEvent != NULL)
124  {
125  SetEvent(hEvent);
126  CloseHandle(hEvent);
127  }
128 }
129 #endif
130 
131 static void cleanupDCOP(int dont_kill_dcop, int wait_for_exit)
132 {
133  TQCString host;
134  TQCString strDCOPServer = DCOPClient::dcopServerFile(host);
135 
136  if(strDCOPServer.isEmpty())
137  {
138  printf("no server file\n");
139  return;
140  }
141  printf("server file %s\n",(const char *)strDCOPServer);
142 
143  pid_t pid = 0;
144  TQFile f(strDCOPServer);
145  if(f.open(IO_ReadOnly))
146  {
147  TQString str;
148  while(f.readLine(str,2048))
149  {
150  pid = str.toULong();
151  if (pid)
152  break;
153  cleanupDCOPsocket(str.ascii());
154  }
155  }
156  f.close();
157  /* Clean up .DCOPserver file */
158  TQFile::remove(strDCOPServer);
159  printf("remove server file %s\n",(const char *)strDCOPServer);
160 
161  if(pid)
162  {
163  if(!dont_kill_dcop)
164  {
165 #ifdef Q_OS_WIN
166  killDCOPWin(pid);
167 #else
168  kill(pid, SIGTERM);
169 #endif
170  }
171  else
172  {
173 #ifdef Q_OS_WIN
174  killDCOPWin(pid);
175 #endif
176  }
177  }
178 
179 #ifdef Q_OS_WIN
180  if(wait_for_exit)
181  {
182  HANDLE hProcess = OpenProcess(SYNCHRONIZE,FALSE,(DWORD)pid);
183  if(hProcess)
184  {
185  WaitForSingleObject(hProcess,INFINITE);
186  CloseHandle(hProcess);
187  }
188  }
189 #else
190  while(wait_for_exit && (kill(pid, 0) == 0))
191  {
192  struct timeval tv;
193  tv.tv_sec = 0;
194  tv.tv_usec = 100000;
195  select(0,0,0,0,&tv);
196  }
197 #endif
198 }
199 
200 int main(int argc, char **argv)
201 {
202  TQCString host;
203 
204  int dont_kill_dcop = (argc == 2) && (strcmp(argv[1], "--nokill") == 0);
205  int wait_for_exit = (argc == 2) && (strcmp(argv[1], "--wait") == 0);
206 
207  cleanupDCOP(dont_kill_dcop, wait_for_exit);
208  return 0;
209 }
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
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dcop by doxygen 1.9.1
This website is maintained by Timothy Pearson.