From d5457ad70ea67a36fadc01d7509cf020c4fbff82 Mon Sep 17 00:00:00 2001 From: Eric Leblond Date: Mon, 19 Nov 2012 11:53:29 +0100 Subject: [PATCH] unix-manager: doc and whitespace fixes --- src/runmode-unix-socket.c | 4 ++-- src/unix-manager.c | 30 +++++++++++++++++------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index d83ff932a2..79888ecc88 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -194,7 +194,7 @@ TmEcode UnixSocketAddPcapFile(json_t *cmd, json_t* answer, void *data) if(!json_is_string(jarg)) { SCLogInfo("error: command is not a string"); json_object_set_new(answer, "message", json_string("command is not a string")); - return TM_ECODE_FAILED; + return TM_ECODE_FAILED; } filename = json_string_value(jarg); #ifdef OS_WIN32 @@ -292,7 +292,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data) if (ConfSet("default-log-dir", cfile->output_dir, 1) != 1) { SCLogInfo("Can not set output dir to '%s'", cfile->output_dir); PcapFilesFree(cfile); - return TM_ECODE_FAILED; + return TM_ECODE_FAILED; } } PcapFilesFree(cfile); diff --git a/src/unix-manager.c b/src/unix-manager.c index 44f3dc500d..3efa79dd1a 100644 --- a/src/unix-manager.c +++ b/src/unix-manager.c @@ -334,7 +334,7 @@ int UnixCommandAccept(UnixCommand *this) /* client connected */ SCLogInfo("Unix socket: client connected"); - + uclient = SCMalloc(sizeof(UnixClient)); if (uclient == NULL) { SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new cient"); @@ -352,7 +352,7 @@ int UnixCommandBackgroundTasks(UnixCommand* this) Task *ltask; TAILQ_FOREACH(ltask, &this->tasks, next) { - int fret = ltask->Func(ltask->data); + int fret = ltask->Func(ltask->data); if (fret != TM_ECODE_OK) { ret = 0; } @@ -380,13 +380,13 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client) int found = 0; Command *lcmd; - jsoncmd = json_loads(command, 0, &error); - if (jsoncmd == NULL) { - SCLogInfo("Invalid command, error on line %d: %s\n", error.line, error.text); + if (server_msg == NULL) { return 0; } - if (server_msg == NULL) { + jsoncmd = json_loads(command, 0, &error); + if (jsoncmd == NULL) { + SCLogInfo("Invalid command, error on line %d: %s\n", error.line, error.text); goto error; } @@ -401,14 +401,14 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client) if (!strcmp(value, lcmd->name)) { int fret = TM_ECODE_OK; found = 1; - if (lcmd->flags & UNIX_CMD_TAKE_ARGS) { + if (lcmd->flags & UNIX_CMD_TAKE_ARGS) { cmd = json_object_get(jsoncmd, "arguments"); if(!json_is_object(cmd)) { SCLogInfo("error: argument is not an object"); goto error_cmd; - } + } } - fret = lcmd->Func(cmd, server_msg, lcmd->data); + fret = lcmd->Func(cmd, server_msg, lcmd->data); if (fret != TM_ECODE_OK) { ret = 0; } @@ -436,6 +436,7 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client) } json_decref(jsoncmd); + json_decref(server_msg); return ret; error_cmd: @@ -512,7 +513,6 @@ int UnixMain(UnixCommand * this) return 1; } - TAILQ_FOREACH(uclient, &this->clients, next) { if (FD_ISSET(uclient->fd, &select_set)) { UnixCommandRun(this, uclient); @@ -613,7 +613,7 @@ UnixCommand command; * \param flags a flag now used to tune the command type * \retval TM_ECODE_OK in case of success, TM_ECODE_FAILED in case of failure */ -TmEcode UnixManagerRegisterCommand(const char * keyword, +TmEcode UnixManagerRegisterCommand(const char * keyword, TmEcode (*Func)(json_t *, json_t *, void *), void *data, int flags) { @@ -663,7 +663,7 @@ TmEcode UnixManagerRegisterCommand(const char * keyword, * \param data a pointer to data that are pass to Func when runned * \retval TM_ECODE_OK in case of success, TM_ECODE_FAILED in case of failure */ -TmEcode UnixManagerRegisterBackgroundTask( +TmEcode UnixManagerRegisterBackgroundTask( TmEcode (*Func)(void *), void *data) { @@ -751,7 +751,11 @@ void *UnixManagerThread(void *td) } -/** \brief spawn the unix socket manager thread */ +/** \brief spawn the unix socket manager thread + * + * \param de_ctx context for detection engine + * \param mode if set to 1, init failure cause suricata exit + * */ void UnixManagerThreadSpawn(DetectEngineCtx *de_ctx, int mode) { ThreadVars *tv_unixmgr = NULL;