From 82bd40bc2b2d024ab7be0f27eea3f871f99cc213 Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期三, 21 十月 2020 16:55:30 +0800
Subject: [PATCH] update

---
 test/test.c |   48 ++++++++++++++++++++++++++++++++++++------------
 1 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/test/test.c b/test/test.c
index 1e27d2f..ab21287 100644
--- a/test/test.c
+++ b/test/test.c
@@ -1,15 +1,39 @@
 #include "usg_common.h"
- 
-int  test() {
-	static int count = 0;
-	count++;
-	return count;
+static void sig_quit(int);
+int
+main(void)
+{
+  sigset_t
+  newmask, oldmask, pendmask;
+  if (signal(SIGQUIT, sig_quit) == SIG_ERR)
+    err_exit(errno, "can鈥檛 catch SIGQUIT");
+  /*
+  * Block SIGQUIT and save current signal mask.
+  */
+  sigemptyset(&newmask);
+  sigaddset(&newmask, SIGQUIT);
+  if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
+    err_exit(errno, "SIG_BLOCK error");
+  sleep(5);
+  /* SIGQUIT here will remain pending */
+  if (sigpending(&pendmask) < 0)
+    err_exit(errno, "sigpending error");
+  if (sigismember(&pendmask, SIGQUIT))
+    printf("\nSIGQUIT pending\n");
+  /*
+  * Restore signal mask which unblocks SIGQUIT.
+  */
+  if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
+    err_exit(errno, "SIG_SETMASK error");
+  printf("SIGQUIT unblocked\n");
+  sleep(5);
+  exit(0);
+  /* SIGQUIT here will terminate with core file */
 }
 
-
-int main() {
-	char host[128];
-	const char * src = "192.168.20.21";
- 	memcpy( host, src, sizeof(host));
-	printf("%s\n", host);
-}
\ No newline at end of file
+static void sig_quit(int signo)
+{
+  printf("caught SIGQUIT\n");
+  if (signal(SIGQUIT, SIG_DFL) == SIG_ERR)
+    err_exit(errno, "can鈥檛 reset SIGQUIT");
+}

--
Gitblit v1.8.0