changeset 988:371f899276ed

Merged
author Sebastien Decugis <sdecugis@freediameter.net>
date Sun, 17 Mar 2013 14:37:44 +0100
parents 46c675a28e40 (diff) 8d7201a747eb (current diff)
children 579298b4c2bc efb4e4ce2a6f
files
diffstat 2 files changed, 15 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/dbg_interactive/dbg_interactive.c	Sun Mar 17 12:18:19 2013 +0100
+++ b/extensions/dbg_interactive/dbg_interactive.c	Sun Mar 17 14:37:44 2013 +0100
@@ -35,6 +35,7 @@
 
 #include <Python.h>
 #include <freeDiameter/extension.h>
+#include <unistd.h>
 
 /* wrapper generated by SWIG */
 #if PY_VERSION_HEX >= 0x03000000
@@ -60,13 +61,20 @@
 	
 	CHECK_FCT_DO(fd_core_waitstartcomplete(), goto end);
 	
-	fd_log_debug("Starting interactive python interpreter [experimental].");
-	if (!arg) {
-		fd_log_debug("Example syntax:");
-		fd_log_debug("   >>> print cvar.fd_g_config.cnf_diamid");
-		fd_log_debug("   '%s'", fd_g_config->cnf_diamid);
+	if (arg) {
+		fd_log_debug("Starting python interpreter with a script file [experimental].");
+		Py_Main(2, dum);
+	} else {
+		if (!isatty(fileno(stdin)) || !isatty(fileno(stdout))) {
+			TRACE_ERROR("[dbg_interactive]: this extension requires freeDiameter to be run from a console terminal!");
+			goto end;
+		}
+		printf("Starting interactive python interpreter [experimental].\n");
+		printf("Example syntax:\n");
+		printf("   >>> print cvar.fd_g_config.cnf_diamid\n");
+		printf("   '%s'\n", fd_g_config->cnf_diamid);
+		Py_Main(1, dum);
 	}
-	Py_Main(arg ? 2 : 1, dum);
 	
 end:	
 	/* Upon exit, issue the order of terminating to fD, if the interpreter was started without a file */
--- a/libfdproto/log.c	Sun Mar 17 12:18:19 2013 +0100
+++ b/libfdproto/log.c	Sun Mar 17 14:37:44 2013 +0100
@@ -117,9 +117,9 @@
 	    default:            fprintf(fstr, local_use_color ? "\e[0;31m" : " ???   ");
     }
     vfprintf(fstr, format, ap);
-    fprintf(fstr, "\n");
     if (local_use_color)
 	     fprintf(fstr, "\e[00m");
+    fprintf(fstr, "\n");
     
     fflush(fstr);
 }
"Welcome to our mercurial repository"