Skip to content

Commit

Permalink
Replace all uses of strerror() by ovs_strerror(), for thread safety.
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Pfaff <[email protected]>
  • Loading branch information
blp committed Jun 28, 2013
1 parent 5fcbed7 commit 10a89ef
Show file tree
Hide file tree
Showing 56 changed files with 298 additions and 269 deletions.
31 changes: 16 additions & 15 deletions lib/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,15 +210,16 @@ make_pidfile(void)

file = fopen(tmpfile, "a+");
if (!file) {
VLOG_FATAL("%s: create failed (%s)", tmpfile, strerror(errno));
VLOG_FATAL("%s: create failed (%s)", tmpfile, ovs_strerror(errno));
}

error = lock_pidfile(file, F_SETLK);
if (error) {
/* Looks like we failed to acquire the lock. Note that, if we failed
* for some other reason (and '!overwrite_pidfile'), we will have
* left 'tmpfile' as garbage in the file system. */
VLOG_FATAL("%s: fcntl(F_SETLK) failed (%s)", tmpfile, strerror(error));
VLOG_FATAL("%s: fcntl(F_SETLK) failed (%s)", tmpfile,
ovs_strerror(error));
}

if (!overwrite_pidfile) {
Expand All @@ -229,16 +230,16 @@ make_pidfile(void)
}

if (fstat(fileno(file), &s) == -1) {
VLOG_FATAL("%s: fstat failed (%s)", tmpfile, strerror(errno));
VLOG_FATAL("%s: fstat failed (%s)", tmpfile, ovs_strerror(errno));
}

if (ftruncate(fileno(file), 0) == -1) {
VLOG_FATAL("%s: truncate failed (%s)", tmpfile, strerror(errno));
VLOG_FATAL("%s: truncate failed (%s)", tmpfile, ovs_strerror(errno));
}

fprintf(file, "%ld\n", pid);
if (fflush(file) == EOF) {
VLOG_FATAL("%s: write failed (%s)", tmpfile, strerror(errno));
VLOG_FATAL("%s: write failed (%s)", tmpfile, ovs_strerror(errno));
}

error = rename(tmpfile, pidfile);
Expand All @@ -249,7 +250,7 @@ make_pidfile(void)

if (error < 0) {
VLOG_FATAL("failed to rename \"%s\" to \"%s\" (%s)",
tmpfile, pidfile, strerror(errno));
tmpfile, pidfile, ovs_strerror(errno));
}

/* Ensure that the pidfile will get deleted on exit. */
Expand Down Expand Up @@ -339,7 +340,7 @@ fork_and_wait_for_startup(int *fdp)
status_msg);
}
} else if (retval < 0) {
VLOG_FATAL("waitpid failed (%s)", strerror(errno));
VLOG_FATAL("waitpid failed (%s)", ovs_strerror(errno));
} else {
NOT_REACHED();
}
Expand All @@ -364,7 +365,7 @@ fork_notify_startup(int fd)

error = write_fully(fd, "", 1, &bytes_written);
if (error) {
VLOG_FATAL("pipe write failed (%s)", strerror(error));
VLOG_FATAL("pipe write failed (%s)", ovs_strerror(error));
}

close(fd);
Expand Down Expand Up @@ -415,7 +416,7 @@ monitor_daemon(pid_t daemon_pid)
} while (retval == -1 && errno == EINTR);

if (retval == -1) {
VLOG_FATAL("waitpid failed (%s)", strerror(errno));
VLOG_FATAL("waitpid failed (%s)", ovs_strerror(errno));
} else if (retval == daemon_pid) {
char *s = process_status_msg(status);
if (should_restart(status)) {
Expand All @@ -433,7 +434,7 @@ monitor_daemon(pid_t daemon_pid)
r.rlim_max = 0;
if (setrlimit(RLIMIT_CORE, &r) == -1) {
VLOG_WARN("failed to disable core dumps: %s",
strerror(errno));
ovs_strerror(errno));
}
}

Expand Down Expand Up @@ -641,13 +642,13 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
return 0;
}
error = errno;
VLOG_WARN("%s: open: %s", pidfile, strerror(error));
VLOG_WARN("%s: open: %s", pidfile, ovs_strerror(error));
goto error;
}

