diff options
author | jjako <jjako> | 2004-01-09 15:19:20 +0000 |
---|---|---|
committer | jjako <jjako> | 2004-01-09 15:19:20 +0000 |
commit | 0141d2023243fbbaba1d04fd157e8ffc729e5e70 (patch) | |
tree | 9fe6a3df502901a889a15fe9cfb1b9547858d8cf /ggsn/ggsn.c | |
parent | 98200dfdf9ef8b570e91920f25b0225cd5d35ea4 (diff) |
Changes to allow compilation under Solaris
Diffstat (limited to 'ggsn/ggsn.c')
-rw-r--r-- | ggsn/ggsn.c | 43 |
1 files changed, 37 insertions, 6 deletions
diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c index 25da64c..75a76a4 100644 --- a/ggsn/ggsn.c +++ b/ggsn/ggsn.c @@ -36,19 +36,15 @@ #include <arpa/inet.h> #include <sys/wait.h> #include <sys/stat.h> +#include <fcntl.h> #include <unistd.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <net/if.h> -#include <features.h> #include <errno.h> -#include <asm/types.h> -#include <sys/socket.h> -#include <linux/netlink.h> - #include <time.h> #include "tun.h" @@ -88,10 +84,38 @@ void log_pid(char *pidfile) { "Failed to create process ID file: %s!", pidfile); return; } - fprintf(file, "%d\n", getpid()); + fprintf(file, "%d\n", (int) getpid()); fclose(file); } +#ifdef __sun__ +int daemon(int nochdir, int noclose) { + int fd; + + switch (fork()) { + case -1: + return (-1); + case 0: + break; + default: + _exit(0); + } + + if (setsid() == -1) + return (-1); + + if (!nochdir) chdir("/"); + + if (!noclose && (fd = open("/dev/null", O_RDWR, 0)) != -1) { + dup2(fd, STDIN_FILENO); + dup2(fd, STDOUT_FILENO); + dup2(fd, STDERR_FILENO); + if (fd > 2) close (fd); + } + return (0); +} +#endif + int encaps_printf(void *p, void *packet, unsigned len) { @@ -192,7 +216,14 @@ int main(int argc, char **argv) /* open a connection to the syslog daemon */ /*openlog(PACKAGE, LOG_PID, LOG_DAEMON);*/ + + /* TODO: Only use LOG__PERROR for linux */ +#ifdef __linux__ openlog(PACKAGE, (LOG_PID | LOG_PERROR), LOG_DAEMON); +#else + openlog(PACKAGE, (LOG_PID), LOG_DAEMON); +#endif + if (cmdline_parser (argc, argv, &args_info) != 0) exit(1); |