From 6b21b772b71d57faabc1db9c67badca1d6288dd3 Mon Sep 17 00:00:00 2001 From: Laurent Declercq Date: Mon, 22 Feb 2016 15:09:54 +0100 Subject: [PATCH] =?UTF-8?q?Fixed:=20warning:=20implicit=20declaration=20of?= =?UTF-8?q?=20function=20=E2=80=98strdup=E2=80=99=20(daemon)=20CS=20fixes?= =?UTF-8?q?=20+=20review=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- daemon/bye_cmd.h | 1 - daemon/bye_syntax.h | 2 -- daemon/daemon_init.c | 32 +++----------------------------- daemon/daemon_init.h | 5 +++-- daemon/defs.h | 2 -- daemon/helo_cmd.h | 2 -- daemon/helo_syntax.h | 2 -- daemon/imscp_daemon.h | 10 ++-------- daemon/lr_cmd.h | 1 - daemon/lr_syntax.h | 6 +++--- daemon/message.h | 1 - daemon/receive_data.h | 2 -- daemon/recv_line.h | 2 -- daemon/say.h | 2 -- daemon/send_data.h | 2 -- daemon/send_line.h | 2 -- daemon/signal-handlers.h | 2 -- daemon/take_connection.h | 3 --- 18 files changed, 11 insertions(+), 68 deletions(-) diff --git a/daemon/bye_cmd.h b/daemon/bye_cmd.h index 4b757e367a..c901e03c83 100644 --- a/daemon/bye_cmd.h +++ b/daemon/bye_cmd.h @@ -1,5 +1,4 @@ #ifndef _BYE_CMD_H - #define _BYE_CMD_H extern int byeSyntax(int fd, char *buffer); diff --git a/daemon/bye_syntax.h b/daemon/bye_syntax.h index 935fea1c12..fff98ba6a2 100644 --- a/daemon/bye_syntax.h +++ b/daemon/bye_syntax.h @@ -1,10 +1,8 @@ #ifndef _BYE_SYNTAX_H - #define _BYE_SYNTAX_H #include #include - #include "defs.h" extern char *message(int message_number); diff --git a/daemon/daemon_init.c b/daemon/daemon_init.c index dedc4e7137..be2e09676f 100644 --- a/daemon/daemon_init.c +++ b/daemon/daemon_init.c @@ -2,37 +2,11 @@ void daemonInit(char *pidfile) { - pid_t pid; - - /* create child process */ - pid = fork(); - if(pid < 0) { - exit(EXIT_FAILURE); - } - - /* terminate parent process */ - if(pid > 0) { - exit(EXIT_SUCCESS); + /* daemonize */ + if(daemon(1, 1) > 1) { + exit(errno); } - /* umask the file mode */ - umask(0); - - /* set new session */ - if(setsid() < 0) { - exit(EXIT_FAILURE); - } - - /* change the current wokring directory to root */ - if(chdir("/") < 0) { - exit(EXIT_FAILURE); - } - - /* close stdin, stdout and stderr */ - close(STDIN_FILENO); - close(STDOUT_FILENO); - close(STDERR_FILENO); - /* open log */ openlog(message(MSG_DAEMON_NAME), LOG_PID, SYSLOG_FACILITY); diff --git a/daemon/daemon_init.h b/daemon/daemon_init.h index e71290bad3..3de6099470 100644 --- a/daemon/daemon_init.h +++ b/daemon/daemon_init.h @@ -1,14 +1,15 @@ #ifndef _DEAMON_INIT_H - #define _DAEMON_INIT_H +#define _XOPEN_SOURCE + #include #include #include #include #include #include - +#include #include "defs.h" extern char *message(int message_number); diff --git a/daemon/defs.h b/daemon/defs.h index be2d6c62c4..7c8d6758c4 100644 --- a/daemon/defs.h +++ b/daemon/defs.h @@ -1,5 +1,4 @@ #ifndef _DEFS_H - #define _DEFS_H /* Syslog daemon options */ @@ -58,5 +57,4 @@ #define MSG_ERROR_SOCKET_CREATE_TXT "socket() error: %s" #define MSG_GOOD_BYE 120 #define MSG_GOOD_BYE_TXT "Good bye\n" - #endif diff --git a/daemon/helo_cmd.h b/daemon/helo_cmd.h index b49b195358..a6037f0983 100644 --- a/daemon/helo_cmd.h +++ b/daemon/helo_cmd.h @@ -1,10 +1,8 @@ #ifndef _HELO_CMD_H - #define _HELO_CMD_H #include #include - #include "defs.h" extern int receiveLine(int fd, char *dest, size_t n); diff --git a/daemon/helo_syntax.h b/daemon/helo_syntax.h index 323f0b5b93..e38a050146 100644 --- a/daemon/helo_syntax.h +++ b/daemon/helo_syntax.h @@ -1,10 +1,8 @@ #ifndef _HELO_SYNTAX_H - #define _HELO_SYNTAX_H #include #include - #include "defs.h" extern char *message(int message_number); diff --git a/daemon/imscp_daemon.h b/daemon/imscp_daemon.h index 001354c525..469acc830f 100644 --- a/daemon/imscp_daemon.h +++ b/daemon/imscp_daemon.h @@ -1,7 +1,8 @@ #ifndef _IMSCP_DAEMON_H - #define _IMSCP_DAEMON_H +#define _POSIX_C_SOURCE 200809L + #include #include #include @@ -15,11 +16,9 @@ #include #include #include - #include "defs.h" char *backendscriptpath = NULL; - struct timeval *tv_rcv; struct timeval *tv_snd; @@ -30,9 +29,4 @@ extern void sigChild (int signo); extern void sigPipe(int signo); extern void takeConnection(int sockfd); -/* TOO review (see feature_test_macros(7) */ -int getopt(int argc, char * const argv[], const char *optstring); -extern char *optarg; -extern int optind, opterr, optopt; - #endif diff --git a/daemon/lr_cmd.h b/daemon/lr_cmd.h index c48a6c920a..2a8c0a5db5 100644 --- a/daemon/lr_cmd.h +++ b/daemon/lr_cmd.h @@ -1,5 +1,4 @@ #ifndef _LR_CMD_H - #define _LR_CMD_H extern int lrSyntax(int fd, char *buffer); diff --git a/daemon/lr_syntax.h b/daemon/lr_syntax.h index e0f50cd816..6b89d62426 100644 --- a/daemon/lr_syntax.h +++ b/daemon/lr_syntax.h @@ -1,16 +1,16 @@ #ifndef _LR_SYNTAX_H - #define _LR_SYNTAX_H + +#define _POSIX_C_SOURCE 200809L + #include #include #include #include #include - #include "defs.h" extern char *backendscriptpath; - extern char *message(int message_number); extern int sendLine(int fd, char *src, size_t len); diff --git a/daemon/message.h b/daemon/message.h index 1a813d266e..3112865b23 100644 --- a/daemon/message.h +++ b/daemon/message.h @@ -1,5 +1,4 @@ #ifndef _MESSAGE_H - #define _MESSAGE_H #include "defs.h" diff --git a/daemon/receive_data.h b/daemon/receive_data.h index 5c23fae7af..b7eb1d9cb2 100644 --- a/daemon/receive_data.h +++ b/daemon/receive_data.h @@ -1,11 +1,9 @@ #ifndef _RECEIVE_DATA_H - #define _RECEIVE_DATA_H #include #include #include - #include "defs.h" int receiveData(int fd, char *dest, size_t n); diff --git a/daemon/recv_line.h b/daemon/recv_line.h index 3d931b900d..221feb4758 100644 --- a/daemon/recv_line.h +++ b/daemon/recv_line.h @@ -1,11 +1,9 @@ #ifndef _RECV_LINE_H - #define _RECV_LINE_H #include #include #include - #include "defs.h" extern char *message(int message_number); diff --git a/daemon/say.h b/daemon/say.h index 2c14fc0e68..2c1f574378 100644 --- a/daemon/say.h +++ b/daemon/say.h @@ -1,9 +1,7 @@ #ifndef _SAY_H - #define _SAY_H #include - #include "defs.h" void say(char *format, char *message); diff --git a/daemon/send_data.h b/daemon/send_data.h index 2ab0e0211f..365dec2eb4 100644 --- a/daemon/send_data.h +++ b/daemon/send_data.h @@ -1,11 +1,9 @@ #ifndef _SEND_DATA_H - #define _SEND_DATA_H #include #include #include - #include "defs.h" int sendData(int fd, char *src, size_t n); diff --git a/daemon/send_line.h b/daemon/send_line.h index bc2f7947db..838fa7dd9a 100644 --- a/daemon/send_line.h +++ b/daemon/send_line.h @@ -1,11 +1,9 @@ #ifndef _SEND_LINE_H - #define _SEND_LINE_H #include #include #include - #include "defs.h" extern char *message(int message_number); diff --git a/daemon/signal-handlers.h b/daemon/signal-handlers.h index 182412eb51..3633b97dc6 100644 --- a/daemon/signal-handlers.h +++ b/daemon/signal-handlers.h @@ -1,5 +1,4 @@ #ifndef _SIGNAL_HANDLERS_H - #define _SIGNAL_HANDLERS_H #include @@ -7,7 +6,6 @@ #include #include #include - #include "defs.h" #if defined(__OpenBSD__) || defined(__FreeBSD__) diff --git a/daemon/take_connection.h b/daemon/take_connection.h index 83250859d8..bf804552ad 100644 --- a/daemon/take_connection.h +++ b/daemon/take_connection.h @@ -1,15 +1,12 @@ #ifndef _TAKE_CONNECTION_H - #define _TAKE_CONNECTION_H #include #include #include - #include "defs.h" extern char *message(int message_number); - extern int sendLine(int fd, char *src, size_t len); extern int heloCommand(int fd); extern int lrCommand(int fd, char *msg);