本文整理汇总了C++中siginterrupt函数的典型用法代码示例。如果您正苦于以下问题:C++ siginterrupt函数的具体用法?C++ siginterrupt怎么用?C++ siginterrupt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了siginterrupt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main (int argc, char *argv[]){
sigset_t allsignals;
sigemptyset(&allsignals);
sigaddset(&allsignals, SIGUSR1);
//sigprocmask(SIG_UNBLOCK, &usr1set, NULL);
sigfillset(&allsignals);
sigprocmask(SIG_BLOCK, &allsignals, NULL);
fflush(stdout);
siginterrupt(SIGUSR1,0);
struct sigaction action, oldaction;
action.sa_handler=entradadatos;
action.sa_mask=allsignals;
action.sa_flags=SA_RESTART;
sigaction (SIGUSR1,&action, NULL);
siginterrupt(SIGUSR1,0);
//(void) signal(SIGUSR1,entradadatos);
printf("Name sacoboxeo\n");
printf("Colour F0F0F0 0F0F0F\n");
printf("RobotOption %i 1\n",USE_NON_BLOCKING);
printf("RobotOption %i %i\n",SIGNAL,SIGUSR1);
sigprocmask(SIG_UNBLOCK, &allsignals, NULL);
while(1){
fflush(stdout);
}
return(0);
}
示例2: okay
/*
* do the "paper work"
* - save my own pid in /var/run/$0.{port#}.pid
*/
static void
okay(int pn)
{
int fd;
char *p, numbuf[80];
if (pidfile[0] == '\0') {
p = rindex(prog, '/');
p = (p == NULL) ? prog : p + 1;
snprintf(pidfile, sizeof pidfile,
"%s%s.%d.pid", _PATH_VARRUN, p, pn);
}
fd = open(pidfile, O_WRONLY|O_CREAT|O_EXCL, 0644);
if (fd < 0) {
perror(pidfile);
exit(21);
}
siginterrupt(SIGTERM, 1);
siginterrupt(SIGHUP, 1);
signal(SIGTERM, quit);
signal(SIGHUP, quit);
signal(SIGINT, quit);
snprintf(numbuf, sizeof numbuf, "%d\n", getpid());
if (write(fd, numbuf, strlen(numbuf)) < 0) {
perror(pidfile);
quit(23);
}
(void) close(fd);
}
示例3: install_signal_handlers
static void install_signal_handlers(void)
{
#ifdef SIGHUP
/* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(ERRNO));
#endif
#ifdef SIGPIPE
/* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(ERRNO));
#endif
#ifdef SIGALRM
/* ignore SIGALRM signal */
if((old_sigalrm_handler = signal(SIGALRM, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGALRM handler: %s", strerror(ERRNO));
#endif
#ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(ERRNO));
else
siginterrupt(SIGINT, 1);
#endif
#ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(ERRNO));
else
siginterrupt(SIGTERM, 1);
#endif
}
示例4: gotsignal
void gotsignal(int signum) {
char msg[100];
switch(signum) {
case SIGUSR1: // kill -s USR1 pid
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
sprintf(msg, "got SIGUSR1 signal:%d\n", signum);
break;
case SIGINT:
signal(SIGINT, gotsignal); siginterrupt(SIGINT, 0);
sprintf(msg, "got SIGINT signal, quitting...:%d\n", signum);
quit=signum;
break;
case SIGQUIT:
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
sprintf(msg, "got SIGQUIT signal, quitting...:%d\n", signum);
quit=signum;
break;
case SIGBUS:
//vmeish(); not to be called (if called, it kills dims process)
sprintf(msg, "got SIGBUS signal:%d\n", signum);
break;
default:
sprintf(msg, "got unknown signal:%d\n", signum);
};
prtLog(msg);
}
示例5: main
int main(int argc, char **argv) {
infolog_SetFacility((char *)"CTP");
infolog_SetStream("",0);
setlinebuf(stdout);
signal(SIGUSR1, gotsignal); siginterrupt(SIGUSR1, 0);
signal(SIGQUIT, gotsignal); siginterrupt(SIGQUIT, 0);
signal(SIGBUS, gotsignal); siginterrupt(SIGBUS, 0);
micrate(-1);
if(micratepresent()) {
SLOT_S= 30; // was 60 before 10.11.2011
} else {
SLOT_S= 5; // in lab just 5secs
};
/*
if(envcmp("VMESITE", "ALICE")==0) {
udpsock= udpopens("alidcscom835", send2PORT);
} else {
udpsock= udpopens("avmes", send2PORT);
}; */
ds_register();
while(1) {
int rc=0;
rc= update_qpll();
if(rc!=0) break;
//printf("sleteping 10secs...\n"); fflush(stdout);
//sleep(1) ;
//msleep(1000);
dtq_sleep(2);
//printf("slept 10secs...\n"); fflush(stdout);
};
ds_stop();
exit(0);
}
示例6: install_signal_handlers
static void install_signal_handlers(void)
{
#ifdef SIGHUP
/* ignore SIGHUP signal */
if((old_sighup_handler = signal(SIGHUP, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGHUP handler: %s", strerror(errno));
#endif
#ifdef SIGPIPE
/* ignore SIGPIPE signal */
if((old_sigpipe_handler = signal(SIGPIPE, SIG_IGN)) == SIG_ERR)
logmsg("cannot install SIGPIPE handler: %s", strerror(errno));
#endif
#ifdef SIGINT
/* handle SIGINT signal with our exit_signal_handler */
if((old_sigint_handler = signal(SIGINT, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGINT handler: %s", strerror(errno));
else
siginterrupt(SIGINT, 1);
#endif
#ifdef SIGTERM
/* handle SIGTERM signal with our exit_signal_handler */
if((old_sigterm_handler = signal(SIGTERM, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGTERM handler: %s", strerror(errno));
else
siginterrupt(SIGTERM, 1);
#endif
#if defined(SIGBREAK) && defined(WIN32)
/* handle SIGBREAK signal with our exit_signal_handler */
if((old_sigbreak_handler = signal(SIGBREAK, exit_signal_handler)) == SIG_ERR)
logmsg("cannot install SIGBREAK handler: %s", strerror(errno));
else
siginterrupt(SIGBREAK, 1);
#endif
}
示例7: test_bye
test_code_t
test_bye (gnutls_session_t session)
{
int ret;
char data[20];
int secs = 6;
#ifndef _WIN32
int old;
signal (SIGALRM, got_alarm);
#endif
sprintf (prio_str, INIT_STR
ALL_CIPHERS ":" ALL_COMP ":" ALL_CERTTYPES ":%s:" ALL_MACS ":"
ALL_KX ":%s", protocol_str, rest);
_gnutls_priority_set_direct (session, prio_str);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return ret;
ret = gnutls_bye (session, GNUTLS_SHUT_WR);
if (ret < 0)
return TEST_FAILED;
#ifndef _WIN32
old = siginterrupt (SIGALRM, 1);
alarm (secs);
#else
setsockopt ((int) gnutls_transport_get_ptr (session), SOL_SOCKET,
SO_RCVTIMEO, (char *) &secs, sizeof (int));
#endif
do
{
ret = gnutls_record_recv (session, data, sizeof (data));
}
while (ret > 0);
#ifndef _WIN32
siginterrupt (SIGALRM, old);
#else
if (WSAGetLastError () == WSAETIMEDOUT ||
WSAGetLastError () == WSAECONNABORTED)
alrm = 1;
#endif
if (ret == 0)
return TEST_SUCCEED;
if (alrm == 0)
return TEST_UNSURE;
return TEST_FAILED;
}
示例8: test_bye
test_code_t
test_bye (gnutls_session session)
{
int ret;
char data[20];
int old, secs = 6;
#ifndef _WIN32
signal (SIGALRM, got_alarm);
#endif
ADD_ALL_CIPHERS (session);
ADD_ALL_COMP (session);
ADD_ALL_CERTTYPES (session);
ADD_ALL_PROTOCOLS (session);
ADD_ALL_MACS (session);
ADD_ALL_KX (session);
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, xcred);
ret = do_handshake (session);
if (ret == TEST_FAILED)
return ret;
ret = gnutls_bye (session, GNUTLS_SHUT_WR);
if (ret < 0)
return TEST_FAILED;
#ifndef _WIN32
old = siginterrupt (SIGALRM, 1);
alarm (secs);
#else
setsockopt (gnutls_transport_get_ptr (session), SOL_SOCKET, SO_RCVTIMEO,
(char *) &secs, sizeof (int));
#endif
do
{
ret = gnutls_record_recv (session, data, sizeof (data));
}
while (ret > 0);
#ifndef _WIN32
siginterrupt (SIGALRM, old);
#else
if (WSAGetLastError () == WSAETIMEDOUT ||
WSAGetLastError () == WSAECONNABORTED)
alrm = 1;
#endif
if (ret == 0)
return TEST_SUCCEED;
if (alrm == 0)
return TEST_UNSURE;
return TEST_FAILED;
}
示例9: voice_install_signal_handler
int voice_install_signal_handler(void)
{
lprintf(L_NOISE, "%s: Installing signal handlers", program_name);
if (signals_initialized)
{
lprintf(L_NOISE, "%s: Signal handlers are already installed",
program_name);
return(OK);
};
old_sigalrm = signal(SIGALRM, signal_sigalrm);
old_sigchld = signal(SIGCHLD, signal_sigchld);
old_sighup = signal(SIGHUP, signal_sighup);
old_sigint = signal(SIGINT, signal_sigint);
old_sigpipe = signal(SIGPIPE, signal_sigpipe);
old_sigquit = signal(SIGQUIT, signal_sigquit);
old_sigterm = signal(SIGTERM, signal_sigterm);
old_sigusr1 = signal(SIGUSR1, signal_sigusr1);
old_sigusr2 = signal(SIGUSR2, signal_sigusr2);
#ifdef HAVE_SIGINTERRUPT
siginterrupt(SIGALRM, TRUE);
siginterrupt(SIGCHLD, TRUE);
siginterrupt(SIGHUP, TRUE);
siginterrupt(SIGINT, TRUE);
siginterrupt(SIGPIPE, TRUE);
siginterrupt(SIGQUIT, TRUE);
siginterrupt(SIGTERM, TRUE);
siginterrupt(SIGUSR1, TRUE);
siginterrupt(SIGUSR2, TRUE);
#endif
alarm(cvd.watchdog_timeout.d.i);
signals_initialized = TRUE;
return(OK);
}
示例10: listen_for_hijackers
/**
* Listen on listener socket
*
*/
static int listen_for_hijackers ( struct hijack_listener *listener,
const char *interface ) {
int fd;
pid_t child;
int rc;
logmsg ( LOG_INFO, "Listening on %s\n", listener->sun.sun_path );
while ( ! signalled ) {
/* Accept new connection, interruptibly */
siginterrupt ( SIGINT, 1 );
siginterrupt ( SIGHUP, 1 );
fd = accept ( listener->fd, NULL, 0 );
siginterrupt ( SIGINT, 0 );
siginterrupt ( SIGHUP, 0 );
if ( fd < 0 ) {
if ( errno == EINTR ) {
continue;
} else {
logmsg ( LOG_ERR, "accept failed: %s\n",
strerror ( errno ) );
goto err;
}
}
/* Fork child process */
child = fork();
if ( child < 0 ) {
logmsg ( LOG_ERR, "fork failed: %s\n",
strerror ( errno ) );
goto err;
}
if ( child == 0 ) {
/* I am the child; run the hijacker */
rc = run_hijacker ( interface, fd );
close ( fd );
exit ( rc );
}
close ( fd );
}
logmsg ( LOG_INFO, "Stopped listening on %s\n",
listener->sun.sun_path );
return 0;
err:
if ( fd >= 0 )
close ( fd );
return -1;
}
示例11: check_signal
void
check_signal()
/* check if a signal has been received and handle it */
{
/* we reinstall the signal handler functions here and not directly in the handlers,
* as it is not supported on some systems (HP-UX) and makes fcron crash */
if (sig_chld > 0) {
wait_chld();
sig_chld = 0;
#ifdef HAVE_SIGNAL
(void)signal(SIGCHLD, sigchild_handler);
siginterrupt(SIGCHLD, 0);
#endif
}
if (sig_conf > 0) {
if (sig_conf == 1) {
/* update configuration */
synchronize_dir(".", 0);
sig_conf = 0;
#ifdef HAVE_SIGNAL
signal(SIGHUP, sighup_handler);
siginterrupt(SIGHUP, 0);
#endif
}
else {
/* reload all configuration */
reload_all(".");
sig_conf = 0;
#ifdef HAVE_SIGNAL
signal(SIGUSR1, sigusr1_handler);
siginterrupt(SIGUSR1, 0);
#endif
}
}
if (sig_debug > 0) {
print_schedule();
debug_opt = (debug_opt > 0) ? 0 : 1;
explain("debug_opt = %d", debug_opt);
sig_debug = 0;
#ifdef HAVE_SIGNAL
signal(SIGUSR2, sigusr2_handler);
siginterrupt(SIGUSR2, 0);
#endif
}
}
示例12: get_con
int get_con(char* servername, int port)
{
struct hostent *h2;
struct sockaddr_in sin;
inrp_by_user = YEA;
show_message("½¨Á¢Á¬ÏßÖÐ (Ctrl-C ÖжÏ) ...");
if ((h2 = gethostbyname(servername)) == NULL)
sin.sin_addr.s_addr = inet_addr(servername);
else
memcpy(&sin.sin_addr.s_addr, h2->h_addr, h2->h_length);
sin.sin_family = AF_INET;
if (!(a = socket(AF_INET, SOCK_STREAM, 0)))
return -1;
sin.sin_port = htons(port);
signal(SIGALRM, (void *) interrupt_chk);
siginterrupt(SIGINT, 1);
alarm(1);
if ((connect(a, (struct sockaddr *) & sin, sizeof(sin))))
{
signal(SIGALRM, SIG_IGN);
return -1;
}
signal(SIGALRM, SIG_IGN);
inrp_by_user = NA;
write(0, " ", 1);
show_message(NULL);
return 1;
}
示例13: signal
/*---------------------------------------------*/ void gotsignal(int signum) {
char msg[100];
// SIGUSR1: // kill -s USR1 pid
signal(signum, gotsignal); siginterrupt(signum, 0);
sprintf(msg, "got signal:%d", signum); prtLog(msg);
if((signum==SIGUSR1) || (signum==SIGQUIT) ) {
int np;
np= getNAllPartitions();
if(np!=0) {
//quit=1; // wait till all partitions stopped
//sprintf(msg, "Waiting for the stop of all partitions before exit");
sprintf(msg, "Unsuccessful attempt to stop ctpproxy, %d partitions active", np);
prtLog(msg);
pq_send(mq_sendmsg,"quitignored");
} else {
quit=10; // stop immediately (no partitions loaded)
};
} else if((signum==SIGKILL) || (signum==SIGINT) ) {
sprintf(msg, "SIGINT, immediate stop"); prtLog(msg);
quit=11; // =9. stop immediately
};
#ifdef PQWAY
if(quit>9) {
pq_send(mq_sendmsg,"quit");
};
#endif
}
示例14: MR_signal_should_restart
void
MR_signal_should_restart(int sig, MR_bool restart)
{
#if defined(MR_HAVE_SIGACTION)
struct sigaction act;
if (sigaction(sig, NULL, &act) != 0) {
MR_perror("error setting signal system call behaviour");
exit(1);
}
if (restart) {
act.sa_flags |= SA_RESTART;
} else {
act.sa_flags &= ~SA_RESTART;
}
if (sigaction(sig, &act, NULL) != 0) {
MR_perror("error setting signal system call behaviour");
exit(1);
}
#elif defined(MR_HAVE_SIGINTERRUPT)
if (siginterrupt(sig, !restart) != 0) {
MR_perror("error setting signal system call behaviour");
exit(1);
}
#endif
}
示例15: joe_set_signal
/* wrapper to hide signal interface differrencies */
int joe_set_signal(int signum, sighandler_t handler)
{
int retval;
#ifdef HAVE_SIGACTION
struct sigaction sact;
memset(&sact, 0, sizeof(sact));
sact.sa_handler = handler;
#ifdef SA_INTERRUPT
sact.sa_flags = SA_INTERRUPT;
#endif
retval = sigaction(signum, &sact, NULL);
#elif defined(HAVE_SIGVEC)
struct sigvec svec;
memset(&svec, 0, sizeof(svec));
svec.sv_handler = handler;
#ifdef HAVE_SV_INTERRUPT
svec.sv_flags = SV_INTERRUPT;
#endif
retval = sigvec(signum, &svec, NULL);
#else
retval = (signal(signum, handler) != SIG_ERR) ? 0 : -1;
#ifdef HAVE_SIGINTERRUPT
siginterrupt(signum, 1);
#endif
#endif
return(retval);
}