gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r13559 - in gnunet: doc/man src/monkey


From: gnunet
Subject: [GNUnet-SVN] r13559 - in gnunet: doc/man src/monkey
Date: Fri, 5 Nov 2010 08:14:52 +0100

Author: safey
Date: 2010-11-05 08:14:52 +0100 (Fri, 05 Nov 2010)
New Revision: 13559

Added:
   gnunet/doc/man/gnunet-monkey.1
Modified:
   gnunet/doc/man/Makefile.am
   gnunet/src/monkey/gnunet-monkey.c
Log:
Monkey parse command arguments using gnunet_getopt_lib.
Adding a man page for Monkey

Modified: gnunet/doc/man/Makefile.am
===================================================================
--- gnunet/doc/man/Makefile.am  2010-11-05 06:35:58 UTC (rev 13558)
+++ gnunet/doc/man/Makefile.am  2010-11-05 07:14:52 UTC (rev 13559)
@@ -8,6 +8,7 @@
   gnunet-search.1 \
   gnunet-statistics.1 \
   gnunet-transport.1 \
-  gnunet-unindex.1
+  gnunet-unindex.1 \
+  gnunet-monkey.1
 
 EXTRA_DIST = ${man_MANS}

Added: gnunet/doc/man/gnunet-monkey.1
===================================================================
--- gnunet/doc/man/gnunet-monkey.1                              (rev 0)
+++ gnunet/doc/man/gnunet-monkey.1      2010-11-05 07:14:52 UTC (rev 13559)
@@ -0,0 +1,45 @@
+.TH GNUNET\-MONKEY 1 "Nov 4, 2010" "GNUnet"
+
+.SH NAME
+gnunet\-monkey \- automatically debugging for services
+
+.SH SYNOPSIS
+.B gnunet-monkey
+.RI [ options ]
+.br
+
+.SH DESCRIPTION
+\fBgnunet\-monkey\fP used to automatically debug a service.
+
+.SH OPTIONS
+
+.TP
+.IP "\-h, \-\-help"
+Print short help on options.
+
+.TP
+.IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL"
+Use LOGLEVEL for logging.  Valid values are DEBUG, INFO, WARNING and ERROR.
+
+.TP
+.IP "\-m, \-\-mode"
+Monkey's mode of operation: text: for writing debugging report in a text file, 
email: for sending debugging report to an email address.
+
+.TP
+.IP "\-b, \-\-binary"
+Path of the binary to debug with Monkey.
+
+.TP
+.IP "\-o, \-\-output"
+Only required in text mode: The path of the text file in which Monkey should 
write the debugging report.
+
+.TP
+.IP "\-v, \-\-version"
+Print GNUnet version number.
+
+
+.SH BUGS
+Report bugs by using Mantis <https://gnunet.org/mantis/> or by sending 
electronic mail to <address@hidden>
+
+.SH SEE ALSO
+gnunet\-service\-monkey(1)

Modified: gnunet/src/monkey/gnunet-monkey.c
===================================================================
--- gnunet/src/monkey/gnunet-monkey.c   2010-11-05 06:35:58 UTC (rev 13558)
+++ gnunet/src/monkey/gnunet-monkey.c   2010-11-05 07:14:52 UTC (rev 13559)
@@ -15,10 +15,14 @@
 #include "gdbmi.h"
 #include "platform.h"
 #include "gnunet_common.h"
+#include "gnunet_getopt_lib.h"
+#include "gnunet_program_lib.h"
 
 extern void sendMail (const char *messageContents);
 static const char* mode;
 static const char* dumpFileName;
+static const char* binaryName;
+static int ret = 0;
 
 void cb_console(const char *str, void *data)
 {
@@ -59,7 +63,7 @@
 {
        FILE* file = fopen(dumpFileName, "w");
        GNUNET_assert(NULL != file);
-       /* FIXME: fprintf(file, message); */
+       fprintf(file, message);
        fclose(file);
 }
 
@@ -105,111 +109,140 @@
  return res;
 }
 