error = lock_pidfile__(file, F_GETLK, &lck);
if (error) {
VLOG_WARN("%s: fcntl: %s", pidfile, strerror(error));
VLOG_WARN("%s: fcntl: %s", pidfile, ovs_strerror(error));
goto error;
}
if (lck.l_type == F_UNLCK) {
Expand Down Expand Up @@ -686,7 +687,7 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
if (unlink(pidfile)) {
error = errno;
VLOG_WARN("%s: failed to delete stale pidfile (%s)",
pidfile, strerror(error));
pidfile, ovs_strerror(error));
goto error;
}
VLOG_DBG("%s: deleted stale pidfile", pidfile);
Expand All @@ -697,7 +698,7 @@ read_pidfile__(const char *pidfile, bool delete_if_stale)
if (!fgets(line, sizeof line, file)) {
if (ferror(file)) {
error = errno;
VLOG_WARN("%s: read: %s", pidfile, strerror(error));
VLOG_WARN("%s: read: %s", pidfile, ovs_strerror(error));
} else {
error = ESRCH;
VLOG_WARN("%s: read: unexpected end of file", pidfile);
Expand Down Expand Up @@ -743,6 +744,6 @@ check_already_running(void)
VLOG_FATAL("%s: already running as pid %ld, aborting", pidfile, pid);
} else if (pid < 0) {
VLOG_FATAL("%s: pidfile check failed (%s), aborting",
pidfile, strerror(-pid));
pidfile, ovs_strerror(-pid));
}
}
9 changes: 5 additions & 4 deletions lib/dpif-linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,8 @@ dpif_linux_flow_dump_next(const struct dpif *dpif_ OVS_UNUSED, void *state_,
if (error == ENOENT) {
VLOG_DBG("dumped flow disappeared on get");
} else if (error) {
VLOG_WARN("error fetching dumped flow: %s", strerror(error));
VLOG_WARN("error fetching dumped flow: %s",
ovs_strerror(error));
}
}
} while (error);
Expand Down Expand Up @@ -1208,7 +1209,7 @@ dpif_linux_recv_set(struct dpif *dpif_, bool enable)
} else {
VLOG_WARN_RL(&error_rl,
"%s: failed to set upcall pid on port: %s",
dpif_name(&dpif->dpif), strerror(error));
dpif_name(&dpif->dpif), ovs_strerror(error));
nl_sock_destroy(sock);

if (error == ENODEV || error == ENOENT) {
Expand Down Expand Up @@ -1321,7 +1322,7 @@ dpif_linux_recv(struct dpif *dpif_, struct dpif_upcall *upcall,
} while (retval < 0 && errno == EINTR);
if (retval < 0) {
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 1);
VLOG_WARN_RL(&rl, "epoll_wait failed (%s)", strerror(errno));
VLOG_WARN_RL(&rl, "epoll_wait failed (%s)", ovs_strerror(errno));
} else if (retval > 0) {
dpif->n_events = retval;
}
Expand Down Expand Up @@ -1492,7 +1493,7 @@ dpif_linux_is_internal_device(const char *name)
ofpbuf_delete(buf);
} else if (error != ENODEV && error != ENOENT) {
VLOG_WARN_RL(&error_rl, "%s: vport query failed (%s)",
name, strerror(error));
name, ovs_strerror(error));
}

return reply.type == OVS_VPORT_TYPE_INTERNAL;
Expand Down
4 changes: 2 additions & 2 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ do_add_port(struct dp_netdev *dp, const char *devname, const char *type,
if (error
&& !(error == EOPNOTSUPP && dpif_netdev_class_is_dummy(dp->class))) {
VLOG_ERR("%s: cannot receive packets on this network device (%s)",
devname, strerror(errno));
devname, ovs_strerror(errno));
netdev_close(netdev);
return error;
}
Expand Down Expand Up @@ -1094,7 +1094,7 @@ dpif_netdev_run(struct dpif *dpif)
static struct vlog_rate_limit rl = VLOG_RATE_LIMIT_INIT(1, 5);

VLOG_ERR_RL(&rl, "error receiving data from %s: %s",
netdev_get_name(port->netdev), strerror(error));
netdev_get_name(port->netdev), ovs_strerror(error));
}
}
ofpbuf_uninit(&packet);
Expand Down
23 changes: 12 additions & 11 deletions lib/dpif.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -216,7 +216,7 @@ dp_enumerate_names(const char *type, struct sset *names)

