2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file monkey/gnunet-monkey.c
23 * @brief Monkey: gnunet automated debugging tool
28 #include "gnunet_common.h"
29 #include "gnunet_getopt_lib.h"
30 #include "gnunet_program_lib.h"
31 #include "gnunet_monkey_action.h"
33 static const char* mode;
34 static const char* dumpFileName;
35 static const char* binaryName;
36 static const char* emailAddress;
37 static const char* edbFilePath;
38 static const char* gdbBinaryPath;
42 * Main function that will launch the action api.
45 * @param args remaining command-line arguments
46 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
47 * @param c configuration
53 const struct GNUNET_CONFIGURATION_Handle *c)
56 struct GNUNET_MONKEY_ACTION_Context *cntxt;
58 if (strcasecmp(mode, "email") == 0) {
59 if (NULL == emailAddress) {
60 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Working in email mode requires an email address!\n");
64 } else if (strcasecmp(mode, "text") == 0) {
65 if (NULL == dumpFileName) {
66 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Working in text mode requires a path for the dump file!\n");
72 /* Initialize context for the Action API */
73 cntxt = GNUNET_malloc(sizeof(struct GNUNET_MONKEY_ACTION_Context));
74 cntxt->binary_name = binaryName;
75 cntxt->expression_database_path = edbFilePath;
76 cntxt->gdb_binary_path = gdbBinaryPath;
78 result = GNUNET_MONKEY_ACTION_rerun_with_gdb(cntxt);
82 case GDB_STATE_EXIT_NORMALLY:
83 GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Debug with gdb, program exited normally!\n");
84 /*FIXME: Valgrind should be launched here */
86 case GDB_STATE_STOPPED:
87 /*FIXME: Expression Database should be inspected here (before writing the report) */
88 if (GNUNET_OK != GNUNET_MONKEY_ACTION_inspect_expression_database(cntxt)) {
89 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error using Expression Database!\n");
93 if(GNUNET_OK != GNUNET_MONKEY_ACTION_format_report(cntxt)){
94 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in generating debug report!\n");
97 if (strcasecmp(mode, "email") == 0) {
98 if (GNUNET_OK != GNUNET_MONKEY_ACTION_report_email(cntxt)) {
99 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error sending email!\n");
104 if (GNUNET_OK != GNUNET_MONKEY_ACTION_report_file(cntxt, dumpFileName)) {
105 GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Error in saving debug file!\n");
116 int main(int argc, char *argv[])
118 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
119 {'m', "mode", NULL, gettext_noop ("monkey's mode of operation: options are \"text\" or \"email\""),
120 GNUNET_YES, &GNUNET_GETOPT_set_string, &mode},
121 {'b', "binary", NULL, gettext_noop ("binary for program to debug with monkey"),
122 GNUNET_YES, &GNUNET_GETOPT_set_string, &binaryName},
123 {'o', "output", NULL, gettext_noop ("path to file to dump monkey's output in case of text mode"),
124 GNUNET_YES, &GNUNET_GETOPT_set_string, &dumpFileName},
125 {'a', "address", NULL, gettext_noop ("address to send email to in case of email mode"),
126 GNUNET_YES, &GNUNET_GETOPT_set_string, &emailAddress},
127 {'d', "database", NULL, gettext_noop ("path to Expression Database file"),
128 GNUNET_YES, &GNUNET_GETOPT_set_string, &edbFilePath},
129 {'g', "gdb", NULL, gettext_noop ("path to gdb binary in use; default is /usr/bin/gdb"),
130 GNUNET_YES, &GNUNET_GETOPT_set_string, &gdbBinaryPath},
131 GNUNET_GETOPT_OPTION_END
135 printf("%s", "Monkey should take arguments: Use --help to get a list of options.\n");
139 if (GNUNET_OK == GNUNET_PROGRAM_run (argc,
143 ("Automatically debug a service"),
144 options, &run, NULL))