From 02bec9a7652b981ee00c5656e9235ee0cc897f99 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Mon, 23 Nov 2020 02:00:58 +0100 Subject: libps: support getting RPC names for WAIT output * libps/Makefile (SRCS): Add ../utils/msgids.c. (../utils/msgids-CPPFLAGS): Add DATADIR macro. * libps/spec.c: Include "../utils/msgids.h". (get_rpc_name): Implement with msgid_info. * utils/msgids.c (parse_opt): Move end code to ... (msgids_scan_std): ... new function. * utils/msgids.h (msgids_scan_std): New prototype. * utils/ps.c (main): Call msgids_scan_std. --- libps/Makefile | 3 ++- libps/spec.c | 8 +++++++- utils/msgids.c | 61 +++++++++++++++++++++++++++++++++++++--------------------- utils/msgids.h | 1 + utils/ps.c | 2 ++ 5 files changed, 51 insertions(+), 24 deletions(-) diff --git a/libps/Makefile b/libps/Makefile index d3c0b187..07d27eeb 100644 --- a/libps/Makefile +++ b/libps/Makefile @@ -24,7 +24,7 @@ makemode := library libname = libps SRCS = context.c filters.c fmt.c host.c proclist.c procstat.c spec.c \ - tty.c user.c write.c + tty.c user.c write.c ../utils/msgids.c installhdrs = ps.h installhdrsubdir = . @@ -33,6 +33,7 @@ OBJS = $(SRCS:.c=.o) msgUser.o termUser.o msg-MIGUFLAGS = -D'MSG_IMPORTS=waittime 1000;' -DUSERPREFIX=ps_ term-MIGUFLAGS = -D'TERM_IMPORTS=waittime 1000;' -DUSERPREFIX=ps_ +../utils/msgids-CPPFLAGS = -DDATADIR=\"${datadir}\" ps_%.h: %_U.h sed 's/_$*_user_/_ps_$*_user_/g' $< > $@ diff --git a/libps/spec.c b/libps/spec.c index 4760c431..c9164f9d 100644 --- a/libps/spec.c +++ b/libps/spec.c @@ -32,10 +32,16 @@ #include "ps.h" #include "common.h" +#include "../utils/msgids.h" /* XXX */ static char *get_syscall_name (int num) { return 0; } -static char *get_rpc_name (mach_msg_id_t it) { return 0; } + +static char *get_rpc_name (mach_msg_id_t it) +{ + const struct msgid_info *info = msgid_info (it); + return info ? info->name : 0; +} /* ---------------------------------------------------------------- */ /* Getter definitions */ diff --git a/utils/msgids.c b/utils/msgids.c index d17f1316..81b49c59 100644 --- a/utils/msgids.c +++ b/utils/msgids.c @@ -171,6 +171,39 @@ static bool nostdinc = FALSE; #define STD_MSGIDS_DIR DATADIR "/msgids/" #define OPT_NOSTDINC -1 +error_t +msgids_scan_std (void) +{ + error_t err = 0; + + /* Insert the files from STD_MSGIDS_DIR at the beginning of the + list, so that their content can be overridden by subsequently + parsed files. */ + if (nostdinc == FALSE) + scan_msgids_dir (&msgids_files_argz, &msgids_files_argz_len, + STD_MSGIDS_DIR, FALSE); + + if (msgids_files_argz != NULL) + { + char *msgids_file = NULL; + + while (! err + && (msgids_file = argz_next (msgids_files_argz, + msgids_files_argz_len, + msgids_file))) + { + err = parse_msgid_list (msgids_file); + if (err) + error (0, err, "%s", msgids_file); + } + + free (msgids_files_argz); + msgids_files_argz = NULL; + } + + return err; +} + static const struct argp_option options[] = { {"nostdinc", OPT_NOSTDINC, 0, 0, @@ -218,29 +251,13 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) return EINVAL; case ARGP_KEY_END: - /* Insert the files from STD_MSGIDS_DIR at the beginning of the - list, so that their content can be overridden by subsequently - parsed files. */ - if (nostdinc == FALSE) - scan_msgids_dir (&msgids_files_argz, &msgids_files_argz_len, - STD_MSGIDS_DIR, FALSE); - - if (msgids_files_argz != NULL) - { - error_t err = 0; - char *msgids_file = NULL; + { + error_t err = msgids_scan_std (); - while (! err - && (msgids_file = argz_next (msgids_files_argz, - msgids_files_argz_len, - msgids_file))) - err = parse_msgid_list (msgids_file); - - free (msgids_files_argz); - if (err) - argp_failure (state, 1, err, "%s", msgids_file); - } - break; + if (err) + argp_failure (state, 1, err, "parsing msgid files"); + break; + } default: return ARGP_ERR_UNKNOWN; diff --git a/utils/msgids.h b/utils/msgids.h index 9d81bb33..546321eb 100644 --- a/utils/msgids.h +++ b/utils/msgids.h @@ -27,6 +27,7 @@ struct msgid_info char *subsystem; }; +error_t msgids_scan_std (void); const struct msgid_info *msgid_info (mach_msg_id_t msgid); extern const struct argp msgid_argp; diff --git a/utils/ps.c b/utils/ps.c index f5103239..2cf6e4bd 100644 --- a/utils/ps.c +++ b/utils/ps.c @@ -367,6 +367,8 @@ main(int argc, char *argv[]) /* Parse our command line. This shouldn't ever return an error. */ argp_parse (&argp, argc, argv, 0, 0, 0); + msgids_scan_std (); + err = proc_stat_list_create(context, &procset); if (err) error(1, err, "proc_stat_list_create"); -- cgit v1.2.3