if (error) {
VLOG_WARN("failed to enumerate %s datapaths: %s", dpif_class->type,
strerror(error));
ovs_strerror(error));
}

return error;
Expand Down Expand Up @@ -311,10 +311,11 @@ dpif_create_and_open(const char *name, const char *type, struct dpif **dpifp)
error = dpif_open(name, type, dpifp);
if (error) {
VLOG_WARN("datapath %s already exists but cannot be opened: %s",
name, strerror(error));
name, ovs_strerror(error));
}
} else if (error) {
VLOG_WARN("failed to create datapath %s: %s", name, strerror(error));
VLOG_WARN("failed to create datapath %s: %s",
name, ovs_strerror(error));
}
return error;
}
Expand Down Expand Up @@ -461,7 +462,7 @@ dpif_port_add(struct dpif *dpif, struct netdev *netdev, odp_port_t *port_nop)
dpif_name(dpif), netdev_name, port_no);
} else {
VLOG_WARN_RL(&error_rl, "%s: failed to add %s as port: %s",
dpif_name(dpif), netdev_name, strerror(error));
dpif_name(dpif), netdev_name, ovs_strerror(error));
port_no = ODPP_NONE;
}
if (port_nop) {
Expand Down Expand Up @@ -518,7 +519,7 @@ dpif_port_exists(const struct dpif *dpif, const char *devname)
int error = dpif->dpif_class->port_query_by_name(dpif, devname, NULL);
if (error != 0 && error != ENOENT && error != ENODEV) {
VLOG_WARN_RL(&error_rl, "%s: failed to query port %s: %s",
dpif_name(dpif), devname, strerror(error));
dpif_name(dpif), devname, ovs_strerror(error));
}

return !error;
Expand All @@ -541,7 +542,7 @@ dpif_port_query_by_number(const struct dpif *dpif, odp_port_t port_no,
} else {
memset(port, 0, sizeof *port);
VLOG_WARN_RL(&error_rl, "%s: failed to query port %"PRIu32": %s",
dpif_name(dpif), port_no, strerror(error));
dpif_name(dpif), port_no, ovs_strerror(error));
}
return error;
}
Expand Down Expand Up @@ -570,7 +571,7 @@ dpif_port_query_by_name(const struct dpif *dpif, const char *devname,
VLOG_RL(&error_rl,
error == ENOENT || error == ENODEV ? VLL_DBG : VLL_WARN,
"%s: failed to query port %s: %s",
dpif_name(dpif), devname, strerror(error));
dpif_name(dpif), devname, ovs_strerror(error));
}
return error;
}
Expand Down Expand Up @@ -1256,7 +1257,7 @@ log_operation(const struct dpif *dpif, const char *operation, int error)
dpif_name(dpif), operation, ofperr_get_name(error));
} else {
VLOG_WARN_RL(&error_rl, "%s: %s failed (%s)",
dpif_name(dpif), operation, strerror(error));
dpif_name(dpif), operation, ovs_strerror(error));
}
}

