Skip to content

Commit

Permalink
Fixed: warning: implicit declaration of function ‘strdup’ (daemon)
Browse files Browse the repository at this point in the history
CS fixes + review
[ci skip]
  • Loading branch information
nuxwin committed Feb 22, 2016
1 parent 1d5b447 commit 6b21b77
Show file tree
Hide file tree
Showing 18 changed files with 11 additions and 68 deletions.
1 change: 0 additions & 1 deletion daemon/bye_cmd.h
@@ -1,5 +1,4 @@
#ifndef _BYE_CMD_H

#define _BYE_CMD_H

extern int byeSyntax(int fd, char *buffer);
Expand Down
2 changes: 0 additions & 2 deletions daemon/bye_syntax.h
@@ -1,10 +1,8 @@
#ifndef _BYE_SYNTAX_H

#define _BYE_SYNTAX_H

#include <stdlib.h>
#include <string.h>

#include "defs.h"

extern char *message(int message_number);
Expand Down
32 changes: 3 additions & 29 deletions daemon/daemon_init.c
Expand Up @@ -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);

Expand Down
5 changes: 3 additions & 2 deletions daemon/daemon_init.h
@@ -1,14 +1,15 @@
#ifndef _DEAMON_INIT_H

#define _DAEMON_INIT_H

#define _XOPEN_SOURCE

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>

#include <errno.h>
#include "defs.h"

extern char *message(int message_number);
Expand Down
2 changes: 0 additions & 2 deletions daemon/defs.h
@@ -1,5 +1,4 @@
#ifndef _DEFS_H

#define _DEFS_H

/* Syslog daemon options */
Expand Down Expand Up @@ -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
2 changes: 0 additions & 2 deletions daemon/helo_cmd.h
@@ -1,10 +1,8 @@
#ifndef _HELO_CMD_H

#define _HELO_CMD_H

#include <stdlib.h>
#include <string.h>

#include "defs.h"

extern int receiveLine(int fd, char *dest, size_t n);
Expand Down
2 changes: 0 additions & 2 deletions daemon/helo_syntax.h
@@ -1,10 +1,8 @@
#ifndef _HELO_SYNTAX_H

#define _HELO_SYNTAX_H

#include <stdlib.h>
#include <string.h>

#include "defs.h"

extern char *message(int message_number);
Expand Down
10 changes: 2 additions & 8 deletions daemon/imscp_daemon.h
@@ -1,7 +1,8 @@
#ifndef _IMSCP_DAEMON_H

#define _IMSCP_DAEMON_H

#define _POSIX_C_SOURCE 200809L

#include <stdlib.h>
#include <syslog.h>
#include <sys/stat.h>
Expand All @@ -15,11 +16,9 @@
#include <unistd.h>
#include <stdio.h>
#include <arpa/inet.h>

#include "defs.h"

char *backendscriptpath = NULL;

struct timeval *tv_rcv;
struct timeval *tv_snd;

Expand All @@ -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
1 change: 0 additions & 1 deletion daemon/lr_cmd.h
@@ -1,5 +1,4 @@
#ifndef _LR_CMD_H

#define _LR_CMD_H

extern int lrSyntax(int fd, char *buffer);
Expand Down
6 changes: 3 additions & 3 deletions daemon/lr_syntax.h
@@ -1,16 +1,16 @@
#ifndef _LR_SYNTAX_H

#define _LR_SYNTAX_H

#define _POSIX_C_SOURCE 200809L

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <libgen.h>

#include "defs.h"

extern char *backendscriptpath;

extern char *message(int message_number);
extern int sendLine(int fd, char *src, size_t len);

Expand Down
1 change: 0 additions & 1 deletion daemon/message.h
@@ -1,5 +1,4 @@
#ifndef _MESSAGE_H

#define _MESSAGE_H

#include "defs.h"
Expand Down
2 changes: 0 additions & 2 deletions daemon/receive_data.h
@@ -1,11 +1,9 @@
#ifndef _RECEIVE_DATA_H

#define _RECEIVE_DATA_H

#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

#include "defs.h"

int receiveData(int fd, char *dest, size_t n);
Expand Down
2 changes: 0 additions & 2 deletions daemon/recv_line.h
@@ -1,11 +1,9 @@
#ifndef _RECV_LINE_H

#define _RECV_LINE_H

#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include "defs.h"

extern char *message(int message_number);
Expand Down
2 changes: 0 additions & 2 deletions daemon/say.h
@@ -1,9 +1,7 @@
#ifndef _SAY_H

#define _SAY_H

#include <syslog.h>

#include "defs.h"

void say(char *format, char *message);
Expand Down
2 changes: 0 additions & 2 deletions daemon/send_data.h
@@ -1,11 +1,9 @@
#ifndef _SEND_DATA_H

#define _SEND_DATA_H

#include <sys/types.h>
#include <unistd.h>
#include <errno.h>

#include "defs.h"

int sendData(int fd, char *src, size_t n);
Expand Down
2 changes: 0 additions & 2 deletions daemon/send_line.h
@@ -1,11 +1,9 @@
#ifndef _SEND_LINE_H

#define _SEND_LINE_H

#include <errno.h>
#include <string.h>
#include <stdlib.h>

#include "defs.h"

extern char *message(int message_number);
Expand Down
2 changes: 0 additions & 2 deletions daemon/signal-handlers.h
@@ -1,13 +1,11 @@
#ifndef _SIGNAL_HANDLERS_H

#define _SIGNAL_HANDLERS_H

#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "defs.h"

#if defined(__OpenBSD__) || defined(__FreeBSD__)
Expand Down
3 changes: 0 additions & 3 deletions daemon/take_connection.h
@@ -1,15 +1,12 @@
#ifndef _TAKE_CONNECTION_H

#define _TAKE_CONNECTION_H

#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#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);
Expand Down

0 comments on commit 6b21b77

Please sign in to comment.