Browse Source

Implement --dry-run (-d) option for clish. The ACTION will not be actually executed. Fix version number of clish.

git-svn-id: https://klish.googlecode.com/svn/trunk@256 0eaa4687-2ee9-07dd-09d9-bcdd2d2dd5fb
Serj Kalichev 13 years ago
parent
commit
a1df9b1b25
7 changed files with 39 additions and 7 deletions
  1. 2 1
      Makefile.am
  2. 2 1
      Makefile.in
  3. 12 2
      bin/clish.cpp
  4. 5 1
      bin/konf.c
  5. 5 1
      bin/konfd.c
  6. 12 1
      clish/clish_script_callback.c
  7. 1 0
      clish/internal.h

+ 2 - 1
Makefile.am

@@ -8,7 +8,8 @@ if DEBUG
   DEBUG_CFLAGS = -DDEBUG
 endif
 
-AM_CFLAGS               = -pedantic -Werror -Wall -DVERSION=$(VERSION) $(DEBUG_CFLAGS)
+AM_CFLAGS               = -pedantic -Werror -Wall $(DEBUG_CFLAGS)
+AM_CXXFLAGS             = -Werror -Wall $(DEBUG_CFLAGS)
 #AM_CFLAGS               = -ansi -pedantic -Werror -Wall -D_POSIX_C_SOURCE=199309 -DVERSION=$(VERSION) $(DEBUG_CFLAGS)
 
 bin_PROGRAMS            =

+ 2 - 1
Makefile.in

@@ -679,7 +679,8 @@ AUTOMAKE_OPTIONS = foreign nostdinc
 AM_CPPFLAGS = -I. -I$(top_srcdir)
 AM_LD = $(CXX)
 @DEBUG_TRUE@DEBUG_CFLAGS = -DDEBUG
-AM_CFLAGS = -pedantic -Werror -Wall -DVERSION=$(VERSION) $(DEBUG_CFLAGS)
+AM_CFLAGS = -pedantic -Werror -Wall $(DEBUG_CFLAGS)
+AM_CXXFLAGS = -Werror -Wall $(DEBUG_CFLAGS)
 lib_LTLIBRARIES = libclish.la liblub.la $(am__append_3) libtinyrl.la \
 	libtinyxml.la libkonf.la
 lib_LIBRARIES = 

+ 12 - 2
bin/clish.cpp

@@ -4,6 +4,10 @@
 // A simple client for libclish
 //-------------------------------------
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -17,7 +21,8 @@
 #define VERSION 1.2.2
 #endif
 #define QUOTE(t) #t
-#define version(v) printf("%s\n", QUOTE(v))
+/* #define version(v) printf("%s\n", QUOTE(v)) */
+#define version(v) printf("%s\n", v)
 
 static clish_shell_hooks_t my_hooks = {
     NULL, /* don't worry about init callback */
@@ -43,13 +48,14 @@ int main(int argc, char **argv)
 	bool_t lockless = BOOL_FALSE;
 	bool_t stop_on_error = BOOL_FALSE;
 
-	static const char *shortopts = "hvs:le";
+	static const char *shortopts = "hvs:led";
 /*	static const struct option longopts[] = {
 		{"help",	0, NULL, 'h'},
 		{"version",	0, NULL, 'v'},
 		{"socket",	1, NULL, 's'},
 		{"lockless",	0, NULL, 'l'},
 		{"stop-on-error", 0, NULL, 'e'},
+		{"dry-run",	0, NULL, 'd'},
 		{NULL,		0, NULL, 0}
 	};
 */
@@ -71,6 +77,9 @@ int main(int argc, char **argv)
 		case 'e':
 			stop_on_error = BOOL_TRUE;
 			break;
+		case 'd':
+			my_hooks.script_fn = clish_dryrun_callback;
+			break;
 		case 'h':
 			help(0, argv[0]);
 			exit(0);
@@ -153,6 +162,7 @@ static void help(int status, const char *argv0)
 			"of the konfd daemon.\n");
 		printf("\t-l, --lockless\tDon't use locking mechanism.\n");
 		printf("\t-e, --stop-on-error\tStop programm execution on error.\n");
+		printf("\t-d, --dry-run\tDon't actually execute ACTION scripts.\n");
 	}
 }
 

+ 5 - 1
bin/konf.c

@@ -5,6 +5,10 @@
  * The client to communicate to konfd configuration daemon.
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -24,7 +28,7 @@
 #define VERSION 1.2.2
 #endif
 #define QUOTE(t) #t
-#define version(v) printf("%s\n", QUOTE(v))
+#define version(v) printf("%s\n", v)
 
 static void help(int status, const char *argv0);
 

+ 5 - 1
bin/konfd.c

@@ -5,6 +5,10 @@
  *
  */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
@@ -29,7 +33,7 @@
 #define VERSION 1.2.2
 #endif
 #define QUOTE(t) #t
-#define version(v) printf("%s\n", QUOTE(v))
+#define version(v) printf("%s\n", v)
 
 #define KONFD_CONFIG_PATH "/tmp/running-config"
 

+ 12 - 1
clish/clish_script_callback.c

@@ -8,14 +8,25 @@
 #include <stdlib.h>
 
 #include "private.h"
+
 /*--------------------------------------------------------- */
 bool_t clish_script_callback(const clish_shell_t * shell, const char *script)
 {
 #ifdef DEBUG
 	fprintf(stderr, "SYSTEM: %s\n", script);
-#endif				/* DEBUG */
+#endif /* DEBUG */
 
 	return (0 == system(script)) ? BOOL_TRUE : BOOL_FALSE;
 }
 
 /*--------------------------------------------------------- */
+bool_t clish_dryrun_callback(const clish_shell_t * shell, const char *script)
+{
+#ifdef DEBUG
+	fprintf(stderr, "DRY-RUN: %s\n", script);
+#endif /* DEBUG */
+
+	return BOOL_TRUE;
+}
+
+/*--------------------------------------------------------- */

+ 1 - 0
clish/internal.h

@@ -22,6 +22,7 @@ extern struct termios clish_default_tty_termios;
 /* clish callback functions */
 extern clish_shell_access_fn_t clish_access_callback;
 extern clish_shell_script_fn_t clish_script_callback;
+extern clish_shell_script_fn_t clish_dryrun_callback;
 extern clish_shell_config_fn_t clish_config_callback;
 
 /* tclish callback functions */