[GRASS-SVN] r43530 - grass/branches/develbranch_6/display/d.mon/cmd

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 19 20:55:02 EDT 2010


Author: hamish
Date: 2010-09-20 00:55:02 +0000 (Mon, 20 Sep 2010)
New Revision: 43530

Modified:
   grass/branches/develbranch_6/display/d.mon/cmd/main.c
Log:
use G_spawn() instead of G_system()

Modified: grass/branches/develbranch_6/display/d.mon/cmd/main.c
===================================================================
--- grass/branches/develbranch_6/display/d.mon/cmd/main.c	2010-09-20 00:27:21 UTC (rev 43529)
+++ grass/branches/develbranch_6/display/d.mon/cmd/main.c	2010-09-20 00:55:02 UTC (rev 43530)
@@ -20,6 +20,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <grass/gis.h>
+#include <grass/spawn.h>
 #include <grass/glocale.h>
 
 /* Changed for truecolor 24bit support by 
@@ -30,7 +31,7 @@
  * example; nlev=8 means 8bit for each R, G, B equal to 24bit truecolor
  */
 
-int run(char *, char *);
+int run(char *, char *, char *);
 
 int main(int argc, char *argv[])
 {
@@ -99,7 +100,7 @@
 
 
     if (unlock->answer)
-	run("release -f", unlock->answer);
+	run("release", "-f", unlock->answer);
 
     if (!select->answer && !no_auto_select->answer)
 	select->answer = start->answer;
@@ -109,15 +110,15 @@
 
     error = 0;
     if (status->answer)
-	error += run("status", "");
+	error += run("status", "", "");
     else if (list->answer)
-	error += run("list", "");
+	error += run("list", "", "");
     if (release->answer)
-	error += run("release", "");
+	error += run("release", "", "");
     if (stop->answer)
-	error += run("stop", stop->answer);
+	error += run("stop", "", stop->answer);
     if (start->answer) {
-	error += run("start", start->answer);
+	error += run("start", "", start->answer);
 	if (error) {		/* needed procedure failed */
 	    if (mon_name != NULL) {
 		/* restore the previous environ. */
@@ -128,11 +129,12 @@
 	}
     }
     if (select->answer) {
-	oops = run("select", select->answer);	/* couldn't select */
-	if (oops && start->answer && strcmp(start->answer, select->answer) == 0) {	/* try once more */
+	oops = run("select", "", select->answer);	/* couldn't select */
+	if (oops && start->answer && strcmp(start->answer, select->answer) == 0) {
+	    /* try once more */
 	    G_message(_("Problem selecting %s. Will try once more"),
 		      select->answer);
-	    oops = run("select", select->answer);	/* couldn't select */
+	    oops = run("select", "", select->answer);	/* couldn't select */
 	}
 	if (oops) {		/* needed procedure failed */
 	    if (mon_name != NULL) {
@@ -145,17 +147,26 @@
 	error += oops;
     }
     if (print->answer)
-	error += run("which", "");
+	error += run("which", "", "");
+
     exit(error ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
-int run(char *pgm, char *name)
+int run(char *pgm, char *flags, char *name)
 {
-    char command[1024];
+    char path[GPATH_MAX];
+    int stat;
 
-    sprintf(command, "\"%s\"/etc/mon.%s %s", G_gisbase(), pgm, name);
+    sprintf(path, "%s/etc/mon.%s", G_gisbase(), pgm);
 
-    G_debug(1, "run: [%s]", command);
+    if (*flags) {
+	if ((stat = G_spawn(path, pgm, flags, name, NULL)))
+	    G_sleep(3);
+    }
+    else {
+	if ((stat = G_spawn(path, pgm, name, NULL)))
+	    G_sleep(3);
+    }
 
-    return G_system(command);
+    return stat;
 }



More information about the grass-commit mailing list