Changes in owl.c [1d21d9f:3b8a563]
Legend:
- Unmodified
- Added
- Removed
-
owl.c
r1d21d9f r3b8a563 41 41 char *confdir; 42 42 bool debug; 43 bool rm_debug;44 43 } owl_options; 45 44 … … 50 49 fprintf(stderr, " -n,--no-subs don't load zephyr subscriptions\n"); 51 50 fprintf(stderr, " -d,--debug enable debugging\n"); 52 fprintf(stderr, " -D,--remove-debug enable debugging and delete previous debug file\n");53 51 fprintf(stderr, " -v,--version print the Barnowl version number and exit\n"); 54 52 fprintf(stderr, " -h,--help print this help message\n"); … … 66 64 { "tty", 1, 0, 't' }, 67 65 { "debug", 0, 0, 'd' }, 68 { "remove-debug", 0, 0, 'D' },69 66 { "version", 0, 0, 'v' }, 70 67 { "help", 0, 0, 'h' }, … … 88 85 opts->tty = g_strdup(optarg); 89 86 break; 90 case 'D':91 opts->rm_debug = 1;92 /* fallthrough */93 87 case 'd': 94 88 opts->debug = 1; … … 166 160 * was ignored due to user settings or otherwise. 167 161 */ 168 staticint owl_process_message(owl_message *m) {162 int owl_process_message(owl_message *m) { 169 163 const owl_filter *f; 170 164 /* if this message it on the puntlist, nuke it and continue */ … … 251 245 } 252 246 253 static gboolean owl_process_messages_prepare(GSource *source, int *timeout) {254 *timeout = -1;255 return owl_global_messagequeue_pending(&g);256 }257 258 static gboolean owl_process_messages_check(GSource *source) {259 return owl_global_messagequeue_pending(&g);260 }261 262 247 /* 263 248 * Process any new messages we have waiting in the message queue. 249 * Returns 1 if any messages were added to the message list, and 0 otherwise. 264 250 */ 265 static gboolean owl_process_messages_dispatch(GSource *source, GSourceFunc callback, gpointer user_data) { 251 int owl_process_messages(owl_ps_action *d, void *p) 252 { 266 253 int newmsgs=0; 267 254 int followlast = owl_global_should_followlast(&g); … … 287 274 owl_mainwin_redisplay(owl_global_get_mainwin(&g)); 288 275 } 289 return TRUE; 290 } 291 292 static GSourceFuncs owl_process_messages_funcs = { 293 owl_process_messages_prepare, 294 owl_process_messages_check, 295 owl_process_messages_dispatch, 296 NULL 297 }; 298 299 void owl_process_input_char(owl_input j) 300 { 301 int ret; 302 303 owl_global_set_lastinputtime(&g, time(NULL)); 304 ret = owl_keyhandler_process(owl_global_get_keyhandler(&g), j); 305 if (ret!=0 && ret!=1) { 306 owl_function_makemsg("Unable to handle keypress"); 307 } 276 return newmsgs; 308 277 } 309 278 … … 365 334 } 366 335 367 static void sig_handler_main_thread(void *data) { 368 int sig = GPOINTER_TO_INT(data); 369 370 owl_function_debugmsg("Got signal %d", sig); 371 if (sig == SIGWINCH) { 336 void sig_handler(int sig, siginfo_t *si, void *data) 337 { 338 if (sig==SIGWINCH) { 339 /* we can't inturrupt a malloc here, so it just sets a flag 340 * schedulding a resize for later 341 */ 372 342 owl_function_resize(); 373 } else if (sig == SIGTERM || sig == SIGHUP) { 343 } else if (sig==SIGPIPE || sig==SIGCHLD) { 344 /* Set a flag and some info that we got the sigpipe 345 * so we can record that we got it and why... */ 346 owl_global_set_errsignal(&g, sig, si); 347 } else if (sig==SIGTERM || sig==SIGHUP) { 374 348 owl_function_quit(); 375 } else if (sig == SIGINT && owl_global_take_interrupt(&g)) { 376 owl_input in; 377 in.ch = in.uch = owl_global_get_startup_tio(&g)->c_cc[VINTR]; 378 owl_process_input_char(in); 379 } 380 } 381 382 static void sig_handler(const siginfo_t *siginfo, void *data) { 383 /* If it was an interrupt, set a flag so we can handle it earlier if 384 * needbe. sig_handler_main_thread will check the flag to make sure 385 * no one else took it. */ 386 if (siginfo->si_signo == SIGINT) { 387 owl_global_add_interrupt(&g); 388 } 389 /* Send a message to the main thread. */ 390 owl_select_post_task(sig_handler_main_thread, 391 GINT_TO_POINTER(siginfo->si_signo), NULL); 392 } 393 394 #define CHECK_RESULT(s, syscall) \ 395 G_STMT_START { \ 396 if ((syscall) != 0) { \ 397 perror((s)); \ 398 exit(1); \ 399 } \ 400 } G_STMT_END 349 } 350 } 351 352 void sigint_handler(int sig, siginfo_t *si, void *data) 353 { 354 owl_global_set_interrupted(&g); 355 } 356 357 static int owl_errsignal_pre_select_action(owl_ps_action *a, void *data) 358 { 359 siginfo_t si; 360 int signum; 361 if ((signum = owl_global_get_errsignal_and_clear(&g, &si)) > 0) { 362 owl_function_error("Got unexpected signal: %d %s (code: %d band: %ld errno: %d)", 363 signum, signum==SIGPIPE?"SIGPIPE":"SIG????", 364 si.si_code, si.si_band, si.si_errno); 365 } 366 return 0; 367 } 401 368 402 369 void owl_register_signal_handlers(void) { 403 struct sigaction sig_ignore = { .sa_handler = SIG_IGN }; 404 struct sigaction sig_default = { .sa_handler = SIG_DFL }; 405 sigset_t sigset; 406 int ret, i; 407 const int signals[] = { SIGABRT, SIGBUS, SIGCHLD, SIGFPE, SIGHUP, SIGILL, 408 SIGINT, SIGQUIT, SIGSEGV, SIGTERM, SIGWINCH }; 409 410 /* Sanitize our signals; the mask and dispositions from our parent 411 * aren't really useful. Signal list taken from equivalent code in 412 * Chromium. */ 413 CHECK_RESULT("sigemptyset", sigemptyset(&sigset)); 414 if ((ret = pthread_sigmask(SIG_SETMASK, &sigset, NULL)) != 0) { 415 errno = ret; 416 perror("pthread_sigmask"); 417 } 418 for (i = 0; i < G_N_ELEMENTS(signals); i++) { 419 CHECK_RESULT("sigaction", sigaction(signals[i], &sig_default, NULL)); 420 } 421 422 /* Turn off SIGPIPE; we check the return value of write. */ 423 CHECK_RESULT("sigaction", sigaction(SIGPIPE, &sig_ignore, NULL)); 424 425 /* Register some signals with the signal thread. */ 426 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGWINCH)); 427 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGTERM)); 428 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGHUP)); 429 CHECK_RESULT("sigaddset", sigaddset(&sigset, SIGINT)); 430 owl_signal_init(&sigset, sig_handler, NULL); 370 struct sigaction sigact; 371 372 /* signal handler */ 373 /*sigact.sa_handler=sig_handler;*/ 374 sigact.sa_sigaction=sig_handler; 375 sigemptyset(&sigact.sa_mask); 376 sigact.sa_flags=SA_SIGINFO; 377 sigaction(SIGWINCH, &sigact, NULL); 378 sigaction(SIGALRM, &sigact, NULL); 379 sigaction(SIGPIPE, &sigact, NULL); 380 sigaction(SIGTERM, &sigact, NULL); 381 sigaction(SIGHUP, &sigact, NULL); 382 383 sigact.sa_sigaction=sigint_handler; 384 sigaction(SIGINT, &sigact, NULL); 431 385 } 432 386 … … 481 435 482 436 #endif /* OWL_STDERR_REDIR */ 437 438 static int owl_refresh_pre_select_action(owl_ps_action *a, void *data) 439 { 440 owl_colorpair_mgr *cpmgr; 441 442 /* if a resize has been scheduled, deal with it */ 443 owl_global_check_resize(&g); 444 /* update the terminal if we need to */ 445 owl_window_redraw_scheduled(); 446 /* On colorpair shortage, reset and redraw /everything/. NOTE: if we 447 * still overflow, this be useless work. With 8-colors, we get 64 448 * pairs. With 256-colors, we get 32768 pairs with ext-colors 449 * support and 256 otherwise. */ 450 cpmgr = owl_global_get_colorpair_mgr(&g); 451 if (cpmgr->overflow) { 452 owl_function_debugmsg("colorpairs: used all %d pairs; reset pairs and redraw.", 453 owl_util_get_colorpairs()); 454 owl_fmtext_reset_colorpairs(cpmgr); 455 owl_function_full_redisplay(); 456 owl_window_redraw_scheduled(); 457 } 458 return 0; 459 } 460 483 461 484 462 int main(int argc, char **argv, char **env) … … 490 468 const char *dir; 491 469 owl_options opts; 492 GSource *source;493 470 494 471 if (!GLIB_CHECK_VERSION (2, 12, 0)) … … 505 482 g.load_initial_subs = opts.load_initial_subs; 506 483 484 owl_register_signal_handlers(); 507 485 owl_start_curses(); 508 486 509 487 /* owl global init */ 510 488 owl_global_init(&g); 511 if (opts.rm_debug) unlink(OWL_DEBUG_FILE);512 489 if (opts.debug) owl_global_set_debug_on(&g); 513 490 if (opts.confdir) owl_global_set_confdir(&g, opts.confdir); … … 516 493 g_strfreev(argv_copy); 517 494 owl_global_set_haveaim(&g); 518 519 owl_register_signal_handlers();520 495 521 496 /* register STDIN dispatch; throw away return, we won't need it */ … … 577 552 owl_function_debugmsg("startup: executing perl startup, if applicable"); 578 553 perlout = owl_perlconfig_execute("BarnOwl::Hooks::_startup();"); 579 if (perlout)g_free(perlout);554 g_free(perlout); 580 555 581 556 /* welcome message */ … … 610 585 owl_global_push_context(&g, OWL_CTX_INTERACTIVE|OWL_CTX_RECV, NULL, "recv", NULL); 611 586 612 source = owl_window_redraw_source_new(); 613 g_source_attach(source, NULL); 614 g_source_unref(source); 615 616 source = g_source_new(&owl_process_messages_funcs, sizeof(GSource)); 617 g_source_attach(source, NULL); 618 g_source_unref(source); 587 owl_select_add_pre_select_action(owl_refresh_pre_select_action, NULL, NULL); 588 owl_select_add_pre_select_action(owl_process_messages, NULL, NULL); 589 owl_select_add_pre_select_action(owl_errsignal_pre_select_action, NULL, NULL); 619 590 620 591 owl_function_debugmsg("startup: entering main loop"); … … 623 594 /* Shut down everything. */ 624 595 owl_zephyr_shutdown(); 625 owl_signal_shutdown();626 596 owl_shutdown_curses(); 627 597 return 0;
Note: See TracChangeset
for help on using the changeset viewer.