static int handle_netdev_show(int argc, char *argv[], int optind) { if (argc <= optind + 1) { return show_any(); } const char *devname = argv[optind + 1]; int fd = socket(PF_LAPD, SOCK_SEQPACKET, 0); if (fd < 0) { print_usage("Cannot create socket: %s\n", strerror(errno)); return 1; } struct ifreq ifr; strncpy(ifr.ifr_name, devname, IFNAMSIZ); if (ioctl(fd, SIOCGIFFLAGS, &ifr) < 0) { close(fd); fprintf(stderr, "ioctl(SIOCGIFFLAGS): %s\n", strerror(errno)); } printf("%s: %s %s\n", ifr.ifr_name, (ifr.ifr_flags & IFF_UP) ? "UP" : "DOWN", (ifr.ifr_flags & IFF_ALLMULTI) ? "NT" : "TE"); return 0; }
static void signal_handler( int num, siginfo_t *info, void *foo ) { ucontext_t *uctx = foo; #else static void signal_handler( int num ) { #endif DirectResult ret; int i; DirectLink *l, *n; SigHandled *sig = NULL; void *addr = NULL; // fflush(stdout); // fflush(stderr); for (i=0; i<NUM_SIGS_TO_HANDLE; i++) { if (sigs_handled[i].signum == num) { sig = &sigs_handled[i]; /* Using SA_RESETHAND, so... */ sig->signum = -1; break; } } /* ret = direct_sigaction( num, &sig->old_action, NULL ); if (ret) { D_DERROR( ret, "Direct/Signals: Unable to restore previous handler for signal %d!\n", num ); sig = NULL; } */ #ifndef SA_SIGINFO D_LOG( Direct_Signals, FATAL, " --> Caught signal %d <--\n", num ); #else if (info && info > (siginfo_t*) 0x100) { bool shown = false; /* Kernel genrated signal? */ if (info->si_code > 0 && info->si_code < 0x80) { addr = info->si_addr; switch (num) { case SIGSEGV: shown = show_segv( info, uctx ); break; case SIGBUS: shown = show_bus( info, uctx ); break; case SIGILL: shown = show_ill( info, uctx ); break; case SIGFPE: shown = show_fpe( info, uctx ); break; default: D_LOG( Direct_Signals, FATAL, " --> Caught signal %d <--\n", info->si_signo ); addr = NULL; shown = true; break; } } else shown = show_any( info, uctx ); if (!shown) D_LOG( Direct_Signals, FATAL, " --> Caught signal %d (unknown origin) <--\n", info->si_signo ); } else D_LOG( Direct_Signals, FATAL, " --> Caught signal %d, no siginfo available <--\n", num ); #endif direct_log_lock( NULL ); direct_trace_print_stacks(); direct_log_unlock( NULL ); /* Loop through all handlers. */ direct_mutex_lock( &handlers_lock ); direct_list_foreach_safe (l, n, handlers) { DirectSignalHandler *handler = (DirectSignalHandler*) l; if (handler->num != num && handler->num != DIRECT_SIGNAL_ANY) continue; switch (handler->func( num, addr, handler->ctx )) { case DSHR_OK: break; case DSHR_REMOVE: direct_list_remove( &handlers, &handler->link ); D_MAGIC_CLEAR( handler ); D_FREE( handler ); break; case DSHR_RESUME: D_LOG( Direct_Signals, FATAL, " '-> cured!\n" ); direct_mutex_unlock( &handlers_lock ); if (sig) { ret = direct_sigaction( num, &sig->new_action, NULL ); if (ret) D_DERROR( ret, "Direct/Signals: Unable to reinstall handler for signal %d!\n", num ); else sig->signum = num; } return; default: D_BUG( "unknown result" ); break; } }