Expand Down Expand Up @@ -1292,7 +1293,7 @@ log_flow_message(const struct dpif *dpif, int error, const char *operation,
}
ds_put_format(&ds, "%s ", operation);
if (error) {
ds_put_format(&ds, "(%s) ", strerror(error));
ds_put_format(&ds, "(%s) ", ovs_strerror(error));
}
odp_flow_format(key, key_len, mask, mask_len, &ds);
if (stats) {
Expand Down Expand Up @@ -1355,7 +1356,7 @@ log_execute_message(struct dpif *dpif, const struct dpif_execute *execute,
ds_put_format(&ds, "%s: execute ", dpif_name(dpif));
format_odp_actions(&ds, execute->actions, execute->actions_len);
if (error) {
ds_put_format(&ds, " failed (%s)", strerror(error));
ds_put_format(&ds, " failed (%s)", ovs_strerror(error));
}
ds_put_format(&ds, " on packet %s", packet);
vlog(THIS_MODULE, error ? VLL_WARN : VLL_DBG, "%s", ds_cstr(&ds));
Expand Down
4 changes: 2 additions & 2 deletions lib/entropy.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2009, 2010, 2011 Nicira, Inc.
/* Copyright (c) 2008, 2009, 2010, 2011, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,7 +39,7 @@ get_entropy(void *buffer, size_t n)

fd = open(urandom, O_RDONLY);
if (fd < 0) {
VLOG_ERR("%s: open failed (%s)", urandom, strerror(errno));
VLOG_ERR("%s: open failed (%s)", urandom, ovs_strerror(errno));
return errno ? errno : EINVAL;
}

Expand Down
6 changes: 3 additions & 3 deletions lib/fatal-signal.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira, Inc.
* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -84,7 +84,7 @@ fatal_signal_init(void)
xsigaction(sig_nr, NULL, &old_sa);
if (old_sa.sa_handler == SIG_DFL
&& signal(sig_nr, fatal_signal_handler) == SIG_ERR) {
VLOG_FATAL("signal failed (%s)", strerror(errno));
VLOG_FATAL("signal failed (%s)", ovs_strerror(errno));
}
}
atexit(atexit_handler);
Expand Down Expand Up @@ -238,7 +238,7 @@ fatal_signal_unlink_file_now(const char *file)
{
int error = unlink(file) ? errno : 0;
if (error) {
VLOG_WARN("could not unlink \"%s\" (%s)", file, strerror(error));
VLOG_WARN("could not unlink \"%s\" (%s)", file, ovs_strerror(error));
}

fatal_signal_remove_file_to_unlink(file);
Expand Down
5 changes: 3 additions & 2 deletions lib/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,8 @@ json_from_file(const char *file_name)
stream = fopen(file_name, "r");
if (!stream) {
return json_string_create_nocopy(
xasprintf("error opening \"%s\": %s", file_name, strerror(errno)));
xasprintf("error opening \"%s\": %s", file_name,
ovs_strerror(errno)));
}
json = json_from_stream(stream);
fclose(stream);
Expand Down Expand Up @@ -1063,7 +1064,7 @@ json_from_stream(FILE *stream)
if (ferror(stream)) {
json_destroy(json);
json = json_string_create_nocopy(
xasprintf("error reading JSON stream: %s", strerror(errno)));
xasprintf("error reading JSON stream: %s", ovs_strerror(errno)));
}

return json;
Expand Down
7 changes: 4 additions & 3 deletions lib/jsonrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jsonrpc_run(struct jsonrpc *rpc)
} else {
if (retval != -EAGAIN) {
VLOG_WARN_RL(&rl, "%s: send error: %s",
rpc->name, strerror(-retval));
rpc->name, ovs_strerror(-retval));
jsonrpc_error(rpc, -retval);
}
break;
Expand Down Expand Up @@ -307,7 +307,7 @@ jsonrpc_recv(struct jsonrpc *rpc, struct jsonrpc_msg **msgp)
return EAGAIN;
} else {
VLOG_WARN_RL(&rl, "%s: receive error: %s",
rpc->name, strerror(-retval));
rpc->name, ovs_strerror(-retval));
jsonrpc_error(rpc, -retval);
return rpc->status;
}
Expand Down Expand Up @@ -1116,7 +1116,8 @@ jsonrpc_session_set_dscp(struct jsonrpc_session *s,
error = pstream_set_dscp(s->pstream, dscp);
if (error) {
VLOG_ERR("%s: failed set_dscp %s",
reconnect_get_name(s->reconnect), strerror(error));
reconnect_get_name(s->reconnect),
ovs_strerror(error));
}
/*
* XXX race window between setting dscp to listening socket
Expand Down
4 changes: 2 additions & 2 deletions lib/learning-switch.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ lswitch_handshake(struct lswitch *sw)

if (error) {
VLOG_INFO_RL(&rl, "%s: failed to queue default flows (%s)",
rconn_get_name(sw->rconn), strerror(error));
rconn_get_name(sw->rconn), ovs_strerror(error));
}
} else {
VLOG_INFO_RL(&rl, "%s: failed to set usable protocol",
Expand Down Expand Up @@ -433,7 +433,7 @@ queue_tx(struct lswitch *sw, struct ofpbuf *b)
} else {
VLOG_WARN_RL(&rl, "%016llx: %s: send: %s",
sw->datapath_id, rconn_get_name(sw->rconn),
strerror(retval));
ovs_strerror(retval));
}
}
}
Expand Down
Loading

0 comments on commit 10a89ef

Please sign in to comment.