• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sigsetjmp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: ia32_step

void
ia32_step(void)
{
	int rv;

	rv = sigsetjmp(exec_1step_jmpbuf, 1);
	switch (rv) {
	case 0:
		break;

	case 1:
		VERBOSE(("ia32_step: return from exception"));
		break;

	case 2:
		VERBOSE(("ia32_step: return from panic"));
		return;

	default:
		VERBOSE(("ia32_step: return from unknown cause"));
		break;
	}

	do {
		exec_1step();
#if !defined(IA32_SUPPORT_DEBUG_REGISTER)
		if (CPU_TRAP) {
			CPU_DR6 |= CPU_DR6_BS;
			INTERRUPT(1, TRUE, FALSE, 0);
		}
#endif
		if (dmac.working) {
			dmax86();
		}
	} while (CPU_REMCLOCK > 0);
}
开发者ID:josejl1987,项目名称:neko-tracer,代码行数:36,代码来源:interface.c


示例2: check_functionality

/*
 * check_functionality() - make sure the memory is detached correctly
 */
void check_functionality(void)
{
	/* stat the shared memory segment */
	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1)
		tst_brkm(TBROK | TERRNO, cleanup,
			 "could not stat in signal handler");

	if (buf.shm_nattch != 0) {
		tst_resm(TFAIL, "# of attaches is incorrect");
		return;
	}

	/*
	 * Try writing to the shared memory.  This should generate a
	 * SIGSEGV which will be caught below.
	 *
	 * This is wrapped by the sigsetjmp() call that will take care of
	 * restoring the program's context in an elegant way in conjunction
	 * with the call to siglongjmp() in the signal handler.
	 *
	 * An attempt to do the assignment without using the sigsetjmp()
	 * and siglongjmp() calls will result in an infinite loop.  Program
	 * control is returned to the assignment statement after the execution
	 * of the signal handler and another SIGSEGV will be generated.
	 */

	if (sigsetjmp(env, 1) == 0) {
		*shared = 2;
	}

	if (pass) {
		tst_resm(TPASS, "shared memory detached correctly");
	} else {
		tst_resm(TFAIL, "shared memory was not detached correctly");
	}
}
开发者ID:MohdVara,项目名称:ltp,代码行数:39,代码来源:shmdt01.c


示例3: OPENSSL_cpuid_setup

void OPENSSL_cpuid_setup(void)
	{
	sigset_t oset;
	struct sigaction ill_act,oact;

	if (OPENSSL_s390xcap_P) return;

	TINYCLR_SSL_MEMSET(&ill_act,0,sizeof(ill_act));
	ill_act.sa_handler = ill_handler;
	sigfillset(&ill_act.sa_mask);
	sigdelset(&ill_act.sa_mask,SIGILL);
	sigdelset(&ill_act.sa_mask,SIGTRAP);
	sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
	sigaction (SIGILL,&ill_act,&oact);

	/* protection against missing store-facility-list-extended */
	if (sigsetjmp(ill_jmp,0) == 0)
		OPENSSL_s390xcap_P = OPENSSL_s390x_facilities();
	else
		OPENSSL_s390xcap_P = 1UL<<63;

	sigaction (SIGILL,&oact,NULL);
	sigprocmask(SIG_SETMASK,&oset,NULL);
	}
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:24,代码来源:s390xcap.cpp


示例4: get_stack_bottom

static char * get_stack_bottom(void) {
    /*
     * for autovar, must be volatile
     */
    volatile char *c;

    seg_handler = Signal( SIGSEGV, segfault);
    bus_handler = Signal( SIGBUS, segfault);
    c = (char *) &c;
    if ( sigsetjmp( jmpbuf, 1 ) != 0) {
        Signal( SIGSEGV, seg_handler);
        Signal( SIGBUS, bus_handler);
        return ((char *) c);
    }
    /*
     * now sigsetjump() is OK
     */
    canjump = 1;
    while (1) {
        *c = *c;
        c++;
    }
    return ( NULL);
} /* end of get_stack_bottom */
开发者ID:joenjoin,项目名称:geeks4c,代码行数:24,代码来源:get_stack_bottom_addr.c


示例5: RcvMsgFromMQ

/* ----------------------------------------------------------------
 * 功    能:从消息队列中读取消息,消息最大为MSGSIZE
 * 输入参数:
 *           iMsgid    消息队列的标识符
 *           lMsgType  消息的类型
 *           iTimeOut  超时时间(0:无限等待接收消息,>0:超时时间)
 * 输出参数:szRcvBuf  收到的数据
 * 返 回 值: 0   成功/-1  失败
 * 作    者:
 * 日    期:2012/12/27
 * 调用说明:
 * 修改日志:修改日期    修改者      修改内容简述
 * ----------------------------------------------------------------
 */
int RcvMsgFromMQ(int iMsgid, long lMsgType, int iTimeOut, char *szRcvBuf)
{
    int rcvlen;
    struct MsgBuf mb;

    if (iMsgid <= 0 || lMsgType <= 0 || iTimeOut < 0 || szRcvBuf == NULL)
    {
        return FAIL;
    }

    if (iTimeOut > 0)
    {
        signal(SIGALRM, RcvMsgTimeOutProc);
        if (sigsetjmp(RcvMsgTimeOut, 1) != 0)
        {
            PRINT_LOG(ERROR_LVL, "RcvMsgFromMQ(msgid=%d) Timeout", 
                      iMsgid);
            return SUCC;
        }
        alarm(iTimeOut);
    }

    memset(&mb, 0, sizeof(mb));
    rcvlen = msgrcv(iMsgid, &mb, MSGSIZE, lMsgType, 0);
    if (rcvlen == -1)
    {
        PRINT_LOG(ERROR_LVL, "call msgrcv(msgid=%d) fail[%d-%s]", 
                  iMsgid, errno, strerror(errno));
        return FAIL;
    }
    alarm(0);

    memcpy(szRcvBuf, mb.mbuf, rcvlen);

    return (rcvlen);
}
开发者ID:cqm0609,项目名称:kms_db2,代码行数:50,代码来源:Msgq.c