-int main(int argc, char *argv[])
+
+
+/**
+ * Main function that will be run by the scheduler.
+ *
+ * @param cls closure
+ * @param s the scheduler to use
+ * @param args remaining command-line arguments
+ * @param cfgfile name of the configuration file used (for saving, can be 
NULL!)
+ * @param c configuration
+ */
+static void
+run (void *cls,
+     struct GNUNET_SCHEDULER_Handle *s,
+     char *const *args,
+     const char *cfgfile,
+     const struct GNUNET_CONFIGURATION_Handle *c)
 {
- mi_aux_term *xterm_tty=NULL;
- const char* binaryName;
- const char* argument;
- int i = 1;
- 
- argument = argv[i];
- GNUNET_assert(NULL != argument);
- do {
-        if (strcasecmp(argument, "--mode") == 0) {
-                argument = argv[++i];
-                GNUNET_assert(NULL != argument);
-                mode = argument;
-        }
-        else if (strcasecmp(argument, "--binary") == 0) {
-                argument = argv[++i];
-                GNUNET_assert(NULL != argument);
-                binaryName = argument;
-        }
-        else if (strcasecmp(argument, "--output") == 0) {
-                argument = argv[++i];
-                GNUNET_assert(NULL != argument);
-                dumpFileName = argument;
-        }
-        else 
-                GNUNET_log(GNUNET_ERROR_TYPE_ERROR, _("Monkey: Error: 
Unexpected argument\n"));
- } while (NULL != (argument = argv[++i]));
- GNUNET_assert((NULL != binaryName) || (NULL != mode));
- GNUNET_assert(!((strcasecmp(mode, "text") == 0) && (NULL == dumpFileName)));
- 
- 
- /* This is like a file-handle for fopen.
-    Here we have all the state of gdb "connection". */
- mi_h *h;
+       mi_aux_term *xterm_tty=NULL;
+       
+       /* This is like a file-handle for fopen.
+           Here we have all the state of gdb "connection". */
+        mi_h *h;
 
- /* Connect to gdb child. */
- h=mi_connect_local();
- if (!h)
-   {
-    printf("Connect failed\n");
-    return 1;
-   }
- printf("Connected to gdb!\n");
+        /* Connect to gdb child. */
+        h=mi_connect_local();
+        if (!h)
+          {
+           printf("Connect failed\n");
+           ret = 1;
+           return;
+          }
+        printf("Connected to gdb!\n");
 
- /* Set all callbacks. */
- mi_set_console_cb(h,cb_console,NULL);
- mi_set_target_cb(h,cb_target,NULL);
- mi_set_log_cb(h,cb_log,NULL);
- mi_set_async_cb(h,cb_async,NULL);
- mi_set_to_gdb_cb(h,cb_to,NULL);
- mi_set_from_gdb_cb(h,cb_from,NULL);
+        /* Set all callbacks. */
+        mi_set_console_cb(h,cb_console,NULL);
+        mi_set_target_cb(h,cb_target,NULL);
+        mi_set_log_cb(h,cb_log,NULL);
+        mi_set_async_cb(h,cb_async,NULL);
+        mi_set_to_gdb_cb(h,cb_to,NULL);
+        mi_set_from_gdb_cb(h,cb_from,NULL);
 
- /* Set the name of the child and the command line aguments. */
- if (!gmi_set_exec(h, binaryName, NULL))
-   {
-    printf("Error setting exec y args\n");
-    mi_disconnect(h);
-    return 1;
-   }
+        /* Set the name of the child and the command line aguments. */
+        if (!gmi_set_exec(h, binaryName, NULL))
+          {
+           printf("Error setting exec y args\n");
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
 
- /* Tell gdb to attach the child to a terminal. */
- if (!gmi_target_terminal(h, ttyname(STDIN_FILENO)))
-   {
-    printf("Error selecting target terminal\n");
-    mi_disconnect(h);
-    return 1;
-   }
+        /* Tell gdb to attach the child to a terminal. */
+        if (!gmi_target_terminal(h, ttyname(STDIN_FILENO)))
+          {
+           printf("Error selecting target terminal\n");
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
 
- /* Run the program. */
- if (!gmi_exec_run(h))
-   {
-    printf("Error in run!\n");
-    mi_disconnect(h);
-    return 1;
-   }
- /* Here we should be stopped when the program crashes */
- if (!wait_for_stop(h))
-   {
-    mi_disconnect(h);
-    return 1;
-   }
+        /* Run the program. */
+        if (!gmi_exec_run(h))
+          {
+           printf("Error in run!\n");
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
+        /* Here we should be stopped when the program crashes */
+        if (!wait_for_stop(h))
+          {
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
 
- /* Continue execution. */
- if (!gmi_exec_continue(h))
-   {
-    printf("Error in continue!\n");
-    mi_disconnect(h);
-    return 1;
-   }
- /* Here we should be terminated. */
- if (!wait_for_stop(h))
-   {
-    mi_disconnect(h);
-    return 1;
-   }
+        /* Continue execution. */
+        if (!gmi_exec_continue(h))
+          {
+           printf("Error in continue!\n");
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
+        /* Here we should be terminated. */
+        if (!wait_for_stop(h))
+          {
+           mi_disconnect(h);
+           ret = 1;
+           return;
+          }
 
- /* Exit from gdb. */
- gmi_gdb_exit(h);
- /* Close the connection. */
- mi_disconnect(h);
- /* Wait 5 seconds and close the auxiliar terminal. */
- printf("Waiting 5 seconds\n");
- sleep(5);
- gmi_end_aux_term(xterm_tty);
+        /* Exit from gdb. */
+        gmi_gdb_exit(h);
+        /* Close the connection. */
+        mi_disconnect(h);
+        /* Wait 5 seconds and close the auxiliar terminal. */
+        printf("Waiting 5 seconds\n");
+        sleep(5);
+        gmi_end_aux_term(xterm_tty);
+}
 
- return 0;
+
+int main(int argc, char *argv[])
+{
+       /*
+        * FIXME: 
+        * Command should accept email address to which monkey sends the 
debugging report.
+        * The email address can also be read from the configuration file.
+        */
+ static const struct GNUNET_GETOPT_CommandLineOption options[] = {
+     {'m', "mode", NULL, gettext_noop ("monkey's mode of operation: options 
are \"text\" or \"email\""),
+      GNUNET_YES, &GNUNET_GETOPT_set_string, &mode},
+     {'b', "binary", NULL, gettext_noop ("binary for program to debug with 
monkey"),
+      GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName},
+     {'o', "output", NULL, gettext_noop ("path to file to dump monkey's output 
in case of working in text mode"),
+      GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName},
+      GNUNET_GETOPT_OPTION_END
+   };
+ 
+ if (argc < 2) {
+        printf("%s", "Monkey should take arguments: Use --help to get a list 
of options.\n");
+        return 1;
+ }
+ 
+ if (GNUNET_OK == GNUNET_PROGRAM_run (argc,
+                       argv,
+                       "gnunet-monkey",
+                       gettext_noop
+                       ("Automatically debug a service"),
+                       options, &run, NULL))
+     {
+       return ret;
+     }
+
+     return 1;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]