unix-manager: doc and whitespace fixes

pull/215/head
Eric Leblond 14 years ago
parent af16c418b7
commit d5457ad70e

@ -194,7 +194,7 @@ TmEcode UnixSocketAddPcapFile(json_t *cmd, json_t* answer, void *data)
if(!json_is_string(jarg)) { if(!json_is_string(jarg)) {
SCLogInfo("error: command is not a string"); SCLogInfo("error: command is not a string");
json_object_set_new(answer, "message", json_string("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); filename = json_string_value(jarg);
#ifdef OS_WIN32 #ifdef OS_WIN32
@ -292,7 +292,7 @@ TmEcode UnixSocketPcapFilesCheck(void *data)
if (ConfSet("default-log-dir", cfile->output_dir, 1) != 1) { if (ConfSet("default-log-dir", cfile->output_dir, 1) != 1) {
SCLogInfo("Can not set output dir to '%s'", cfile->output_dir); SCLogInfo("Can not set output dir to '%s'", cfile->output_dir);
PcapFilesFree(cfile); PcapFilesFree(cfile);
return TM_ECODE_FAILED; return TM_ECODE_FAILED;
} }
} }
PcapFilesFree(cfile); PcapFilesFree(cfile);

@ -334,7 +334,7 @@ int UnixCommandAccept(UnixCommand *this)
/* client connected */ /* client connected */
SCLogInfo("Unix socket: client connected"); SCLogInfo("Unix socket: client connected");
uclient = SCMalloc(sizeof(UnixClient)); uclient = SCMalloc(sizeof(UnixClient));
if (uclient == NULL) { if (uclient == NULL) {
SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new cient"); SCLogError(SC_ERR_MEM_ALLOC, "Can't allocate new cient");
@ -352,7 +352,7 @@ int UnixCommandBackgroundTasks(UnixCommand* this)
Task *ltask; Task *ltask;
TAILQ_FOREACH(ltask, &this->tasks, next) { TAILQ_FOREACH(ltask, &this->tasks, next) {
int fret = ltask->Func(ltask->data); int fret = ltask->Func(ltask->data);
if (fret != TM_ECODE_OK) { if (fret != TM_ECODE_OK) {
ret = 0; ret = 0;
} }
@ -380,13 +380,13 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client)
int found = 0; int found = 0;
Command *lcmd; Command *lcmd;
jsoncmd = json_loads(command, 0, &error); if (server_msg == NULL) {
if (jsoncmd == NULL) {
SCLogInfo("Invalid command, error on line %d: %s\n", error.line, error.text);
return 0; 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; goto error;
} }
@ -401,14 +401,14 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client)
if (!strcmp(value, lcmd->name)) { if (!strcmp(value, lcmd->name)) {
int fret = TM_ECODE_OK; int fret = TM_ECODE_OK;
found = 1; found = 1;
if (lcmd->flags & UNIX_CMD_TAKE_ARGS) { if (lcmd->flags & UNIX_CMD_TAKE_ARGS) {
cmd = json_object_get(jsoncmd, "arguments"); cmd = json_object_get(jsoncmd, "arguments");
if(!json_is_object(cmd)) { if(!json_is_object(cmd)) {
SCLogInfo("error: argument is not an object"); SCLogInfo("error: argument is not an object");
goto error_cmd; goto error_cmd;
} }
} }
fret = lcmd->Func(cmd, server_msg, lcmd->data); fret = lcmd->Func(cmd, server_msg, lcmd->data);
if (fret != TM_ECODE_OK) { if (fret != TM_ECODE_OK) {
ret = 0; ret = 0;
} }
@ -436,6 +436,7 @@ int UnixCommandExecute(UnixCommand * this, char *command, UnixClient *client)
} }
json_decref(jsoncmd); json_decref(jsoncmd);
json_decref(server_msg);
return ret; return ret;
error_cmd: error_cmd:
@ -512,7 +513,6 @@ int UnixMain(UnixCommand * this)
return 1; return 1;
} }
TAILQ_FOREACH(uclient, &this->clients, next) { TAILQ_FOREACH(uclient, &this->clients, next) {
if (FD_ISSET(uclient->fd, &select_set)) { if (FD_ISSET(uclient->fd, &select_set)) {
UnixCommandRun(this, uclient); UnixCommandRun(this, uclient);
@ -613,7 +613,7 @@ UnixCommand command;
* \param flags a flag now used to tune the command type * \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 * \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 *), TmEcode (*Func)(json_t *, json_t *, void *),
void *data, int flags) 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 * \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 * \retval TM_ECODE_OK in case of success, TM_ECODE_FAILED in case of failure
*/ */
TmEcode UnixManagerRegisterBackgroundTask( TmEcode UnixManagerRegisterBackgroundTask(
TmEcode (*Func)(void *), TmEcode (*Func)(void *),
void *data) 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) void UnixManagerThreadSpawn(DetectEngineCtx *de_ctx, int mode)
{ {
ThreadVars *tv_unixmgr = NULL; ThreadVars *tv_unixmgr = NULL;

Loading…
Cancel
Save