the msg() function will print the errno for us when
provided with the M_ERRNO flag.
Therefore, don't bother printing errno explicitly and always
pass M_ERRNO to msg().
Signed-off-by: Antonio Quartulli <antonio@openvpn.net>
Acked-by: Arne Schwabe <arne@rfc2549.org>
Message-Id: <20170713080527.13299-1-a@unstable.cc>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15056.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
... | ... |
@@ -1878,17 +1878,15 @@ man_connect(struct management *man) |
1878 | 1878 |
#if UNIX_SOCK_SUPPORT |
1879 | 1879 |
if (man->settings.flags & MF_UNIX_SOCK) |
1880 | 1880 |
{ |
1881 |
- msg(D_LINK_ERRORS, |
|
1882 |
- "MANAGEMENT: connect to unix socket %s failed: %s", |
|
1883 |
- sockaddr_unix_name(&man->settings.local_unix, "NULL"), |
|
1884 |
- strerror_ts(status, &gc)); |
|
1881 |
+ msg(D_LINK_ERRORS | M_ERRNO, |
|
1882 |
+ "MANAGEMENT: connect to unix socket %s failed", |
|
1883 |
+ sockaddr_unix_name(&man->settings.local_unix, "NULL")); |
|
1885 | 1884 |
} |
1886 | 1885 |
else |
1887 | 1886 |
#endif |
1888 |
- msg(D_LINK_ERRORS, |
|
1889 |
- "MANAGEMENT: connect to %s failed: %s", |
|
1890 |
- print_sockaddr(man->settings.local->ai_addr, &gc), |
|
1891 |
- strerror_ts(status, &gc)); |
|
1887 |
+ msg(D_LINK_ERRORS | M_ERRNO, |
|
1888 |
+ "MANAGEMENT: connect to %s failed", |
|
1889 |
+ print_sockaddr(man->settings.local->ai_addr, &gc)); |
|
1892 | 1890 |
throw_signal_soft(SIGTERM, "management-connect-failed"); |
1893 | 1891 |
goto done; |
1894 | 1892 |
} |
... | ... |
@@ -928,10 +928,8 @@ create_temp_file(const char *directory, const char *prefix, struct gc_arena *gc) |
928 | 928 |
else if (fd == -1 && errno != EEXIST) |
929 | 929 |
{ |
930 | 930 |
/* Something else went wrong, no need to retry. */ |
931 |
- struct gc_arena gcerr = gc_new(); |
|
932 |
- msg(M_FATAL, "Could not create temporary file '%s': %s", |
|
933 |
- retfname, strerror_ts(errno, &gcerr)); |
|
934 |
- gc_free(&gcerr); |
|
931 |
+ msg(M_FATAL | M_ERRNO, "Could not create temporary file '%s'", |
|
932 |
+ retfname); |
|
935 | 933 |
return NULL; |
936 | 934 |
} |
937 | 935 |
} |
... | ... |
@@ -797,7 +797,7 @@ tunnel_server_tcp(struct context *top) |
797 | 797 |
multi.top.c2.inotify_fd = inotify_init(); |
798 | 798 |
if (multi.top.c2.inotify_fd < 0) |
799 | 799 |
{ |
800 |
- msg(D_MULTI_ERRORS, "MULTI: inotify_init error: %s", strerror(errno)); |
|
800 |
+ msg(D_MULTI_ERRORS | M_ERRNO, "MULTI: inotify_init error"); |
|
801 | 801 |
} |
802 | 802 |
#endif |
803 | 803 |
|
... | ... |
@@ -325,7 +325,7 @@ tunnel_server_udp_single_threaded(struct context *top) |
325 | 325 |
multi.top.c2.inotify_fd = inotify_init(); |
326 | 326 |
if (multi.top.c2.inotify_fd < 0) |
327 | 327 |
{ |
328 |
- msg(D_MULTI_ERRORS, "MULTI: inotify_init error: %s", strerror(errno)); |
|
328 |
+ msg(D_MULTI_ERRORS | M_ERRNO, "MULTI: inotify_init error"); |
|
329 | 329 |
} |
330 | 330 |
#endif |
331 | 331 |
|
... | ... |
@@ -2355,7 +2355,7 @@ multi_process_post(struct multi_context *m, struct multi_instance *mi, const uns |
2355 | 2355 |
} |
2356 | 2356 |
else |
2357 | 2357 |
{ |
2358 |
- msg(M_NONFATAL, "MULTI: inotify_add_watch error: %s", strerror(errno)); |
|
2358 |
+ msg(M_NONFATAL | M_ERRNO, "MULTI: inotify_add_watch error"); |
|
2359 | 2359 |
} |
2360 | 2360 |
} |
2361 | 2361 |
#endif |
... | ... |
@@ -3137,8 +3137,7 @@ check_file_access(const int type, const char *file, const int mode, const char * |
3137 | 3137 |
/* Scream if an error is found */ |
3138 | 3138 |
if (errcode > 0) |
3139 | 3139 |
{ |
3140 |
- msg(M_NOPREFIX|M_OPTERR, "%s fails with '%s': %s", |
|
3141 |
- opt, file, strerror(errno)); |
|
3140 |
+ msg(M_NOPREFIX | M_OPTERR | M_ERRNO, "%s fails with '%s'", opt, file); |
|
3142 | 3141 |
} |
3143 | 3142 |
|
3144 | 3143 |
/* Return true if an error occured */ |
... | ... |
@@ -1297,11 +1297,9 @@ socket_bind(socket_descriptor_t sd, |
1297 | 1297 |
} |
1298 | 1298 |
if (bind(sd, cur->ai_addr, cur->ai_addrlen)) |
1299 | 1299 |
{ |
1300 |
- const int errnum = openvpn_errno(); |
|
1301 |
- msg(M_FATAL, "%s: Socket bind failed on local address %s: %s", |
|
1300 |
+ msg(M_FATAL | M_ERRNO, "%s: Socket bind failed on local address %s", |
|
1302 | 1301 |
prefix, |
1303 |
- print_sockaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc), |
|
1304 |
- strerror_ts(errnum, &gc)); |
|
1302 |
+ print_sockaddr_ex(local->ai_addr, ":", PS_SHOW_PORT, &gc)); |
|
1305 | 1303 |
} |
1306 | 1304 |
gc_free(&gc); |
1307 | 1305 |
} |
... | ... |
@@ -3888,12 +3886,11 @@ socket_bind_unix(socket_descriptor_t sd, |
3888 | 3888 |
|
3889 | 3889 |
if (bind(sd, (struct sockaddr *) local, sizeof(struct sockaddr_un))) |
3890 | 3890 |
{ |
3891 |
- const int errnum = openvpn_errno(); |
|
3892 |
- msg(M_FATAL, "%s: Socket bind[%d] failed on unix domain socket %s: %s", |
|
3891 |
+ msg(M_FATAL | M_ERRNO, |
|
3892 |
+ "%s: Socket bind[%d] failed on unix domain socket %s", |
|
3893 | 3893 |
prefix, |
3894 | 3894 |
(int)sd, |
3895 |
- sockaddr_unix_name(local, "NULL"), |
|
3896 |
- strerror_ts(errnum, &gc)); |
|
3895 |
+ sockaddr_unix_name(local, "NULL")); |
|
3897 | 3896 |
} |
3898 | 3897 |
|
3899 | 3898 |
#ifdef HAVE_UMASK |
... | ... |
@@ -178,7 +178,7 @@ status_flush(struct status_output *so) |
178 | 178 |
const off_t off = lseek(so->fd, (off_t)0, SEEK_CUR); |
179 | 179 |
if (ftruncate(so->fd, off) != 0) |
180 | 180 |
{ |
181 |
- msg(M_WARN, "Failed to truncate status file: %s", strerror(errno)); |
|
181 |
+ msg(M_WARN | M_ERRNO, "Failed to truncate status file"); |
|
182 | 182 |
} |
183 | 183 |
} |
184 | 184 |
#elif defined(HAVE_CHSIZE) |
... | ... |
@@ -3022,16 +3022,14 @@ utun_open_helper(struct ctl_info ctlInfo, int utunnum) |
3022 | 3022 |
|
3023 | 3023 |
if (fd < 0) |
3024 | 3024 |
{ |
3025 |
- msg(M_INFO, "Opening utun (%s): %s", "socket(SYSPROTO_CONTROL)", |
|
3026 |
- strerror(errno)); |
|
3025 |
+ msg(M_INFO | M_ERRNO, "Opening utun (socket(SYSPROTO_CONTROL))"); |
|
3027 | 3026 |
return -2; |
3028 | 3027 |
} |
3029 | 3028 |
|
3030 | 3029 |
if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) |
3031 | 3030 |
{ |
3032 | 3031 |
close(fd); |
3033 |
- msg(M_INFO, "Opening utun (%s): %s", "ioctl(CTLIOCGINFO)", |
|
3034 |
- strerror(errno)); |
|
3032 |
+ msg(M_INFO | M_ERRNO, "Opening utun (ioctl(CTLIOCGINFO))"); |
|
3035 | 3033 |
return -2; |
3036 | 3034 |
} |
3037 | 3035 |
|
... | ... |
@@ -3049,8 +3047,7 @@ utun_open_helper(struct ctl_info ctlInfo, int utunnum) |
3049 | 3049 |
|
3050 | 3050 |
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) < 0) |
3051 | 3051 |
{ |
3052 |
- msg(M_INFO, "Opening utun (%s): %s", "connect(AF_SYS_CONTROL)", |
|
3053 |
- strerror(errno)); |
|
3052 |
+ msg(M_INFO | M_ERRNO, "Opening utun (connect(AF_SYS_CONTROL))"); |
|
3054 | 3053 |
close(fd); |
3055 | 3054 |
return -1; |
3056 | 3055 |
} |