Browse Source

The syslog command logging is disabled by default. The -o (--log) option enables logging

git-svn-id: https://klish.googlecode.com/svn/trunk@494 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
5a33fd4e79
6 changed files with 31 additions and 3 deletions
  1. 11 1
      bin/clish.cpp
  2. 2 0
      clish/shell.h
  3. 1 0
      clish/shell/private.h
  4. 15 1
      clish/shell/shell_execute.c
  5. 1 0
      clish/shell/shell_new.c
  6. 1 1
      clish/shell/shell_startup.c

+ 11 - 1
bin/clish.cpp

@@ -62,6 +62,7 @@ int main(int argc, char **argv)
 	bool_t quiet = BOOL_FALSE;
 	bool_t utf8 = BOOL_FALSE;
 	bool_t bit8 = BOOL_FALSE;
+	bool_t log = BOOL_FALSE;
 	const char *xml_path = getenv("CLISH_PATH");
 	const char *view = getenv("CLISH_VIEW");
 	const char *viewid = getenv("CLISH_VIEWID");
@@ -71,7 +72,7 @@ int main(int argc, char **argv)
 	struct sigaction sigpipe_act;
 	sigset_t sigpipe_set;
 
-	static const char *shortopts = "hvs:ledx:w:i:bqu8";
+	static const char *shortopts = "hvs:ledx:w:i:bqu8o";
 #ifdef HAVE_GETOPT_H
 	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
@@ -87,6 +88,7 @@ int main(int argc, char **argv)
 		{"quiet",	0, NULL, 'q'},
 		{"utf8",	0, NULL, 'u'},
 		{"8bit",	0, NULL, '8'},
+		{"log",		0, NULL, 'o'},
 		{NULL,		0, NULL, 0}
 	};
 #endif
@@ -137,6 +139,9 @@ int main(int argc, char **argv)
 		case '8':
 			bit8 = BOOL_TRUE;
 			break;
+		case 'o':
+			log = BOOL_TRUE;
+			break;
 		case 'd':
 			my_hooks.script_fn = clish_dryrun_callback;
 			break;
@@ -207,6 +212,10 @@ int main(int argc, char **argv)
 		clish_shell__set_utf8(shell, BOOL_FALSE);
 #endif
 	}
+	/* Set logging */
+	if (log)
+		clish_shell__set_log(shell, log);
+
 	/* Execute startup */
 	running = clish_shell_startup(shell);
 	if (running) {
@@ -272,6 +281,7 @@ static void help(int status, const char *argv0)
 		printf("\t-i, --viewid\tSet the startup viewid.\n");
 		printf("\t-u, --utf8\tForce UTF-8 encoding.\n");
 		printf("\t-8, --8bit\tForce 8-bit encoding.\n");
+		printf("\t-o, --log\tEnable command logging to syslog's local0.\n");
 	}
 }
 

+ 2 - 0
clish/shell.h

@@ -346,6 +346,8 @@ void clish_shell__set_timeout(clish_shell_t *instance, int timeout);
 char *clish_shell__get_line(clish_context_t *context);
 char *clish_shell__get_full_line(clish_context_t *context);
 char *clish_shell__get_params(clish_context_t *context);
+void clish_shell__set_log(clish_shell_t *instance, bool_t log);
+bool_t clish_shell__get_log(const clish_shell_t *instance);
 
 _END_C_DECL
 

+ 1 - 0
clish/shell/private.h

@@ -57,6 +57,7 @@ struct clish_shell_s {
 	char *default_shebang;
 	char *fifo_name; /* The name of temporary fifo file. */
 	bool_t interactive; /* Is shell interactive. */
+	bool_t log; /* If command logging is enabled */
 
 	/* Static params for var expanding. The refactoring is needed. */
 	clish_param_t *param_depth;

+ 15 - 1
clish/shell/shell_execute.c

@@ -275,7 +275,7 @@ int clish_shell_execute(clish_context_t *context, char **out)
 		this->client_hooks->config_fn(context);
 
 	/* Call logging callback */
-	if (this->client_hooks->log_fn) {
+	if (clish_shell__get_log(this) && this->client_hooks->log_fn) {
 		char *full_line = clish_shell__get_full_line(context);
 		this->client_hooks->log_fn(context, full_line, result);
 		lub_string_free(full_line);
@@ -404,4 +404,18 @@ void *clish_shell__get_client_cookie(const clish_shell_t * this)
 	return this->client_cookie;
 }
 
+/*-------------------------------------------------------- */
+void clish_shell__set_log(clish_shell_t *this, bool_t log)
+{
+	assert(this);
+	this->log = log;
+}
+
+/*-------------------------------------------------------- */
+bool_t clish_shell__get_log(const clish_shell_t *this)
+{
+	assert(this);
+	return this->log;
+}
+
 /*----------------------------------------------------------- */

+ 1 - 0
clish/shell/shell_new.c

@@ -52,6 +52,7 @@ static void clish_shell_init(clish_shell_t * this,
 	this->default_shebang = lub_string_dup("/bin/sh");
 	this->fifo_name = NULL;
 	this->interactive = BOOL_TRUE; /* The interactive shell by default. */
+	this->log = BOOL_FALSE; /* Disable logging by default */
 
 	/* Create internal ptypes and params */
 	/* Current depth */

+ 1 - 1
clish/shell/shell_startup.c

@@ -22,7 +22,7 @@ int clish_shell_startup(clish_shell_t *this)
 	context.cmd = this->startup;
 	context.pargv = NULL;
 	/* Call log initialize */
-	if (this->client_hooks->log_fn)
+	if (clish_shell__get_log(this) && this->client_hooks->log_fn)
 		this->client_hooks->log_fn(&context, NULL, 0);
 	/* Call startup script */
 	res = clish_shell_execute(&context, NULL);