当前位置: 首页>>代码示例>>C++>>正文


C++ set_signal_handler函数代码示例

本文整理汇总了C++中set_signal_handler函数的典型用法代码示例。如果您正苦于以下问题:C++ set_signal_handler函数的具体用法?C++ set_signal_handler怎么用?C++ set_signal_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了set_signal_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setup_signal_handlers

pk_err_t setup_signal_handlers(void (*caught_handler)(int sig),
			const int *caught_signals, const int *ignored_signals)
{
	int i;

	if (caught_signals != NULL) {
		for (i=0; caught_signals[i] != 0; i++) {
			if (set_signal_handler(caught_signals[i],
						caught_handler)) {
				pk_log(LOG_ERROR, "unable to register signal "
						"handler for signal %d",
						caught_signals[i]);
				return PK_CALLFAIL;
			}
		}
	}
	if (ignored_signals != NULL) {
		for (i=0; ignored_signals[i] != 0; i++) {
			if (set_signal_handler(ignored_signals[i], SIG_IGN)) {
				pk_log(LOG_ERROR, "unable to ignore signal %d",
						ignored_signals[i]);
				return PK_CALLFAIL;
			}
		}
	}
	return PK_SUCCESS;
}
开发者ID:CaptainCPS,项目名称:openisr,代码行数:27,代码来源:util.c

示例2: cs_exit

void cs_exit(int32_t sig)
{
	if (cs_dump_stack && (sig == SIGSEGV || sig == SIGBUS || sig == SIGQUIT))
		cs_dumpstack(sig);

	set_signal_handler(SIGHUP , 1, SIG_IGN);
	set_signal_handler(SIGPIPE, 1, SIG_IGN);

  struct s_client *cl = cur_client();
  if (!cl)
  	return;

	// this is very important - do not remove
	if (cl->typ != 's') {
		cs_debug_mask(D_TRACE, "thread %8lX ended!", (unsigned long)pthread_self());

		free_client(cl);

		//Restore signals before exiting thread
		set_signal_handler(SIGPIPE , 0, cs_sigpipe);
		set_signal_handler(SIGHUP  , 1, cs_reload_config);

		pthread_exit(NULL);
		return;
	}

	if (!exit_oscam)
	  exit_oscam = sig?sig:1;
}
开发者ID:westaus,项目名称:oscam,代码行数:29,代码来源:oscam.c

示例3: lizard_decompress_safe

byte *
lizard_decompress_safe(const byte *in, struct lizard_buffer *buf, uns expected_length)
  /* Decompresses in into buf, sets *ptr to the data, and returns the
   * uncompressed length.  If an error has occured, -1 is returned and errno is
   * set.  The buffer buf is automatically reallocated.  SIGSEGV is caught in
   * case of buffer-overflow.  The function is not re-entrant because of a
   * static longjmp handler.  */
{
  uns lock_offset = ALIGN_TO(expected_length + 3, CPU_PAGE_SIZE);	// +3 due to the unaligned access
  if (lock_offset > buf->len)
    lizard_realloc(buf, lock_offset);
  volatile ucw_sighandler_t old_handler = set_signal_handler(SIGSEGV, sigsegv_handler);
  byte *ptr;
  if (!setjmp(safe_decompress_jump))
  {
    ptr = buf->ptr + buf->len - lock_offset;
    int len = lizard_decompress(in, ptr);
    if (len != (int) expected_length)
    {
      ptr = NULL;
      errno = EINVAL;
    }
  }
  else
  {
    msg(L_ERROR, "SIGSEGV caught in lizard_decompress()");
    ptr = NULL;
    errno = EFAULT;
  }
  set_signal_handler(SIGSEGV, old_handler);
  return ptr;
}
开发者ID:NZOI,项目名称:moe-cms,代码行数:32,代码来源:lizard-safe.c

示例4: init_signal_pre

/* Sets signal handlers to ignore for early startup of OSCam because for example log
   could cause SIGPIPE errors and the normal signal handlers can't be used at this point. */
static void init_signal_pre(void)
{
		set_signal_handler(SIGPIPE , 1, SIG_IGN);
		set_signal_handler(SIGWINCH, 1, SIG_IGN);
		set_signal_handler(SIGALRM , 1, SIG_IGN);
		set_signal_handler(SIGHUP  , 1, SIG_IGN);
}
开发者ID:westaus,项目名称:oscam,代码行数:9,代码来源:oscam.c

示例5: set_signal_handlers

static int set_signal_handlers(void)
{
	if ((set_signal_handler(SIGHUP, signal_handler) == -1)
	     || (set_signal_handler(SIGINT, signal_handler) == -1)
	     || (set_signal_handler(SIGTERM, signal_handler) == -1)
	     || (set_signal_handler(SIGPIPE, SIG_IGN) == -1))
		return -1;
	return 0;
}
开发者ID:pombredanne,项目名称:fstitch,代码行数:9,代码来源:fuse_serve.c

示例6: makedaemon

void
makedaemon(char *logname)
{
  int uid = 32767;
  int gid = 32767;
  char *user = "nobody";
  struct passwd *pwd;
  int logfd;

  logfd = open(logname, O_WRONLY | O_CREAT | O_APPEND);
  if(logfd < 0) {
    debug(DBG_GLOBAL, 0, "Could not open logfile '%s', exiting", logname);
    exit(255);
  }

  if(getuid() == 0) {
    pwd = getpwnam(user);
    if(pwd) {
      uid = pwd->pw_uid;
      gid = pwd->pw_gid;
    }
    debug(DBG_GLOBAL, 0,
          "Launched as root, trying to become %s (uid %d, gid %d)..",
          user, uid, gid);
    notminus(setgroups(0, (const gid_t *) 0), "setgroups");
    initgroups(user, gid);      // not critical if fails
    notminus(setgid(gid), "setgid");
    notminus(setegid(gid), "setegid");
    notminus(setuid(uid), "setuid");
    notminus(seteuid(gid), "seteuid");
    debug(DBG_GLOBAL, 0, "now forking");
  }


  if(fork() != 0)
    exit(0);

  setsid();
  set_signal_handler(SIGHUP, SIG_IGN);
  set_signal_handler(SIGPIPE, SIG_IGN);

  if(fork() != 0)
    exit(0);

  //chdir("/tmp");
  //chroot("/tmp");
  //umask(077);


  close(0);
  close(1);
  close(2);
  dup2(logfd, 1);
  dup2(logfd, 2);
  debug(DBG_GLOBAL, 0, "Started as a daemon");
}
开发者ID:ayourtch,项目名称:libay,代码行数:56,代码来源:os-ay.c

示例7: main

int main(int argc, char **argv) {
	int ret = EXIT_SUCCESS;
	int opt;
	kga_init();
	set_signal_handler(SIGHUP, interrupted);
	set_signal_handler(SIGINT, interrupted);
	set_signal_handler(SIGTERM, interrupted);
	try_scope {
		while ((opt = getopt(argc, argv, "r:d:ti")) != -1) {
			switch(opt) {
			case 'i':
				pkg_confirm = common_confirm;
				break;
			case 'r':
				root = optarg;
				break;
			case 'd':
				db_path = optarg;
				break;
			default:
				throw(pkg_main_incorrect_cmd, 1, "unknown option", NULL);
				break;
			};
		};
		int real_argc = argc - optind;
		char **real_argv = &argv[optind];
		if (!real_argc) {
			throw(pkg_main_incorrect_cmd, 1, "no subcommand", NULL);
		} else if (!strcmp(real_argv[0], "install")) {
			if (real_argc != 2) {
				throw(pkg_main_incorrect_cmd, 1, "incorrect subcommand", NULL);
			};
			pkg_install(real_argv[1], root, db_path, 0, stderr);
		} else if (!strcmp(real_argv[0], "upgrade")) {
			if (real_argc != 2) {
				throw(pkg_main_incorrect_cmd, 1, "incorrect subcommand", NULL);
			};
			pkg_install(real_argv[1], root, db_path, PKG_UPGRADE, stderr);
		} else if (!strcmp(real_argv[0], "drop")) {
			if (real_argc < 2 || real_argc > 3) {
				throw(pkg_main_incorrect_cmd, 1, "incorrect subcommand", NULL);
			};
			char *slash;
			if ((slash = strchr(real_argv[1], '/'))) {
				*slash = '\0';
				pkg_drop(root, db_path, real_argv[1], &slash[1], stderr);
				
			} else {
				pkg_drop(root, db_path, real_argv[1], real_argc == 2 ? NULL : real_argv[2], stderr);
			}
		} else {
			throw(pkg_main_incorrect_cmd, 1, "unknown subcommand", NULL);
		};
	};
	catch {
		if (exception()->type == &pkg_main_incorrect_cmd) {
开发者ID:kasymovga,项目名称:ports-tools3,代码行数:56,代码来源:pkg_main.c

示例8: SMTP_ehlo

int SMTP_ehlo(int sock, char smtp_mode, const char *host, char *name, char *password, int *opt)
/* send a "EHLO" message to the SMTP listener, return extension status bits */
{
  struct opt *hp;
  char auth_response[511];
  SIGHANDLERTYPE alrmsave;
  const int tmout = (mytimeout >= TIMEOUT_HELO ? mytimeout : TIMEOUT_HELO);

  SockPrintf(sock,"%cHLO %s\r\n", (smtp_mode == 'S') ? 'E' : smtp_mode, host);
  if (outlevel >= O_MONITOR)
      report(stdout, "%cMTP> %cHLO %s\n", 
	    smtp_mode, (smtp_mode == 'S') ? 'E' : smtp_mode, host);

  alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
  set_timeout(tmout);

  *opt = 0;
  while ((SockRead(sock, smtp_response, sizeof(smtp_response)-1)) != -1)
  {
      size_t n;

      set_timeout(0);
      (void)set_signal_handler(SIGALRM, alrmsave);

      n = strlen(smtp_response);
      if (n > 0 && smtp_response[n-1] == '\n')
	  smtp_response[--n] = '\0';
      if (n > 0 && smtp_response[n-1] == '\r')
	  smtp_response[--n] = '\0';
      if (n < 4)
	  return SM_ERROR;
      smtp_response[n] = '\0';
      if (outlevel >= O_MONITOR)
	  report(stdout, "%cMTP< %s\n", smtp_mode, smtp_response);
      for (hp = extensions; hp->name; hp++)
	  if (!strncasecmp(hp->name, smtp_response+4, strlen(hp->name))) {
	      *opt |= hp->value;
	      if (strncmp(hp->name, "AUTH ", 5) == 0)
		strncpy(auth_response, smtp_response, sizeof(auth_response));
		auth_response[sizeof(auth_response)-1] = '\0';
	  }
      if ((smtp_response[0] == '1' || smtp_response[0] == '2' || smtp_response[0] == '3') && smtp_response[3] == ' ') {
	  if (*opt & ESMTP_AUTH)
		SMTP_auth(sock, smtp_mode, name, password, auth_response);
	  return SM_OK;
      }
      else if (smtp_response[3] != '-')
	  return SM_ERROR;

      alrmsave = set_signal_handler(SIGALRM, null_signal_handler);
      set_timeout(tmout);
  }
  return SM_UNRECOVERABLE;
}
开发者ID:BackupTheBerlios,项目名称:fetchmail,代码行数:54,代码来源:smtp.c

示例9: main

int
main(int argc, char **argv)
{
    int ret;

    settings_init();

    if (set_signal_handler(signals) == -1) {
        return -1;
    }

    tc_time_init();

    if (read_args(argc, argv) == -1) {
        return -1;
    }

    if (srv_settings.log_path == NULL) {
        srv_settings.log_path = "error_intercept.log";  
    }

    if (tc_log_init(srv_settings.log_path) == -1) {
        return -1;
    }

    ret = tc_event_loop_init(&s_event_loop, MAX_FD_NUM);
    if (ret == TC_EVENT_ERROR) {
        tc_log_info(LOG_ERR, 0, "event loop init failed");
        return -1;
    }

    /* output debug info */
    output_for_debug();
    if (set_details() == -1) {
        return -1;
    }

    if (interception_init(&s_event_loop, srv_settings.binded_ip,
                          srv_settings.port) == TC_ERROR)
    {
        return -1;
    }

    if (set_timer() == -1) {
        return -1;
    }

#if (INTERCEPT_COMBINED)
    tc_event_timer_add(&s_event_loop, CHECK_INTERVAL, interception_push);
#endif
    tc_event_timer_add(&s_event_loop, OUTPUT_INTERVAL,
            interception_output_stat);

    /* run now */
    tc_event_process_cycle(&s_event_loop);

    server_release_resources();

    return 0;
}
开发者ID:Alienfeel,项目名称:tcpcopy,代码行数:60,代码来源:main.c

示例10: set_signal_handler

void StackPrinter::initialize(const char* program_path, time_t startT)
{
  /* store off program path so we can use it later */
  icky_global_program_name = program_path;
  startTime = startT;
  set_signal_handler();
}
开发者ID:Knochenschaeler,项目名称:keeperrl,代码行数:7,代码来源:stack_printer.cpp

示例11: main

int
main( int argc, char **argv )
{
    /* Save our program name - for error messages */
	set_DeadPipe_handler(DeadPipe);
    InitMyApp (CLASS_IDENT, argc, argv, NULL, NULL, 0 );
	LinkAfterStepConfig();

    set_signal_handler( SIGSEGV );

    ConnectX( ASDefaultScr, 0 );
    ConnectAfterStep (WINDOW_CONFIG_MASK |
                      WINDOW_NAME_MASK |
                      M_END_WINDOWLIST, 0);
    Config = CreateIdentConfig ();

    /* Request a list of all windows, while we load our config */
    SendInfo ("Send_WindowList", 0);

    LoadBaseConfig ( GetBaseOptions);
	LoadColorScheme();
	LoadConfig ("ident", GetOptions);
    CheckConfigSanity();
	ReloadASDatabase();
	ReloadCategories(True);

	if (MyArgs.src_window == 0)
		MyArgs.src_window = get_target_window();

	/* And at long last our main loop : */
    HandleEvents();
	return 0 ;
}
开发者ID:Remmy,项目名称:afterstep,代码行数:33,代码来源:Ident.c

示例12: main

int main(int argc, char **argv) {
    int y, x;
    
    set_signal_handler();

    initscr(); 

    curs_set(0);
    cbreak(); 
    noecho(); 
    keypad(stdscr, TRUE); 
    scrollok(stdscr, TRUE);

    space.wormhole_y = rand() % (LINES - 1) + 1; 
    space.wormhole_x = rand() % (COLS - 1);
    y = rand() % (LINES - 1) + 1;
    x = rand() % (COLS - 1);



    hud.moves = 0;
    store.starcount = 0;
    plot_stars_randomly(); 
    mvprintw(y, x, aircraft.ship); 
    control_ship(y, x);

    refresh();
    endwin(); 

    return(0);
}
开发者ID:DuckieNukeEm,项目名称:StarDork,代码行数:31,代码来源:stardork.c

示例13: init

int init(int argc, char *argv[])
{
  mtn = mtn_init(MODULE_NAME);
  ctx = calloc(1,sizeof(CTX));
  if(!mtn){
    return(-1);
  }
  if(!ctx){
    mtnlogger(NULL, 0, "[error] %s: %s\n", __func__, strerror(errno));
    return(-1);
  }
  mtn->mps_max = 512;
  mtn->logtype = 0;
  mtn->logmode = MTNLOG_STDERR;
  ctx->afd     = -1;
  ctx->nobuf   = 1;
  ctx->text    = 1;
  ctx->delim   = newstr(" ");
  ctx->targets = newarg(0);
  ctx->arg_max = sysconf(_SC_ARG_MAX);
  ctx->cpu_num = sysconf(_SC_NPROCESSORS_ONLN);
  ctx->job_max = sysconf(_SC_NPROCESSORS_ONLN);
  ctx->cmdargs = parse(argc, argv);
  gettimeofday(&(ctx->polltv), NULL);
  if(init_pipe() == -1){
    return(-1);
  }
  if(init_poll() == -1){
    return(-1);
  }
  ctx->job = calloc(ctx->job_max, sizeof(MTNJOB));
  set_signal_handler();
  mtnlogger(mtn, 1, "LogLevel: %d\n", mtn->loglevel);
  return(0);
}
开发者ID:kizkoh,项目名称:mtnd,代码行数:35,代码来源:mtnexec.c

示例14: makedaemon

/*
 * Fork a child process and then kill the parent so make the calling
 * program a daemon process.
 */
void
makedaemon(void)
{
	if (fork() != 0)
		exit(0);

	setsid();
	set_signal_handler(SIGHUP, SIG_IGN);

	if (fork() != 0)
		exit(0);

	chdir("/");
	umask(0177);

#if NDEBUG
        /*
         * When not in debugging mode, close the standard file
         * descriptors.
         */
	close(0);
	close(1);
	close(2);
#endif
}
开发者ID:OPSF,项目名称:uClinux,代码行数:29,代码来源:daemon.c

示例15: main

/*
 *  main
 */
int main(int argc, char *argv[])
{
	int ret;
	char *user;

	progname = argv[0] ? argv[0] : "lttng";

	/* For Mathieu Desnoyers a.k.a. Dr. Tracing */
	user = getenv("USER");
	if (user != NULL && ((strncmp(progname, "drtrace", 7) == 0 ||
				strncmp("compudj", user, 7) == 0))) {
		MSG("%c[%d;%dmWelcome back Dr Tracing!%c[%dm\n", 27,1,33,27,0);
	}
	/* Thanks Mathieu */

	ret = set_signal_handler();
	if (ret < 0) {
		clean_exit(ret);
	}

	ret = parse_args(argc, argv);
	if (ret != 0) {
		clean_exit(ret);
	}

	return 0;
}
开发者ID:MatthewKhouzam,项目名称:lttng-tools,代码行数:30,代码来源:lttng.c


注:本文中的set_signal_handler函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。