void enable_interrupts( void ) { if( --mutex <= 0 ) { mutex = 0; if( sighup_pending ) sighup_handler( SIGHUP ); if( sigint_pending ) sigint_handler( SIGINT ); } }
/************************** *** Logging management *** **************************/ void logging_init() { /* Set the default handler */ g_log_set_default_handler(spop_log_handler, NULL); /* Open the log file */ g_log_file_path = config_get_string_opt("log_file", "/var/log/spopd.log"); if (strlen(g_log_file_path) > 0) { /* Install a handler so that we can reopen the file on SIGHUP */ if (signal(SIGHUP, sighup_handler) == SIG_ERR) g_error("Can't install signal handler: %s", g_strerror(errno)); /* And open the file using this handler :) */ sighup_handler(0); } }
/* #### sigcontext doesn't exist in Solaris. This should be updated to be correct for Solaris. */ static SIGTYPE sighandler (int sig) { if (audio_fd > 0) { reset_device (0); close (audio_fd); } if (sig == SIGHUP && sighup_handler) sighup_handler (sig); else if (sig == SIGINT && sigint_handler) sigint_handler (sig); else exit (1); }
/* Intercept SIGINT and SIGHUP in order to close the audio and mixer devices before terminating sound output; this requires reliable signals as provided by "syssignal.h" */ static SIGTYPE sighandler (int sig) { if (mix_fd > 0) { if (audio_vol >= 0) { ioctl(mix_fd,SOUND_MIXER_WRITE_PCM,&audio_vol); audio_vol = -1; } if (mix_fd != audio_fd) close(mix_fd); mix_fd = -1; } if (audio_fd > 0) { ioctl(audio_fd,SNDCTL_DSP_SYNC,NULL); ioctl(audio_fd,SNDCTL_DSP_RESET,NULL); close(audio_fd); audio_fd = -1; } if (sig == SIGHUP && sighup_handler) sighup_handler(sig); else if (sig == SIGINT && sigint_handler) sigint_handler(sig); else exit(1); }
int main(int argc, char **argv) { int option; while ((option = getopt(argc, argv, "ace:fhlnr:s:u:zLK:O:S:")) != -1) { switch (option) { case 'a': slflags |= IFF_LINK2; slflags &= ~IFF_LINK0; break; case 'c': slflags |= IFF_LINK0; slflags &= ~IFF_LINK2; break; case 'e': exit_cmd = (char*) strdup (optarg); break; case 'f': foreground = 1; break; case 'h': flow_control |= CRTSCTS; break; case 'l': modem_control = CLOCAL; /* clear HUPCL too */ break; case 'n': slflags |= IFF_LINK1; break; case 'r': redial_cmd = (char*) strdup (optarg); break; case 's': speed = atoi(optarg); break; case 'u': config_cmd = (char*) strdup (optarg); break; case 'z': redial_on_startup = 1; break; case 'L': uucp_lock = 1; break; case 'K': keepal = atoi(optarg); break; case 'O': outfill = atoi(optarg); break; case 'S': sl_unit = atoi(optarg); break; case '?': default: usage(); exit_handler(1); } } if (optind == argc - 1) dev = argv[optind]; if (optind < (argc - 1)) warnx("too many args, first='%s'", argv[optind]); if (optind > (argc - 1)) warnx("not enough args"); if (dev == NULL) { usage(); exit_handler(2); } if (strncmp(_PATH_DEV, dev, sizeof(_PATH_DEV) - 1)) { strcpy(tty_path, _PATH_DEV); strcat(tty_path, "/"); strncat(tty_path, dev, 10); dev = tty_path; } dvname = strrchr(dev, '/'); /* always succeeds */ dvname++; /* trailing tty pathname component */ snprintf(pidfilename, sizeof(pidfilename), "%sslattach.%s.pid", _PATH_VARRUN, dvname); printf("%s\n",pidfilename); if (!foreground) daemon(0,0); /* fork, setsid, chdir /, and close std*. */ /* daemon() closed stderr, so log errors from here on. */ openlog("slattach",LOG_CONS|LOG_PID,LOG_DAEMON); acquire_line(); /* get tty device as controlling terminal */ setup_line(0); /* configure for slip line discipline */ slip_discipline(); /* switch to slip line discipline */ /* upon INT log a timestamp and exit. */ if (signal(SIGINT,sigint_handler) == SIG_ERR) syslog(LOG_NOTICE,"cannot install SIGINT handler: %m"); /* upon TERM log a timestamp and exit. */ if (signal(SIGTERM,sigterm_handler) == SIG_ERR) syslog(LOG_NOTICE,"cannot install SIGTERM handler: %m"); /* upon HUP redial and reconnect. */ if (signal(SIGHUP,sighup_handler) == SIG_ERR) syslog(LOG_NOTICE,"cannot install SIGHUP handler: %m"); if (redial_on_startup) sighup_handler(0); else if (!(modem_control & CLOCAL)) { if (ioctl(fd, TIOCMGET, &comstate) < 0) syslog(LOG_NOTICE,"cannot get carrier state: %m"); if (!(comstate & TIOCM_CD)) { /* check for carrier */ /* force a redial if no carrier */ kill (getpid(), SIGHUP); } else configure_network(); } else configure_network(); /* configure the network if needed. */ for (;;) { sigset_t mask; sigemptyset(&mask); sigsuspend(&mask); } }