[Openvas-commits] r10648 - in trunk/openvas-cli: . omp

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Tue Mar 29 08:32:49 CEST 2011


Author: mattm
Date: 2011-03-29 08:32:49 +0200 (Tue, 29 Mar 2011)
New Revision: 10648

Modified:
   trunk/openvas-cli/ChangeLog
   trunk/openvas-cli/omp/omp.c
Log:
	* omp/omp.c (main): For -X, if XML is "-" then read XML from stdin.

Modified: trunk/openvas-cli/ChangeLog
===================================================================
--- trunk/openvas-cli/ChangeLog	2011-03-29 06:28:33 UTC (rev 10647)
+++ trunk/openvas-cli/ChangeLog	2011-03-29 06:32:49 UTC (rev 10648)
@@ -1,3 +1,7 @@
+2011-03-29  Matthew Mundell <matthew.mundell at greenbone.net>
+
+	* omp/omp.c (main): For -X, if XML is "-" then read XML from stdin.
+
 2011-02-21  Michael Wiegand <michael.wiegand at greenbone.net>
 
 	Post release version bump.

Modified: trunk/openvas-cli/omp/omp.c
===================================================================
--- trunk/openvas-cli/omp/omp.c	2011-03-29 06:28:33 UTC (rev 10647)
+++ trunk/openvas-cli/omp/omp.c	2011-03-29 06:32:49 UTC (rev 10648)
@@ -945,7 +945,7 @@
      "Add text in stdin as file on task.", NULL},
     /* Command as XML. */
     {"xml", 'X', 0, G_OPTION_ARG_STRING, &cmd_xml,
-     "XML command (e.g. \"<help/>\", \"<get_version/>\")",
+     "XML command (e.g. \"<help/>\"\").  \"-\" to read from stdin.",
      "<command>"},
     {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &rest,
      NULL, NULL},
@@ -1412,6 +1412,32 @@
           getchar ();
         }
 
+      if (strcmp (cmd_xml, "-") == 0)
+        {
+          GError *error;
+          gchar *content;
+          gsize content_len;
+          GIOChannel *stdin_channel;
+
+          /* Mixing stream and file descriptor IO might lead to trouble. */
+          error = NULL;
+          stdin_channel = g_io_channel_unix_new (fileno (stdin));
+          g_io_channel_read_to_end (stdin_channel, &content, &content_len,
+                                    &error);
+          g_io_channel_shutdown (stdin_channel, TRUE, NULL);
+          g_io_channel_unref (stdin_channel);
+          if (error)
+            {
+              fprintf (stderr, "Failed to read from stdin: %s\n",
+                       error->message);
+              g_error_free (error);
+              exit (EXIT_FAILURE);
+            }
+
+          g_free (cmd_xml);
+          cmd_xml = content;
+        }
+
       if (be_verbose)
         printf ("Sending to manager: %s\n", cmd_xml);
 



More information about the Openvas-commits mailing list