diff --git a/ps/common.h b/ps/common.h index 66d8d643..72ffa744 100644 --- a/ps/common.h +++ b/ps/common.h @@ -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[]); diff --git a/ps/display.c b/ps/display.c index 67d14390..e965f062 100644 --- a/ps/display.c +++ b/ps/display.c @@ -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 \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: diff --git a/ps/global.c b/ps/global.c index 706d3e39..1d4bc48a 100644 --- a/ps/global.c +++ b/ps/global.c @@ -507,3 +507,12 @@ void self_info(void){ open_psdb(namelist_file); fprintf(stderr,"namelist_file=\"%s\"\n",namelist_file?namelist_file:""); } + +void __attribute__ ((__noreturn__)) +catastrophic_failure(const char *filename, + unsigned int linenum, + const char *message) +{ + error_at_line(0, 0, filename, linenum, message); + abort(); +} diff --git a/ps/parser.c b/ps/parser.c index 26842278..89016969 100644 --- a/ps/parser.c +++ b/ps/parser.c @@ -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)"); diff --git a/ps/select.c b/ps/select.c index 6a87fcc5..cbe38a7e 100644 --- a/ps/select.c +++ b/ps/select.c @@ -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--) \ diff --git a/ps/sortformat.c b/ps/sortformat.c index d83b7d41..01eeead1 100644 --- a/ps/sortformat.c +++ b/ps/sortformat.c @@ -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!");