add function sf_usage and sf_parse_daemon_mode_and_action

connection_manager
yuqing 2018-07-20 17:16:06 +08:00
parent b27ecc4c1e
commit a64f3ffab4
3 changed files with 35 additions and 1 deletions

View File

@ -224,7 +224,7 @@ static int client_sock_read(int sock, short event, void *arg)
}
else {
logWarning("file: "__FILE__", line: %d, "
"client ip: %s, req_count: %ld, recv timeout",
"client ip: %s, req_count: %"PRId64", recv timeout",
__LINE__, pTask->client_ip, pTask->req_count);
}

View File

@ -5,6 +5,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <pthread.h>
#include "sf_util.h"
@ -72,3 +73,30 @@ int sf_printbuffer(char* buffer,int32_t len)
return(0);
}
void sf_usage(const char *program)
{
fprintf(stderr, "Usage: %s <config_file> [--without-daemon | --no-daemon] "
"[start | stop | restart]\n", program);
}
void sf_parse_daemon_mode_and_action(int argc, char *argv[],
bool *daemon_mode, char **action)
{
int i;
*daemon_mode = true;
for (i=2; i<argc; i++) {
if (strcmp(argv[i], "--without-daemon") == 0 ||
strcmp(argv[i], "--no-daemon") == 0)
{
*daemon_mode = false;
break;
}
}
if (argc - (*daemon_mode ? 0 : 1) > 2) {
*action = argv[argc - 1];
} else {
*action = NULL;
}
}

View File

@ -48,6 +48,12 @@ int64_t getticks() ;
void log_plus(const int priority, const char* file, int line, const char* fmt, ...);
int sf_printbuffer(char* buffer,int32_t len);
void sf_usage(const char *program);
void sf_parse_daemon_mode_and_action(int argc, char *argv[],
bool *daemon_mode, char **action);
#ifdef __cplusplus
}
#endif