From be8d5841618808420cbbf20e7d5349d71a958b29 Mon Sep 17 00:00:00 2001 From: Jesse Smith Date: Sun, 9 Dec 2018 19:32:04 -0400 Subject: [PATCH] Added some defines and compile-time conditionals to make some components of sysvinit compile on FreeBSD. --- doc/Changelog | 3 ++- src/bootlogd.c | 8 ++++++++ src/init.c | 20 +++++++++++++++++--- src/init.h | 9 +++++++++ src/shutdown.c | 7 +++++++ src/utmp.c | 4 ++++ 6 files changed, 47 insertions(+), 4 deletions(-) diff --git a/doc/Changelog b/doc/Changelog index 7328a1d..8008200 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -13,7 +13,8 @@ sysvinit (2.94) unreleased; urgency=low is taken. * Removed unnecessary malloc.h includes. Memory allocation and freeing is now handled in stdlib.h - + * Added defines for FreeBSD to make some components compile + on FreeBSD 11. sysvinit (2.93) released; urgency=low diff --git a/src/bootlogd.c b/src/bootlogd.c index 2b32744..bf3983c 100644 --- a/src/bootlogd.c +++ b/src/bootlogd.c @@ -47,7 +47,15 @@ #include #include #include +#ifdef __linux__ #include +#endif + +#ifdef __FreeBSD__ +#include +#include +#endif + #include #ifdef __linux__ #include diff --git a/src/init.c b/src/init.c index 0a56111..f877444 100644 --- a/src/init.c +++ b/src/init.c @@ -52,7 +52,11 @@ Version information is not placed in the top-level Makefile by default #include #include #include +#ifdef __FreeBSD__ +#include +#else #include +#endif #include #include #include @@ -62,6 +66,9 @@ Version information is not placed in the top-level Makefile by default #ifdef WITH_SELINUX # include #endif +#ifdef __FreeBSD__ +extern char **environ; +#endif #ifdef __i386__ # ifdef __GLIBC__ @@ -521,8 +528,12 @@ int receive_state(int fd) * Set the process title. */ #ifdef __GNUC__ +#ifndef __FreeBSD__ __attribute__ ((format (printf, 1, 2))) #endif +#endif +/* This function already exists on FreeBSD. No need to delcare it. */ +#ifndef __FreeBSD__ static int setproctitle(char *fmt, ...) { va_list ap; @@ -542,6 +553,7 @@ static int setproctitle(char *fmt, ...) return len; } +#endif /* * Set console_dev to a working console. @@ -2160,9 +2172,11 @@ int make_pipe(int fd) /* * Attempt to re-exec. + * Renaming to my_re_exec since re_exec is now a common function name + * which conflicts. */ static -void re_exec(void) +void my_re_exec(void) { CHILD *ch; sigset_t mask, oldset; @@ -2279,7 +2293,7 @@ void fifo_new_level(int level) runlevel = read_level(level); if (runlevel == 'U') { runlevel = oldlevel; - re_exec(); + my_re_exec(); } else { if (oldlevel != 'S' && runlevel == 'S') console_stty(); if (runlevel == '6' || runlevel == '0' || @@ -2681,7 +2695,7 @@ void process_signals() #endif if (runlevel == 'U') { runlevel = oldlevel; - re_exec(); + my_re_exec(); } else { if (oldlevel != 'S' && runlevel == 'S') console_stty(); if (runlevel == '6' || runlevel == '0' || diff --git a/src/init.h b/src/init.h index 7a35706..1b70d6d 100644 --- a/src/init.h +++ b/src/init.h @@ -154,3 +154,12 @@ extern char prevlevel; #define D_WROTE_WTMP_RLEVEL -16 #define D_WROTE_UTMP_RLEVEL -17 +#ifdef __FreeBSD__ +#define UTMP_FILE "/var/run/utmp" +#define RUN_LVL 1 +struct utmp +{ + char ut_id[4]; +}; +#endif + diff --git a/src/shutdown.c b/src/shutdown.c index 91a4097..0e6f450 100644 --- a/src/shutdown.c +++ b/src/shutdown.c @@ -54,13 +54,20 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#else #include +#endif #include #include "paths.h" #include "reboot.h" #include "initreq.h" #include "init.h" +#ifdef __FreeBSD__ +extern char **environ; +#endif #define MESSAGELEN 256 diff --git a/src/utmp.c b/src/utmp.c index c1ae0c9..fce3e32 100644 --- a/src/utmp.c +++ b/src/utmp.c @@ -32,7 +32,11 @@ #include #include #include +#ifdef __FreeBSD__ +#include +#else #include +#endif #include "init.h" #include "initreq.h"