From e649f6245f73b99e5c2501f789a3b363c2a25554 Mon Sep 17 00:00:00 2001
From: veega2022 <zhuweijia@huawei.com>
Date: Wed, 10 May 2023 18:05:01 +0800
Subject: [PATCH 03/18] fix signal proc func api modified to be open to the
 public

move sig_init api to op_logs public header file

Signed-off-by: wangkang <wangkang124@hisilicon.com>
---
 hikp_init_main.c                    | 20 --------------------
 libhikptdev/src/rciep/hikpt_rciep.h |  2 +-
 tool_lib/op_logs.c                  | 23 ++++++++++++++++++++++-
 tool_lib/op_logs.h                  |  3 ++-
 4 files changed, 25 insertions(+), 23 deletions(-)

diff --git a/hikp_init_main.c b/hikp_init_main.c
index 4102c69..4629b40 100644
--- a/hikp_init_main.c
+++ b/hikp_init_main.c
@@ -19,26 +19,6 @@
 /* hikptool command adapter */
 struct cmd_adapter g_tool = { 0 };
 
-static void _sig_ign_handle(int arg)
-{
-	signal_op_log_write(arg);
-	hikp_unlock();
-	_exit(1);
-}
-
-static void sig_init(void)
-{
-	(void)signal(SIGINT, _sig_ign_handle); /* Quit process */
-	(void)signal(SIGTERM, _sig_ign_handle);
-	(void)signal(SIGQUIT, _sig_ign_handle);
-	(void)signal(SIGHUP, _sig_ign_handle);
-	(void)signal(SIGSEGV, _sig_ign_handle);
-	(void)signal(SIGBUS, _sig_ign_handle);
-	(void)signal(SIGFPE, _sig_ign_handle);
-	(void)signal(SIGABRT, _sig_ign_handle);
-	(void)signal(SIGTSTP, _sig_ign_handle); /* Stop process */
-}
-
 static void show_tool_version(const struct cmd_adapter *adapter)
 {
 	printf("%s version %s Huawei\n", adapter->name, adapter->version);
diff --git a/libhikptdev/src/rciep/hikpt_rciep.h b/libhikptdev/src/rciep/hikpt_rciep.h
index 8fbb3c0..dd08759 100644
--- a/libhikptdev/src/rciep/hikpt_rciep.h
+++ b/libhikptdev/src/rciep/hikpt_rciep.h
@@ -40,7 +40,7 @@
 #define MAX_LOCK_COUNT 5
 #define LOCK_CHECK_GAP_US 1000
 #define CPL_CHECK_GAP_US 1000
-#define WAIT_CPL_MAX_MS 5000
+#define WAIT_CPL_MAX_MS 8000
 
 enum {
 	HIKP_RESOURCE_DIR,
diff --git a/tool_lib/op_logs.c b/tool_lib/op_logs.c
index d6082a3..069428d 100644
--- a/tool_lib/op_logs.c
+++ b/tool_lib/op_logs.c
@@ -14,7 +14,9 @@
 #include <syslog.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <signal.h>
 #include "tool_lib.h"
+#include "hikptdev_plug.h"
 #include "op_logs.h"
 
 static char g_op_log[OP_LOG_FILE_PATH_MAXLEN] = {0};
@@ -23,7 +25,6 @@ static bool g_record = true;
 static bool g_log_info;
 static char g_input_buf[OP_LOG_FILE_W_MAXSIZE + 1] = {0};
 
-
 static void op_log_write(const char *log_data)
 {
 	size_t w_size;
@@ -414,3 +415,23 @@ SIGNAL_LOG_OUT:
 	(void)close(fd);
 	(void)uda_unfcntl(&op_log_fd, UDA_FLOCK_BLOCK);
 }
+
+static void signal_handle(int arg)
+{
+	signal_op_log_write(arg);
+	hikp_unlock();
+	_exit(1);
+}
+
+void sig_init(void)
+{
+	(void)signal(SIGINT,  signal_handle); /* Quit process */
+	(void)signal(SIGTERM, signal_handle);
+	(void)signal(SIGQUIT, signal_handle);
+	(void)signal(SIGHUP,  signal_handle);
+	(void)signal(SIGSEGV, signal_handle);
+	(void)signal(SIGBUS,  signal_handle);
+    (void)signal(SIGFPE,  signal_handle);
+    (void)signal(SIGABRT, signal_handle);
+    (void)signal(SIGTSTP, signal_handle); /* Stop process */
+}
diff --git a/tool_lib/op_logs.h b/tool_lib/op_logs.h
index 597f063..6b6e421 100644
--- a/tool_lib/op_logs.h
+++ b/tool_lib/op_logs.h
@@ -45,7 +45,8 @@ struct op_log_print_t {
 	char *str;
 };
 
-void signal_op_log_write(int signal_code);
+void sig_init(void);
+
 void op_log_on(void);
 void op_log_off(void);
 int op_log_initialise(const char *log_dir);
-- 
2.25.1