示例6: gdk_pixbuf__jpeg_image_stop_load

/*
 * context - returned from image_begin_load
 *
 * free context, unref gdk_pixbuf
 */
static gboolean
gdk_pixbuf__jpeg_image_stop_load (gpointer data, GError **error)
{
	JpegProgContext *context = (JpegProgContext *) data;
        gboolean retval;

	g_return_val_if_fail (context != NULL, TRUE);
	
        /* FIXME this thing needs to report errors if
         * we have unused image data
         */
        
	if (context->pixbuf)
		g_object_unref (context->pixbuf);
	
	/* if we have an error? */
	context->jerr.error = error;
	if (sigsetjmp (context->jerr.setjmp_buffer, 1)) {
                retval = FALSE;
	} else {
		jpeg_finish_decompress (&context->cinfo);
                retval = TRUE;
	}

        jpeg_destroy_decompress (&context->cinfo);

	if (context->cinfo.src) {
		my_src_ptr src = (my_src_ptr) context->cinfo.src;
		
		g_free (src);
	}

	g_free (context);

        return retval;
}
开发者ID:AlexiaChen,项目名称:ImageMagick_Cmake,代码行数:41,代码来源:io-jpeg.c


示例7: _runtest

void _runtest(const char* filename, int linenum, const char* testname, void (*f)())
{
  TRACE_ENTER;
  static sigjmp_buf sigjmpbuf;
  static jmp_buf jmpbuf;
  int rc = 0;
  int code = sigsetjmp(sigjmpbuf, 1);
  if (code == 0) {
    code = setjmp(jmpbuf);
    if (code == 0) {
      _catch_signals(filename, linenum, testname, &rc, &sigjmpbuf, &jmpbuf);
      (*f)();
      _release_signals();
    } else {
      TRACE_CATCH;
      rc = code;
      _release_signals();
    }
  } else {
    //printf("after siglongjmp\n");
    TRACE_CATCH;
    //printf("after trace_catch\n");
    rc = code;
    _release_signals();
    //printf("after release_signals\n");
  }

  if (rc == 0 && __verbose) {
    printf("Passed %s\n\n", testname);
  }
  else if (rc != 0) {
    __tests_failed++;
    printf("%s:%d: Failed %s\n\n", filename, linenum, testname);
  }
  TRACE_EXIT;
}
开发者ID:FredFoonly,项目名称:poe,代码行数:36,代码来源:testing.c


示例8: g_print_stats


