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 */ /* global.c */
extern void self_info(void); extern void self_info(void);
extern void catastrophic_failure(const char *filename, unsigned int linenum,
const char *message);
/* parser.c */ /* parser.c */
extern int arg_parse(int argc, char *argv[]); 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 */ if(signo==SIGPIPE) _exit(0); /* "ps | head" will cause this */
/* fprintf() is not reentrant, but we _exit() anyway */ /* fprintf() is not reentrant, but we _exit() anyway */
fprintf(stderr, fprintf(stderr,
_("\n\n" _("Signal %d (%s) caught by %s (%s).\n"),
"Signal %d (%s) caught by %s (%s).\n"
"Please send bug reports to <procps@freelists.org>\n"),
signo, signo,
signal_number_to_name(signo), signal_number_to_name(signo),
myname, myname,
procps_version 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; t_end->need = 0;
break; break;
default: default:
fprintf(stderr, _("please report this bug\n")); catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
// FALL THROUGH // FALL THROUGH
case CF_PRINT_AS_NEEDED: case CF_PRINT_AS_NEEDED:
case CF_PRINT_EVERY_TIME: case CF_PRINT_EVERY_TIME:

View File

@ -507,3 +507,12 @@ void self_info(void){
open_psdb(namelist_file); open_psdb(namelist_file);
fprintf(stderr,"namelist_file=\"%s\"\n",namelist_file?namelist_file:"<no System.map 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."); return _("Embedded '-' among SysV options makes no sense.");
break; break;
case '\0': case '\0':
return _("Please report the \"SysV \\0 can't happen\" bug."); catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
break; break;
default: default:
return _("Unsupported SysV option."); return _("Unsupported SysV option.");
@ -728,7 +728,7 @@ static const char *parse_bsd_option(void){
return _("Embedded '-' among BSD options makes no sense."); return _("Embedded '-' among BSD options makes no sense.");
break; break;
case '\0': case '\0':
return _("Please report the \"BSD \\0 can't happen\" bug."); catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
break; break;
default: default:
return _("Unsupported option (BSD syntax)"); return _("Unsupported option (BSD syntax)");

View File

@ -84,7 +84,7 @@ static int proc_was_listed(proc_t *buf){
while(sn){ while(sn){
switch(sn->typecode){ switch(sn->typecode){
default: 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) \ #define return_if_match(foo,bar) \
i=sn->n; while(i--) \ 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" ; trailer = (otype=='b') ? "END_BSD" : "END_SYS5" ;
fnode = do_one_spec("pid",NULL); 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 = sfn->f_cooked; while(endp->next) endp = endp->next; /* find end */
endp->next = fnode; endp->next = fnode;
fnode = do_one_spec(trailer,NULL); 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 = fnode; while(endp->next) endp = endp->next; /* find end */
endp->next = sfn->f_cooked; endp->next = sfn->f_cooked;
sfn->f_cooked = fnode; sfn->f_cooked = fnode;
@ -539,7 +539,7 @@ static const char *parse_O_option(sf_node *sfn){
already_parsed_sort = 1; already_parsed_sort = 1;
break; break;
default: /*** junk ***/ default: /*** junk ***/
return _("Bug: parse_O_option got weirdness!"); catastrophic_failure(__FILE__, __LINE__, _("please report this bug"));
} }
return err; /* could be NULL */ return err; /* could be NULL */
} }
@ -754,7 +754,7 @@ const char *process_sf_options(int localbroken){
if(err) return err; 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 */ /* merge formatting info of sf_list into format_list here */
sf_walk = sf_list; sf_walk = sf_list;
@ -884,7 +884,7 @@ const char *process_sf_options(int localbroken){
if(format_modifiers & FM_j){ if(format_modifiers & FM_j){
fn = do_one_spec("pgid", NULL); fn = do_one_spec("pgid", NULL);
if(!fmt_add_after("PPID", fn)) if(!fmt_add_after("PID", fn)) 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); fn = do_one_spec("sid", NULL);
if(!fmt_add_after("PGID", fn)) return _("Lost my PGID!"); if(!fmt_add_after("PGID", fn)) return _("Lost my PGID!");
} }
@ -899,7 +899,7 @@ const char *process_sf_options(int localbroken){
fmt_delete("NI"); fmt_delete("NI");
fn = do_one_spec("class", NULL); fn = do_one_spec("class", NULL);
if(!fmt_add_after("PRI", fn)) 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 */ fmt_delete("PRI"); /* we want a different one */
fn = do_one_spec("pri", NULL); fn = do_one_spec("pri", NULL);
if(!fmt_add_after("CLS", fn)) return _("Lost my CLS!"); if(!fmt_add_after("CLS", fn)) return _("Lost my CLS!");