<commit_before>/*This code is part of the Epoch Init System.
* The Epoch Init System is maintained by Subsentient.
* This software is public domain.
* Please read the file UNLICENSE.TXT for more information.*/

/**CLI parsing, etc. main() is here.**/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <grp.h>
#include <pwd.h>
#include <sys/reboot.h>
#include <sys/shm.h>

#ifndef NO_EXECINFO
#include <execinfo.h>
#endif

#include "epoch.h"

#define ArgIs(z) !strcmp(CArg, z)
#define CmdIs(z) __CmdIs(argv[0], z)

/*Forward declarations for static functions.*/
static ReturnCode ProcessGenericHalt(int argc, char **argv);
static Bool __CmdIs(const char *CArg, const char *InCmd);
static void PrintEpochHelp(const char *RootCommand, const char *InCmd);
static ReturnCode HandleEpochCommand(int argc, char **argv);
static void SigHandler(int Signal);
static void SetDefaultProcessTitle(int argc, char **argv);

/*
 * Actual functions.
 */
 
 
Bool AreInit;

static Bool __CmdIs(const char *CArg, const char *InCmd)
{ /*Check if we are or end in the command name specified.*/
	const char *TWorker = CArg;
	
	if ((TWorker = strstr(CArg, InCmd)))
	{
		while (*TWorker != '\0') ++TWorker;
		TWorker -= strlen(InCmd);
		
		if (!strcmp(TWorker, InCmd))
		{
			return true;
		}
	}
			
	return false;
}

static void SigHandler(int Signal)
{
	const char *ErrorM = NULL;
	char OutMsg[MAX_LINE_SIZE * 2] = { '\0' };
	static Bool RecursiveProblem = false;
#ifndef NO_EXECINFO
	void *BTList[25];
	char **BTStrings;
	size_t BTSize;
	char *TWorker = OutMsg;
#endif
	
	switch (Signal)
	{
		case SIGINT:
		{
			static unsigned LastKillAttempt = 0;
			
			if (AreInit)
			{
				if (CurrentTask.Set && CurrentBootMode != BOOT_NEUTRAL
					&& (LastKillAttempt == 0 || CurrentBootMode == BOOT_SHUTDOWN || time(NULL) > (LastKillAttempt + 5)))
				{
					char MsgBuf[MAX_LINE_SIZE];
					ReturnCode KilledOK = SUCCESS;
					
					snprintf(MsgBuf, sizeof MsgBuf, 
							"\n%sKilling task %s. %s",
							CONSOLE_COLOR_YELLOW, CurrentTask.TaskName, CONSOLE_ENDCOLOR);

					if (CurrentBootMode == BOOT_BOOTUP)
					{
						strncat(MsgBuf, "Press CTRL-ALT-DEL within 5 seconds to reboot.", MAX_LINE_SIZE - strlen(MsgBuf) - 1);
					}
					
					puts(MsgBuf);
					
					WriteLogLine(MsgBuf, true);
					
					if (CurrentTask.PID == 0)
					{
						Bool *TPtr = (void*)CurrentTask.Node;
						
						*TPtr = true;
						
						KilledOK = SUCCESS;
					}
					else
					{
						KilledOK = !kill(CurrentTask.PID, SIGKILL);
					}
					
					if (!KilledOK)
					{
						snprintf(MsgBuf, sizeof MsgBuf, "%sUnable to kill %s.%s",
								CONSOLE_COLOR_RED, CurrentTask.TaskName, CONSOLE_ENDCOLOR);
					}
					else
					{
						snprintf(MsgBuf, sizeof MsgBuf, "%s%s was successfully killed.%s", CONSOLE_COLOR_GREEN,
								CurrentTask.TaskName, CONSOLE_ENDCOLOR);
					}
					puts(MsgBuf);
					
					WriteLogLine(MsgBuf, true);
					
					LastKillAttempt = time(NULL);
					return;
				}
				else
				{
					if (CurrentBootMode == BOOT_SHUTDOWN)
					{
						puts(CONSOLE_COLOR_YELLOW "System halt/reboot already in progress." CONSOLE_ENDCOLOR);
						return;
					}
					else
					{
						LaunchShutdown(OSCTL_REBOOT);
					}
				}
			}
			else
			{
				puts("SIGINT received. Exiting.");
				ShutdownMemBus(false);
				exit(0);
			}
		}
		case SIGSEGV:
		{
			ErrorM = "A segmentation fault has occurred in Epoch!";
			break;
		}
		case SIGILL:
		{
			ErrorM = "Epoch has encountered an illegal instruction!";
			break;
		}
		case SIGFPE:
		{
			ErrorM = "Epoch has encountered an arithmetic error!";
			break;
		}
		case SIGABRT:
		{
			ErrorM = "Epoch has received an abort signal!";
			break;
		}
		case SIGUSR2: /**We are init and being ordered to restart ourselves.**/
		{
			WriteLogLine(CONSOLE_COLOR_RED "Received SIGUSR2, reexecuting as requested." CONSOLE_ENDCOLOR, true);
			ReexecuteEpoch();
			return;
		}
		
	}
	
	if (RecursiveProblem)
	{
		EmulWall("Epoch: Recursive fault detected. Sleeping forever.", false);
		while (1) sleep(1);
	}
	
	RecursiveProblem = true;
	
#ifndef NO_EXECINFO
	BTSize = backtrace(BTList, 25);
	BTStrings = backtrace_symbols(BTList, BTSize);

	snprintf(OutMsg, sizeof OutMsg, "%s\n\nBacktrace:\n", ErrorM);
	TWorker += strlen(TWorker);
	
	for (; BTSize > 0 && *BTStrings != NULL; --BTSize, ++BTStrings, TWorker += strlen(TWorker))
	{
		snprintf(TWorker, sizeof OutMsg - strlen(OutMsg) - 1, "\n%s", *BTStrings);
	}
#else
	snprintf(OutMsg, sizeof OutMsg, "%s\n\nEpoch was compiled without backtrace support.", ErrorM);
#endif
	
	if (AreInit)
	{
		EmulWall(OutMsg, false);
		EmergencyShell();
	}
	else
	{
		SpitError(OutMsg);
		exit(1);
	}
}
	
