pidgin/gtkmain.c

changeset 29991
37e306c31983
parent 29662
fc97e81006c3
child 30477
d05e44644f80
equal deleted inserted replaced
29990:198caf410219 29991:37e306c31983
165 pid = waitpid(-1, &status, WNOHANG); 165 pid = waitpid(-1, &status, WNOHANG);
166 } while (pid != 0 && pid != (pid_t)-1); 166 } while (pid != 0 && pid != (pid_t)-1);
167 167
168 if ((pid == (pid_t) - 1) && (errno != ECHILD)) { 168 if ((pid == (pid_t) - 1) && (errno != ECHILD)) {
169 char errmsg[BUFSIZ]; 169 char errmsg[BUFSIZ];
170 snprintf(errmsg, BUFSIZ, "Warning: waitpid() returned %d", pid); 170 snprintf(errmsg, sizeof(errmsg), "Warning: waitpid() returned %d", pid);
171 perror(errmsg); 171 perror(errmsg);
172 } 172 }
173 } 173 }
174 174
175 static void sighandler(int sig) 175 static void sighandler(int sig)
537 sigset_t sigset; 537 sigset_t sigset;
538 RETSIGTYPE (*prev_sig_disp)(int); 538 RETSIGTYPE (*prev_sig_disp)(int);
539 char errmsg[BUFSIZ]; 539 char errmsg[BUFSIZ];
540 GIOChannel *signal_channel; 540 GIOChannel *signal_channel;
541 GIOStatus signal_status; 541 GIOStatus signal_status;
542 guint signal_channel_watcher;
542 #ifndef DEBUG 543 #ifndef DEBUG
543 char *segfault_message_tmp; 544 char *segfault_message_tmp;
544 #endif 545 #endif
545 GError *error = NULL; 546 GError *error;
546 #endif 547 #endif
547 int opt; 548 int opt;
548 gboolean gui_check; 549 gboolean gui_check;
549 gboolean debug_enabled; 550 gboolean debug_enabled;
550 gboolean migration_failed = FALSE; 551 gboolean migration_failed = FALSE;
606 ); 607 );
607 608
608 /* we have to convert the message (UTF-8 to console 609 /* we have to convert the message (UTF-8 to console
609 charset) early because after a segmentation fault 610 charset) early because after a segmentation fault
610 it's not a good practice to allocate memory */ 611 it's not a good practice to allocate memory */
612 error = NULL;
611 segfault_message = g_locale_from_utf8(segfault_message_tmp, 613 segfault_message = g_locale_from_utf8(segfault_message_tmp,
612 -1, NULL, NULL, &error); 614 -1, NULL, NULL, &error);
613 if (segfault_message != NULL) { 615 if (segfault_message != NULL) {
614 g_free(segfault_message_tmp); 616 g_free(segfault_message_tmp);
615 } 617 }
650 if (signal_status != G_IO_STATUS_NORMAL) { 652 if (signal_status != G_IO_STATUS_NORMAL) {
651 fprintf(stderr, "Failed to set the signal channel to raw " 653 fprintf(stderr, "Failed to set the signal channel to raw "
652 "binary: %s", error->message); 654 "binary: %s", error->message);
653 exit(1); 655 exit(1);
654 } 656 }
655 g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL); 657 signal_channel_watcher = g_io_add_watch(signal_channel, G_IO_IN, mainloop_sighandler, NULL);
658 g_io_channel_unref(signal_channel);
656 659
657 /* Let's not violate any PLA's!!!! */ 660 /* Let's not violate any PLA's!!!! */
658 /* jseymour: whatever the fsck that means */ 661 /* jseymour: whatever the fsck that means */
659 /* Robot101: for some reason things like gdm like to block * 662 /* Robot101: for some reason things like gdm like to block *
660 * useful signals like SIGCHLD, so we unblock all the ones we * 663 * useful signals like SIGCHLD, so we unblock all the ones we *
661 * declare a handler for. thanks JSeymour and Vann. */ 664 * declare a handler for. thanks JSeymour and Vann. */
662 if (sigemptyset(&sigset)) { 665 if (sigemptyset(&sigset)) {
663 snprintf(errmsg, BUFSIZ, "Warning: couldn't initialise empty signal set"); 666 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't initialise empty signal set");
664 perror(errmsg); 667 perror(errmsg);
665 } 668 }
666 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) { 669 for(sig_indx = 0; catch_sig_list[sig_indx] != -1; ++sig_indx) {
667 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) { 670 if((prev_sig_disp = signal(catch_sig_list[sig_indx], sighandler)) == SIG_ERR) {
668 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d for catching", 671 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d for catching",
669 catch_sig_list[sig_indx]); 672 catch_sig_list[sig_indx]);
670 perror(errmsg); 673 perror(errmsg);
671 } 674 }
672 if(sigaddset(&sigset, catch_sig_list[sig_indx])) { 675 if(sigaddset(&sigset, catch_sig_list[sig_indx])) {
673 snprintf(errmsg, BUFSIZ, "Warning: couldn't include signal %d for unblocking", 676 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't include signal %d for unblocking",
674 catch_sig_list[sig_indx]); 677 catch_sig_list[sig_indx]);
675 perror(errmsg); 678 perror(errmsg);
676 } 679 }
677 } 680 }
678 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) { 681 for(sig_indx = 0; ignore_sig_list[sig_indx] != -1; ++sig_indx) {
679 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) { 682 if((prev_sig_disp = signal(ignore_sig_list[sig_indx], SIG_IGN)) == SIG_ERR) {
680 snprintf(errmsg, BUFSIZ, "Warning: couldn't set signal %d to ignore", 683 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't set signal %d to ignore",
681 ignore_sig_list[sig_indx]); 684 ignore_sig_list[sig_indx]);
682 perror(errmsg); 685 perror(errmsg);
683 } 686 }
684 } 687 }
685 688
686 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) { 689 if (sigprocmask(SIG_UNBLOCK, &sigset, NULL)) {
687 snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals"); 690 snprintf(errmsg, sizeof(errmsg), "Warning: couldn't unblock signals");
688 perror(errmsg); 691 perror(errmsg);
689 } 692 }
690 #endif 693 #endif
691 694
692 /* scan command-line options */ 695 /* scan command-line options */
975 978
976 gtk_main(); 979 gtk_main();
977 980
978 #ifdef HAVE_SIGNAL_H 981 #ifdef HAVE_SIGNAL_H
979 g_free(segfault_message); 982 g_free(segfault_message);
983 g_source_remove(signal_channel_watcher);
984 close(signal_sockets[0]);
985 close(signal_sockets[1]);
980 #endif 986 #endif
981 987
982 #ifdef _WIN32 988 #ifdef _WIN32
983 winpidgin_cleanup(); 989 winpidgin_cleanup();
984 #endif 990 #endif

mercurial