Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions src/mctpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -3074,9 +3074,11 @@ static int setup_testing(ctx *ctx) {

static void print_usage(ctx *ctx)
{
fprintf(stderr, "mctpd [-v] [-N]\n");
fprintf(stderr, "mctpd [-v] [-N] [-t usecs] [-r {bus-owner,endpoint}]\n");
fprintf(stderr, " -v verbose\n");
fprintf(stderr, " -N testing mode. Not safe for production\n");
fprintf(stderr, " -t timeout in usecs\n");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timeout for what? This may need to be a little more descriptive.

And why microseconds here? milliseconds may be easier to deal with.

fprintf(stderr, " -r role of mctpd in the network\n");
}

static int parse_args(ctx *ctx, int argc, char **argv)
Expand All @@ -3085,12 +3087,18 @@ static int parse_args(ctx *ctx, int argc, char **argv)
{ .name = "help", .has_arg = no_argument, .val = 'h' },
{ .name = "verbose", .has_arg = no_argument, .val = 'v' },
{ .name = "testing", .has_arg = no_argument, .val = 'N' },
{ .name = "timeout", .has_arg = required_argument, .val = 't' },
{ .name = "role", .has_arg = required_argument, .val = 'r' },
{ 0 },
};
int c;

// default values
ctx->mctp_timeout = 250000; // 250ms
ctx->bus_owner = true;

for (;;) {
c = getopt_long(argc, argv, "+hvN", options, NULL);
c = getopt_long(argc, argv, "+hvNt:r:", options, NULL);
if (c == -1)
break;

Expand All @@ -3101,6 +3109,23 @@ static int parse_args(ctx *ctx, int argc, char **argv)
case 'v':
ctx->verbose = true;
break;
case 't':
ctx->mctp_timeout = strtoull(optarg, NULL, 10);
if (ctx->mctp_timeout == 0) {
warnx("Timeout must be a non-zero u64");
return errno;
}
break;
case 'r':
if (!strcmp(optarg, "bus-owner"))
ctx->bus_owner = true;
else if (!strcmp(optarg, "endpoint"))
ctx->bus_owner = false;
else {
warnx("Role can only be one of: bus-owner, endpoint");
return -EINVAL;
}
break;
case 'h':
default:
print_usage(ctx);
Expand Down Expand Up @@ -3137,9 +3162,6 @@ static int fill_uuid(ctx *ctx)
static int setup_config(ctx *ctx)
{
int rc;
// TODO: this will go in a config file or arguments.
ctx->mctp_timeout = 250000; // 250ms
ctx->bus_owner = true;
rc = fill_uuid(ctx);
if (rc < 0)
return rc;
Expand Down