diff --git a/src/dns-manager/nm-dns-dnsmasq.c b/src/dns-manager/nm-dns-dnsmasq.c index 4cee16089..5c72d7bad 100644 --- a/src/dns-manager/nm-dns-dnsmasq.c +++ b/src/dns-manager/nm-dns-dnsmasq.c @@ -482,24 +482,6 @@ update (NMDnsPlugin *plugin, /****************************************************************/ -static const char * -dm_exit_code_to_msg (int status) -{ - if (status == 1) - return "Configuration problem"; - else if (status == 2) - return "Network access problem (address in use; permissions; etc)"; - else if (status == 3) - return "Filesystem problem (missing file/directory; permissions; etc)"; - else if (status == 4) - return "Memory allocation failure"; - else if (status == 5) - return "Other problem"; - else if (status >= 11) - return "Lease-script 'init' process failure"; - return "Unknown error"; -} - static void child_quit (NMDnsPlugin *plugin, gint status) { @@ -510,9 +492,8 @@ child_quit (NMDnsPlugin *plugin, gint status) if (WIFEXITED (status)) { err = WEXITSTATUS (status); if (err) { - _LOGW ("dnsmasq exited with error: %s (%d)", - dm_exit_code_to_msg (err), - err); + _LOGW ("dnsmasq exited with error: %s", + nm_utils_dnsmasq_status_to_string (err, NULL, 0)); } else failed = FALSE; } else if (WIFSTOPPED (status)) diff --git a/src/dnsmasq-manager/nm-dnsmasq-manager.c b/src/dnsmasq-manager/nm-dnsmasq-manager.c index d905446b4..b25001c40 100644 --- a/src/dnsmasq-manager/nm-dnsmasq-manager.c +++ b/src/dnsmasq-manager/nm-dnsmasq-manager.c @@ -110,36 +110,6 @@ nm_cmd_line_add_string (NMCmdLine *cmd, const char *str) /*******************************************/ -static void -dm_exit_code (guint dm_exit_status) -{ - char *msg = "Unknown error"; - - switch (dm_exit_status) { - case 1: - msg = "Configuration problem"; - break; - case 2: - msg = "Network access problem (address in use; permissions; etc)"; - break; - case 3: - msg = "Filesystem problem (missing file/directory; permissions; etc)"; - break; - case 4: - msg = "Memory allocation failure"; - break; - case 5: - msg = "Other problem"; - break; - default: - if (dm_exit_status >= 11) - msg = "Lease-script 'init' process failure"; - break; - } - - _LOGW ("dnsmasq exited with error: %s (%d)", msg, dm_exit_status); -} - static void dm_watch_cb (GPid pid, gint status, gpointer user_data) { @@ -149,8 +119,10 @@ dm_watch_cb (GPid pid, gint status, gpointer user_data) if (WIFEXITED (status)) { err = WEXITSTATUS (status); - if (err != 0) - dm_exit_code (err); + if (err != 0) { + _LOGW ("dnsmasq exited with error: %s", + nm_utils_dnsmasq_status_to_string (err, NULL, 0)); + } } else if (WIFSTOPPED (status)) { _LOGW ("dnsmasq stopped unexpectedly with signal %d", WSTOPSIG (status)); } else if (WIFSIGNALED (status)) { diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index cc15c7830..f9ae5f9a9 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -3168,3 +3168,40 @@ nm_utils_lifetime_get (guint32 timestamp, return TRUE; } +const char * +nm_utils_dnsmasq_status_to_string (int status, char *dest, guint size) +{ + static char buffer[128]; + char *msg, *ret; + gs_free char *msg_free = NULL; + int len; + + if (status == 0) + msg = "Success"; + else if (status == 1) + msg = "Configuration problem"; + else if (status == 2) + msg = "Network access problem (address in use, permissions)"; + else if (status == 3) + msg = "Filesystem problem (missing file/directory, permissions)"; + else if (status == 4) + msg = "Memory allocation failure"; + else if (status == 5) + msg = "Other problem"; + else if (status >= 11) + msg = msg_free = g_strdup_printf ("Lease script failed with error %d", status - 10); + else + msg = "Unknown problem"; + + if (dest) { + ret = dest; + len = size; + } else { + ret = buffer; + len = sizeof (buffer); + } + + g_snprintf (ret, len, "%s (%d)", msg, status); + + return ret; +} diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index a7172a5b3..7a0f909bc 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -398,4 +398,6 @@ gboolean nm_utils_lifetime_get (guint32 timestamp, gboolean nm_utils_ip4_address_is_link_local (in_addr_t addr); +const char *nm_utils_dnsmasq_status_to_string (int status, char *dest, guint size); + #endif /* __NM_CORE_UTILS_H__ */