ps: add catastrophic_failure()

The catastrophic_failure function tries to make bug reporting useful
by telling in which line error occured, and drops core.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2012-01-10 21:47:11 +01:00
parent bf88c882ed
commit 809906b6a7
6 changed files with 23 additions and 14 deletions

View File

@ -334,6 +334,8 @@ extern void do_help(const char *opt, int rc) NORETURN;
/* global.c */
extern void self_info(void);
extern void catastrophic_failure(const char *filename, unsigned int linenum,
const char *message);
/* parser.c */
extern int arg_parse(int argc, char *argv[]);

View File

@ -41,15 +41,13 @@ static void signal_handler(int signo){
if(signo==SIGPIPE) _exit(0); /* "ps | head" will cause this */
/* fprintf() is not reentrant, but we _exit() anyway */
fprintf(stderr,
_("\n\n"
"Signal %d (%s) caught by %s (%s).\n"
"Please send bug reports to <procps@freelists.org>\n"),
_("Signal %d (%s) caught by %s (%s).\n"),
signo,
signal_number_to_name(signo),
myname,
procps_version
);
_exit(signo+128);
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
}
/////////////////////////////////////////////////////////////////////////////////////
@ -250,7 +248,7 @@ static void lists_and_needs(void){
t_end->need = 0;
break;
default:
fprintf(stderr, _("please report this bug\n"));
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
// FALL THROUGH
case CF_PRINT_AS_NEEDED:
case CF_PRINT_EVERY_TIME:

View File

@ -507,3 +507,12 @@ void self_info(void){
open_psdb(namelist_file);
fprintf(stderr,"namelist_file=\"%s\"\n",namelist_file?namelist_file:"<no System.map file>");
}
void __attribute__ ((__noreturn__))
catastrophic_failure(const char *filename,
unsigned int linenum,
const char *message)
{
error_at_line(0, 0, filename, linenum, message);
abort();
}

View File

@ -483,7 +483,7 @@ static const char *parse_sysv_option(void){
return _("Embedded '-' among SysV options makes no sense.");
break;
case '\0':
return _("Please report the \"SysV \\0 can't happen\" bug.");
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
break;
default:
return _("Unsupported SysV option.");
@ -728,7 +728,7 @@ static const char *parse_bsd_option(void){
return _("Embedded '-' among BSD options makes no sense.");
break;
case '\0':
return _("Please report the \"BSD \\0 can't happen\" bug.");
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
break;
default:
return _("Unsupported option (BSD syntax)");

View File

@ -84,7 +84,7 @@ static int proc_was_listed(proc_t *buf){
while(sn){
switch(sn->typecode){
default:
printf(_("Internal error in ps! Please report this bug.\n"));
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
#define return_if_match(foo,bar) \
i=sn->n; while(i--) \

View File

@ -96,12 +96,12 @@ static void O_wrap(sf_node *sfn, int otype){
trailer = (otype=='b') ? "END_BSD" : "END_SYS5" ;
fnode = do_one_spec("pid",NULL);
if(!fnode)fprintf(stderr,_("Seriously crashing. Goodbye cruel world.\n"));
if(!fnode)catastrophic_failure(__FILE__, __LINE__, _("Seriously crashing. Goodbye cruel world."));
endp = sfn->f_cooked; while(endp->next) endp = endp->next; /* find end */
endp->next = fnode;
fnode = do_one_spec(trailer,NULL);
if(!fnode) { fprintf(stderr,_("Seriously crashing. Goodbye cruel world.\n")); exit(1); }
if(!fnode)catastrophic_failure(__FILE__, __LINE__, _("Seriously crashing. Goodbye cruel world."));
endp = fnode; while(endp->next) endp = endp->next; /* find end */
endp->next = sfn->f_cooked;
sfn->f_cooked = fnode;
@ -539,7 +539,7 @@ static const char *parse_O_option(sf_node *sfn){
already_parsed_sort = 1;
break;
default: /*** junk ***/
return _("Bug: parse_O_option got weirdness!");
catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
}
return err; /* could be NULL */
}
@ -754,7 +754,7 @@ const char *process_sf_options(int localbroken){
if(err) return err;
}
if(format_list) printf(_("Bug: must reset the list first!\n"));
if(format_list) catastrophic_failure(__FILE__, __LINE__, _("Bug: must reset the list first!"));
/* merge formatting info of sf_list into format_list here */
sf_walk = sf_list;
@ -884,7 +884,7 @@ const char *process_sf_options(int localbroken){
if(format_modifiers & FM_j){
fn = do_one_spec("pgid", NULL);
if(!fmt_add_after("PPID", fn)) if(!fmt_add_after("PID", fn))
return _("Internal error, no PID or PPID for -j option.");
catastrophic_failure(__FILE__, __LINE__, _("Internal error, no PID or PPID for -j option."));
fn = do_one_spec("sid", NULL);
if(!fmt_add_after("PGID", fn)) return _("Lost my PGID!");
}
@ -899,7 +899,7 @@ const char *process_sf_options(int localbroken){
fmt_delete("NI");
fn = do_one_spec("class", NULL);
if(!fmt_add_after("PRI", fn))
return _("Internal error, no PRI for -c option.");
catastrophic_failure(__FILE__, __LINE__, _("Internal error, no PRI for -c option."));
fmt_delete("PRI"); /* we want a different one */
fn = do_one_spec("pri", NULL);
if(!fmt_add_after("CLS", fn)) return _("Lost my CLS!");