runmodes: typedef runmode enum and use as type

Also remove function to set the library mode. This is easy enough to
do with SCRunmodeSet, and we don't want to add a specific setter for
each and every runmode.

Ticket: #7240
pull/12891/head
Jason Ish 2 years ago committed by Victor Julien
parent b3513d7073
commit ad8e8dd0e8

@ -16,6 +16,7 @@
*/
#include "suricata.h"
#include "runmodes.h"
#include "conf.h"
#include "pcap.h"
#include "runmode-lib.h"
@ -94,9 +95,9 @@ int main(int argc, char **argv)
return 1;
}
/* Set lib runmode. There is currently no way to set it via the
* Conf API. */
SuricataSetLibRunmode();
/* Set the runmode to library mode. Perhaps in the future this
* should be done in some library bootstrap function. */
SCRunmodeSet(RUNMODE_LIB);
/* Validate/finalize the runmode. */
if (SCFinalizeRunMode() != TM_ECODE_OK) {

@ -81,7 +81,7 @@ const char *thread_name_heartbeat = "HB";
*/
typedef struct RunMode_ {
/* the runmode type */
enum RunModes runmode;
enum SCRunModes runmode;
const char *name;
const char *description;
/* runmode function */
@ -177,7 +177,7 @@ static const char *RunModeTranslateModeToName(int runmode)
* \param runmode The runmode type.
* \param runmode_custom_id The runmode custom id.
*/
static RunMode *RunModeGetCustomMode(enum RunModes runmode, const char *custom_mode)
static RunMode *RunModeGetCustomMode(enum SCRunModes runmode, const char *custom_mode)
{
if (runmode < RUNMODE_USER_MAX) {
for (int i = 0; i < runmodes[runmode].cnt; i++) {
@ -473,7 +473,7 @@ int RunModeNeedsBypassManager(void)
* \param description Description for this runmode.
* \param RunModeFunc The function to be run for this runmode.
*/
void RunModeRegisterNewRunMode(enum RunModes runmode, const char *name, const char *description,
void RunModeRegisterNewRunMode(enum SCRunModes runmode, const char *name, const char *description,
int (*RunModeFunc)(void), int (*RunModeIsIPSEnabled)(void))
{
if (RunModeGetCustomMode(runmode, name) != NULL) {
@ -535,7 +535,7 @@ int RunModeOutputFiledataEnabled(void)
return filedata_logger_count > 0;
}
bool IsRunModeSystem(enum RunModes run_mode_to_check)
bool IsRunModeSystem(enum SCRunModes run_mode_to_check)
{
switch (run_mode_to_check) {
case RUNMODE_PCAP_FILE:
@ -548,7 +548,7 @@ bool IsRunModeSystem(enum RunModes run_mode_to_check)
}
}
bool IsRunModeOffline(enum RunModes run_mode_to_check)
bool IsRunModeOffline(enum SCRunModes run_mode_to_check)
{
switch(run_mode_to_check) {
case RUNMODE_CONF_TEST:

@ -24,7 +24,7 @@
#define SURICATA_RUNMODES_H
/* Run mode */
enum RunModes {
typedef enum SCRunModes {
RUNMODE_UNKNOWN = 0,
RUNMODE_PCAP_DEV,
RUNMODE_PCAP_FILE,
@ -60,7 +60,7 @@ enum RunModes {
#endif
RUNMODE_DUMP_FEATURES,
RUNMODE_MAX,
};
} SCRunMode;
/* Run Mode Global Thread Names */
extern const char *thread_name_autofp;
@ -83,7 +83,7 @@ void RunModeListRunmodes(void);
int RunModeEngineIsIPS(int capture_mode, const char *runmode, const char *capture_plugin_name);
void RunModeDispatch(int, const char *, const char *capture_plugin_name, const char *capture_plugin_args);
void RunModeRegisterRunModes(void);
void RunModeRegisterNewRunMode(enum RunModes, const char *, const char *, int (*RunModeFunc)(void),
void RunModeRegisterNewRunMode(SCRunMode, const char *, const char *, int (*RunModeFunc)(void),
int (*RunModeIsIPSEnabled)(void));
void RunModeInitializeThreadSettings(void);
void RunModeInitializeOutputs(void);
@ -92,8 +92,8 @@ void RunModeShutDown(void);
/* bool indicating if filedata logger is enabled */
int RunModeOutputFiledataEnabled(void);
/** bool indicating if run mode is offline */
bool IsRunModeOffline(enum RunModes run_mode_to_check);
bool IsRunModeSystem(enum RunModes run_mode_to_check);
bool IsRunModeOffline(SCRunMode run_mode_to_check);
bool IsRunModeSystem(SCRunMode run_mode_to_check);
void RunModeEnablesBypassManager(void);
int RunModeNeedsBypassManager(void);

@ -262,12 +262,12 @@ int RunmodeIsUnittests(void)
}
#endif
int SCRunmodeGet(void)
SCRunMode SCRunmodeGet(void)
{
return suricata.run_mode;
}
void SCRunmodeSet(int run_mode)
void SCRunmodeSet(SCRunMode run_mode)
{
suricata.run_mode = run_mode;
}
@ -3067,8 +3067,3 @@ void SuricataPostInit(void)
}
SCPledge();
}
void SuricataSetLibRunmode(void)
{
suricata.run_mode = RUNMODE_LIB;
}

@ -121,8 +121,8 @@ enum {
#include "runmodes.h"
typedef struct SCInstance_ {
enum RunModes run_mode;
enum RunModes aux_run_mode;
enum SCRunModes run_mode;
enum SCRunModes aux_run_mode;
char pcap_dev[128];
char *sig_file;
@ -191,14 +191,14 @@ int RunmodeIsUnittests(void);
/**
* \brief Get the current run mode.
*/
int SCRunmodeGet(void);
SCRunMode SCRunmodeGet(void);
/**
* \brief Set the current run mode.
*
* Mainly exposed outside of suricata.c as a unit-test helper.
*/
void SCRunmodeSet(int run_mode);
void SCRunmodeSet(SCRunMode run_mode);
int SuriHasSigFile(void);
@ -227,7 +227,4 @@ int WindowsInitService(int argc, char **argv);
const char *GetProgramVersion(void);
/* Library only methods. */
void SuricataSetLibRunmode(void);
#endif /* SURICATA_SURICATA_H */

@ -72,6 +72,8 @@ void SCDropMainThreadCaps(uint32_t userid, uint32_t groupid)
CAP_SYS_NICE,
-1);
break;
default:
break;
}
if (capng_change_id(userid, groupid, CAPNG_DROP_SUPP_GRP |

Loading…
Cancel
Save