2 /* This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "FvwmIconMan.h"
23 #include "readconfig.h"
27 #include "libs/fvwmsignal.h"
28 #include "libs/Module.h"
29 #include "libs/FTips.h"
30 #include "libs/Parse.h"
34 FlocaleWinString
*FwinString
;
35 int mods_unused
= DEFAULT_MODS_UNUSED
;
37 static RETSIGTYPE
TerminateHandler(int);
39 char *copy_string(char **target
, const char *src
)
49 return *target
= NULL
;
53 ConsoleDebug(CORE
, "copy_string: 1: 0x%lx\n", (unsigned long)*target
);
60 ConsoleDebug(CORE
, "copy_string: 2\n");
61 *target
= (char *)safemalloc((len
+ 1) * sizeof(char));
63 ConsoleDebug(CORE
, "copy_string: 3\n");
73 struct malloc_header
*head
= (struct malloc_header
*)p
;
78 if (head
->magic
!= MALLOC_MAGIC
)
80 fprintf(stderr
, "Corrupted memory found in Free\n");
84 if (head
->len
> MemUsed
)
86 fprintf(stderr
, "Free block too big\n");
94 void PrintMemuse(void)
96 ConsoleDebug(CORE
, "Memory used: %ld\n", MemUsed
);
109 void PrintMemuse(void)
117 TerminateHandler(int sig
)
119 fvwmSetTerminate(sig
);
127 ConsoleDebug(CORE
, "Bye Bye\n");
132 DeadPipe(int nothing
)
142 fd_set readset
, saveset
;
143 fd_set_size_t fd_width
= x_fd
;
148 * Calculate which is descriptor is numerically higher:
149 * this determines how wide the descriptor set needs to be ...
151 if (fd_width
< fvwm_fd
[1])
153 fd_width
= fvwm_fd
[1];
158 FD_SET(fvwm_fd
[1], &saveset
);
159 FD_SET(x_fd
, &saveset
);
164 while (!isTerminated
)
166 /* Check the pipes for anything to read, and block if
167 * there is nothing there yet ...
171 if (fvwmSelect(fd_width
, &readset
, NULL
, NULL
, &tv
) < 0)
174 "Internal error with select: errno=%s\n",
180 if (FD_ISSET(x_fd
, &readset
) || FPending(theDisplay
))
184 if (FD_ISSET(fvwm_fd
[1], &readset
))
190 if ((ms
= FTipsCheck(theDisplay
)))
192 tv
.tv_sec
= ms
/ 1000;
193 tv
.tv_usec
= (ms
% 1000) * 1000;
204 main(int argc
, char **argv
)
208 #ifdef HAVE_LIBEFENCE
209 extern int EF_PROTECT_BELOW
, EF_PROTECT_FREE
;
211 EF_PROTECT_BELOW
= 1;
215 FlocaleInit(LC_CTYPE
, "", "", "FvwmIconMan");
217 OpenConsole(OUTPUT_FILE
);
222 MyName
= GetFileNameFromPath(argv
[0]);
226 if (strcasecmp(argv
[6], "Transient")==0 ||
227 strcasecmp(argv
[6], "-Transient") == 0)
229 globals
.transient
= 1;
236 ModuleLen
= strlen(MyName
) + 1;
237 Module
= safemalloc(ModuleLen
+1);
239 strcpy(Module
+1, MyName
);
244 "%s version %s should only be executed by fvwm!\n",
248 fvwm_fd
[0] = atoi(argv
[1]);
249 fvwm_fd
[1] = atoi(argv
[2]);
252 #ifdef HAVE_SIGACTION
254 struct sigaction sigact
;
256 sigemptyset(&sigact
.sa_mask
);
257 sigaddset(&sigact
.sa_mask
, SIGPIPE
);
258 sigaddset(&sigact
.sa_mask
, SIGINT
);
259 sigaddset(&sigact
.sa_mask
, SIGHUP
);
260 sigaddset(&sigact
.sa_mask
, SIGTERM
);
261 sigaddset(&sigact
.sa_mask
, SIGQUIT
);
263 sigact
.sa_flags
= SA_RESTART
;
267 sigact
.sa_handler
= TerminateHandler
;
269 sigaction(SIGPIPE
, &sigact
, NULL
);
270 sigaction(SIGINT
, &sigact
, NULL
);
271 sigaction(SIGHUP
, &sigact
, NULL
);
272 sigaction(SIGTERM
, &sigact
, NULL
);
273 sigaction(SIGQUIT
, &sigact
, NULL
);
276 /* We don't have sigaction(), so fall back to less robust methods. */
277 #ifdef USE_BSD_SIGNALS
285 signal(SIGPIPE
, TerminateHandler
);
286 signal(SIGINT
, TerminateHandler
);
287 signal(SIGHUP
, TerminateHandler
);
288 signal(SIGTERM
, TerminateHandler
);
289 signal(SIGQUIT
, TerminateHandler
);
290 #ifdef HAVE_SIGINTERRUPT
291 siginterrupt(SIGPIPE
, 0);
292 siginterrupt(SIGINT
, 0);
293 siginterrupt(SIGHUP
, 0);
294 siginterrupt(SIGTERM
, 0);
295 siginterrupt(SIGQUIT
, 0);
300 FlocaleAllocateWinString(&FwinString
);
302 for (i
= 0; i
< globals
.num_managers
; i
++)
307 assert(globals
.managers
);
310 fvwm_fd
, M_CONFIGURE_WINDOW
| M_RES_CLASS
| M_RES_NAME
|
311 M_ADD_WINDOW
| M_DESTROY_WINDOW
| M_ICON_NAME
|
312 M_DEICONIFY
| M_ICONIFY
| M_ICON_LOCATION
| M_END_WINDOWLIST
|
313 M_NEW_DESK
| M_NEW_PAGE
| M_FOCUS_CHANGE
| M_WINDOW_NAME
|
314 M_CONFIG_INFO
| M_SENDCONFIG
| M_VISIBLE_NAME
|
315 M_MINI_ICON
| M_STRING
| M_WINDOWSHADE
| M_DEWINDOWSHADE
);
316 /* extended messages */
317 SetMessageMask(fvwm_fd
, MX_VISIBLE_ICON_NAME
| MX_PROPERTY_CHANGE
);
319 SendText(fvwm_fd
, "Send_WindowList", 0);
321 /* tell fvwm we're running */
322 SendFinishedStartupNotification(fvwm_fd
);
324 /* Lock on send only for iconify and deiconify (for NoIconAction) */
325 SetSyncMask(fvwm_fd
, M_DEICONIFY
| M_ICONIFY
);
326 SetNoGrabMask(fvwm_fd
, M_DEICONIFY
| M_ICONIFY
);