core: introduce nm_utils_dnsmasq_status_to_string()
This commit is contained in:
@@ -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))
|
||||
|
@@ -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)) {
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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__ */
|
||||
|
Reference in New Issue
Block a user