//.........这里部分代码省略.........
	}
      else
	{
	  g_act_1.buffer.r_pos = md_first (&g_act_1.buffer);
	}

      //proc_match = g_bmatch_dummy;

      md_g_free_cb (&g_act_1._match_rr, g_cl_mrr);
    }

  __d_is_wb w_d_s = g_act_1.w_d;

  g_act_1.w_d = g_act_1.w_d_pr;

  g_do_ppprint (&g_act_1, F_GH_PRE_PRINT, &g_act_1.pre_print_mech,
		g_act_1.g_proc4_pr);

  if (gfl0 & F_OPT_LOADQA)
    {
      goto r_end;
    }

  g_act_1.w_d = w_d_s;

  void *ptr;

  size_t c = 0;

  g_setjmp (F_SIGERR_CONTINUE, "g_print_stats(loop)", NULL, NULL);

  g_act_1.buffer.offset = 0;

  if (!sigsetjmp(g_sigjmp.env, 1))
    {
      while ((ptr = g_read (buffer, &g_act_1, g_act_1.block_sz)))
	{
	  if ((gfl & F_OPT_KILL_GLOBAL))
	    {
	      break;
	    }

	  if ((r = proc_match (ptr, &g_act_1, &g_act_1.buffer)))
	    {
	      if (r == -1)
		{
		  print_str ("ERROR: %s: [%d] matching record failed\n",
			     g_act_1.file, r);
		  break;
		}

	      continue;
	    }

	  c++;
	  g_act_1.g_proc4 ((void*) &g_act_1, ptr, NULL);

	}

    }
  else
    {
      print_str (
	  "ERROR: %s: an exception has occured, terminating enumeration and attempt cleanup..\n",
	  g_act_1.file);
      EXITVAL = 2;
开发者ID:nixnodes,项目名称:glutil,代码行数:67,代码来源:omfp.c


示例9: main

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

	if (signal(SIGPIPE,sig_pipe)==SIG_ERR)
		perror("signal_SIGPIPE");
	if (signal(SIGALRM,sig_alrm)==SIG_ERR)
		perror("signal_SIGALRM");

	int i;
	for (i=1;i<8;i++)
	{
		if (!strncmp(argv[i],"-n",2))
			nsublist=atoi(argv[i+1]);
		else if (!strncmp(argv[i],"-p",2))
			nchild=atoi(argv[i+1]);
		else if (!strncmp(argv[i],"-e",2))
			strcpy(sortpath,argv[i+1]);
		else if (!strncmp(argv[i],"-k",2))
			ansk=atoi(argv[i+1]);
	}	

	read(0,&ndata,4);
	int unsortData=ndata;
	int sortData=0;

	// printf("n:%d,p:%d,k:%d,path:%s;data %d\n",nsublist,nchild,ansk,sortpath,ndata);
	fflush(stdout);

	int buf[trans_buf_size];
	int nByte,remainByte;

	char bufname[100];
	int unreadData=ndata;
	for (i=0;i<((ndata%nsublist)?nsublist+1:nsublist);i++)
	{
		tmpfp[i]=tmpfile();
		tmpfp2[i]=tmpfile();
			
		subread[i]=0;
	
		sublen[i]=ndata/nsublist;
		if (unreadData<sublen[i])
			sublen[i]=unreadData;

		remainByte=sublen[i]*4;
		while (remainByte>=4*trans_buf_size)
		{
			memset(buf,0,trans_buf_size*4);
			nByte=read(0,buf,4*trans_buf_size);
			
			fwrite(buf,4,nByte/4,tmpfp2[i]);
			remainByte-=nByte;
		};
		while (remainByte!=0)
		{
			memset(buf,0,trans_buf_size*4);
			nByte=read(0,buf,remainByte);
			fwrite(buf,4,nByte/4,tmpfp2[i]);
			remainByte-=nByte;
		};
		unreadData-=sublen[i];
	};

	// printf("read data finish!\n");
	fflush(stdout);


	for (i=0;i<nchild;i++)
		make_child(i);

	// printf("make child finish!\n");
	fflush(stdout);
	
	fd_set rfd,wfd;
	struct timeval tv;
	tv.tv_sec=100;
	tv.tv_usec=0;
	int retval,maxfd;

	for (i=0;i<nchild;i++)
		childsub[i]=-1;

	while (!(sortData==ndata))
	{
		if (sigsetjmp(jmpbuf,1)==1)
		{
			// fprintf(stderr,"jumped\n");
			unsortData=ndata-sortData;
		}
		  /* Parent reads from pipe 1, writes to pipe 0*/
		FD_ZERO(&rfd);
		FD_ZERO(&wfd);
		maxfd=-1;
		// fprintf(stderr,"data unsorted: %d\n",unsortData);
		if (unsortData>0)
			for (i=0;i<nchild;i++)
			{
				FD_SET(pipefd[i][0][1],&wfd);
				if (pipefd[i][0][1]>maxfd)
					maxfd=pipefd[i][0][1];
//.........这里部分代码省略.........
开发者ID:ayzk,项目名称:Linux_Merge_sort,代码行数:101,代码来源:mergesort.c


示例10: ssh_watch

/*
 * Periodically test network connection. On signals, determine what
 * happened or what to do with child. Return as necessary for exit 
 * or restart of child.
 */
int
ssh_watch(int sock)
{
	int	r;
	int	val;
	static	int	secs_left;
	int	my_poll_time = first_poll_time;
	time_t	now;
	double	secs_to_shutdown;

#if defined(HAVE_SETPROCTITLE)
	setproctitle("parent of %d (%d)", 
	    (int)cchild, start_count);
#endif

	for (;;) {
		if (restart_ssh) {
			errlog(LOG_INFO, "signalled to kill and restart ssh");
			ssh_kill();
			return P_RESTART;
		}
		if ((val = sigsetjmp(jumpbuf, 1)) == 0) {

			errlog(LOG_DEBUG, "check on child %d", cchild);

			/* poll for expired child */
			r = ssh_wait(WNOHANG);
			if (r != P_CONTINUE) {
				errlog(LOG_DEBUG, 
				    "expired child, returning %d", r);
				return r;
			}

			secs_left = alarm(0);
			if (secs_left == 0)
				secs_left = my_poll_time;

			my_poll_time = poll_time;

			if (max_lifetime != 0) {
				time(&now);
				secs_to_shutdown = max_lifetime - difftime(now,pid_start_time);
				if (secs_to_shutdown < poll_time)
					secs_left = secs_to_shutdown;
			}

			errlog(LOG_DEBUG, 
			    "set alarm for %d secs", secs_left);

			alarm(secs_left);
			dolongjmp = 1;
			pause();

		} else {

			switch(val) {
			case SIGINT:
			case SIGTERM:
			case SIGQUIT:
			case SIGABRT:
				errlog(LOG_INFO, 
				    "received signal to exit (%d)", val);
				ssh_kill();
				return P_EXIT;
				break;
			case SIGALRM:
				if (exceeded_lifetime()) {
					ssh_kill();
					return P_EXIT;
				}

				if (writep && sock != -1 &&
				    !conn_test(sock, mhost, writep)) {
					errlog(LOG_INFO, 
					    "port down, restarting ssh");
					ssh_kill();
					return P_RESTART;
				}
#ifdef TOUCH_PIDFILE
				/*
				 * utimes() with a NULL time argument sets
				 * file access and modification times to
				 * the current time
				 */
				if (pid_file_name && 
				    utimes(pid_file_name, NULL) != 0) {
					errlog(LOG_ERR,
					    "could not touch pid file: %s",
					    strerror(errno));
				}
#endif
				break;
			default:
				break;
			}
//.........这里部分代码省略.........
开发者ID:ipmobiletech,项目名称:Android_SSH,代码行数:101,代码来源:autossh.c


示例11: run_test

int run_test( test_func test, const char* func_name )
{
  printf("Running %s ...\n", func_name );
  
#if MODE == EXCEPTION_MODE
  /* On Windows, run all tests in same process.
     Flag errors by throwing an exception.
   */
  try {
    (*test)();
    return 0;
  }
  catch (ErrorExcept) {
    printf( "  %s: FAILED\n", func_name );
    return 1;
  }
  catch (...) {
    printf( "  %s: UNCAUGHT EXCEPTION\n", func_name );
    return 1;
  }
    
#elif MODE == FORK_MODE
    /* For non-Windows OSs, fork() and run test in child process. */
  pid_t pid = fork();
  int status;
  
    /* Fork failed? */
  if (pid == -1) {  
    perror( "fork()" );
    abort(); /* abort all tests (can't fork child processes) */
  }
  
    /* If child process*/
  if (pid == 0) {
    (*test)();  /* call test function */
    exit(0);    /* if function returned, then it succeeded */
  }
  
    /* If here, then parent process */
    
    /* Wait until child process exits */
  waitpid( pid, &status, 0 );
  
    /* Check child exit status */
  if (WIFSIGNALED(status)) {
    if (WTERMSIG(status))
      printf("  %s: TERMINATED (signal %d)\n", func_name, (int)WTERMSIG(status) );
    if (WCOREDUMP(status))
      printf("  %s: CORE DUMP\n", func_name);
    return 1;
  }
  else if(WEXITSTATUS(status)) {
    printf( "  %s: FAILED\n", func_name );
    return 1;
  }
  else {
    return 0;
  }
  
#elif MODE == LONGJMP_MODE
    // Save stack state at this location.
  int rval = sigsetjmp( jmpenv, 1 );
    // If rval is zero, then we haven't run the test yet. 
    // If rval is non-zero then
    // a) we ran the test
    // b) the test failed
    // c) we did a longjmp back to the location where we called setsigjmp.
    
    // run test
  if (!rval) {
    (*test)();
    return 0;
  }
    // some check failed
  else if (rval == -1) {
    printf( "  %s: FAILED\n", func_name );
    return 1;
  }
    // a signal was raised (e.g. segfault)
  else {
    printf( "  %s: TERMINATED (signal %d)\n", func_name, rval );
    return 1;
  }
#else
  #error "MODE not set"
#endif // MODE
}
开发者ID:chrismullins,项目名称:moab,代码行数:87,代码来源:TestUtil.hpp


示例12: wall

/*
 *	Wall function.
 */
void wall(const char *text, int remote)
{
	FILE			*tp;
	struct sigaction	sa;
	struct utmp		*utmp;
	time_t			t;
	char			term[UT_LINESIZE+ strlen(_PATH_DEV) + 1];
	char			line[81];
	char			hostname[HOST_NAME_MAX+1];
	char			*date, *p;
	char			*user, *tty;
	int			fd, flags;

	/*
	 *	Make sure tp and fd aren't in a register. Some versions
	 *	of gcc clobber those after longjmp (or so I understand).
	 */
	(void) &tp;
	(void) &fd;

	getuidtty(&user, &tty);

	/* Get and report current hostname, to make it easier to find
	   out which machine is being shut down. */
	if (0 != gethostname(hostname, sizeof(hostname))) {
		strncpy(hostname, "[unknown]", sizeof(hostname)-1);
	}
	/* If hostname is truncated, it is unspecified if the string
	   is null terminated or not.  Make sure we know it is null
	   terminated. */
	hostname[sizeof(hostname)-1] = 0;

	/* Get the time */
	time(&t);
	date = ctime(&t);
	for(p = date; *p && *p != '\n'; p++)
		;
	*p = 0;
	
	if (remote) {
		snprintf(line, sizeof(line),
			"\007\r\nRemote broadcast message (%s):\r\n\r\n",
			date);
	} else {
		snprintf(line, sizeof(line),
			"\007\r\nBroadcast message from %[email protected]%s %s(%s):\r\n\r\n",
			user, hostname, tty, date);
	}

	/*
	 *	Fork to avoid us hanging in a write()
	 */
	if (fork() != 0)
		return;
	
	memset(&sa, 0, sizeof(sa));
	sa.sa_handler = handler;
	sa.sa_flags = 0;
	sigemptyset(&sa.sa_mask);
	sigaction(SIGALRM, &sa, NULL);

	setutent();

	while ((utmp = getutent()) != NULL) {
		if(utmp->ut_type != USER_PROCESS ||
		   utmp->ut_user[0] == 0) continue;
		if (strncmp(utmp->ut_line, _PATH_DEV, strlen(_PATH_DEV)) == 0) {
			term[0] = 0;
			strncat(term, utmp->ut_line, sizeof(term)-1);
		} else
			snprintf(term, sizeof(term), _PATH_DEV "%.*s",
				UT_LINESIZE, utmp->ut_line);
		if (strstr(term, "/../")) continue;

		fd = -1;
		tp = NULL;

		/*
		 *	Open it non-delay
		 */
		if (sigsetjmp(jbuf, 1) == 0) {
			alarm(2);
			flags = O_WRONLY|O_NDELAY|O_NOCTTY;
			if (file_isatty(term) &&
			    (fd = open(term, flags)) >= 0) {
				if (isatty(fd) &&
				    (tp = fdopen(fd, "w")) != NULL) {
					fputs(line, tp);
					feputs(text, tp);
					fflush(tp);
				}
			}
		}
		alarm(0);
		if (fd >= 0) close(fd);
		if (tp != NULL) fclose(tp);
	}
//.........这里部分代码省略.........
开发者ID:Distrotech,项目名称:sysvinit,代码行数:101,代码来源:dowall.c


示例13: main

int
main(int argc, char *argv[])
{
	START(argc, argv, "blk_recovery");

	if (argc != 5)
		FATAL("usage: %s bsize file first_lba lba", argv[0]);

	Bsize = strtoul(argv[1], NULL, 0);
	const char *path = argv[2];

	PMEMblkpool *handle;
	if ((handle = pmemblk_create(path, Bsize, 0,
			S_IWUSR | S_IRUSR)) == NULL)
		FATAL("!%s: pmemblk_create", path);

	OUT("%s block size %zu usable blocks %zu",
			argv[1], Bsize, pmemblk_nblock(handle));

	/* write the first lba */
	off_t lba = strtoul(argv[3], NULL, 0);
	unsigned char buf[Bsize];

	construct(buf);
	if (pmemblk_write(handle, buf, lba) < 0)
		FATAL("!write     lba %zu", lba);

	OUT("write     lba %zu: %s", lba, ident(buf));

	/* reach into the layout and write-protect the map */
	struct btt_info *infop = (void *)handle +
		roundup(sizeof (struct pmemblk), BLK_FORMAT_DATA_ALIGN);

	void *mapaddr = (void *)infop + le32toh(infop->mapoff);
	void *flogaddr = (void *)infop + le32toh(infop->flogoff);

	OUT("write-protecting map, length %zu", (size_t)(flogaddr - mapaddr));
	MPROTECT(mapaddr, (size_t)(flogaddr - mapaddr), PROT_READ);

	/* arrange to catch SEGV */
	struct sigaction v;
	sigemptyset(&v.sa_mask);
	v.sa_flags = 0;
	v.sa_handler = signal_handler;
	SIGACTION(SIGSEGV, &v, NULL);

	/* map each file argument with the given map type */
	lba = strtoul(argv[4], NULL, 0);

	construct(buf);

	if (!sigsetjmp(Jmp, 1)) {
		if (pmemblk_write(handle, buf, lba) < 0)
			FATAL("!write     lba %zu", lba);
		else
			FATAL("write     lba %zu: %s", lba, ident(buf));
	}

	pmemblk_close(handle);

	int result = pmemblk_check(path);
	if (result < 0)
		OUT("!%s: pmemblk_check", path);
	else if (result == 0)
		OUT("%s: pmemblk_check: not consistent", path);
	else
		OUT("%s: consistent", path);

	DONE(NULL);
}
开发者ID:harrybaa,项目名称:nvml,代码行数:70,代码来源:blk_recovery.c


示例14: callmgr_main

/* the volatile qualifiers should be removed as well.                  */ 
int callmgr_main(int argc, char **argv, char **envp) {
  struct in_addr inetaddr;
  int inet_sock, unix_sock;
  fd_set call_set;
  PPTP_CONN * conn;
  VECTOR * call_list;
  int max_fd=0;
  volatile int first=1;
  int retval;
  int i;
  char * volatile phonenr;

  /* Step 0: Check arguments */
  if (argc < 2) 
    fatal("Usage: %s ip.add.ress.here [--phone <phone number>]", argv[0]);
  phonenr = argc==3 ? argv[2] : NULL;
  if (inet_aton(argv[1], &inetaddr)==0)
    fatal("Invalid IP address: %s", argv[1]);

  /* Step 1: Open sockets. */
  if ((inet_sock = open_inetsock(inetaddr)) < 0)
    fatal("Could not open control connection to %s", argv[1]);
  if ((unix_sock = open_unixsock(inetaddr)) < 0)
    fatal("Could not open unix socket for %s", argv[1]);

  /* Step 1b: FORK and return status to calling process. */
  switch (fork()) {
  case 0: /* child. stick around. */
    break;
  case -1: /* failure.  Fatal. */
    fatal("Could not fork.");
  default: /* Parent. Return status to caller. */
    exit(0);
  }

  /* re-open stderr as /dev/null to release it */
  file2fd("/dev/null", "wb", STDERR_FILENO);

  /* Step 1c: Clean up unix socket on TERM */
  if (sigsetjmp(callmgr_env, 1)!=0)
    goto cleanup;

  signal(SIGINT, callmgr_sighandler);
  signal(SIGTERM, callmgr_sighandler);

  signal(SIGPIPE, callmgr_do_nothing);
  signal(SIGUSR1, callmgr_do_nothing); /* signal state change; wake up accept */

  /* Step 2: Open control connection and register callback */
  if ((conn = pptp_conn_open(inet_sock, 1, NULL/* callback */)) == NULL) {
    close(unix_sock); close(inet_sock); fatal("Could not open connection.");
  }

  FD_ZERO(&call_set);
  max_fd = unix_sock;
  call_list = vector_create();
  { 
    struct local_conninfo *conninfo = malloc(sizeof(*conninfo));
    if (conninfo==NULL) {
      close(unix_sock); close(inet_sock); fatal("No memory.");
    }
    conninfo->call_list = call_list;
    conninfo->call_set  = &call_set;
    pptp_conn_closure_put(conn, conninfo);
  }

  if (sigsetjmp(callmgr_env, 1)!=0) goto shutdown;

  /* Step 3: Get FD_SETs */
  do {
    int rc;
    fd_set read_set = call_set, write_set;
    FD_ZERO (&write_set);
    FD_SET (unix_sock, &read_set);
    pptp_fd_set(conn, &read_set, &write_set, &max_fd);

    for (; max_fd > 0 ; max_fd--) {
      if (FD_ISSET (max_fd, &read_set) ||
          FD_ISSET (max_fd, &write_set))
        break;
    }

    /* Step 4: Wait on INET or UNIX event */

    if ((rc = select(max_fd+1, &read_set, &write_set, NULL, NULL)) <0)
      /* a signal or somesuch. */
      continue;

    /* Step 5a: Handle INET events */
    pptp_dispatch(conn, &read_set, &write_set);

    /* Step 5b: Handle new connection to UNIX socket */
    if (FD_ISSET(unix_sock, &read_set)) {
      /* New call! */
      struct sockaddr_un from;
      int len = sizeof(from);
      PPTP_CALL * call;
      struct local_callinfo *lci;
      int s;
//.........这里部分代码省略.........
开发者ID:froggatt,项目名称:edimax-br-6528n,代码行数:101,代码来源:pptp_callmgr.c


示例15: FileRepSubProcess_Main

void
FileRepSubProcess_Main()
{
	const char *statmsg;

	MemoryContext fileRepSubProcessMemoryContext;

	sigjmp_buf	local_sigjmp_buf;

	MyProcPid = getpid();

	MyStartTime = time(NULL);

	/*
	 * Create a PGPROC so we can use LWLocks in FileRep sub-processes.  The
	 * routine also register clean up at process exit
	 */
	InitAuxiliaryProcess();

	InitBufferPoolBackend();

	FileRepSubProcess_ConfigureSignals();

	/*
	 * If an exception is encountered, processing resumes here.
	 *
	 * See notes in postgres.c about the design of this coding.
	 */
	if (sigsetjmp(local_sigjmp_buf, 1) != 0)
	{
		/* Prevents interrupts while cleaning up */
		HOLD_INTERRUPTS();

		/* Report the error to the server log */
		EmitErrorReport();

		LWLockReleaseAll();

		if (FileRepPrimary_IsResyncManagerOrWorker())
		{
			LockReleaseAll(DEFAULT_LOCKMETHOD, false);
		}

		if (FileRepIsBackendSubProcess(fileRepProcessType))
		{
			AbortBufferIO();
			UnlockBuffers();

			/* buffer pins are released here: */
			ResourceOwnerRelease(CurrentResourceOwner,
								 RESOURCE_RELEASE_BEFORE_LOCKS,
								 false, true);
		}

		/*
		 * We can now go away.	Note that because we'll call InitProcess, a
		 * callback will be registered to do ProcKill, which will clean up
		 * necessary state.
		 */
		proc_exit(0);
	}

	/* We can now handle ereport(ERROR) */
	PG_exception_stack = &local_sigjmp_buf;

	PG_SETMASK(&UnBlockSig);

	/*
	 * Identify myself via ps
	 */

	statmsg = FileRepProcessTypeToString[fileRepProcessType];

	init_ps_display(statmsg, "", "", "");

	/* Create the memory context where cross-transaction state is stored */
	fileRepSubProcessMemoryContext = AllocSetContextCreate(TopMemoryContext,
														   "filerep subprocess memory context",
														   ALLOCSET_DEFAULT_MINSIZE,
														   ALLOCSET_DEFAULT_INITSIZE,
														   ALLOCSET_DEFAULT_MAXSIZE);

	MemoryContextSwitchTo(fileRepSubProcessMemoryContext);

	stateChangeRequestCounter++;

	FileRepSubProcess_ProcessSignals();

	switch (fileRepProcessType)
	{
		case FileRepProcessTypePrimarySender:
			FileRepPrimary_StartSender();
			break;

		case FileRepProcessTypeMirrorReceiver:
			FileRepMirror_StartReceiver();
			break;

		case FileRepProcessTypeMirrorConsumer:
		case FileRepProcessTypeMirrorConsumerWriter:
//.........这里部分代码省略.........
开发者ID:PengJi,项目名称:gpdb-comments,代码行数:101,代码来源:cdbfilerepservice.c


示例16: get_mem_layout

int get_mem_layout (struct memchunk *chunk_list, int size)
{
    unsigned long endPage = 0xffffffff;
    unsigned int pageNum = endPage/PAGE_SIZE;
    unsigned long startPage = 0x00000000;
    int numberOfChunk=0;
    char str = 'a';
    int firstPage = 1;
    currentAddress = startPage;

    
//initial the handler   
	initialHandler();
	

    int page = 0;
    while(page<pageNum){
        page++;
        sigsetjmp(sigbuf,1);
        //check if the page of memory is accessable
        if(status ==0){
        
            if(firstPage ==1){
                firstPage =0;
                chunk_list[numberOfChunk].start = (void *) currentAddress;
				chunk_list[numberOfChunk].length = PAGE_SIZE; 
				chunk_list[numberOfChunk].RW=status-1;
				preStatus =status;
                status=0;
                currentAddress += PAGE_SIZE;
            }else{
                //check if the last page is not accessable
                if(preStatus ==0){
                    chunk_list[numberOfChunk].length+=PAGE_SIZE;
                    currentAddress += PAGE_SIZE;
                    preStatus=status;	
			        status=0;
                }else{
                    numberOfChunk+=1;
                    chunk_list[numberOfChunk].start = (void *) currentAddress;
				    chunk_list[numberOfChunk].length = PAGE_SIZE; 
				    chunk_list[numberOfChunk].RW=status-1;
				    currentAddress += PAGE_SIZE;
				    preStatus =status;
                    status=0;
                }
            }//check if the last page has different accessability with this one
        }else if((numberOfChunk<size) && (preStatus != status)&&(status!=0)){
            if(firstPage==1){
                firstPage = 0;
                chunk_list[numberOfChunk].start = (void *) currentAddress;
				chunk_list[numberOfChunk].length = PAGE_SIZE; 
				chunk_list[numberOfChunk].RW=status-1;
				preStatus =status;
                status=0;

				    	
            }else{
                numberOfChunk+=1;
                chunk_list[numberOfChunk].start = (void *) currentAddress;
				chunk_list[numberOfChunk].length = PAGE_SIZE; 
				chunk_list[numberOfChunk].RW=status-1;
				preStatus =status;
                status=0;

                
            }
            currentAddress += PAGE_SIZE;
        }else if((status!=0)&&(status == preStatus)){
            chunk_list[numberOfChunk].length += PAGE_SIZE;
            currentAddress += PAGE_SIZE;
            preStatus=status;	
			status=0;
			
        }
        
        
        //make sure if this is the end of page and return value
        if (currentAddress==(endPage-PAGE_SIZE+1) || numberOfChunk==size-1)
		{
			return numberOfChunk+1;
		}

		status=0;
		// check if it's readable   
		str = *((char *) currentAddress);
		status = 1;

		// check if it's writeable
		*((char *) currentAddress) = str;
		status = 2;
        
        
        

        
        
    
    
    }
//.........这里部分代码省略.........
开发者ID:chongyangye,项目名称:379Assignment,代码行数:101,代码来源:memchunk.c


示例17: mark_phase_young

VOIDCDECL mark_phase_young() 
{
  unsigned int i,j;
  unsigned long stack_size;
  ATerm *stackTop;
  ATerm *start, *stop;
  ProtEntry *prot;

#ifdef WIN32

  unsigned int r_eax, r_ebx, r_ecx, r_edx, \
    r_esi, r_edi, r_esp, r_ebp;
  ATerm reg[8], *real_term;

  __asm {
      /* Get the registers into local variables to check them
         for aterms later. */
    mov r_eax, eax
      mov r_ebx, ebx
      mov r_ecx, ecx
      mov r_edx, edx
      mov r_esi, esi
      mov r_edi, edi
      mov r_esp, esp
      mov r_ebp, ebp
      }
    /* Put the register-values into an array */
  reg[0] = (ATerm) r_eax;
  reg[1] = (ATerm) r_ebx;
  reg[2] = (ATerm) r_ecx;
  reg[3] = (ATerm) r_edx;
  reg[4] = (ATerm) r_esi;
  reg[5] = (ATerm) r_edi;
  reg[6] = (ATerm) r_esp;
  reg[7] = (ATerm) r_ebp;

  for(i=0; i<8; i++) {
    real_term = AT_isInsideValidTerm(reg[i]);
    if (real_term != NULL) {
      AT_markTerm_young(real_term);
    }
    if (AT_isValidSymbol((Symbol)reg[i])) {
       AT_markSymbol_young((Symbol)reg[i]);
    }
  }

    /* The register variables are on the stack aswell
       I set them to zero so they won't be processed again when
       the stack is traversed. The reg-array is also in the stack
       but that will be adjusted later */
  r_eax = 0;
  r_ebx = 0;
  r_ecx = 0;
  r_edx = 0;
  r_esi = 0;
  r_edi = 0;
  r_esp = 0;
  r_ebp = 0;

#else
  sigjmp_buf env;

    /* Traverse possible register variables */
  sigsetjmp(env,0);

  start = (ATerm *)((char *)env);
  stop  = ((ATerm *)(((char *)env) + sizeof(sigjmp_buf)));
  mark_memory_young(start, stop);
#endif

  stackTop = stack_top();
  start = MIN(stackTop, stackBot);
  stop  = MAX(stackTop, stackBot);

  stack_size = stop-start;
  STATS(stack_depth, stack_size);

  mark_memory_young(start, stop);

  /* Traverse protected terms */
  for(i=0; i<at_prot_table_size; i++) {
    ProtEntry *cur = at_prot_table[i];
    while(cur) {
      for(j=0; j<cur->size; j++) {
	if(cur->start[j])
	   AT_markTerm_young(cur->start[j]);
      }
      cur = cur->next;
    }
  }

  for (prot=at_prot_memory; prot != NULL; prot=prot->next) {
    mark_memory_young((ATerm *)prot->start, (ATerm *)(((char *)prot->start) + prot->size));
  }
    
  AT_markProtectedSymbols_young();

   /* Mark 'parked' symbol */
  if (AT_isValidSymbol(at_parked_symbol)) {
      /*fprintf(stderr,"mark_phase_young: AT_markSymbol_young(%d)\n",at_parked_symbol);*/
//.........这里部分代码省略.........
开发者ID:bmmoore,项目名称:sglr-server,代码行数:101,代码来源:gc.c


示例18: CheckpointerMain

/*
 * Main entry point for checkpointer process
 *
 * This is invoked from AuxiliaryProcessMain, which has already created the
 * basic execution environment, but not enabled signals yet.
 */
void
CheckpointerMain(void)
{
	sigjmp_buf	local_sigjmp_buf;
	MemoryContext checkpointer_context;

	CheckpointerShmem->checkpointer_pid = MyProcPid;

	/*
	 * Properly accept or ignore signals the postmaster might send us
	 *
	 * Note: we deliberately ignore SIGTERM, because during a standard Unix
	 * system shutdown cycle, init will SIGTERM all processes at once.  We
	 * want to wait for the backends to exit, whereupon the postmaster will
	 * tell us it's okay to shut down (via SIGUSR2).
	 */
	pqsignal(SIGHUP, ChkptSigHupHandler);		/* set flag to read config
												 * file */
	pqsignal(SIGINT, ReqCheckpointHandler);		/* request checkpoint */
	pqsignal(SIGTERM, SIG_IGN); /* ignore SIGTERM */
	pqsignal(SIGQUIT, chkpt_quickdie);	/* hard crash time */
	pqsignal(SIGALRM, SIG_IGN);
	pqsignal(SIGPIPE, SIG_IGN);
	pqsignal(SIGUSR1, chkpt_sigusr1_handler);
	pqsignal(SIGUSR2, ReqShutdownHandler);		/* request shutdown */

	/*
	 * Reset some signals that are accepted by postmaster but not here
	 */
	pqsignal(SIGCHLD, SIG_DFL);
	pqsignal(SIGTTIN, SIG_DFL);
	pqsignal(SIGTTOU, SIG_DFL);
	pqsignal(SIGCONT, SIG_DFL);
	pqsignal(SIGWINCH, SIG_DFL);

	/* We allow SIGQUIT (quickdie) at all times */
	sigdelset(&BlockSig, SIGQUIT);

	/*
	 * Initialize so that first time-driven event happens at the correct time.
	 */
	last_checkpoint_time = last_xlog_switch_time = (pg_time_t) time(NULL);

	/*
	 * Create a resource owner to keep track of our resources (currently only
	 * buffer pins).
	 */
	CurrentResourceOwner = ResourceOwnerCreate(NULL, "Checkpointer");

	/*
	 * Create a memory context that we will do all our work in.  We do this so
	 * that we can reset the context during error recovery and thereby avoid
	 * possible memory leaks.  Formerly this code just ran in
	 * TopMemoryContext, but resetting that would be a really bad idea.
	 */
	checkpointer_context = AllocSetContextCreate(TopMemoryContext,
												 "Checkpointer",
												 ALLOCSET_DEFAULT_SIZES);
	MemoryContextSwitchTo(checkpointer_context);

	/*
	 * If an exception is encountered, processing resumes here.
	 *
	 * See notes in postgres.c about the design of this coding.
	 */
	if (sigsetjmp(local_sigjmp_buf, 1) != 0)
	{
		/* Since not using PG_TRY, must reset error stack by hand */
		error_context_stack = NULL;

		/* Prevent interrupts while cleaning up */
		HOLD_INTERRUPTS();

		/* Report the error to the server log */
		EmitErrorReport();

		/*
		 * These operations are really just a minimal subset of
		 * AbortTransaction().  We don't have very many resources to worry
		 * about in checkpointer, but we do have LWLocks, buffers, and temp
		 * files.
		 */
		LWLockReleaseAll();
		ConditionVariableCancelSleep();
		pgstat_report_wait_end();
		AbortBufferIO();
		UnlockBuffers();
		/* buffer pins are released here: */
		ResourceOwnerRelease(CurrentResourceOwner,
							 RESOURCE_RELEASE_BEFORE_LOCKS,
							 false, true);
		/* we needn't bother with the other ResourceOwnerRelease phases */
		AtEOXact_Buffers(false);
		AtEOXact_SMgr();
//.........这里部分代码省略.........
开发者ID:Tao-Ma,项目名称:postgres,代码行数:101,代码来源:checkpointer.c


示例19: dg_send_recv

ssize_t
dg_send_recv(int fd, const void *outbuff, size_t outbytes,
			 void *inbuff, size_t inbytes,
			 const SA *destaddr, socklen_t destlen)
{
	ssize_t			n;
	struct iovec	iovsend[2], iovrecv[2];

	if (rttinit == 0) {
		rtt_init(&rttinfo);		/* first time we're called */
		rttinit = 1;
		rtt_d_flag = 1;
	}

	sendhdr.seq++;
	msgsend.msg_name = destaddr;
	msgsend.msg_namelen = destlen;
	msgsend.msg_iov = iovsend;
	msgsend.msg_iovlen = 2;
	iovsend[0].iov_base = &sendhdr;
	iovsend[0].iov_len = sizeof(struct hdr);
	iovsend[1].iov_base = outbuff;
	iovsend[1].iov_len = outbytes;

	msgrecv.msg_name = NULL;
	msgrecv.msg_namelen = 0;
	msgrecv.msg_iov = iovrecv;
	msgrecv.msg_iovlen = 2;
	iovrecv[0].iov_base = &recvhdr;
	iovrecv[0].iov_len = sizeof(struct hdr);
	iovrecv[1].iov_base = inbuff;
	iovrecv[1].iov_len = inbytes;
/* end dgsendrecv1 */

/* include dgsendrecv2 */
	if (signal(SIGALRM, sig_alrm) == SIG_ERR) {
		perror("signal error");
		exit(1);
	}
	rtt_newpack(&rttinfo);		/* initialize for this packet */

sendagain:
#ifdef	RTT_DEBUG
	fprintf(stderr, "send %4d: ", sendhdr.seq);
#endif
	sendhdr.ts = rtt_ts(&rttinfo);
	int nbytes = 0;	/* must first figure out what return value should be */
	int i;
	for (i = 0; i < msgsend.msg_iovlen; i++)
		nbytes += msgsend.msg_iov[i].iov_len;
	if (sendmsg(fd, &msgsend, 0) != nbytes) {
		perror("sendmsg error");
		exit(1);
	}

	alarm(rtt_start(&rttinfo));	/* calc timeout value & start timer */
#ifdef	RTT_DEBUG
	rtt_debug(&rttinfo);
#endif

	if (sigsetjmp(jmpbuf, 1) != 0) {
		if (rtt_timeout(&rttinfo) < 0) {
			fprintf(stderr, "dg_send_recv: no response from server, giving up\n");
			rttinit = 0;	/* reinit in case we're called again */
			errno = ETIMEDOUT;
			return(-1);
		}
#ifdef	RTT_DEBUG
		fprintf(stderr, "dg_send_recv: timeout, retransmitting\n");
#endif
		goto sendagain;
	}

	do {
		if ((n = recvmsg(fd, &msgrecv, 0)) < 0) {
			perror("recvmsg error");
			exit(1);
		}
#ifdef	RTT_DEBUG
		fprintf(stderr, "recv %4d\n", recvhdr.seq);
#endif
	} while (n < sizeof(struct hdr) || recvhdr.seq != sendhdr.seq);

	alarm(0);			/* stop SIGALRM timer */
		/* 4calculate & store new RTT estimator values */
	rtt_stop(&rttinfo, rtt_ts(&rttinfo) - recvhdr.ts);

	return(n - sizeof(struct hdr));	/* return size of received datagram */
}
开发者ID:hechenyu,项目名称:unix_code,代码行数:89,代码来源:dg_send_recv.c


示例20: print_collf

/*
 * ~p command.
 */
static void
print_collf(FILE *collf, struct header *hp)
{
	char *lbuf = NULL;
	FILE *obuf = stdout;
	struct attachment *ap;
	char *cp;
	enum gfield	gf;
	size_t	linecnt, maxlines, linesize = 0, linelen, count, count2;

	(void)&obuf;
	(void)&cp;
	fflush(collf);
	rewind(collf);
	count = count2 = fsize(collf);
	if (is_a_tty[0] && is_a_tty[1] && (cp = value("crt")) != NULL) {
		for (linecnt = 0;
			fgetline(&lbuf, &linesize, &count2, NULL, collf, 0);
			linecnt++);
		rewind(collf);
		maxlines = (*cp == '\0' ? screensize() : atoi(cp));
		maxlines -= 4;
		if (hp->h_to)
			maxlines--;
		if (hp->h_subject)
			maxlines--;
		if (hp->h_cc)
			maxlines--;
		if (hp->h_bcc)
			maxlines--;
		if (hp->h_attach)
			maxlines--;
		maxlines -= myaddrs(hp) != NULL || hp->h_from != NULL;
		maxlines -= value("ORGANIZATION") != NULL ||
			hp->h_organization != NULL;
		maxlines -= value("replyto") != NULL || hp->h_replyto != NULL;
		maxlines -= value("sender") != NULL || hp->h_sender != NULL;
		if (linecnt > maxlines) {
			cp = get_pager();
			if (sigsetjmp(pipejmp, 1))
				goto endpipe;
			obuf = Popen(cp, "w", NULL, 1);
			if (obuf == NULL) {
				perror(cp);
				obuf = stdout;
			} else
				safe_signal(SIGPIPE, onpipe);
		}
	}
	fprintf(obuf, catgets(catd, CATSET, 62,
				"-------\nMessage contains:\n"));
	gf = GIDENT|GTO|GSUB 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sigsetmask函数代码示例发布时间:2022-05-30
下一篇:
C++ sigset函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap