Use patty_error_fmt() for errors in pattyd(8)
This commit is contained in:
parent
d1b507e81f
commit
7eca9a09c9
1 changed files with 39 additions and 34 deletions
73
bin/pattyd.c
73
bin/pattyd.c
|
@ -37,7 +37,9 @@ static int usage(int argc, char **argv, const char *message, ...) {
|
|||
|
||||
struct context {
|
||||
char *config_file;
|
||||
|
||||
patty_daemon *daemon;
|
||||
patty_error e;
|
||||
};
|
||||
|
||||
static int handle_sock(struct context *ctx,
|
||||
|
@ -45,15 +47,15 @@ static int handle_sock(struct context *ctx,
|
|||
int argc,
|
||||
char **argv) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "%s: line %d: Invalid arguments for 'sock'\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid arguments for 'sock'",
|
||||
lineno);
|
||||
|
||||
goto error_invalid_args;
|
||||
}
|
||||
|
||||
if (patty_daemon_set_sock_path(ctx->daemon, argv[1]) < 0) {
|
||||
fprintf(stderr, "%s: line %d: Unable to set socket path to %s: %s\n",
|
||||
ctx->config_file, lineno, argv[1], strerror(errno));
|
||||
patty_error_fmt(&ctx->e, "line %d: Unable to set socket path to %s: %s",
|
||||
lineno, argv[1], strerror(errno));
|
||||
|
||||
goto error_set_sock_path;
|
||||
}
|
||||
|
@ -70,15 +72,15 @@ static int handle_pid(struct context *ctx,
|
|||
int argc,
|
||||
char **argv) {
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "%s: line %d: Invalid arguments for 'sock'\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid arguments for 'sock'",
|
||||
lineno);
|
||||
|
||||
goto error_invalid_args;
|
||||
}
|
||||
|
||||
if (patty_daemon_set_pidfile(ctx->daemon, argv[1]) < 0) {
|
||||
fprintf(stderr, "%s: line %d: Unable to set pidfile to %s: %s\n",
|
||||
ctx->config_file, lineno, argv[1], strerror(errno));
|
||||
patty_error_fmt(&ctx->e, "line %d: Unable to set pidfile to %s: %s",
|
||||
lineno, argv[1], strerror(errno));
|
||||
|
||||
goto error_set_pidfile;
|
||||
}
|
||||
|
@ -98,20 +100,21 @@ static int handle_if(struct context *ctx,
|
|||
patty_error e;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "%s: line %d: No interface name provided\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: No interface name provided",
|
||||
lineno);
|
||||
|
||||
goto error_invalid;
|
||||
} else if (argc < 3) {
|
||||
fprintf(stderr, "%s: line %d: No interface options provided\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: No interface options provided",
|
||||
lineno);
|
||||
|
||||
goto error_invalid;
|
||||
}
|
||||
|
||||
if ((iface = patty_bin_if_create(argc, argv, &e)) == NULL) {
|
||||
fprintf(stderr, "%s: line %d: %s\n",
|
||||
ctx->config_file, lineno, patty_error_string(&e));
|
||||
patty_error_fmt(&ctx->e, "line %d: %s",
|
||||
lineno,
|
||||
patty_error_set(&e)? patty_error_string(&e): strerror(errno));
|
||||
|
||||
goto error_invalid;
|
||||
} else {
|
||||
|
@ -125,8 +128,7 @@ static int handle_if(struct context *ctx,
|
|||
}
|
||||
|
||||
if (patty_daemon_if_add(ctx->daemon, iface) < 0) {
|
||||
fprintf(stderr, "%s: line %d: Unable to create interface %s: %s\n",
|
||||
ctx->config_file,
|
||||
patty_error_fmt(&ctx->e, "line %d: Unable to create interface %s: %s",
|
||||
lineno,
|
||||
patty_ax25_if_name(iface),
|
||||
strerror(errno));
|
||||
|
@ -148,30 +150,30 @@ static int handle_route(struct context *ctx,
|
|||
int argc,
|
||||
char **argv) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "%s: line %d: Invalid route declaration\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid route declaration",
|
||||
lineno);
|
||||
|
||||
goto error_invalid_route;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "default") == 0) {
|
||||
if (argc != 4 || strcmp(argv[2], "if") != 0) {
|
||||
fprintf(stderr, "%s: line %d: Invalid default route declaration\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid default route declaration",
|
||||
lineno);
|
||||
|
||||
goto error_invalid_route;
|
||||
}
|
||||
|
||||
if (patty_daemon_route_add_default(ctx->daemon, argv[3]) < 0) {
|
||||
fprintf(stderr, "%s: line %d: Unable to add default route for interface %s: %s",
|
||||
ctx->config_file, lineno, argv[3], strerror(errno));
|
||||
patty_error_fmt(&ctx->e, "line %d: Unable to add default route for interface %s: %s",
|
||||
lineno, argv[3], strerror(errno));
|
||||
|
||||
goto error_daemon_route_add;
|
||||
}
|
||||
} else if (strcmp(argv[1], "station") == 0) {
|
||||
if (argc < 7 || strcmp(argv[3], "if") != 0 || strcmp(argv[5], "path") != 0) {
|
||||
fprintf(stderr, "%s: line %d: Invalid station route declaration\n",
|
||||
ctx->config_file, lineno);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid station route declaration",
|
||||
lineno);
|
||||
|
||||
goto error_invalid_route;
|
||||
}
|
||||
|
@ -181,14 +183,14 @@ static int handle_route(struct context *ctx,
|
|||
argv[2],
|
||||
(const char **)&argv[6],
|
||||
argc - 6) < 0) {
|
||||
fprintf(stderr, "%s: line %d: Unable to add route for interface %s: %s\n",
|
||||
ctx->config_file, lineno, argv[4], strerror(errno));
|
||||
patty_error_fmt(&ctx->e, "line %d: Unable to add route for interface %s: %s",
|
||||
lineno, argv[4], strerror(errno));
|
||||
|
||||
goto error_daemon_route_add;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%s: line %d: Invalid route type '%s'",
|
||||
ctx->config_file, lineno, argv[1]);
|
||||
patty_error_fmt(&ctx->e, "line %d: Invalid route type '%s'",
|
||||
lineno, argv[1]);
|
||||
|
||||
goto error_invalid_route;
|
||||
}
|
||||
|
@ -256,8 +258,8 @@ static int handle_config_line(patty_conf_file *file,
|
|||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s: line %d: Unknown configuration value '%s'",
|
||||
ctx->config_file, lineno, argv[0]);
|
||||
patty_error_fmt(&ctx->e, "line %d: Unknown configuration value '%s'",
|
||||
lineno, argv[0]);
|
||||
|
||||
done:
|
||||
free(argv);
|
||||
|
@ -364,6 +366,7 @@ int main(int argc, char **argv) {
|
|||
.config_file = DEFAULT_CONFIG_FILE
|
||||
};
|
||||
|
||||
memset(&ctx.e, '\0', sizeof(ctx.e));
|
||||
memset(flags, '\0', sizeof(flags));
|
||||
|
||||
if ((ctx.daemon = patty_daemon_new()) == NULL) {
|
||||
|
@ -413,10 +416,12 @@ int main(int argc, char **argv) {
|
|||
goto error_config;
|
||||
}
|
||||
} else if (patty_conf_read(ctx.config_file, handle_config_line, &ctx) < 0) {
|
||||
if (errno) {
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0], "patty_conf_read()", ctx.config_file, strerror(errno));
|
||||
}
|
||||
fprintf(stderr, "%s: %s: %s: %s\n",
|
||||
argv[0],
|
||||
"patty_conf_read()",
|
||||
ctx.config_file,
|
||||
patty_error_set(&ctx.e)? patty_error_string(&ctx.e):
|
||||
strerror(errno));
|
||||
|
||||
goto error_config;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue