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;
231 /* Optionally accept an alias to use as the transient
232 * FvwmIconMan instance.
242 ModuleLen
= strlen(MyName
) + 1;
243 Module
= safemalloc(ModuleLen
+1);
245 strcpy(Module
+1, MyName
);
250 "%s version %s should only be executed by fvwm!\n",
254 fvwm_fd
[0] = atoi(argv
[1]);
255 fvwm_fd
[1] = atoi(argv
[2]);
258 #ifdef HAVE_SIGACTION
260 struct sigaction sigact
;
262 sigemptyset(&sigact
.sa_mask
);
263 sigaddset(&sigact
.sa_mask
, SIGPIPE
);
264 sigaddset(&sigact
.sa_mask
, SIGINT
);
265 sigaddset(&sigact
.sa_mask
, SIGHUP
);
266 sigaddset(&sigact
.sa_mask
, SIGTERM
);
267 sigaddset(&sigact
.sa_mask
, SIGQUIT
);
269 sigact
.sa_flags
= SA_RESTART
;
273 sigact
.sa_handler
= TerminateHandler
;
275 sigaction(SIGPIPE
, &sigact
, NULL
);
276 sigaction(SIGINT
, &sigact
, NULL
);
277 sigaction(SIGHUP
, &sigact
, NULL
);
278 sigaction(SIGTERM
, &sigact
, NULL
);
279 sigaction(SIGQUIT
, &sigact
, NULL
);
282 /* We don't have sigaction(), so fall back to less robust methods. */
283 #ifdef USE_BSD_SIGNALS
291 signal(SIGPIPE
, TerminateHandler
);
292 signal(SIGINT
, TerminateHandler
);
293 signal(SIGHUP
, TerminateHandler
);
294 signal(SIGTERM
, TerminateHandler
);
295 signal(SIGQUIT
, TerminateHandler
);
296 #ifdef HAVE_SIGINTERRUPT
297 siginterrupt(SIGPIPE
, 0);
298 siginterrupt(SIGINT
, 0);
299 siginterrupt(SIGHUP
, 0);
300 siginterrupt(SIGTERM
, 0);
301 siginterrupt(SIGQUIT
, 0);
306 FlocaleAllocateWinString(&FwinString
);
308 for (i
= 0; i
< globals
.num_managers
; i
++)
313 assert(globals
.managers
);
316 fvwm_fd
, M_CONFIGURE_WINDOW
| M_RES_CLASS
| M_RES_NAME
|
317 M_ADD_WINDOW
| M_DESTROY_WINDOW
| M_ICON_NAME
|
318 M_DEICONIFY
| M_ICONIFY
| M_ICON_LOCATION
| M_END_WINDOWLIST
|
319 M_NEW_DESK
| M_NEW_PAGE
| M_FOCUS_CHANGE
| M_WINDOW_NAME
|
320 M_CONFIG_INFO
| M_SENDCONFIG
| M_VISIBLE_NAME
|
321 M_MINI_ICON
| M_STRING
| M_WINDOWSHADE
| M_DEWINDOWSHADE
);
322 /* extended messages */
323 SetMessageMask(fvwm_fd
, MX_VISIBLE_ICON_NAME
| MX_PROPERTY_CHANGE
);
325 SendText(fvwm_fd
, "Send_WindowList", 0);
327 /* tell fvwm we're running */
328 SendFinishedStartupNotification(fvwm_fd
);
330 /* Lock on send only for iconify and deiconify (for NoIconAction) */
331 SetSyncMask(fvwm_fd
, M_DEICONIFY
| M_ICONIFY
);
332 SetNoGrabMask(fvwm_fd
, M_DEICONIFY
| M_ICONIFY
);