From 278f6d7b6d163e4e906da5706a09d71c7ef8144e Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 31 Oct 2009 05:12:12 +0100 Subject: fix segfault on "abrt-pyhook-helper -p X --- src/Hooks/abrt-pyhook-helper.cpp | 132 ++++++++++++++++++--------------------- 1 file changed, 61 insertions(+), 71 deletions(-) (limited to 'src') diff --git a/src/Hooks/abrt-pyhook-helper.cpp b/src/Hooks/abrt-pyhook-helper.cpp index eebda55..e20fc49 100644 --- a/src/Hooks/abrt-pyhook-helper.cpp +++ b/src/Hooks/abrt-pyhook-helper.cpp @@ -18,7 +18,8 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include + +#include /* We can easily get rid of abrtlib (libABRTUtils.so) usage in this file, * but DebugDump will pull it in anyway */ #include "abrtlib.h" @@ -27,74 +28,63 @@ # include #endif -const char *argp_program_version = "abrt-pyhook-helper " VERSION; -const char *argp_program_bug_address = ""; - -static char doc[] = "abrt-pyhook-helper -- stores crash data to abrt shared directory"; - -static struct argp_option options[] = { - {"pid" , 'p', "PID" , 0, "PID of process that caused the crash" }, - {"executable", 'e', "PATH" , 0, "absolute path to the program that crashed" }, - {"uuid" , 'u', "UUID" , 0, "hash generated from the backtrace"}, - {"cmdline" , 'c', "TEXT" , 0, "command line of the crashed program"}, - {"loginuid" , 'l', "UID" , 0, "login UID"}, - { 0 } -}; +#define MAX_BT_SIZE (1024*1024) -struct arguments -{ - char *pid; - char *executable; - char *uuid; - char *cmdline; - char *loginuid; -}; +static char *pid; +static char *executable; +static char *uuid; +static char *cmdline; +static char *loginuid; -static error_t -parse_opt(int key, char *arg, struct argp_state *state) +int main(int argc, char** argv) { - /* Get the input argument from argp_parse, which we - know is a pointer to our arguments structure. */ - struct arguments *arguments = (struct arguments*)state->input; - - switch (key) + // Parse options + static const struct option longopts[] = { + // name , has_arg , flag, val + { "pid" , required_argument, NULL, 'p' }, + { "executable", required_argument, NULL, 'e' }, + { "uuid" , required_argument, NULL, 'u' }, + { "cmdline" , required_argument, NULL, 'c' }, + { "loginuid" , required_argument, NULL, 'l' }, + }; + int opt; + while ((opt = getopt_long(argc, argv, "p:e:u:c:l:", longopts, NULL)) != -1) { - case 'p': arguments->pid = arg; break; - case 'e': arguments->executable = arg; break; - case 'u': arguments->uuid = arg; break; - case 'c': arguments->cmdline = arg; break; - case 'l': arguments->loginuid = arg; break; - - case ARGP_KEY_ARG: - argp_usage(state); - exit(1); - break; - - case ARGP_KEY_END: - if (!arguments->pid) + switch (opt) { - argp_usage(state); - exit(1); + case 'p': + pid = optarg; + break; + case 'e': + executable = optarg; + break; + case 'u': + uuid = optarg; + break; + case 'c': + cmdline = optarg; + break; + case 'l': + loginuid = optarg; + break; + default: + usage: + error_msg_and_die( + "Usage: abrt-pyhook-helper [OPTIONS]