mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-19 12:40:42 +01:00
merge: branch 'th/strerror_r'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1715
This commit is contained in:
commit
4fad098e8e
7 changed files with 54 additions and 29 deletions
|
|
@ -810,7 +810,7 @@ sett_conn_changed(NMSettingsConnection *sett_conn,
|
|||
nm_log_dbg(LOGD_WIFI,
|
||||
"iwd: profile at %s not removed: %s (%i)",
|
||||
orig_full_path,
|
||||
strerror(errno),
|
||||
nm_strerror_native(errno),
|
||||
errno);
|
||||
|
||||
removed = TRUE;
|
||||
|
|
@ -1431,7 +1431,7 @@ try_delete_file:
|
|||
if (g_remove(full_path) == 0)
|
||||
_LOGD("IWD profile at %s removed", full_path);
|
||||
else if (errno != ENOENT)
|
||||
_LOGD("IWD profile at %s not removed: %s (%i)", full_path, strerror(errno), errno);
|
||||
_LOGD("IWD profile at %s not removed: %s (%i)", full_path, nm_strerror_native(errno), errno);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
|||
|
|
@ -174,7 +174,7 @@ stop(NMDhcpClient *client, gboolean release)
|
|||
*/
|
||||
if (kill(pid, sig) == -1) {
|
||||
errsv = errno;
|
||||
_LOGE("failed to kill dhcpcd %d:%s", errsv, strerror(errsv));
|
||||
_LOGE("failed to kill dhcpcd %d:%s", errsv, nm_strerror_native(errsv));
|
||||
}
|
||||
|
||||
/* When this function exits NM expects the PID to be -1.
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include "libnm-glib-aux/nm-default-glib-i18n-lib.h"
|
||||
|
||||
#include "nm-errno.h"
|
||||
#include "libnm-std-aux/nm-std-utils.h"
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
|
|
@ -100,26 +101,10 @@ nm_strerror(int nmerr)
|
|||
const char *
|
||||
nm_strerror_native_r(int errsv, char *buf, gsize buf_size)
|
||||
{
|
||||
char *buf2;
|
||||
NM_AUTO_PROTECT_ERRNO(errsv2);
|
||||
const char *buf2;
|
||||
|
||||
nm_assert(buf);
|
||||
nm_assert(buf_size > 0);
|
||||
|
||||
#if (!defined(__GLIBC__) && !defined(__UCLIBC__)) || ((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
|
||||
/* XSI-compliant */
|
||||
{
|
||||
int errno_saved = errno;
|
||||
|
||||
if (strerror_r(errsv, buf, buf_size) != 0) {
|
||||
g_snprintf(buf, buf_size, "Unspecified errno %d", errsv);
|
||||
errno = errno_saved;
|
||||
}
|
||||
buf2 = buf;
|
||||
}
|
||||
#else
|
||||
/* GNU-specific */
|
||||
buf2 = strerror_r(errsv, buf, buf_size);
|
||||
#endif
|
||||
buf2 = _nm_strerror_r(errsv, buf, buf_size);
|
||||
|
||||
/* like g_strerror(), ensure that the error message is UTF-8. */
|
||||
if (!g_get_charset(NULL) && !g_utf8_validate(buf2, -1, NULL)) {
|
||||
|
|
|
|||
|
|
@ -92,3 +92,43 @@ out_huge:
|
|||
}
|
||||
return SIZE_MAX;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/**
|
||||
* _nm_strerror_r:
|
||||
* @errsv: the errno passed to strerror_r()
|
||||
* @buf: the string buffer, must be non-null
|
||||
* @buf_size: the size of the buffer, must be positive.
|
||||
*
|
||||
* A wrapper around strerror_r(). Does little else, aside clearing up the
|
||||
* confusion about the different versions of the function.
|
||||
*
|
||||
* errno is preserved.
|
||||
*
|
||||
* Returns: the error string. This is either a static strong or @buf. It
|
||||
* is not guaranteed to be @buf.
|
||||
*/
|
||||
const char *
|
||||
_nm_strerror_r(int errsv, char *buf, size_t buf_size)
|
||||
{
|
||||
NM_AUTO_PROTECT_ERRNO(errsv2);
|
||||
char *buf2;
|
||||
|
||||
nm_assert(buf);
|
||||
nm_assert(buf_size > 0);
|
||||
|
||||
#if (!defined(__GLIBC__) && !defined(__UCLIBC__)) || ((_POSIX_C_SOURCE >= 200112L) && !_GNU_SOURCE)
|
||||
/* XSI-compliant */
|
||||
if (strerror_r(errsv, buf, buf_size) != 0) {
|
||||
snprintf(buf, buf_size, "Unspecified errno %d", errsv);
|
||||
}
|
||||
buf2 = buf;
|
||||
#else
|
||||
/* GNU-specific */
|
||||
buf2 = strerror_r(errsv, buf, buf_size);
|
||||
#endif
|
||||
|
||||
nm_assert(buf2);
|
||||
return buf2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,6 @@
|
|||
|
||||
size_t nm_utils_get_next_realloc_size(bool true_realloc, size_t requested);
|
||||
|
||||
const char *_nm_strerror_r(int errsv, char *buf, size_t buf_size);
|
||||
|
||||
#endif /* __NM_STD_UTILS_H__ */
|
||||
|
|
|
|||
|
|
@ -12,11 +12,6 @@
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* strerror() is not thread-safe. Patch systemd-sources via a define. */
|
||||
#define strerror(errsv) nm_strerror_native(errsv)
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* systemd detects whether compiler supports "-Wstringop-truncation" to disable
|
||||
* the warning at particular places. Since we anyway build with -Wno-pragma,
|
||||
* we don't do that and just let systemd call
|
||||
|
|
|
|||
|
|
@ -94,12 +94,15 @@ cmd_resolve_address(void)
|
|||
NI_NAMEREQD);
|
||||
if (ret != 0) {
|
||||
if (ret == EAI_SYSTEM) {
|
||||
int errsv = errno;
|
||||
char buf[1024];
|
||||
|
||||
fprintf(stderr,
|
||||
"getnameinfo() failed: %d (%s), system error: %d (%s)\n",
|
||||
ret,
|
||||
gai_strerror(ret),
|
||||
errno,
|
||||
strerror(errno));
|
||||
errsv,
|
||||
_nm_strerror_r(errsv, buf, sizeof(buf)));
|
||||
} else {
|
||||
fprintf(stderr, "getnameinfo() failed: %d (%s)\n", ret, gai_strerror(ret));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue