contrib/chg/chg.c
changeset 29369 85a18f3c0bdd
parent 29357 66d41c9e9222
child 29370 3ddf4d0c4170
equal deleted inserted replaced
29367:4e6e280e238f 29369:85a18f3c0bdd
   421 
   421 
   422 error:
   422 error:
   423 	abortmsgerrno("failed to set up signal handlers");
   423 	abortmsgerrno("failed to set up signal handlers");
   424 }
   424 }
   425 
   425 
       
   426 static void restoresignalhandler()
       
   427 {
       
   428 	struct sigaction sa;
       
   429 	memset(&sa, 0, sizeof(sa));
       
   430 	sa.sa_handler = SIG_DFL;
       
   431 	sa.sa_flags = SA_RESTART;
       
   432 	if (sigemptyset(&sa.sa_mask) < 0)
       
   433 		goto error;
       
   434 
       
   435 	if (sigaction(SIGHUP, &sa, NULL) < 0)
       
   436 		goto error;
       
   437 	if (sigaction(SIGINT, &sa, NULL) < 0)
       
   438 		goto error;
       
   439 	if (sigaction(SIGTERM, &sa, NULL) < 0)
       
   440 		goto error;
       
   441 	if (sigaction(SIGWINCH, &sa, NULL) < 0)
       
   442 		goto error;
       
   443 	if (sigaction(SIGCONT, &sa, NULL) < 0)
       
   444 		goto error;
       
   445 	if (sigaction(SIGTSTP, &sa, NULL) < 0)
       
   446 		goto error;
       
   447 
       
   448 	peerpid = 0;
       
   449 	return;
       
   450 
       
   451 error:
       
   452 	abortmsgerrno("failed to restore signal handlers");
       
   453 }
       
   454 
   426 /* This implementation is based on hgext/pager.py (post 369741ef7253)
   455 /* This implementation is based on hgext/pager.py (post 369741ef7253)
   427  * Return 0 if pager is not started, or pid of the pager */
   456  * Return 0 if pager is not started, or pid of the pager */
   428 static pid_t setuppager(hgclient_t *hgc, const char *const args[],
   457 static pid_t setuppager(hgclient_t *hgc, const char *const args[],
   429 		       size_t argsize)
   458 		       size_t argsize)
   430 {
   459 {
   606 	}
   635 	}
   607 
   636 
   608 	setupsignalhandler(hgc_peerpid(hgc));
   637 	setupsignalhandler(hgc_peerpid(hgc));
   609 	pid_t pagerpid = setuppager(hgc, argv + 1, argc - 1);
   638 	pid_t pagerpid = setuppager(hgc, argv + 1, argc - 1);
   610 	int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1);
   639 	int exitcode = hgc_runcommand(hgc, argv + 1, argc - 1);
       
   640 	restoresignalhandler();
   611 	hgc_close(hgc);
   641 	hgc_close(hgc);
   612 	freecmdserveropts(&opts);
   642 	freecmdserveropts(&opts);
   613 	if (pagerpid)
   643 	if (pagerpid)
   614 		waitpager(pagerpid);
   644 		waitpager(pagerpid);
   615 
   645