1 |
/* Trace RPCs sent to selected ports |
/* Trace RPCs sent to selected ports |
2 |
|
|
3 |
Copyright (C) 1998,99,2001,02,03 Free Software Foundation, Inc. |
Copyright (C) 1998,99,2001,02,03,05 Free Software Foundation, Inc. |
4 |
|
|
5 |
This file is part of the GNU Hurd. |
This file is part of the GNU Hurd. |
6 |
|
|
25 |
#include <mach/message.h> |
#include <mach/message.h> |
26 |
#include <assert.h> |
#include <assert.h> |
27 |
#include <fcntl.h> |
#include <fcntl.h> |
28 |
|
#include <fnmatch.h> |
29 |
|
#include <sys/stat.h> |
30 |
|
#include <dirent.h> |
31 |
#include <unistd.h> |
#include <unistd.h> |
32 |
#include <argp.h> |
#include <argp.h> |
33 |
#include <error.h> |
#include <error.h> |
42 |
static const struct argp_option options[] = |
static const struct argp_option options[] = |
43 |
{ |
{ |
44 |
{"output", 'o', "FILE", 0, "Send trace output to FILE instead of stderr."}, |
{"output", 'o', "FILE", 0, "Send trace output to FILE instead of stderr."}, |
45 |
{"rpc-list", 'I', "FILE", 0, |
{"rpc-list", 'i', "FILE", 0, |
46 |
"Read FILE for assocations of message ID numbers to names."}, |
"Read FILE for assocations of message ID numbers to names."}, |
47 |
|
{0, 'I', "DIR", 0, |
48 |
|
"Add the directory DIR to the list of directories to be searched for files containing message ID numbers."}, |
49 |
{0} |
{0} |
50 |
}; |
}; |
51 |
|
|
1064 |
{ |
{ |
1065 |
const char *outfile = 0; |
const char *outfile = 0; |
1066 |
char **cmd_argv = 0; |
char **cmd_argv = 0; |
|
error_t err; |
|
1067 |
|
|
1068 |
/* Parse our options... */ |
/* Parse our options... */ |
1069 |
error_t parse_opt (int key, char *arg, struct argp_state *state) |
error_t parse_opt (int key, char *arg, struct argp_state *state) |
1074 |
outfile = arg; |
outfile = arg; |
1075 |
break; |
break; |
1076 |
|
|
1077 |
case 'I': |
case 'i': |
1078 |
parse_msgid_list (arg); |
parse_msgid_list (arg); |
1079 |
break; |
break; |
1080 |
|
|
1081 |
|
case 'I': |
1082 |
|
{ |
1083 |
|
struct dirent **eps; |
1084 |
|
int n; |
1085 |
|
|
1086 |
|
static int |
1087 |
|
msgids_file_p (const struct dirent *eps) |
1088 |
|
{ |
1089 |
|
if (fnmatch ("*.msgids", eps->d_name, 0) != FNM_NOMATCH) |
1090 |
|
return 1; |
1091 |
|
return 0; |
1092 |
|
} |
1093 |
|
|
1094 |
|
n = scandir (arg, &eps, msgids_file_p, NULL); |
1095 |
|
if (n >= 0) |
1096 |
|
{ |
1097 |
|
for (int cnt = 0; cnt < n; ++cnt) |
1098 |
|
{ |
1099 |
|
char *msgids_file; |
1100 |
|
struct stat st; |
1101 |
|
if (asprintf (&msgids_file, |
1102 |
|
"%s/%s", arg, eps[cnt]->d_name) < 0) |
1103 |
|
error (1, errno, "asprintf"); |
1104 |
|
parse_msgid_list (msgids_file); |
1105 |
|
free (msgids_file); |
1106 |
|
} |
1107 |
|
} |
1108 |
|
/* If the directory couldn't be scanned for whatever |
1109 |
|
reason, just ignore it. */ |
1110 |
|
} |
1111 |
|
break; |
1112 |
|
|
1113 |
case ARGP_KEY_NO_ARGS: |
case ARGP_KEY_NO_ARGS: |
1114 |
argp_usage (state); |
argp_usage (state); |
1115 |
return EINVAL; |
return EINVAL; |