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.
29 #include <gtk/gtkmain.h>
30 #include <gtk/gtkrc.h>
39 #include <sys/types.h>
42 #ifdef HAVE_STARTUP_NOTIFICATION
43 # define SN_API_NOT_YET_FROZEN
44 # include <libsn/sn-launchee.h>
45 # include <gdk/gdkx.h>
51 #include "mainwindow.h"
52 #include "folderview.h"
53 #include "summaryview.h"
54 #include "prefs_common.h"
55 #include "prefs_account.h"
56 #include "prefs_actions.h"
57 #include "prefs_ext_prog.h"
58 #include "prefs_fonts.h"
59 #include "prefs_msg_colors.h"
60 #include "prefs_spelling.h"
61 #include "prefs_themes.h"
62 #include "prefs_wrapping.h"
63 #include "prefs_display_header.h"
68 #include "manage_window.h"
69 #include "alertpanel.h"
70 #include "statusbar.h"
71 #include "addressbook.h"
79 #include "prefs_toolbar.h"
99 #ifdef HAVE_STARTUP_NOTIFICATION
100 static SnLauncheeContext *sn_context = NULL;
101 static SnDisplay *sn_display = NULL;
104 static gint lock_socket = -1;
105 static gint lock_socket_tag = 0;
109 ONLINE_MODE_DONT_CHANGE,
114 static struct RemoteCmd {
116 gboolean receive_all;
118 const gchar *compose_mailto;
119 GPtrArray *attach_files;
121 gboolean status_full;
122 GPtrArray *status_folders;
123 GPtrArray *status_full_folders;
130 static void parse_cmd_opt(int argc, char *argv[]);
132 static gint prohibit_duplicate_launch (void);
133 static gchar * get_crashfile_name (void);
134 static gint lock_socket_remove (void);
135 static void lock_socket_input_cb (gpointer data,
137 GdkInputCondition condition);
141 gchar *get_socket_name (void);
144 static void open_compose_new (const gchar *address,
145 GPtrArray *attach_files);
147 static void send_queue (void);
148 static void initial_processing (FolderItem *item, gpointer data);
149 static void quit_signal_handler (int sig);
150 static void install_basic_sighandlers (void);
151 static void exit_sylpheed (MainWindow *mainwin);
155 _("File `%s' already exists.\n"
156 "Can't create folder.")
159 #define MAKE_DIR_IF_NOT_EXIST(dir) \
161 if (!is_dir_exist(dir)) { \
162 if (is_file_exist(dir)) { \
164 (_("File `%s' already exists.\n" \
165 "Can't create folder."), \
169 if (make_dir(dir) < 0) \
174 static MainWindow *static_mainwindow;
176 #ifdef HAVE_STARTUP_NOTIFICATION
177 static void sn_error_trap_push(SnDisplay *display, Display *xdisplay)
179 gdk_error_trap_push();
182 static void sn_error_trap_pop(SnDisplay *display, Display *xdisplay)
184 gdk_error_trap_pop();
187 static void startup_notification_complete(gboolean with_window)
190 GtkWidget *hack = NULL;
193 /* this is needed to make the startup notification leave,
194 * if we have been launched from a menu.
195 * We have to display a window, so let it be very little */
196 hack = gtk_window_new(GTK_WINDOW_POPUP);
197 gtk_widget_set_uposition(hack, 0, 0);
198 gtk_widget_set_usize(hack, 1, 1);
199 gtk_widget_show(hack);
202 xdisplay = GDK_DISPLAY();
203 sn_display = sn_display_new(xdisplay,
206 sn_context = sn_launchee_context_new_from_environment(sn_display,
207 DefaultScreen(xdisplay));
209 if (sn_context != NULL)
211 sn_launchee_context_complete(sn_context);
212 sn_launchee_context_unref(sn_context);
213 sn_display_unref(sn_display);
216 #endif /* HAVE_STARTUP_NOTIFICATION */
218 void sylpheed_gtk_idle(void)
220 while(gtk_events_pending())
221 gtk_main_iteration();
224 int main(int argc, char *argv[])
228 FolderView *folderview;
230 if (!sylpheed_init(&argc, &argv)) {
234 prog_version = PROG_VERSION;
236 argv0 = g_strdup(argv[0]);
239 parse_cmd_opt(argc, argv);
244 gtk_init(&argc, &argv);
245 crash_main(cmd.crash_params);
248 crash_install_handlers();
250 install_basic_sighandlers();
252 /* check and create unix domain socket */
253 lock_socket = prohibit_duplicate_launch();
254 if (lock_socket < 0) {
255 #ifdef HAVE_STARTUP_NOTIFICATION
256 if(gtk_init_check(&argc, &argv))
257 startup_notification_complete(TRUE);
261 if (cmd.status || cmd.status_full) {
262 puts("0 Sylpheed not running.");
263 lock_socket_remove();
268 gtk_init(&argc, &argv);
271 gtk_widget_set_default_colormap(gdk_rgb_get_cmap());
272 gtk_widget_set_default_visual(gdk_rgb_get_visual());
274 #if USE_THREADS || USE_LDAP
276 if (!g_thread_supported())
277 g_error(_("g_thread is not supported by glib.\n"));
280 /* parse gtkrc files */
281 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtkrc-2.0",
283 gtk_rc_parse(userrc);
285 userrc = g_strconcat(get_home_dir(), G_DIR_SEPARATOR_S, ".gtk",
286 G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
287 gtk_rc_parse(userrc);
289 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "gtkrc-2.0", NULL);
290 gtk_rc_parse(userrc);
293 userrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
294 gtk_accel_map_load (userrc);
297 gtk_settings_set_long_property(gtk_settings_get_default(),
298 "gtk-can-change-accels",
299 (glong)TRUE, "XProperty");
301 CHDIR_RETURN_VAL_IF_FAIL(get_home_dir(), 1);
303 MAKE_DIR_IF_NOT_EXIST(RC_DIR);
304 MAKE_DIR_IF_NOT_EXIST(get_imap_cache_dir());
305 MAKE_DIR_IF_NOT_EXIST(get_news_cache_dir());
306 MAKE_DIR_IF_NOT_EXIST(get_mime_tmp_dir());
307 MAKE_DIR_IF_NOT_EXIST(get_tmp_dir());
308 MAKE_DIR_IF_NOT_EXIST(RC_DIR G_DIR_SEPARATOR_S "uidl");
310 set_log_file(RC_DIR G_DIR_SEPARATOR_S "sylpheed.log");
312 folder_system_init();
314 prefs_common_read_config();
318 prefs_ext_prog_init();
319 prefs_wrapping_init();
320 prefs_msg_colors_init();
322 gtkaspell_checkers_init();
323 prefs_spelling_init();
326 sock_set_io_timeout(prefs_common.io_timeout_secs);
328 prefs_actions_read_config();
329 prefs_display_header_read_config();
330 /* prefs_filtering_read_config(); */
331 addressbook_read_file();
332 renderer_read_config();
336 folderview_initialize();
341 mainwin = main_window_create
342 (prefs_common.sep_folder | prefs_common.sep_msg << 1);
343 folderview = mainwin->folderview;
345 /* register the callback of unix domain socket input */
346 lock_socket_tag = gdk_input_add(lock_socket,
347 GDK_INPUT_READ | GDK_INPUT_EXCEPTION,
348 lock_socket_input_cb,
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 folder_func_to_all_folders(initial_processing, (gpointer *)mainwin);
376 /* if Sylpheed crashed, rebuild caches */
377 if (!cmd.crash && is_file_exist(get_crashfile_name())) {
378 debug_print("Sylpheed crashed, checking for new messages in local folders\n");
379 folderview_check_new(NULL);
381 /* make the crash-indicator file */
382 str_write_to_file("foo", get_crashfile_name());
384 addressbook_read_file();
386 inc_autocheck_timer_init(mainwin);
388 /* ignore SIGPIPE signal for preventing sudden death of program */
389 signal(SIGPIPE, SIG_IGN);
391 if (cmd.online_mode == ONLINE_MODE_OFFLINE)
392 main_window_toggle_work_offline(mainwin, TRUE);
393 if (cmd.online_mode == ONLINE_MODE_ONLINE)
394 main_window_toggle_work_offline(mainwin, FALSE);
397 inc_all_account_mail(mainwin, FALSE,
398 prefs_common.newmail_notify_manu);
399 else if (prefs_common.chk_on_startup)
400 inc_all_account_mail(mainwin, TRUE,
401 prefs_common.newmail_notify_manu);
402 else if (cmd.receive)
403 inc_mail(mainwin, prefs_common.newmail_notify_manu);
405 gtk_widget_grab_focus(folderview->ctree);
408 open_compose_new(cmd.compose_mailto, cmd.attach_files);
409 if (cmd.attach_files) {
410 ptr_array_free_strings(cmd.attach_files);
411 g_ptr_array_free(cmd.attach_files, TRUE);
412 cmd.attach_files = NULL;
416 if (cmd.status_folders) {
417 g_ptr_array_free(cmd.status_folders, TRUE);
418 cmd.status_folders = NULL;
420 if (cmd.status_full_folders) {
421 g_ptr_array_free(cmd.status_full_folders, TRUE);
422 cmd.status_full_folders = NULL;
425 sylpheed_register_idle_function(sylpheed_gtk_idle);
427 prefs_toolbar_init();
429 plugin_load_all("GTK2");
431 static_mainwindow = mainwin;
433 #ifdef HAVE_STARTUP_NOTIFICATION
434 startup_notification_complete(FALSE);
438 exit_sylpheed(mainwin);
443 static void save_all_caches(FolderItem *item, gpointer data)
447 folder_item_write_cache(item);
450 static void exit_sylpheed(MainWindow *mainwin)
454 debug_print("shutting down\n");
456 inc_autocheck_timer_remove();
458 if (prefs_common.clean_on_exit)
459 main_window_empty_trash(mainwin, prefs_common.ask_on_clean);
461 /* save prefs for opened folder */
462 if(mainwin->folderview->opened)
466 item = gtk_ctree_node_get_row_data(GTK_CTREE(mainwin->folderview->ctree), mainwin->folderview->opened);
467 summary_save_prefs_to_folderitem(mainwin->folderview->summaryview, item);
470 /* save all state before exiting */
472 folder_func_to_all_folders(save_all_caches, NULL);
474 main_window_get_size(mainwin);
475 main_window_get_position(mainwin);
476 prefs_common_write_config();
477 account_write_config_all();
478 addressbook_export_to_file();
480 filename = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, MENU_RC, NULL);
481 gtk_accel_map_save(filename);
484 /* delete temporary files */
485 remove_all_files(get_mime_tmp_dir());
489 /* delete crashfile */
491 unlink(get_crashfile_name());
493 lock_socket_remove();
495 main_window_destroy(mainwin);
497 plugin_unload_all("GTK2");
499 prefs_toolbar_done();
501 addressbook_destroy();
505 prefs_ext_prog_done();
506 prefs_wrapping_done();
507 prefs_msg_colors_done();
509 prefs_spelling_done();
510 gtkaspell_checkers_quit();
516 static void parse_cmd_opt(int argc, char *argv[])
520 for (i = 1; i < argc; i++) {
521 if (!strncmp(argv[i], "--receive-all", 13))
522 cmd.receive_all = TRUE;
523 else if (!strncmp(argv[i], "--receive", 9))
525 else if (!strncmp(argv[i], "--compose", 9)) {
526 const gchar *p = argv[i + 1];
529 cmd.compose_mailto = NULL;
530 if (p && *p != '\0' && *p != '-') {
531 if (!strncmp(p, "mailto:", 7))
532 cmd.compose_mailto = p + 7;
534 cmd.compose_mailto = p;
537 } else if (!strncmp(argv[i], "--attach", 8)) {
538 const gchar *p = argv[i + 1];
541 while (p && *p != '\0' && *p != '-') {
542 if (!cmd.attach_files)
543 cmd.attach_files = g_ptr_array_new();
544 if (*p != G_DIR_SEPARATOR)
545 file = g_strconcat(sylpheed_get_startup_dir(),
550 g_ptr_array_add(cmd.attach_files, file);
554 } else if (!strncmp(argv[i], "--send", 6)) {
556 } else if (!strncmp(argv[i], "--version", 9)) {
557 puts("Sylpheed version " VERSION);
559 } else if (!strncmp(argv[i], "--status-full", 13)) {
560 const gchar *p = argv[i + 1];
562 cmd.status_full = TRUE;
563 while (p && *p != '\0' && *p != '-') {
564 if (!cmd.status_full_folders)
565 cmd.status_full_folders =
567 g_ptr_array_add(cmd.status_full_folders,
572 } else if (!strncmp(argv[i], "--status", 8)) {
573 const gchar *p = argv[i + 1];
576 while (p && *p != '\0' && *p != '-') {
577 if (!cmd.status_folders)
578 cmd.status_folders = g_ptr_array_new();
579 g_ptr_array_add(cmd.status_folders,
584 } else if (!strncmp(argv[i], "--online", 8)) {
585 cmd.online_mode = ONLINE_MODE_ONLINE;
586 } else if (!strncmp(argv[i], "--offline", 9)) {
587 cmd.online_mode = ONLINE_MODE_OFFLINE;
588 } else if (!strncmp(argv[i], "--help", 6)) {
589 g_print(_("Usage: %s [OPTION]...\n"),
590 g_basename(argv[0]));
592 puts(_(" --compose [address] open composition window"));
593 puts(_(" --attach file1 [file2]...\n"
594 " open composition window with specified files\n"
596 puts(_(" --receive receive new messages"));
597 puts(_(" --receive-all receive new messages of all accounts"));
598 puts(_(" --send send all queued messages"));
599 puts(_(" --status [folder]... show the total number of messages"));
600 puts(_(" --status-full [folder]...\n"
601 " show the status of each folder"));
602 puts(_(" --online switch to online mode"));
603 puts(_(" --offline switch to offline mode"));
604 puts(_(" --debug debug mode"));
605 puts(_(" --help display this help and exit"));
606 puts(_(" --version output version information and exit"));
607 puts(_(" --config-dir output configuration directory"));
610 } else if (!strncmp(argv[i], "--crash", 7)) {
612 cmd.crash_params = g_strdup(argv[i + 1]);
614 } else if (!strncmp(argv[i], "--config-dir", sizeof "--config-dir" - 1)) {
621 if (cmd.attach_files && cmd.compose == FALSE) {
623 cmd.compose_mailto = NULL;
627 static gint get_queued_message_num(void)
631 queue = folder_get_default_queue();
632 if (!queue) return -1;
634 folder_item_scan(queue);
635 return queue->total_msgs;
638 static void initial_processing(FolderItem *item, gpointer data)
640 MainWindow *mainwin = (MainWindow *)data;
643 g_return_if_fail(item);
644 buf = g_strdup_printf(_("Processing (%s)..."),
647 : _("top level folder"));
648 debug_print("%s\n", buf);
651 main_window_cursor_wait(mainwin);
653 if (item->prefs->enable_processing)
654 folder_item_apply_processing(item);
656 debug_print("done.\n");
657 STATUSBAR_POP(mainwin);
658 main_window_cursor_normal(mainwin);
661 static void draft_all_messages(void)
663 GList *compose_list = compose_get_compose_list();
667 for (elem = compose_list; elem != NULL && elem->data != NULL;
669 Compose *c = (Compose*)elem->data;
675 gboolean clean_quit(gpointer data)
677 static gboolean firstrun = TRUE;
683 /*!< Good idea to have the main window stored in a
684 * static variable so we can check that variable
685 * to see if we're really allowed to do things
686 * that actually the spawner is supposed to
687 * do (like: sending mail, composing messages).
688 * Because, really, if we're the spawnee, and
689 * we touch GTK stuff, we're hosed. See the
692 /* FIXME: Use something else to signal that we're
693 * in the original spawner, and not in a spawned
695 if (!static_mainwindow)
698 draft_all_messages();
700 exit_sylpheed(static_mainwindow);
706 void app_will_exit(GtkWidget *widget, gpointer data)
708 MainWindow *mainwin = data;
710 if (compose_get_compose_list()) {
711 gint val = alertpanel(_("Really quit?"),
712 _("Composing message exists."),
713 _("Draft them"), _("Discard them"), _("Don't quit"));
717 case G_ALERTALTERNATE:
720 draft_all_messages();
723 manage_window_focus_in(mainwin->window, NULL, NULL);
726 if (prefs_common.warn_queued_on_exit && get_queued_message_num() > 0) {
727 if (alertpanel(_("Queued messages"),
728 _("Some unsent messages are queued. Exit now?"),
729 _("OK"), _("Cancel"), NULL) != G_ALERTDEFAULT)
731 manage_window_focus_in(mainwin->window, NULL, NULL);
737 * CLAWS: want this public so crash dialog can delete the
743 gchar *get_socket_name(void)
745 static gchar *filename = NULL;
747 if (filename == NULL) {
748 filename = g_strdup_printf("%s%csylpheed-%d",
749 g_get_tmp_dir(), G_DIR_SEPARATOR,
756 static gchar *get_crashfile_name(void)
758 static gchar *filename = NULL;
760 if (filename == NULL) {
761 filename = g_strdup_printf("%s%csylpheed-crashed",
762 get_tmp_dir(), G_DIR_SEPARATOR);
768 static gint prohibit_duplicate_launch(void)
773 path = get_socket_name();
774 uxsock = fd_connect_unix(path);
777 return fd_open_unix(path);
780 /* remote command mode */
782 debug_print("another Sylpheed is already running.\n");
785 fd_write_all(uxsock, "receive_all\n", 12);
786 else if (cmd.receive)
787 fd_write_all(uxsock, "receive\n", 8);
788 else if (cmd.compose && cmd.attach_files) {
789 gchar *str, *compose_str;
792 if (cmd.compose_mailto)
793 compose_str = g_strdup_printf("compose_attach %s\n",
796 compose_str = g_strdup("compose_attach\n");
798 fd_write_all(uxsock, compose_str, strlen(compose_str));
801 for (i = 0; i < cmd.attach_files->len; i++) {
802 str = g_ptr_array_index(cmd.attach_files, i);
803 fd_write_all(uxsock, str, strlen(str));
804 fd_write_all(uxsock, "\n", 1);
807 fd_write_all(uxsock, ".\n", 2);
808 } else if (cmd.compose) {
811 if (cmd.compose_mailto)
812 compose_str = g_strdup_printf
813 ("compose %s\n", cmd.compose_mailto);
815 compose_str = g_strdup("compose\n");
817 fd_write_all(uxsock, compose_str, strlen(compose_str));
819 } else if (cmd.send) {
820 fd_write_all(uxsock, "send\n", 5);
821 } else if (cmd.online_mode == ONLINE_MODE_ONLINE) {
822 fd_write(uxsock, "online\n", 6);
823 } else if (cmd.online_mode == ONLINE_MODE_OFFLINE) {
824 fd_write(uxsock, "offline\n", 7);
825 } else if (cmd.status || cmd.status_full) {
828 const gchar *command;
832 command = cmd.status_full ? "status-full\n" : "status\n";
833 folders = cmd.status_full ? cmd.status_full_folders :
836 fd_write_all(uxsock, command, strlen(command));
837 for (i = 0; folders && i < folders->len; ++i) {
838 folder = g_ptr_array_index(folders, i);
839 fd_write_all(uxsock, folder, strlen(folder));
840 fd_write_all(uxsock, "\n", 1);
842 fd_write_all(uxsock, ".\n", 2);
844 fd_gets(uxsock, buf, sizeof(buf));
845 if (!strncmp(buf, ".\n", 2)) break;
849 fd_write_all(uxsock, "popup\n", 6);
855 static gint lock_socket_remove(void)
859 if (lock_socket < 0) return -1;
861 if (lock_socket_tag > 0)
862 gdk_input_remove(lock_socket_tag);
863 fd_close(lock_socket);
864 filename = get_socket_name();
870 static GPtrArray *get_folder_item_list(gint sock)
874 GPtrArray *folders = NULL;
877 fd_gets(sock, buf, sizeof(buf));
878 if (!strncmp(buf, ".\n", 2)) break;
880 if (!folders) folders = g_ptr_array_new();
881 item = folder_find_item_from_identifier(buf);
883 g_ptr_array_add(folders, item);
885 g_warning("no such folder: %s\n", buf);
891 static void lock_socket_input_cb(gpointer data,
893 GdkInputCondition condition)
895 MainWindow *mainwin = (MainWindow *)data;
899 sock = fd_accept(source);
900 fd_gets(sock, buf, sizeof(buf));
902 if (!strncmp(buf, "popup", 5)) {
903 main_window_popup(mainwin);
904 } else if (!strncmp(buf, "receive_all", 11)) {
905 inc_all_account_mail(mainwin, FALSE,
906 prefs_common.newmail_notify_manu);
907 } else if (!strncmp(buf, "receive", 7)) {
908 inc_mail(mainwin, prefs_common.newmail_notify_manu);
909 } else if (!strncmp(buf, "compose_attach", 14)) {
913 mailto = g_strdup(buf + strlen("compose_attach") + 1);
914 files = g_ptr_array_new();
915 while (fd_gets(sock, buf, sizeof(buf)) > 0) {
916 if (buf[0] == '.' && buf[1] == '\n') break;
918 g_ptr_array_add(files, g_strdup(buf));
920 open_compose_new(mailto, files);
921 ptr_array_free_strings(files);
922 g_ptr_array_free(files, TRUE);
924 } else if (!strncmp(buf, "compose", 7)) {
925 open_compose_new(buf + strlen("compose") + 1, NULL);
926 } else if (!strncmp(buf, "send", 4)) {
928 } else if (!strncmp(buf, "online", 6)) {
929 main_window_toggle_work_offline(mainwin, FALSE);
930 } else if (!strncmp(buf, "offline", 7)) {
931 main_window_toggle_work_offline(mainwin, TRUE);
932 } else if (!strncmp(buf, "status-full", 11) ||
933 !strncmp(buf, "status", 6)) {
937 folders = get_folder_item_list(sock);
938 status = folder_get_status
939 (folders, !strncmp(buf, "status-full", 11));
940 fd_write_all(sock, status, strlen(status));
941 fd_write_all(sock, ".\n", 2);
943 if (folders) g_ptr_array_free(folders, TRUE);
949 static void open_compose_new(const gchar *address, GPtrArray *attach_files)
954 Xstrdup_a(addr, address, return);
958 compose_new(NULL, addr, attach_files);
961 static void send_queue(void)
965 for (list = folder_get_list(); list != NULL; list = list->next) {
966 Folder *folder = list->data;
969 gint res = procmsg_send_queue
970 (folder->queue, prefs_common.savemsg);
973 alertpanel_error(_("Some errors occurred while sending queued messages."));
975 folder_item_scan(folder->queue);
980 static void quit_signal_handler(int sig)
982 debug_print("Quitting on signal %d\n", sig);
984 g_timeout_add(0, clean_quit, NULL);
987 static void install_basic_sighandlers()
990 struct sigaction act;
995 sigaddset(&mask, SIGTERM);
998 sigaddset(&mask, SIGINT);
1001 sigaddset(&mask, SIGHUP);
1004 act.sa_handler = quit_signal_handler;
1009 sigaction(SIGTERM, &act, 0);
1012 sigaction(SIGINT, &act, 0);
1015 sigaction(SIGHUP, &act, 0);
1018 sigprocmask(SIG_UNBLOCK, &mask, 0);