summaryrefslogtreecommitdiff
path: root/shaping/src/main.cpp
diff options
context:
space:
mode:
authorliuchang <[email protected]>2023-04-07 10:14:26 +0000
committerliuchang <[email protected]>2023-04-07 10:14:26 +0000
commit19e152a2928a4a12edd4bb0e4c8df68785bb3b07 (patch)
treea72c01f96c1cb955d922aa69f68cb750697749a0 /shaping/src/main.cpp
parent121cc045981f27de604ba7b6cebdf2a5efe1b868 (diff)
add signal process for log conf reload
Diffstat (limited to 'shaping/src/main.cpp')
-rw-r--r--shaping/src/main.cpp28
1 files changed, 27 insertions, 1 deletions
diff --git a/shaping/src/main.cpp b/shaping/src/main.cpp
index 7f106ed..2291db5 100644
--- a/shaping/src/main.cpp
+++ b/shaping/src/main.cpp
@@ -3,7 +3,10 @@
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
+#include <signal.h>
+#include "log.h"
+#include "utils.h"
#include "shaper.h"
#include "shaper_stat.h"
#include "shaper_marsio.h"
@@ -29,13 +32,36 @@ static void *shaper_thread_loop(void *data)
return NULL;
}
+static void sig_handler(int signo)
+{
+ if (signo == SIGHUP)
+ {
+ LOG_INFO("%s: recv SIGHUP, reload zlog.conf", LOG_TAG_SHAPING);
+ LOG_RELOAD();
+ }
+
+ return;
+}
+
int main(int argc, char **argv)
{
struct shaping_ctx *ctx = NULL;
+ if (LOG_INIT("./conf/zlog.conf") == -1)
+ {
+ return -1;
+ }
+
+ if (signal(SIGHUP, sig_handler) == SIG_ERR)
+ {
+ LOG_ERROR("%s: unable to register SIGHUP signal handler, error %d: %s", LOG_TAG_SHAPING, errno, strerror(errno));
+ LOG_CLOSE();
+ return -1;
+ }
+
ctx = shaping_engine_init();
if (!ctx) {
- return 0;
+ return -1;
}
for (int i = 0; i < ctx->thread_num; i++) {