本文整理汇总了C++中sigsetjmp函数的典型用法代码示例。如果您正苦于以下问题:C++ sigsetjmp函数的具体用法?C++ sigsetjmp怎么用?C++ sigsetjmp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sigsetjmp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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");
}
}
示例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);
}
示例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 */
示例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);
}
示例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;
}
示例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;
}
示例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;
示例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];
//.........这里部分代码省略.........
示例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;
}
//.........这里部分代码省略.........
示例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
}
示例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);
}
//.........这里部分代码省略.........
示例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);
}
示例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;
//.........这里部分代码省略.........
示例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:
//.........这里部分代码省略.........