2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2004 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkrc.h>
37 #include <sys/types.h>
40 #ifdef HAVE_STARTUP_NOTIFICATION
41 # define SN_API_NOT_YET_FROZEN
42 # include <libsn/sn-launchee.h>
43 # include <gdk/gdkx.h>
49 #include "mainwindow.h"
50 #include "folderview.h"
51 #include "summaryview.h"
52 #include "prefs_common.h"
53 #include "prefs_account.h"
54 #include "prefs_actions.h"
55 #include "prefs_ext_prog.h"
56 #include "prefs_fonts.h"
57 #include "prefs_msg_colors.h"
58 #include "prefs_spelling.h"
59 #include "prefs_themes.h"
60 #include "prefs_wrapping.h"
61 #include "prefs_display_header.h"
66 #include "manage_window.h"
67 #include "alertpanel.h"
68 #include "statusbar.h"
69 #include "addressbook.h"
77 #include "prefs_toolbar.h"
97 #ifdef HAVE_STARTUP_NOTIFICATION
98 static SnLauncheeContext *sn_context = NULL;
99 static SnDisplay *sn_display = NULL;
102 static gint lock_socket = -1;
103 static gint lock_socket_tag = 0;
107 ONLINE_MODE_DONT_CHANGE,
112 static struct RemoteCmd {
114 gboolean receive_all;
116 const gchar *compose_mailto;
117 GPtrArray *attach_files;
119 gboolean status_full;
120 GPtrArray *status_folders;
121 GPtrArray *status_full_folders;
128 static void parse_cmd_opt(int argc, char *argv[]);
130 static gint prohibit_duplicate_launch (void);
131 static gchar * get_crashfile_name (void);
132 static gint lock_socket_remove (void);
133 static void lock_socket_input_cb (gpointer data,
135 GdkInputCondition condition);
139 gchar *get_socket_name (void);
142 static void open_compose_new (const gchar *address,
143 GPtrArray *attach_files);
145 static void send_queue (void);
146 static void initial_processing (FolderItem *item, gpointer data);
147 static void quit_signal_handler (int sig);
148 static void install_basic_sighandlers (void);
149 static void exit_sylpheed (MainWindow *mainwin);
153 _("File `%s' already exists.\n"
154 "Can't create folder.")
157 #define MAKE_DIR_IF_NOT_EXIST(dir) \
159 if (!is_dir_exist(dir)) { \
160 if (is_file_exist(dir)) { \
162 (_("File `%s' already exists.\n" \
163 "Can't create folder."), \
167 if (make_dir(dir) < 0) \
172 static MainWindow *static_mainwindow;
174 #ifdef HAVE_STARTUP_NOTIFICATION
175 static void sn_error_trap_push(SnDisplay *display, Display *xdisplay)
177 gdk_error_trap_push();
180 static void sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
182 gdk_error_trap_pop();
185 static void startup_notification_complete(gboolean with_window)
188 GtkWidget *hack = NULL;
191 /* this is needed to make the startup notification leave,
192 * if we have been launched from a menu.
193 * We have to display a window, so let it be very little */
194 hack = gtk_window_new(GTK_WINDOW_POPUP);
195 gtk_widget_set_uposition(hack, 0, 0);
196 gtk_widget_set_usize(hack, 1, 1);
197 gtk_widget_show(hack);
200 xdisplay = GDK_DISPLAY();
201 sn_display = sn_display_new(xdisplay,
204 sn_context = sn_launchee_context_new_from_environment(sn_display,
205 DefaultScreen(xdisplay));
207 if (sn_context != NULL)
209 sn_launchee_context_complete(sn_context);
210 sn_launchee_context_unref(sn_context);
211 sn_display_unref(sn_display);
214 #endif /* HAVE_STARTUP_NOTIFICATION */
216 void sylpheed_gtk_idle(void)
218 while(gtk_events_pending())
219 gtk_main_iteration();
222 int main(int argc, char *argv[])
226 FolderView *folderview;
228 if (!sylpheed_init(&argc, &argv)) {
232 prog_version = PROG_VERSION;
234 argv0 = g_strdup(argv[0]);
237 parse_cmd_opt(argc, argv);
242 gtk_init(&argc, &argv);
243 crash_main(cmd.crash_params);
246 crash_install_handlers();
248 install_basic_sighandlers();
250 /* check and create unix domain socket */
251 lock_socket = prohibit_duplicate_launch();
252 if (lock_socket < 0) {
253 #ifdef HAVE_STARTUP_NOTIFICATION
254 if(gtk_init_check(&argc, &argv))
255 startup_notification_complete(TRUE);
260 if (cmd.status || cmd.status_full) {
261 puts("0 Sylpheed not running.");
262 lock_socket_remove();
267 gtk_init(&argc, &argv);
270 gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
271 gtk_widget_set_default_visual(gdk_rgb_get_visual());
273 #if USE_THREADS || USE_LDAP
275 if (!g_thread_supported())
276 g_error(_("g_thread is not supported by glib.\n"));
279 /* parse gtkrc files */
280 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
282 gtk_rc_parse(userrc);
284 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
285 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
286 gtk_rc_parse(userrc);
288 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
289 gtk_rc_parse(userrc);
292 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
293 gtk_accel_map_load (userrc);
296 gtk_settings_set_long_property(gtk_settings_get_default(),
297 "gtk-can-change-accels",
298 (glong)TRUE, "XProperty");
300 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
302 MAKE_DIR_IF_NOT_EXIST(RC_DIR);
303 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
304 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
305 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
306 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
307 MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
309 set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
311 folder_system_init();
313 prefs_common_read_config();
317 prefs_ext_prog_init();
318 prefs_wrapping_init();
319 prefs_msg_colors_init();
321 gtkaspell_checkers_init();
322 prefs_spelling_init();
325 sock_set_io_timeout(prefs_common.io_timeout_secs);
327 prefs_actions_read_config();
328 prefs_display_header_read_config();
329 /* prefs_filtering_read_config(); */
330 addressbook_read_file();
331 renderer_read_config();
335 folderview_initialize();
340 mainwin = main_window_create
341 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
342 folderview = mainwin->folderview;
344 /* register the callback of unix domain socket input */
345 lock_socket_tag = gdk_input_add(lock_socket,
346 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
347 lock_socket_input_cb,
350 prefs_account_init();
351 account_read_config_all();
353 if (folder_read_list() < 0) {
354 if (!run_wizard(mainwin, TRUE))
359 if (!account_get_list()) {
360 if (!run_wizard(mainwin, FALSE))
362 account_read_config_all();
363 if(!account_get_list())
364 exit_sylpheed(mainwin);
367 account_set_missing_folder();
368 folder_set_missing_folders();
369 folderview_set(folderview);
371 prefs_matcher_read_config();
373 /* make one all-folder processing before using sylpheed */
374 main_window_cursor_wait(mainwin);
375 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
376 main_window_cursor_normal(mainwin);
378 /* if Sylpheed crashed, rebuild caches */
379 if (!cmd.crash && is_file_exist(get_crashfile_name())) {
380 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
381 folderview_check_new(NULL);
383 /* make the crash-indicator file */
384 str_write_to_file("foo", get_crashfile_name());
386 addressbook_read_file();
388 inc_autocheck_timer_init(mainwin);
390 /* ignore SIGPIPE signal for preventing sudden death of program */
391 signal(SIGPIPE, SIG_IGN);
393 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
394 main_window_toggle_work_offline(mainwin, TRUE);
395 if (cmd.online_mode == ONLINE_MODE_ONLINE)
396 main_window_toggle_work_offline(mainwin, FALSE);
399 inc_all_account_mail(mainwin, FALSE,
400 prefs_common.newmail_notify_manu);
401 else if (prefs_common.chk_on_startup)
402 inc_all_account_mail(mainwin, TRUE,
403 prefs_common.newmail_notify_manu);
404 else if (cmd.receive)
405 inc_mail(mainwin, prefs_common.newmail_notify_manu);
407 gtk_widget_grab_focus(folderview->ctree);
410 open_compose_new(cmd.compose_mailto, cmd.attach_files);
411 if (cmd.attach_files) {
412 ptr_array_free_strings(cmd.attach_files);
413 g_ptr_array_free(cmd.attach_files, TRUE);
414 cmd.attach_files = NULL;
418 if (cmd.status_folders) {
419 g_ptr_array_free(cmd.status_folders, TRUE);
420 cmd.status_folders = NULL;
422 if (cmd.status_full_folders) {
423 g_ptr_array_free(cmd.status_full_folders, TRUE);
424 cmd.status_full_folders = NULL;
427 sylpheed_register_idle_function(sylpheed_gtk_idle);
429 prefs_toolbar_init();
431 plugin_load_all("GTK2");
433 static_mainwindow = mainwin;
435 #ifdef HAVE_STARTUP_NOTIFICATION
436 startup_notification_complete(FALSE);
440 exit_sylpheed(mainwin);
445 static void save_all_caches(FolderItem *item, gpointer data)
449 folder_item_write_cache(item);
452 static void exit_sylpheed(MainWindow *mainwin)
456 debug_print("shutting down\n");
458 inc_autocheck_timer_remove();
460 if (prefs_common.clean_on_exit)
461 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
463 /* save prefs for opened folder */
464 if(mainwin->folderview->opened)
468 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
469 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
472 /* save all state before exiting */
474 folder_func_to_all_folders(save_all_caches, NULL);
476 main_window_get_size(mainwin);
477 main_window_get_position(mainwin);
478 prefs_common_write_config();
479 account_write_config_all();
480 addressbook_export_to_file();
482 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
483 gtk_accel_map_save(filename);
486 /* delete temporary files */
487 remove_all_files(get_mime_tmp_dir());
491 /* delete crashfile */
493 unlink(get_crashfile_name());
495 lock_socket_remove();
497 main_window_destroy(mainwin);
499 plugin_unload_all("GTK2");
501 prefs_toolbar_done();
503 addressbook_destroy();
507 prefs_ext_prog_done();
508 prefs_wrapping_done();
509 prefs_msg_colors_done();
511 prefs_spelling_done();
512 gtkaspell_checkers_quit();
518 static void parse_cmd_opt(int argc, char *argv[])
522 for (i = 1; i < argc; i++) {
523 if (!strncmp(argv[i], "--receive-all", 13))
524 cmd.receive_all = TRUE;
525 else if (!strncmp(argv[i], "--receive", 9))
527 else if (!strncmp(argv[i], "--compose", 9)) {
528 const gchar *p = argv[i + 1];
531 cmd.compose_mailto = NULL;
532 if (p && *p != '\0' && *p != '-') {
533 if (!strncmp(p, "mailto:", 7))
534 cmd.compose_mailto = p + 7;
536 cmd.compose_mailto = p;
539 } else if (!strncmp(argv[i], "--attach", 8)) {
540 const gchar *p = argv[i + 1];
543 while (p && *p != '\0' && *p != '-') {
544 if (!cmd.attach_files)
545 cmd.attach_files = g_ptr_array_new();
546 if (*p != G_DIR_SEPARATOR)
547 file = g_strconcat(sylpheed_get_startup_dir(),
552 g_ptr_array_add(cmd.attach_files, file);
556 } else if (!strncmp(argv[i], "--send", 6)) {
558 } else if (!strncmp(argv[i], "--version", 9)) {
559 puts("Sylpheed version " VERSION);
561 } else if (!strncmp(argv[i], "--status-full", 13)) {
562 const gchar *p = argv[i + 1];
564 cmd.status_full = TRUE;
565 while (p && *p != '\0' && *p != '-') {
566 if (!cmd.status_full_folders)
567 cmd.status_full_folders =
569 g_ptr_array_add(cmd.status_full_folders,
574 } else if (!strncmp(argv[i], "--status", 8)) {
575 const gchar *p = argv[i + 1];
578 while (p && *p != '\0' && *p != '-') {
579 if (!cmd.status_folders)
580 cmd.status_folders = g_ptr_array_new();
581 g_ptr_array_add(cmd.status_folders,
586 } else if (!strncmp(argv[i], "--online", 8)) {
587 cmd.online_mode = ONLINE_MODE_ONLINE;
588 } else if (!strncmp(argv[i], "--offline", 9)) {
589 cmd.online_mode = ONLINE_MODE_OFFLINE;
590 } else if (!strncmp(argv[i], "--help", 6)) {
591 gchar *base = g_path_get_basename(argv[0]);
592 g_print(_("Usage: %s [OPTION]...\n"), base);
594 puts(_(" --compose [address] open composition window"));
595 puts(_(" --attach file1 [file2]...\n"
596 " open composition window with specified files\n"
598 puts(_(" --receive receive new messages"));
599 puts(_(" --receive-all receive new messages of all accounts"));
600 puts(_(" --send send all queued messages"));
601 puts(_(" --status [folder]... show the total number of messages"));
602 puts(_(" --status-full [folder]...\n"
603 " show the status of each folder"));
604 puts(_(" --online switch to online mode"));
605 puts(_(" --offline switch to offline mode"));
606 puts(_(" --debug debug mode"));
607 puts(_(" --help display this help and exit"));
608 puts(_(" --version output version information and exit"));
609 puts(_(" --config-dir output configuration directory"));
613 } else if (!strncmp(argv[i], "--crash", 7)) {
615 cmd.crash_params = g_strdup(argv[i + 1]);
617 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
624 if (cmd.attach_files && cmd.compose == FALSE) {
626 cmd.compose_mailto = NULL;
630 static gint get_queued_message_num(void)
634 queue = folder_get_default_queue();
635 if (!queue) return -1;
637 folder_item_scan(queue);
638 return queue->total_msgs;
641 static void initial_processing(FolderItem *item, gpointer data)
643 MainWindow *mainwin = (MainWindow *)data;
646 g_return_if_fail(item);
647 buf = g_strdup_printf(_("Processing (%s)..."),
650 : _("top level folder"));
651 debug_print("%s\n", buf);
655 if (item->prefs->enable_processing)
656 folder_item_apply_processing(item);
658 debug_print("done.\n");
659 STATUSBAR_POP(mainwin);
662 static void draft_all_messages(void)
664 GList *compose_list = compose_get_compose_list();
668 for (elem = compose_list; elem != NULL && elem->data != NULL;
670 Compose *c = (Compose*)elem->data;
676 gboolean clean_quit(gpointer data)
678 static gboolean firstrun = TRUE;
684 /*!< Good idea to have the main window stored in a
685 * static variable so we can check that variable
686 * to see if we're really allowed to do things
687 * that actually the spawner is supposed to
688 * do (like: sending mail, composing messages).
689 * Because, really, if we're the spawnee, and
690 * we touch GTK stuff, we're hosed. See the
693 /* FIXME: Use something else to signal that we're
694 * in the original spawner, and not in a spawned
696 if (!static_mainwindow)
699 draft_all_messages();
701 exit_sylpheed(static_mainwindow);
707 void app_will_exit(GtkWidget *widget, gpointer data)
709 MainWindow *mainwin = data;
711 if (compose_get_compose_list()) {
712 gint val = alertpanel(_("Really quit?"),
713 _("Composing message exists."),
714 _("Draft them"), _("Discard them"), _("Don't quit"));
718 case G_ALERTALTERNATE:
721 draft_all_messages();
724 manage_window_focus_in(mainwin->window, NULL, NULL);
727 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
728 if (alertpanel(_("Queued messages"),
729 _("Some unsent messages are queued. Exit now?"),
730 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
732 manage_window_focus_in(mainwin->window, NULL, NULL);
738 * CLAWS: want this public so crash dialog can delete the
744 gchar *get_socket_name(void)
746 static gchar *filename = NULL;
748 if (filename == NULL) {
749 filename = g_strdup_printf("%s%csylpheed-%d",
750 g_get_tmp_dir(), G_DIR_SEPARATOR,
757 static gchar *get_crashfile_name(void)
759 static gchar *filename = NULL;
761 if (filename == NULL) {
762 filename = g_strdup_printf("%s%csylpheed-crashed",
763 get_tmp_dir(), G_DIR_SEPARATOR);
769 static gint prohibit_duplicate_launch(void)
774 path = get_socket_name();
775 uxsock = fd_connect_unix(path);
778 return fd_open_unix(path);
781 /* remote command mode */
783 debug_print("another Sylpheed is already running.\n");
786 fd_write_all(uxsock, "receive_all\n", 12);
787 else if (cmd.receive)
788 fd_write_all(uxsock, "receive\n", 8);
789 else if (cmd.compose && cmd.attach_files) {
790 gchar *str, *compose_str;
793 if (cmd.compose_mailto)
794 compose_str = g_strdup_printf("compose_attach %s\n",
797 compose_str = g_strdup("compose_attach\n");
799 fd_write_all(uxsock, compose_str, strlen(compose_str));
802 for (i = 0; i < cmd.attach_files->len; i++) {
803 str = g_ptr_array_index(cmd.attach_files, i);
804 fd_write_all(uxsock, str, strlen(str));
805 fd_write_all(uxsock, "\n", 1);
808 fd_write_all(uxsock, ".\n", 2);
809 } else if (cmd.compose) {
812 if (cmd.compose_mailto)
813 compose_str = g_strdup_printf
814 ("compose %s\n", cmd.compose_mailto);
816 compose_str = g_strdup("compose\n");
818 fd_write_all(uxsock, compose_str, strlen(compose_str));
820 } else if (cmd.send) {
821 fd_write_all(uxsock, "send\n", 5);
822 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
823 fd_write(uxsock, "online\n", 6);
824 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
825 fd_write(uxsock, "offline\n", 7);
826 } else if (cmd.status || cmd.status_full) {
829 const gchar *command;
833 command = cmd.status_full ? "status-full\n" : "status\n";
834 folders = cmd.status_full ? cmd.status_full_folders :
837 fd_write_all(uxsock, command, strlen(command));
838 for (i = 0; folders && i < folders->len; ++i) {
839 folder = g_ptr_array_index(folders, i);
840 fd_write_all(uxsock, folder, strlen(folder));
841 fd_write_all(uxsock, "\n", 1);
843 fd_write_all(uxsock, ".\n", 2);
845 fd_gets(uxsock, buf, sizeof(buf));
846 if (!strncmp(buf, ".\n", 2)) break;
850 fd_write_all(uxsock, "popup\n", 6);
856 static gint lock_socket_remove(void)
860 if (lock_socket < 0) return -1;
862 if (lock_socket_tag > 0)
863 gdk_input_remove(lock_socket_tag);
864 fd_close(lock_socket);
865 filename = get_socket_name();
871 static GPtrArray *get_folder_item_list(gint sock)
875 GPtrArray *folders = NULL;
878 fd_gets(sock, buf, sizeof(buf));
879 if (!strncmp(buf, ".\n", 2)) break;
881 if (!folders) folders = g_ptr_array_new();
882 item = folder_find_item_from_identifier(buf);
884 g_ptr_array_add(folders, item);
886 g_warning("no such folder: %s\n", buf);
892 static void lock_socket_input_cb(gpointer data,
894 GdkInputCondition condition)
896 MainWindow *mainwin = (MainWindow *)data;
900 sock = fd_accept(source);
901 fd_gets(sock, buf, sizeof(buf));
903 if (!strncmp(buf, "popup", 5)) {
904 main_window_popup(mainwin);
905 } else if (!strncmp(buf, "receive_all", 11)) {
906 inc_all_account_mail(mainwin, FALSE,
907 prefs_common.newmail_notify_manu);
908 } else if (!strncmp(buf, "receive", 7)) {
909 inc_mail(mainwin, prefs_common.newmail_notify_manu);
910 } else if (!strncmp(buf, "compose_attach", 14)) {
914 mailto = g_strdup(buf + strlen("compose_attach") + 1);
915 files = g_ptr_array_new();
916 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
917 if (buf[0] == '.' && buf[1] == '\n') break;
919 g_ptr_array_add(files, g_strdup(buf));
921 open_compose_new(mailto, files);
922 ptr_array_free_strings(files);
923 g_ptr_array_free(files, TRUE);
925 } else if (!strncmp(buf, "compose", 7)) {
926 open_compose_new(buf + strlen("compose") + 1, NULL);
927 } else if (!strncmp(buf, "send", 4)) {
929 } else if (!strncmp(buf, "online", 6)) {
930 main_window_toggle_work_offline(mainwin, FALSE);
931 } else if (!strncmp(buf, "offline", 7)) {
932 main_window_toggle_work_offline(mainwin, TRUE);
933 } else if (!strncmp(buf, "status-full", 11) ||
934 !strncmp(buf, "status", 6)) {
938 folders = get_folder_item_list(sock);
939 status = folder_get_status
940 (folders, !strncmp(buf, "status-full", 11));
941 fd_write_all(sock, status, strlen(status));
942 fd_write_all(sock, ".\n", 2);
944 if (folders) g_ptr_array_free(folders, TRUE);
950 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
955 Xstrdup_a(addr, address, return);
959 compose_new(NULL, addr, attach_files);
962 static void send_queue(void)
966 for (list = folder_get_list(); list != NULL; list = list->next) {
967 Folder *folder = list->data;
970 gint res = procmsg_send_queue
971 (folder->queue, prefs_common.savemsg);
974 alertpanel_error(_("Some errors occurred while sending queued messages."));
976 folder_item_scan(folder->queue);
981 static void quit_signal_handler(int sig)
983 debug_print("Quitting on signal %d\n", sig);
985 g_timeout_add(0, clean_quit, NULL);
988 static void install_basic_sighandlers()
991 struct sigaction act;
996 sigaddset(&mask, SIGTERM);
999 sigaddset(&mask, SIGINT);
1002 sigaddset(&mask, SIGHUP);
1005 act.sa_handler = quit_signal_handler;
1010 sigaction(SIGTERM, &act, 0);
1013 sigaction(SIGINT, &act, 0);
1016 sigaction(SIGHUP, &act, 0);
1019 sigprocmask(SIG_UNBLOCK, &mask, 0);