Permalink
Browse files

Remove barely-usable, unstable BSD support, fix PID tracking a bit.

  • Loading branch information...
1 parent 9de2f08 commit 5d7ec01df5e5a67f0e38d7798e7d0a449a06a23e @Subsentient committed May 8, 2014
Showing with 71 additions and 286 deletions.
  1. +0 −19 buildepoch.sh
  2. +4 −15 src/actions.c
  3. +8 −31 src/config.c
  4. +0 −2 src/console.c
  5. +9 −25 src/epoch.h
  6. +19 −30 src/main.c
  7. +2 −2 src/membus.c
  8. +0 −15 src/modes.c
  9. +29 −14 src/parse.c
  10. +0 −133 src/utilfuncs.c
View
19 buildepoch.sh
@@ -147,25 +147,6 @@ rm -rf objects built
mkdir objects
cd objects
-if [ $(uname -s) = "Linux" ]; then
- CFLAGS=$CFLAGS" -DLINUX"
-fi
-
-if [ $(uname -s) = "OpenBSD" ]; then
- CFLAGS=$CFLAGS" -DOPENBSD"
- LDFLAGS=$LDFLAGS" -lutil -static"
-fi
-
-if [ $(uname -s) = "NetBSD" ]; then
- CFLAGS=$CFLAGS" -DNETBSD"
- LDFLAGS=$LDFLAGS" -lutil -static"
-fi
-
-if [ $(uname -s) = "FreeBSD" ]; then
- CFLAGS=$CFLAGS" -DFREEBSD"
- LDFLAGS=$LDFLAGS" -lutil -static"
-fi
-
CMD "$CC $CFLAGS -c ../src/actions.c"
CMD "$CC $CFLAGS -c ../src/config.c"
CMD "$CC $CFLAGS -c ../src/console.c"
View
19 src/actions.c
@@ -11,9 +11,7 @@
#include <time.h>
#include <unistd.h>
#include <sys/reboot.h>
-#ifdef LINUX
#include <sys/mount.h>
-#endif
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
@@ -24,9 +22,7 @@
#include "epoch.h"
/*Prototypes.*/
-#ifdef LINUX
static void MountVirtuals(void);
-#endif
static void PrimaryLoop(void);
static void ApplyGlobalEnvVars(void);
@@ -37,7 +33,6 @@ static Bool ContinuePrimaryLoop = true;
struct _EnvVarList *GlobalEnvVars;
/*Functions.*/
-#ifdef LINUX
static void MountVirtuals(void)
{
enum { MVIRT_PROC, MVIRT_SYSFS, MVIRT_DEVFS, MVIRT_PTS, MVIRT_SHM };
@@ -84,7 +79,6 @@ static void MountVirtuals(void)
}
}
-#endif
static void PrimaryLoop(void)
{ /*Loop that provides essentially everything we cycle through.*/
@@ -543,7 +537,6 @@ void ReexecuteEpoch(void)
exit(0);
}
-#ifdef LINUX
void PerformExec(const char *Cmd)
{
unsigned long Inc = 0, NumSpaces = 1, cOffset = 0, Inc2 = 0;
@@ -627,7 +620,6 @@ void PerformPivotRoot(const char *NewRoot, const char *OldRootDir)
chdir("/"); /*Reset working directory*/
}
-#endif /*LINUX*/
void FinaliseLogStartup(Bool BlankLog)
@@ -697,9 +689,9 @@ void LaunchBootup(void)
{
WriteLogLine(CONSOLE_COLOR_CYAN VERSIONSTRING " Booting up\n" "Compiled " __DATE__ " " __TIME__ CONSOLE_ENDCOLOR "\n", true);
}
-#ifdef LINUX
+
MountVirtuals(); /*Mounts any virtual filesystems, upon request.*/
-#endif
+
if (Hostname[0] != '\0')
{ /*The system hostname.*/
char TmpBuf[MAX_LINE_SIZE];
@@ -735,7 +727,7 @@ void LaunchBootup(void)
WriteLogLine(TmpBuf, true);
}
-#ifdef LINUX
+
if (DisableCAD)
{
const char *CADMsg[2] = { "Epoch has taken control of CTRL-ALT-DEL events.",
@@ -755,7 +747,7 @@ void LaunchBootup(void)
{
WriteLogLine("Epoch will not request control of CTRL-ALT-DEL events.", true);
}
-#endif
+
WriteLogLine(CONSOLE_COLOR_YELLOW "Starting all objects.\n" CONSOLE_ENDCOLOR, true);
if (!RunAllObjects(true))
@@ -877,9 +869,6 @@ void LaunchShutdown(signed long Signal)
printf("%s%s%s\n", CONSOLE_COLOR_CYAN, AttemptMsg, CONSOLE_ENDCOLOR);
sync(); /*Force sync of disks in case somebody forgot.*/
-#ifndef LINUX
- if (Signal == OSCTL_POWEROFF) Signal = Signal | OSCTL_HALT;
-#endif
reboot(Signal); /*Send the signal.*/
View
39 src/config.c
@@ -354,12 +354,7 @@ rStatus InitConfig(const char *CurConfigFile)
}
else if (!strncmp(Worker, (CurrentAttribute = "DisableCAD"), sizeof "DisableCAD" - 1))
{ /*Should we disable instant reboots on CTRL-ALT-DEL?*/
-#ifndef LINUX
- snprintf(ErrBuf, sizeof ErrBuf, CONFIGWARNTXT
- "DisableCAD is not implemented for non-linux platforms.\nLine %lu in \"%s\".", LineNum, CurConfigFile);
- SpitWarning(ErrBuf);
- WriteLogLine(ErrBuf, true);
-#else
+
if (!GetLineDelim(Worker, DelimCurr))
{
ConfigProblem(CurConfigFile, CONFIG_EMISSINGVAL, CurrentAttribute, NULL, LineNum);
@@ -380,7 +375,6 @@ rStatus InitConfig(const char *CurConfigFile)
ConfigProblem(CurConfigFile, CONFIG_EBADVAL, CurrentAttribute, DelimCurr, LineNum);
}
-#endif
continue;
}
else if (!strncmp(Worker, (CurrentAttribute = "BlankLogOnBoot"), sizeof "BlankLogOnBoot" - 1))
@@ -531,12 +525,6 @@ rStatus InitConfig(const char *CurConfigFile)
/*This will mount /dev, /proc, /sys, /dev/pts, and /dev/shm on boot time, upon request.*/
else if (!strncmp(Worker, (CurrentAttribute = "MountVirtual"), strlen("MountVirtual")))
{
- #ifndef LINUX
- snprintf(ErrBuf, sizeof ErrBuf, CONFIGWARNTXT "MountVirtual is only useful as a Linux config attribute,\n"
- "and is not implemented for non-linux platforms.");
- SpitWarning(ErrBuf);
- WriteLogLine(ErrBuf, true);
- #else
const char *TWorker = DelimCurr;
unsigned long Inc = 0;
char CurArg[MAX_DESCRIPT_SIZE];
@@ -585,7 +573,6 @@ rStatus InitConfig(const char *CurConfigFile)
{
ConfigProblem(CurConfigFile, CONFIG_ETRUNCATED, CurrentAttribute, DelimCurr, LineNum);
}
- #endif
continue;
}
/*Now we get into the actual attribute tags.*/
@@ -973,10 +960,11 @@ rStatus InitConfig(const char *CurConfigFile)
{
CurObj->Opts.StopFailIsCritical = true;
}
- else if (!strcmp(CurArg, "FORK"))
+ else if (!strncmp(CurArg, "FORK", sizeof "FORK" - 1))
{
#ifndef NOMMU
CurObj->Opts.Fork = true;
+ if (!strcmp(CurArg, "FORKN")) CurObj->Opts.ForkScanOnce = true;
#else
snprintf(ErrBuf, sizeof ErrBuf, CONFIGWARNTXT "Object \"%s\" has specified the FORK option,\n"
"but this is not supported on NOMMU builds. Disabling the object.", CurObj->ObjectID);
@@ -987,23 +975,11 @@ rStatus InitConfig(const char *CurConfigFile)
}
else if (!strcmp(CurArg, "EXEC"))
{
- #ifdef LINUX
CurObj->Opts.Exec = true;
- #else
- const char *const String = CONFIGWARNTXT "This is not a Linux build, and EXEC support is not implemented for non-linux platforms\n"
- "because the usefulness of this outside of Linux is questionable.";
- SpitWarning(String);
- WriteLogLine(String, true);
- #endif
}
else if (!strcmp(CurArg, "PIVOT"))
{
- #ifdef LINUX
CurObj->Opts.PivotRoot = true;
- #else
- SpitWarning("This is not a Linux build, and PIVOT support is not implemented for non-linux platforms\n"
- "because the usefulness of this outside of Linux is questionable.");
- #endif
}
else if (!strcmp(CurArg, "RAWDESCRIPTION"))
{
@@ -1017,6 +993,10 @@ rStatus InitConfig(const char *CurConfigFile)
{
CurObj->Opts.AutoRestart = true;
}
+ else if (!strcmp(CurArg, "NOTRACK"))
+ {
+ CurObj->Opts.NoTrack = true;
+ }
else if (!strcmp(CurArg, "FORCESHELL"))
{
#ifndef NOSHELL
@@ -2929,9 +2909,8 @@ rStatus ReloadConfig(void)
/*Do this to prevent some weird options from being changeable by a config reload.*/
GlobalOpts[0] = EnableLogging;
-#ifdef LINUX
GlobalOpts[1] = DisableCAD;
-#endif
+
WriteLogLine("CONFIG: Initializing new configuration.", true);
if (!InitConfig(ConfigFile))
@@ -2964,9 +2943,7 @@ rStatus ReloadConfig(void)
/*And then restore those options to their previous states.*/
EnableLogging = GlobalOpts[0];
-#ifdef LINUX
DisableCAD = GlobalOpts[1];
-#endif
if (!ConfigOK) return ConfigOK;
View
2 src/console.c
@@ -16,9 +16,7 @@
/*The banner we show upon startup.*/
struct _BootBanner BootBanner;
/*Should we Disable CTRL-ALT-DEL instant reboots?*/
-#ifdef LINUX
Bool DisableCAD = true;
-#endif
static const char *const ExitStrings[] = { CONSOLE_COLOR_RED "FAIL" CONSOLE_ENDCOLOR,
CONSOLE_COLOR_GREEN "Done" CONSOLE_ENDCOLOR,
View
34 src/epoch.h
@@ -63,24 +63,11 @@
#define VERSIONSTRING "Epoch Init System (git/master)"
/*Power control magic.*/
-#ifndef LINUX /*BSD.*/
- #define OSCTL_REBOOT 0
- #define OSCTL_HALT 0x8
-
- #ifdef OPENBSD
- #define OSCTL_POWEROFF 0x1000
- #elif defined FREEBSD
- #define OSCTL_POWEROFF 0x4000
- #else /*This is probably not correct for anything beyond netbsd, but we need a generic else so I can hit F8 in Geany and build.*/
- #define OSCTL_POWEROFF 0x800 /*Bitwise or-ed to turn on, don't worry, it matches.*/
- #endif
-#else /*We're Linux*/
- #define OSCTL_REBOOT 0x1234567
- #define OSCTL_HALT 0xcdef0123
- #define OSCTL_POWEROFF 0x4321fedc
- #define OSCTL_DISABLE_CTRLALTDEL 0 /*Now isn't this hilarious. It's zero.*/
- #define OSCTL_ENABLE_CTRLALTDEL 0x89abcdef
-#endif /*LINUX*/
+#define OSCTL_REBOOT 0x1234567
+#define OSCTL_HALT 0xcdef0123
+#define OSCTL_POWEROFF 0x4321fedc
+#define OSCTL_DISABLE_CTRLALTDEL 0 /*Now isn't this hilarious. It's zero.*/
+#define OSCTL_ENABLE_CTRLALTDEL 0x89abcdef
/*Colors for text output.*/
#define CONSOLE_COLOR_BLACK "\033[30m"
@@ -123,10 +110,8 @@
#define MEMBUS_CODE_REBOOT "INIT_REBOOT"
#define MEMBUS_CODE_RESET "EPOCH_REINIT" /*Forces a reset of the object table.*/
-#ifdef LINUX
#define MEMBUS_CODE_CADON "CADON"
#define MEMBUS_CODE_CADOFF "CADOFF"
-#endif /*LINUX*/
/*Codes that one expects to find information after.*/
#define MEMBUS_CODE_OBJSTART "OBJSTART"
#define MEMBUS_CODE_OBJSTOP "OBJSTOP"
@@ -160,7 +145,8 @@ enum _StopMode { STOP_NONE, STOP_COMMAND, STOP_PID, STOP_PIDFILE, STOP_INVALID }
enum { COPT_HALTONLY = 1, COPT_PERSISTENT, COPT_FORK, COPT_SERVICE, COPT_AUTORESTART,
COPT_FORCESHELL, COPT_NOSTOPWAIT, COPT_STOPTIMEOUT, COPT_TERMSIGNAL,
- COPT_RAWDESCRIPTION, COPT_PIVOTROOT, COPT_EXEC, COPT_RUNONCE, COPT_MAX };
+ COPT_RAWDESCRIPTION, COPT_PIVOTROOT, COPT_EXEC, COPT_RUNONCE, COPT_FORKSCANONCE,
+ COPT_NOTRACK, COPT_MAX };
/*Trinary return values for functions.*/
typedef enum { FAILURE, SUCCESS, WARNING } rStatus;
@@ -230,8 +216,10 @@ typedef struct _EpochObjectTable
unsigned int RunOnce : 1; /*Tells us to disable ourselves upon completion whenever we are started.*/
unsigned int StartFailIsCritical : 1; /*Starting this object is so important we're going to drop you to a shell if it fails.*/
unsigned int StopFailIsCritical : 1; /*Same but for stopping.*/
+ unsigned int NoTrack : 1; /*Don't track the PID with AdvancedPIDFind().*/
#ifndef NOMMU
unsigned int Fork : 1; /*Essentially do the same thing (with an Epoch twist) as Command& in sh.*/
+ unsigned int ForkScanOnce : 1; /*Same as Fork, but only scans through the PID once.*/
#endif
} Opts;
@@ -297,9 +285,7 @@ extern ObjTable *ObjectTable;
extern struct _BootBanner BootBanner;
extern char CurRunlevel[MAX_DESCRIPT_SIZE];
extern struct _MemBusInterface MemBus;
-#ifdef LINUX
extern Bool DisableCAD;
-#endif
extern char Hostname[256];
extern char Domainname[256];
extern struct _HaltParams HaltParams;
@@ -352,10 +338,8 @@ extern void EmergencyShell(void);
extern void ReexecuteEpoch(void);
extern void RecoverFromReexec(Bool ViaMemBus);
extern void FinaliseLogStartup(Bool BlankLog);
-#ifdef LINUX
extern void PerformExec(const char *Cmd_);
extern void PerformPivotRoot(const char *NewRoot, const char *OldRootDir);
-#endif
/*modes.c*/
extern rStatus SendPowerControl(const char *MembusCode);
View
49 src/main.c
@@ -16,12 +16,8 @@
#include <pwd.h>
#include <sys/reboot.h>
#include <sys/shm.h>
-#ifndef LINUX
-#include <fcntl.h>
-#include <util.h>
-#endif
-#if !defined NO_EXECINFO && defined LINUX
+#ifndef NO_EXECINFO
#include <execinfo.h>
#endif
@@ -65,7 +61,7 @@ static void SigHandler(int Signal)
const char *ErrorM = NULL;
char OutMsg[MAX_LINE_SIZE * 2] = { '\0' };
static Bool RecursiveProblem = false;
-#if defined LINUX && !defined NO_EXECINFO
+#ifndef NO_EXECINFO
void *BTList[25];
char **BTStrings;
size_t BTSize;
@@ -188,7 +184,7 @@ static void SigHandler(int Signal)
RecursiveProblem = true;
-#if !defined NO_EXECINFO && defined LINUX
+#ifndef NO_EXECINFO
BTSize = backtrace(BTList, 25);
BTStrings = backtrace_symbols(BTList, BTSize);
@@ -251,15 +247,13 @@ static void PrintEpochHelp(const char *RootCommand, const char *InCmd)
"Prints information about the object specified.\n\t"
"If an object is not specified, it prints info on all known objects."
),
-#ifdef LINUX
( "setcad [on/off]:\n\t" CONSOLE_ENDCOLOR
"Sets Ctrl-Alt-Del instant reboot modes. If set to on,\n\t"
"striking Ctrl-Alt-Del at a console will instantly reboot the system\n\t"
"without intervention by Epoch. Otherwise, if set to off, Epoch will\n\t"
"perform a normal reboot when Ctrl-Alt-Del is pressed."
),
-#endif
( "configreload:\n\t" CONSOLE_ENDCOLOR
@@ -298,13 +292,8 @@ static void PrintEpochHelp(const char *RootCommand, const char *InCmd)
"Prints the current version of the Epoch Init System."
)
};
-#ifdef LINUX
enum { HCMD, SHTDN, ENDIS, STAP, REL, OBJRL, STATUS, SETCAD, CONFRL, REEXEC,
RLCTL, GETPID, KILLOBJ, VER, ENUM_MAX };
-#else
- enum { HCMD, SHTDN, ENDIS, STAP, REL, OBJRL, STATUS, CONFRL, REEXEC,
- RLCTL, GETPID, KILLOBJ, VER, ENUM_MAX };
-#endif
printf("%s\nCompiled %s %s\n\n", VERSIONSTRING, __DATE__, __TIME__);
@@ -349,13 +338,11 @@ static void PrintEpochHelp(const char *RootCommand, const char *InCmd)
printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[STATUS]);
return;
}
-#ifdef LINUX
else if (!strcmp(InCmd, "setcad"))
{
printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[SETCAD]);
return;
}
-#endif
else if (!strcmp(InCmd, "configreload"))
{
printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[CONFRL]);
@@ -690,8 +677,8 @@ static rStatus HandleEpochCommand(int argc, char **argv)
enum _StopMode StopMode;
unsigned char TermSignal = 0, ReloadCommandSignal = 0, *BinWorker = NULL;
unsigned long StartedSince, UserID, GroupID, Inc = 0, StopTimeout;
- Bool HaltCmdOnly = false, IsService = false, AutoRestart = false, NoStopWait = false;
- Bool ForceShell = false, RawDescription = false, Fork = false, RunOnce = false;
+ Bool HaltCmdOnly = false, IsService = false, AutoRestart = false, NoStopWait = false, NoTrack = false;
+ Bool ForceShell = false, RawDescription = false, Fork = false, RunOnce = false, ForkScanOnce = false;
char RLExpect[MEMBUS_MSGSIZE], ObjectID[MAX_DESCRIPT_SIZE], ObjectDescription[MAX_DESCRIPT_SIZE];
Worker = InBuf + strlen(MEMBUS_CODE_LSOBJS " ");
@@ -763,6 +750,9 @@ static rStatus HandleEpochCommand(int argc, char **argv)
case COPT_FORK:
Fork = true;
break;
+ case COPT_FORKSCANONCE:
+ ForkScanOnce = true;
+ break;
case COPT_SERVICE:
IsService = true;
break;
@@ -778,6 +768,9 @@ static rStatus HandleEpochCommand(int argc, char **argv)
case COPT_NOSTOPWAIT:
NoStopWait = true;
break;
+ case COPT_NOTRACK:
+ NoTrack = true;
+ break;
case COPT_EXEC:
Exec = true;
break;
@@ -826,7 +819,7 @@ static rStatus HandleEpochCommand(int argc, char **argv)
printf("Started since %s, for total of %lu mins.\n", TimeBuf, Offset);
}
- if (IsService || AutoRestart || HaltCmdOnly || Persistent || Fork || StopTimeout != 10 ||
+ if (IsService || AutoRestart || HaltCmdOnly || Persistent || Fork || StopTimeout != 10 || NoTrack ||
ForceShell || RawDescription || NoStopWait || PivotRoot || RunOnce || TermSignal != SIGTERM || Exec)
{
printf("Options:");
@@ -836,13 +829,18 @@ static rStatus HandleEpochCommand(int argc, char **argv)
if (HaltCmdOnly) printf(" HALTONLY");
if (Persistent) printf(" PERSISTENT");
if (ForceShell) printf(" FORCESHELL");
- if (Fork) printf(" FORK");
+ if (Fork)
+ {
+ if (ForkScanOnce) printf(" FORKN");
+ else printf(" FORK");
+ }
if (RawDescription) printf(" RAWDESCRIPTION");
if (TermSignal != SIGTERM) printf(" TERMSIGNAL=%u", TermSignal);
if (NoStopWait) printf(" NOSTOPWAIT");
if (PivotRoot) printf(" PIVOT");
if (Exec) printf(" EXEC");
if (RunOnce) printf(" RUNONCE");
+ if (NoTrack) printf(" NOTRACK");
if (StopTimeout != 10) printf(" STOPTIMEOUT=%lu", StopTimeout);
putchar('\n');
@@ -968,7 +966,6 @@ static rStatus HandleEpochCommand(int argc, char **argv)
ShutdownMemBus(false);
return RV;
}
-#ifdef LINUX
else if (ArgIs("setcad"))
{
const char *MCode = NULL, *ReportLump = NULL;
@@ -1026,7 +1023,6 @@ static rStatus HandleEpochCommand(int argc, char **argv)
ShutdownMemBus(false);
return RetVal;
}
-#endif /*LINUX*/
else if (ArgIs("enable") || ArgIs("disable"))
{
rStatus RV = SUCCESS;
@@ -1541,14 +1537,7 @@ int main(int argc, char **argv)
if (getpid() == 1)
{ /*Just us, as init. That means, begin bootup.*/
const char *TRunlevel = NULL, *TConfigFile = getenv("epochconfig");
- #ifndef LINUX /*For non-linux we need to set up the console.*/
- int Desc = open("/dev/console", O_RDWR);
-
- if (Desc != -1) /*Dunno how we expect to warn anyone about this if we can't print.*/
- {
- login_tty(Desc);
- }
- #endif
+
if (TConfigFile != NULL)
{ /*Someone specified a config file from disk?*/
snprintf(ConfigFile, MAX_LINE_SIZE, "%s", TConfigFile);
View
4 src/membus.c
@@ -436,6 +436,7 @@ void ParseMemBus(void)
if (Worker->Opts.Persistent) *BinWorker++ = COPT_PERSISTENT;
#ifndef NOMMU
if (Worker->Opts.Fork) *BinWorker++ = COPT_FORK;
+ if (Worker->Opts.ForkScanOnce) *BinWorker++ = COPT_FORKSCANONCE;
#endif /*NOMMU*/
if (Worker->Opts.IsService) *BinWorker++ = COPT_SERVICE;
if (Worker->Opts.AutoRestart) *BinWorker++ = COPT_AUTORESTART;
@@ -444,6 +445,7 @@ void ParseMemBus(void)
if (Worker->Opts.Exec) *BinWorker++ = COPT_EXEC;
if (Worker->Opts.PivotRoot) *BinWorker++ = COPT_PIVOTROOT;
if (Worker->Opts.RunOnce) *BinWorker++ = COPT_RUNONCE;
+ if (Worker->Opts.NoTrack) *BinWorker++ = COPT_NOTRACK;
*BinWorker = 0;
MemBus_BinWrite(OutBuf, MEMBUS_MSGSIZE, true);
@@ -836,7 +838,6 @@ void ParseMemBus(void)
return;
}
/*Ctrl-Alt-Del control.*/
-#ifdef LINUX
else if (BusDataIs(MEMBUS_CODE_CADOFF))
{
if (!reboot(OSCTL_DISABLE_CTRLALTDEL))
@@ -859,7 +860,6 @@ void ParseMemBus(void)
MemBus_Write(MEMBUS_CODE_FAILURE " " MEMBUS_CODE_CADON, true);
}
}
-#endif /*LINUX*/
else if (BusDataIs(MEMBUS_CODE_SENDPID))
{
char TmpBuf[MEMBUS_MSGSIZE];
View
15 src/modes.c
@@ -42,7 +42,6 @@ rStatus SendPowerControl(const char *MembusCode)
PCode[1] = MEMBUS_CODE_FAILURE " " MEMBUS_CODE_REBOOT;
PErrMsg = "Unable to reboot.";
}
-#ifdef LINUX
else if (!strcmp(MembusCode, MEMBUS_CODE_CADON))
{
PCode[0] = MEMBUS_CODE_ACKNOWLEDGED " " MEMBUS_CODE_CADON;
@@ -55,7 +54,6 @@ rStatus SendPowerControl(const char *MembusCode)
PCode[1] = MEMBUS_CODE_FAILURE " " MEMBUS_CODE_CADOFF;
PErrMsg = "Unable to disable CTRL-ALT-DEL instant reboot.";
}
-#endif /*LINUX*/
else
{
SpitError("Invalid MEMBUS_CODE passed to SendPowerControl().");
@@ -191,9 +189,7 @@ void EmulWall(const char *InStream, Bool ShowUser)
const char *OurUser = getenv("USER");
char OurHostname[512] = { '\0' };
DIR *DevDir;
-#ifdef LINUX
DIR *PtsDir;
-#endif
struct dirent *DirPtr;
char FileNameBuf[MAX_LINE_SIZE];
int FileDescriptor = 0;
@@ -240,18 +236,10 @@ void EmulWall(const char *InStream, Bool ShowUser)
{ /*Now write to the ttys.*/
while ((DirPtr = readdir(DevDir))) /*See, we use fopen() as a way to check if the file exists.*/
{ /*Your eyes bleeding yet?*/
-#ifdef LINUX
if (!strncmp(DirPtr->d_name, "tty", sizeof "tty" - 1) &&
strlen(DirPtr->d_name) > sizeof "tty" - 1 &&
isdigit(DirPtr->d_name[sizeof "tty" - 1]) &&
atoi(DirPtr->d_name + sizeof "tty" - 1) > 0)
-#else /*BSD style.*/
- if ((!strncmp(DirPtr->d_name, "ttyC", sizeof "ttyC" - 1) &&
- strlen(DirPtr->d_name) > sizeof "ttyC" - 1 &&
- strcmp(DirPtr->d_name + sizeof "ttyC" - 1, "cfg")) ||
- ( !strncmp(DirPtr->d_name, "ttyp", sizeof "ttyp" - 1) &&
- strlen(DirPtr->d_name) > sizeof "ttyp" - 1) )
-#endif
{
snprintf(FileNameBuf, MAX_LINE_SIZE, "/dev/%s", DirPtr->d_name);
@@ -268,7 +256,6 @@ void EmulWall(const char *InStream, Bool ShowUser)
closedir(DevDir);
}
-#ifdef LINUX
if ((PtsDir = opendir("/dev/pts/")))
{
while ((DirPtr = readdir(PtsDir)))
@@ -288,8 +275,6 @@ void EmulWall(const char *InStream, Bool ShowUser)
}
closedir(PtsDir);
}
-#endif
-
}
rStatus EmulShutdown(long ArgumentCount, const char **ArgStream)
View
43 src/parse.c
@@ -345,34 +345,53 @@ static rStatus ExecuteConfigObject(ObjTable *InObj, const char *CurCmd)
/**Parent code resumes.**/
waitpid(LaunchPID, &RawExitStatus, 0); /*Wait for the process to exit.*/
-
- CurrentTask.Set = false;
- CurrentTask.Node = NULL;
- CurrentTask.TaskName = NULL;
- CurrentTask.PID = 0; /*Set back to zero for the next one.*/
if (CurCmd == InObj->ObjectStartCommand)
{
InObj->ObjectPID = LaunchPID; /*Save our PID.*/
-#ifndef NOSHELL
if (!ShellDissolves)
{
++InObj->ObjectPID; /*This probably won't always work, but 99.9999999% of the time, yes, it will.*/
}
-#endif
+
if (InObj->Opts.IsService)
{ /*If we specify that this is a service, one up the PID again.*/
++InObj->ObjectPID;
}
-#ifndef NOMMU
+
+#ifndef NOMMU
/*The PID is obviously going to be one greater.*/
if (InObj->Opts.Fork) ++InObj->ObjectPID;
-#endif
+#endif /*NOMMU*/
+
/*Check if the PID we found is accurate and update it if not. This method is very,
* very accurate compared to the buggy morass above.*/
- AdvancedPIDFind(InObj, true);
+ if (!InObj->Opts.NoTrack)
+ {
+#ifndef NOMMU
+ if (InObj->Opts.Fork && !InObj->Opts.ForkScanOnce)
+ { /*As inconvenient as this is, it's necessary to track properly.*/
+ int Inc = 0;
+ Bool Abort = false;
+
+ /*We are entering something new.*/
+ CurrentTask.PID = 0;
+ CurrentTask.Node = (void*)&Abort;
+
+ /*Ten seconds should be enough for anybody.*/
+ for (; !AdvancedPIDFind(InObj, true) && Inc < 10000; ++Inc) usleep(1000);
+ }
+ else
+#endif /*NOMMU*/
+ AdvancedPIDFind(InObj, true);
+ }
}
+ CurrentTask.Set = false;
+ CurrentTask.Node = NULL;
+ CurrentTask.TaskName = NULL;
+ CurrentTask.PID = 0; /*Set back to zero for the next one.*/
+
/**And back to normalcy after this.------------------**/
switch (WEXITSTATUS(RawExitStatus))
@@ -458,7 +477,6 @@ rStatus ProcessConfigObject(ObjTable *CurObj, Bool IsStartingMode, Bool PrintSta
/*fflush(NULL); *//*Things tend to get clogged up when we don't flush.*/
-#ifdef LINUX
/*This means we are doing an equivalent pivot_root...*/
if (CurObj->Opts.PivotRoot)
{
@@ -491,7 +509,6 @@ rStatus ProcessConfigObject(ObjTable *CurObj, Bool IsStartingMode, Bool PrintSta
/*Jump to a certain option*/
goto JumpStartCheck;
}
-#endif /*LINUX*/
if (CurObj->ObjectPrestartCommand != NULL)
{
@@ -564,9 +581,7 @@ rStatus ProcessConfigObject(ObjTable *CurObj, Bool IsStartingMode, Bool PrintSta
{
CompleteStatusReport(PrintOutStream, ExitStatus, true);
}
-#ifdef LINUX
JumpStartCheck:
-#endif
/* *//**Means we failed to launch it.**//* */
if (CurObj->Opts.StartFailIsCritical && !ExitStatus && CurrentBootMode == BOOT_BOOTUP)
{
View
133 src/utilfuncs.c
@@ -15,26 +15,8 @@
#include <dirent.h>
#include <signal.h>
-#ifndef LINUX
-#include <sys/param.h>
-#include <sys/sysctl.h>
-#endif
-
#include "epoch.h"
-#ifndef LINUX
- #ifdef OPENBSD
- #define STRUCT_KINFO_PROC struct kinfo_proc
- #define _KERN_PROC KERN_PROC
- #define KPSTRING "kern.proc"
- #else
- #define STRUCT_KINFO_PROC struct kinfo_proc2
- #define _KERN_PROC KERN_PROC2
- #define KPSTRING "kern.proc2"
- #endif
-
-#endif /*LINUX*/
-
/**Constants**/
Bool EnableLogging = true;
Bool LogInMemory = true; /*This is necessary so long as we have a readonly filesystem.*/
@@ -284,7 +266,6 @@ void GetCurrentTime(char *OutHr, char *OutMin, char *OutSec, char *OutYear, char
}
unsigned long AdvancedPIDFind(ObjTable *InObj, Bool UpdatePID)
-#ifdef LINUX /**Linux half.**/
{ /*Advaaaanced! Ooh, shiney!
*Ok, seriously now, it finds PIDs by scanning /proc/somenumber/cmdline.*/
DIR *ProcDir = NULL;
@@ -367,121 +348,7 @@ unsigned long AdvancedPIDFind(ObjTable *InObj, Bool UpdatePID)
closedir(ProcDir);
return 0;
-}
-#else /**BSD Half.**/
-{ /*This function's BSD side was written by following inspiration in the
- xfce4-taskmanager source code. It's not a derivative, but
- a lot of it might as well be near identical.
- I do not like BSD's way of getting task information. -Subsentient*/
- int Chunk[6] = { 0 };
- size_t Size = 0;
- char **Arguments = NULL, **TempPtr = NULL;
- char CommandLine[MAX_LINE_SIZE] = { '\0' }, StartCommand[MAX_LINE_SIZE];
- int NumProcesses = 0, Inc = 0;
- unsigned long Countdown = 0;
- STRUCT_KINFO_PROC *KernProc = NULL;
-
- if (!InObj->ObjectStartCommand)
- {
- return 0;
- }
-
- /*Strip forbidden characters.*/
- strncpy(StartCommand, InObj->ObjectStartCommand, sizeof StartCommand - 1);
- StartCommand[sizeof StartCommand - 1] = '\0';
-
- for (Countdown = strlen(StartCommand) - 1; Countdown > 0 &&
- (StartCommand[Countdown] == ' ' || StartCommand[Countdown] == '\t' ||
- StartCommand[Countdown] == '&' || StartCommand[Countdown] == ';'); --Countdown)
- {
- StartCommand[Countdown] = '\0';
- }
-
-
- Chunk[0] = CTL_KERN;
- Chunk[1] = _KERN_PROC;
- Chunk[2] = KERN_PROC_ALL;
- Chunk[3] = Chunk[5] = 0;
- Chunk[4] = sizeof(STRUCT_KINFO_PROC);
-
- if (sysctl(Chunk, 6, NULL, &Size, NULL, 0) == -1)
- {
- const char *const Err = "Unable to get size of " KPSTRING "!";
- SpitError(Err);
- WriteLogLine(Err, true);
- return 0;
- }
-
- Size = (5 * Size / 4);
-
- KernProc = malloc(Size);
-
- Chunk[5] = Size / sizeof(STRUCT_KINFO_PROC);
-
- if (sysctl(Chunk, 6, KernProc, &Size, NULL, 0) == -1)
- {
- const char *const Err = "Unable to read " KPSTRING "!";
- SpitError(Err);
- WriteLogLine(Err, true);
- return 0;
- }
-
- NumProcesses = Size / sizeof(STRUCT_KINFO_PROC);
-
- for (; Inc < NumProcesses; ++Inc)
- {
- Arguments = malloc((Size = 128));
-
- while (1)
- {
- Arguments = realloc(Arguments, Size);
-
- Chunk[0] = CTL_KERN;
- Chunk[1] = KERN_PROC_ARGS;
- Chunk[2] = KernProc[Inc].p_pid;
- Chunk[3] = KERN_PROC_ARGV;
- Chunk[4] = Chunk[5] = 0;
-
- if (sysctl(Chunk, 4, Arguments, &Size, NULL, 0) == 0) break;
-
- Size *= 2;
- }
-
- for (*CommandLine = 0, TempPtr = Arguments; *TempPtr != NULL; ++TempPtr)
- {
- if (TempPtr != Arguments)
- {
- snprintf(CommandLine + strlen(CommandLine),
- sizeof CommandLine - strlen(CommandLine), " ");
- }
-
- if (strlen(*TempPtr) >= sizeof CommandLine)
- {
- (*TempPtr)[strlen(*TempPtr) - 1] = '\0';
- }
-
- snprintf(CommandLine + strlen(CommandLine),
- sizeof CommandLine - strlen(CommandLine), "%s", *TempPtr);
- }
-
- if (!strcmp(CommandLine, StartCommand))
- {
- const unsigned long PID = KernProc[Inc].p_pid;
-
- if (UpdatePID) InObj->ObjectPID = PID;
-
- return PID;
- }
-
- free(Arguments); Arguments = NULL;
-
- }
- free(KernProc);
-
- return 0;
}
-#endif /*LINUX*/
-
unsigned long ReadPIDFile(const ObjTable *InObj)
{

1 comment on commit 5d7ec01

@Subsentient
Owner

I think I owe a good explanation as to why I've removed BSD support.
I want to be perfectly clear here.

I think BSD is still important, but let's face it. They don't want my init system, at least most of them. Now, Epoch was originally designed for Linux. Everything I've done with Epoch has been for Linux before my BSD fling.
That means that properly porting Epoch would be a big job, and I don't use BSD or come in contact with BSD, or know how to deal with BSD enough to properly test Epoch on these platforms, much less know what additions might be necessary to make an init system work well under them.

To be quite blunt, Epoch's code was turning into a smelly pile of crap because of all the preprocessing nightmares that were necessary to make BSD support work. I'm afraid that if things had stayed the same, I would have had a very hard time maintaining Epoch in the future. I couldn't get NetBSD installed properly to clone git and build Epoch, OpenBSD support was buggy and strange with PID tracking problems, and I never got it to work under FreeBSD at all, because I never wrote the process monitoring code for AdvancedPIDFind() for FreeBSD.

I'd be willing to work with someone who knows C, BSD inner boot processes, etc to make Epoch work under the various BSD platforms, but I can't picture myself doing this on my own. I obviously haven't deleted the BSD code, you can still checkout the last revision to have BSD support and poke around there.

In the meantime, I'm working on things to prepare for 1.1. I've got a few extra nice features in mind, and I'll be done soon.

Please sign in to comment.