static void PrintEpochHelp(const char *RootCommand, const char *InCmd)
{ /*Used for help for the epoch command.*/
	const char *HelpMsgs[] =
	{ 
		("[poweroff/halt/reboot]:\n\t" CONSOLE_ENDCOLOR
		
		 "Enter poweroff, halt, or reboot to do the obvious."
		),
		
		( "shutdown [-r/-p/-h] <time>:\n\t" CONSOLE_ENDCOLOR
		  "Wrapper for the 'shutdown' command. See 'shutdown --help' for more."
		),
		
		( "[disable/enable] objectid:\n\t" CONSOLE_ENDCOLOR
		  "Enter disable or enable followed by an object ID to disable or enable\n\tthat object."
		),
		
		( "[start/stop/restart] objectid:\n\t" CONSOLE_ENDCOLOR
		  "Enter start, stop, or restart followed by an object ID to control\n\tthat object."
		),
		
		( "reload objectid:\n\t" CONSOLE_ENDCOLOR
		  "If a reload command exists for the object specified,\n\tthe object is reloaded."
		),
		
		( "objrl objectid [del/add/check] runlevel:\n\t" CONSOLE_ENDCOLOR
		
		  "runlevel del and add do pretty much what it sounds like,\n\t"
		  "and check will tell you if that object is enabled for that runlevel."
		),
		
		( "status [objectid]:\n\t" CONSOLE_ENDCOLOR
		
		  "Prints information about the object specified.\n\t"
		  "If an object is not specified, it prints info on all known objects."
		),
		( "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."
		),
		
		( "configreload:\n\t" CONSOLE_ENDCOLOR
		
		  "Enter configreload to reload the configuration file from disk.\n\t"
		  "This is useful for when you change it\n\t"
		  "to add or remove services, change runlevels, and more."
		),
		
		( "reexec:\n\t" CONSOLE_ENDCOLOR
		
		  "Enter reeexec to partially restart Epoch from disk.\n\t"
		  "This is necessary for updating the Epoch binary to prevent\n\t"
		  "a failure with unmounting the filesystem the binary is on."
		),
		
		( "runlevel:\n\t" CONSOLE_ENDCOLOR
		
		  "Enter runlevel without any arguments to print the current runlevel,\n\t"
		  "or enter an argument as the new runlevel."
		),
		
		( "getpid objectid:\n\t" CONSOLE_ENDCOLOR
		
		  "Retrieves the PID Epoch has on record for the given object.\n\t"
		  "If a PID file is specified, then the PID will be gotten from there."
		),
		
		( "kill objectid:\n\t" CONSOLE_ENDCOLOR
		
		  "Sends SIGKILL to the object specified. If a PID file is specified,\n\t"
		  "the PID will be retrieved from that."
		),
		
		( "version:\n\t" CONSOLE_ENDCOLOR
		
		  "Prints the current version of the Epoch Init System."
		)
	};
	enum { HCMD, SHTDN, ENDIS, STAP, REL, OBJRL, STATUS, SETCAD, CONFRL, REEXEC,
		RLCTL, GETPID, KILLOBJ, VER, ENUM_MAX };
	
	printf("%s\nCompiled %s %s\n\n", VERSIONSTRING, __DATE__, __TIME__);
	
	if (InCmd == NULL)
	{
		short Inc = 0;
		
		puts(CONSOLE_COLOR_RED "Printing all help.\n" CONSOLE_ENDCOLOR "-----\n");
		
		for (; Inc < ENUM_MAX; ++Inc)
		{
			printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[Inc]);
		}
	}
	else if (!strcmp(InCmd, "poweroff") || !strcmp(InCmd, "halt") || !strcmp(InCmd, "reboot"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[HCMD]);
		return;
	}
	else if (!strcmp(InCmd, "shutdown"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[SHTDN]);
		return;
	}
	else if (!strcmp(InCmd, "disable") || !strcmp(InCmd, "enable"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[ENDIS]);
		return;
	}
	else if (!strcmp(InCmd, "start") || !strcmp(InCmd, "stop") || !strcmp(InCmd, "restart"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[STAP]);
		return;
	}
	else if (!strcmp(InCmd, "objrl"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[OBJRL]);
		return;
	}
	else if (!strcmp(InCmd, "status"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[STATUS]);
		return;
	}
	else if (!strcmp(InCmd, "setcad"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[SETCAD]);
		return;
	}
	else if (!strcmp(InCmd, "configreload"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[CONFRL]);
		return;
	}
	else if (!strcmp(InCmd, "reexec"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[REEXEC]);
		return;
	}
	else if (!strcmp(InCmd, "reload"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[REL]);
		return;
	}
	else if (!strcmp(InCmd, "runlevel"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[RLCTL]);
		return;
	}
	else if (!strcmp(InCmd, "getpid"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[GETPID]);
		return;
	}
	else if (!strcmp(InCmd, "kill"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[KILLOBJ]);
		return;
	}
	else if (!strcmp(InCmd, "version"))
	{
		printf(CONSOLE_COLOR_GREEN "%s %s\n\n", RootCommand, HelpMsgs[VER]);
		return;
	}
	else
	{
		fprintf(stderr, "Unknown command name, \"%s\".\n", InCmd);
		return;
	}
}

static ReturnCode ProcessGenericHalt(int argc, char **argv)
{
	/*Figure out what we are.*/
	if (CmdIs("poweroff") || CmdIs("halt") || CmdIs("reboot"))
	{
		char *GCode = NULL, *SuccessMsg = NULL, *FailMsg[2] = { NULL, NULL };
		const char *CArg = NULL;
		signed OSCode = -1;

		if (CmdIs("poweroff"))
		{
			GCode = MEMBUS_CODE_POWEROFF;<commit_msg>Remove colors from help output to fix use with 'less' command<commit_after>/*This code is part of the Epoch Init System.
* The Epoch Init System is maintained by Subsentient.
* This software is public domain.
* Please read the file UNLICENSE.TXT for more information.*/

/**CLI parsing, etc. main() is here.**/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <grp.h>
#include <pwd.h>
#include <sys/reboot.h>
#include <sys/shm.h>

#ifndef NO_EXECINFO
#include <execinfo.h>
#endif

#include "epoch.h"

#define ArgIs(z) !strcmp(CArg, z)
#define CmdIs(z) __CmdIs(argv[0], z)

/*Forward declarations for static functions.*/
static ReturnCode ProcessGenericHalt(int argc, char **argv);
static Bool __CmdIs(const char *CArg, const char *InCmd);
static void PrintEpochHelp(const char *RootCommand, const char *InCmd);
static ReturnCode HandleEpochCommand(int argc, char **argv);
static void SigHandler(int Signal);
static void SetDefaultProcessTitle(int argc, char **argv);

/*
 * Actual functions.
 */
 
 
Bool AreInit;

static Bool __CmdIs(const char *CArg, const char *InCmd)
{ /*Check if we are or end in the command name specified.*/
	const char *TWorker = CArg;
	
	if ((TWorker = strstr(CArg, InCmd)))
	{
		while (*TWorker != '\0') ++TWorker;
		TWorker -= strlen(InCmd);
		
		if (!strcmp(TWorker, InCmd))
		{
			return true;
		}
	}
			
	return false;
}

static void SigHandler(int Signal)
{
	const char *ErrorM = NULL;
	char OutMsg[MAX_LINE_SIZE * 2] = { '\0' };
	static Bool RecursiveProblem = false;
#ifndef NO_EXECINFO
	void *BTList[25];
	char **BTStrings;
	size_t BTSize;
	char *TWorker = OutMsg;
#endif
	
	switch (Signal)
	{
		case SIGINT:
		{
			static unsigned LastKillAttempt = 0;
			
			if (AreInit)
			{
				if (CurrentTask.Set && CurrentBootMode != BOOT_NEUTRAL
					&& (LastKillAttempt == 0 || CurrentBootMode == BOOT_SHUTDOWN || time(NULL) > (LastKillAttempt + 5)))
				{
					char MsgBuf[MAX_LINE_SIZE];
					ReturnCode KilledOK = SUCCESS;
					
					snprintf(MsgBuf, sizeof MsgBuf, 
							"\n%sKilling task %s. %s",
							CONSOLE_COLOR_YELLOW, CurrentTask.TaskName, CONSOLE_ENDCOLOR);

					if (CurrentBootMode == BOOT_BOOTUP)
					{
						strncat(MsgBuf, "Press CTRL-ALT-DEL within 5 seconds to reboot.", MAX_LINE_SIZE - strlen(MsgBuf) - 1);
					}
					
					puts(MsgBuf);
					
					WriteLogLine(MsgBuf, true);
					
					if (CurrentTask.PID == 0)
					{
						Bool *TPtr = (void*)CurrentTask.Node;
						
						*TPtr = true;
						
						KilledOK = SUCCESS;
					}
					else
					{
						KilledOK = !kill(CurrentTask.PID, SIGKILL);
					}
					
					if (!KilledOK)
					{
						snprintf(MsgBuf, sizeof MsgBuf, "%sUnable to kill %s.%s",
								CONSOLE_COLOR_RED, CurrentTask.TaskName, CONSOLE_ENDCOLOR);
					}
					else
					{
						snprintf(MsgBuf, sizeof MsgBuf, "%s%s was successfully killed.%s", CONSOLE_COLOR_GREEN,
								CurrentTask.TaskName, CONSOLE_ENDCOLOR);
					}
					puts(MsgBuf);
					
					WriteLogLine(MsgBuf, true);
					
					LastKillAttempt = time(NULL);
					return;
				}
				else
				{
					if (CurrentBootMode == BOOT_SHUTDOWN)
					{
						puts(CONSOLE_COLOR_YELLOW "System halt/reboot already in progress." CONSOLE_ENDCOLOR);
						return;
					}
					else
					{
						LaunchShutdown(OSCTL_REBOOT);
					}
				}
			}
			else
			{
				puts("SIGINT received. Exiting.");
				ShutdownMemBus(false);
				exit(0);
			}
		}
		case SIGSEGV:
		{
			ErrorM = "A segmentation fault has occurred in Epoch!";
			break;
		}
		case SIGILL:
		{
			ErrorM = "Epoch has encountered an illegal instruction!";
			break;
		}
		case SIGFPE:
		{
			ErrorM = "Epoch has encountered an arithmetic error!";
			break;
		}
		case SIGABRT:
		{
			ErrorM = "Epoch has received an abort signal!";
			break;
		}
		case SIGUSR2: /**We are init and being ordered to restart ourselves.**/
		{
			WriteLogLine(CONSOLE_COLOR_RED "Received SIGUSR2, reexecuting as requested." CONSOLE_ENDCOLOR, true);
			ReexecuteEpoch();
			return;
		}
		
	}
	
	if (RecursiveProblem)
	{
		EmulWall("Epoch: Recursive fault detected. Sleeping forever.", false);
		while (1) sleep(1);
	}
	
	RecursiveProblem = true;
	
#ifndef NO_EXECINFO
	BTSize = backtrace(BTList, 25);
	BTStrings = backtrace_symbols(BTList, BTSize);

	snprintf(OutMsg, sizeof OutMsg, "%s\n\nBacktrace:\n", ErrorM);
	TWorker += strlen(TWorker);
	
	for (; BTSize > 0 && *BTStrings != NULL; --BTSize, ++BTStrings, TWorker += strlen(TWorker))
	{
		snprintf(TWorker, sizeof OutMsg - strlen(OutMsg) - 1, "\n%s", *BTStrings);
	}
#else
	snprintf(OutMsg, sizeof OutMsg, "%s\n\nEpoch was compiled without backtrace support.", ErrorM);
#endif
	
	if (AreInit)
	{
		EmulWall(OutMsg, false);
		EmergencyShell();
	}
	else
	{
		SpitError(OutMsg);
		exit(1);
	}
}
	
static void PrintEpochHelp(const char *RootCommand, const char *InCmd)
{ /*Used for help for the epoch command.*/
	const char *HelpMsgs[] =
	{ 
		("[poweroff/halt/reboot]:\n\t"
		
		 "Enter poweroff, halt, or reboot to do the obvious."
		),
		
		( "shutdown [-r/-p/-h] <time>:\n\t"
		  "Wrapper for the 'shutdown' command. See 'shutdown --help' for more."
		),
		
		( "[disable/enable] objectid:\n\t"
		  "Enter disable or enable followed by an object ID to disable or enable\n\tthat object."
		),
		
		( "[start/stop/restart] objectid:\n\t"
		  "Enter start, stop, or restart followed by an object ID to control\n\tthat object."
		),
		
		( "reload objectid:\n\t"
		  "If a reload command exists for the object specified,\n\tthe object is reloaded."
		),
		
		( "objrl objectid [del/add/check] runlevel:\n\t"
		
		  "runlevel del and add do pretty much what it sounds like,\n\t"
		  "and check will tell you if that object is enabled for that runlevel."
		),
		
		( "status [objectid]:\n\t"
		
		  "Prints information about the object specified.\n\t"
		  "If an object is not specified, it prints info on all known objects."
		),
		( "setcad [on/off]:\n\t"
		
		  "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."
		),
		
		( "configreload:\n\t"
		
		  "Enter configreload to reload the configuration file from disk.\n\t"
		  "This is useful for when you change it\n\t"
		  "to add or remove services, change runlevels, and more."
		),
		
		( "reexec:\n\t"
		
		  "Enter reeexec to partially restart Epoch from disk.\n\t"
		  "This is necessary for updating the Epoch binary to prevent\n\t"
		  "a failure with unmounting the filesystem the binary is on."
		),
		
		( "runlevel:\n\t"
		
		  "Enter runlevel without any arguments to print the current runlevel,\n\t"
		  "or enter an argument as the new runlevel."
		),
		
		( "getpid objectid:\n\t"
		
		  "Retrieves the PID Epoch has on record for the given object.\n\t"
		  "If a PID file is specified, then the PID will be gotten from there."
		),
		
		( "kill objectid:\n\t"
		
		  "Sends SIGKILL to the object specified. If a PID file is specified,\n\t"
		  "the PID will be retrieved from that."
		),
		
		( "version:\n\t"
		
		  "Prints the current version of the Epoch Init System."
		)
	};
	enum { HCMD, SHTDN, ENDIS, STAP, REL, OBJRL, STATUS, SETCAD, CONFRL, REEXEC,
		RLCTL, GETPID, KILLOBJ, VER, ENUM_MAX };
	
	printf("%s\nCompiled %s %s\n\n", VERSIONSTRING, __DATE__, __TIME__);
	
	if (InCmd == NULL)
	{
		short Inc = 0;
		
		puts("Printing all help.\n-----\n");
		
		for (; Inc < ENUM_MAX; ++Inc)
		{
			printf("%s %s\n\n", RootCommand, HelpMsgs[Inc]);
		}
	}
	else if (!strcmp(InCmd, "poweroff") || !strcmp(InCmd, "halt") || !strcmp(InCmd, "reboot"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[HCMD]);
		return;
	}
	else if (!strcmp(InCmd, "shutdown"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[SHTDN]);
		return;
	}
	else if (!strcmp(InCmd, "disable") || !strcmp(InCmd, "enable"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[ENDIS]);
		return;
	}
	else if (!strcmp(InCmd, "start") || !strcmp(InCmd, "stop") || !strcmp(InCmd, "restart"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[STAP]);
		return;
	}
	else if (!strcmp(InCmd, "objrl"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[OBJRL]);
		return;
	}
	else if (!strcmp(InCmd, "status"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[STATUS]);
		return;
	}
	else if (!strcmp(InCmd, "setcad"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[SETCAD]);
		return;
	}
	else if (!strcmp(InCmd, "configreload"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[CONFRL]);
		return;
	}
	else if (!strcmp(InCmd, "reexec"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[REEXEC]);
		return;
	}
	else if (!strcmp(InCmd, "reload"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[REL]);
		return;
	}
	else if (!strcmp(InCmd, "runlevel"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[RLCTL]);
		return;
	}
	else if (!strcmp(InCmd, "getpid"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[GETPID]);
		return;
	}
	else if (!strcmp(InCmd, "kill"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[KILLOBJ]);
		return;
	}
	else if (!strcmp(InCmd, "version"))
	{
		printf("%s %s\n\n", RootCommand, HelpMsgs[VER]);
		return;
	}
	else
	{
		fprintf(stderr, "Unknown command name, \"%s\".\n", InCmd);
		return;
	}
}

static ReturnCode ProcessGenericHalt(int argc, char **argv)
{
	/*Figure out what we are.*/
	if (CmdIs("poweroff") || CmdIs("halt") || CmdIs("reboot"))
	{
		char *GCode = NULL, *SuccessMsg = NULL, *FailMsg[2] = { NULL, NULL };
		const char *CArg = NULL;
		signed OSCode = -1;

		if (CmdIs("poweroff"))
		{
			GCode = MEMBUS_CODE_POWEROFF;
{'fraction_non_alphanumeric': 0.14272809394760613, 'fraction_numerical': 0.00250928435210278, 'mean_word_length': 3.301100798618606, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7673922', 'n_tokens_mistral': 8536, 'n_tokens_neox': 7302, 'n_words': 1953}