dect
/
libnl
Archived
13
0
Fork 0

Use thread-safe strerror_r() instead of strerror()

We have only ever fed well known error codes into strerror()
so it should never have been a problem though.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
This commit is contained in:
Thomas Graf 2013-02-28 13:07:04 +01:00
parent ded20487fd
commit 4d7680c19c
5 changed files with 10 additions and 7 deletions

View File

@ -124,7 +124,7 @@ errout:
static void result_dump_line(struct nl_object *obj, struct nl_dump_params *p)
{
struct flnl_result *res = (struct flnl_result *) obj;
char buf[128];
char buf[256];
nl_dump_line(p, "table %s prefixlen %u next-hop-selector %u\n",
rtnl_route_table2str(res->fr_table_id, buf, sizeof(buf)),
@ -133,7 +133,7 @@ static void result_dump_line(struct nl_object *obj, struct nl_dump_params *p)
nl_rtntype2str(res->fr_type, buf, sizeof(buf)));
nl_dump(p, "scope %s error %s (%d)\n",
rtnl_scope2str(res->fr_scope, buf, sizeof(buf)),
strerror(-res->fr_error), res->fr_error);
strerror_r(-res->fr_error, buf, sizeof(buf)), res->fr_error);
}
static void result_dump_details(struct nl_object *obj, struct nl_dump_params *p)

View File

@ -79,9 +79,10 @@ static int nl_error_handler_verbose(struct sockaddr_nl *who,
struct nlmsgerr *e, void *arg)
{
FILE *ofd = arg ? arg : stderr;
char buf[256];
fprintf(ofd, "-- Error received: %s\n-- Original message: ",
strerror(-e->error));
strerror_r(-e->error, buf, sizeof(buf)));
print_header_content(ofd, &e->msg);
fprintf(ofd, "\n");

View File

@ -879,10 +879,11 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
hdr->nlmsg_len >= nlmsg_msg_size(sizeof(struct nlmsgerr))) {
struct nl_msg *errmsg;
struct nlmsgerr *err = nlmsg_data(hdr);
char buf[256];
fprintf(ofd, " [ERRORMSG] %zu octets\n", sizeof(*err));
fprintf(ofd, " .error = %d \"%s\"\n", err->error,
strerror(-err->error));
strerror_r(-err->error, buf, sizeof(buf)));
fprintf(ofd, " [ORIGINAL MESSAGE] %zu octets\n", sizeof(*hdr));
errmsg = nlmsg_inherit(&err->msg);

View File

@ -208,7 +208,7 @@ static void route_dump_details(struct nl_object *a, struct nl_dump_params *p)
{
struct rtnl_route *r = (struct rtnl_route *) a;
struct nl_cache *link_cache;
char buf[128];
char buf[256];
int i;
link_cache = nl_cache_mngt_require_safe("route/link");
@ -259,7 +259,7 @@ static void route_dump_details(struct nl_object *a, struct nl_dump_params *p)
if ((r->ce_mask & ROUTE_ATTR_CACHEINFO) && r->rt_cacheinfo.rtci_error) {
nl_dump_line(p, " cacheinfo error %d (%s)\n",
r->rt_cacheinfo.rtci_error,
strerror(-r->rt_cacheinfo.rtci_error));
strerror_r(-r->rt_cacheinfo.rtci_error, buf, sizeof(buf)));
}
if (r->ce_mask & ROUTE_ATTR_METRICS) {

View File

@ -70,6 +70,7 @@ void nl_cli_print_version(void)
void nl_cli_fatal(int err, const char *fmt, ...)
{
va_list ap;
char buf[256];
fprintf(stderr, "Error: ");
@ -79,7 +80,7 @@ void nl_cli_fatal(int err, const char *fmt, ...)
va_end(ap);
fprintf(stderr, "\n");
} else
fprintf(stderr, "%s\n", strerror(err));
fprintf(stderr, "%s\n", strerror_r(err, buf, sizeof(buf)));
exit(abs(err));
}