platform: add parameter to nm_platform_sysctl_get() to suppress logging error
In some cases, an error when reading the sysctl value can be expected. In this case, we want to suppress the error message Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
@@ -72,7 +72,7 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
sysctl_get (NMPlatform *platform, const char *path)
|
sysctl_get (NMPlatform *platform, const char *path, gboolean silent_on_error)
|
||||||
{
|
{
|
||||||
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
|
||||||
|
|
||||||
@@ -566,7 +566,7 @@ master_get_option (NMPlatform *platform, int master, const char *option)
|
|||||||
{
|
{
|
||||||
auto_g_free char *path = g_strdup_printf ("master:%d:%s", master, option);
|
auto_g_free char *path = g_strdup_printf ("master:%d:%s", master, option);
|
||||||
|
|
||||||
return sysctl_get (platform, path);
|
return sysctl_get (platform, path, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
@@ -582,7 +582,7 @@ slave_get_option (NMPlatform *platform, int slave, const char *option)
|
|||||||
{
|
{
|
||||||
auto_g_free char *path = g_strdup_printf ("slave:%d:%s", slave, option);
|
auto_g_free char *path = g_strdup_printf ("slave:%d:%s", slave, option);
|
||||||
|
|
||||||
return sysctl_get (platform, path);
|
return sysctl_get (platform, path, FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@@ -1352,13 +1352,14 @@ sysctl_set (NMPlatform *platform, const char *path, const char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
sysctl_get (NMPlatform *platform, const char *path)
|
sysctl_get (NMPlatform *platform, const char *path, gboolean silent_on_error)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *contents;
|
char *contents;
|
||||||
|
|
||||||
if (!g_file_get_contents (path, &contents, NULL, &error)) {
|
if (!g_file_get_contents (path, &contents, NULL, &error)) {
|
||||||
error ("error reading %s: %s", path, error->message);
|
if (!silent_on_error)
|
||||||
|
error ("error reading %s: %s", path, error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1767,7 +1768,7 @@ link_get_physical_port_id (NMPlatform *platform, int ifindex)
|
|||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/phys_port_id", ifname);
|
path = g_strdup_printf ("/sys/class/net/%s/phys_port_id", ifname);
|
||||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||||
id = sysctl_get (platform, path);
|
id = sysctl_get (platform, path, FALSE);
|
||||||
else
|
else
|
||||||
id = NULL;
|
id = NULL;
|
||||||
g_free (path);
|
g_free (path);
|
||||||
@@ -1888,7 +1889,7 @@ link_get_option (int master, const char *category, const char *option)
|
|||||||
{
|
{
|
||||||
auto_g_free char *path = link_option_path (master, category, option);
|
auto_g_free char *path = link_option_path (master, category, option);
|
||||||
|
|
||||||
return path ? nm_platform_sysctl_get (path) : NULL;
|
return path ? nm_platform_sysctl_get (path, FALSE) : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
@@ -2012,7 +2013,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/owner", ifname);
|
path = g_strdup_printf ("/sys/class/net/%s/owner", ifname);
|
||||||
val = nm_platform_sysctl_get (path);
|
val = nm_platform_sysctl_get (path, FALSE);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
if (!val)
|
if (!val)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -2020,7 +2021,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *
|
|||||||
g_free (val);
|
g_free (val);
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/group", ifname);
|
path = g_strdup_printf ("/sys/class/net/%s/group", ifname);
|
||||||
val = nm_platform_sysctl_get (path);
|
val = nm_platform_sysctl_get (path, FALSE);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
if (!val)
|
if (!val)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -2028,7 +2029,7 @@ tun_get_properties (NMPlatform *platform, int ifindex, NMPlatformTunProperties *
|
|||||||
g_free (val);
|
g_free (val);
|
||||||
|
|
||||||
path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname);
|
path = g_strdup_printf ("/sys/class/net/%s/tun_flags", ifname);
|
||||||
val = nm_platform_sysctl_get (path);
|
val = nm_platform_sysctl_get (path, FALSE);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
if (!val)
|
if (!val)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@@ -230,18 +230,20 @@ nm_platform_sysctl_set (const char *path, const char *value)
|
|||||||
/**
|
/**
|
||||||
* nm_platform_sysctl_get:
|
* nm_platform_sysctl_get:
|
||||||
* @path: Absolute path to sysctl
|
* @path: Absolute path to sysctl
|
||||||
|
* @silent_on_error: don't log an error message when the value
|
||||||
|
* could not be read.
|
||||||
*
|
*
|
||||||
* Returns: (transfer full): Contents of the virtual sysctl file.
|
* Returns: (transfer full): Contents of the virtual sysctl file.
|
||||||
*/
|
*/
|
||||||
char *
|
char *
|
||||||
nm_platform_sysctl_get (const char *path)
|
nm_platform_sysctl_get (const char *path, gboolean silent_on_error)
|
||||||
{
|
{
|
||||||
reset_error ();
|
reset_error ();
|
||||||
|
|
||||||
g_return_val_if_fail (path, NULL);
|
g_return_val_if_fail (path, NULL);
|
||||||
g_return_val_if_fail (klass->sysctl_get, NULL);
|
g_return_val_if_fail (klass->sysctl_get, NULL);
|
||||||
|
|
||||||
return klass->sysctl_get (platform, path);
|
return klass->sysctl_get (platform, path, silent_on_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -263,7 +265,7 @@ nm_platform_sysctl_get_int32 (const char *path, gint32 fallback)
|
|||||||
g_return_val_if_fail (path, fallback);
|
g_return_val_if_fail (path, fallback);
|
||||||
|
|
||||||
if (path)
|
if (path)
|
||||||
value = nm_platform_sysctl_get (path);
|
value = nm_platform_sysctl_get (path, FALSE);
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
|
@@ -252,7 +252,7 @@ typedef struct {
|
|||||||
gboolean (*setup) (NMPlatform *);
|
gboolean (*setup) (NMPlatform *);
|
||||||
|
|
||||||
gboolean (*sysctl_set) (NMPlatform *, const char *path, const char *value);
|
gboolean (*sysctl_set) (NMPlatform *, const char *path, const char *value);
|
||||||
char * (*sysctl_get) (NMPlatform *, const char *path);
|
char * (*sysctl_get) (NMPlatform *, const char *path, gboolean silent_on_error);
|
||||||
|
|
||||||
GArray *(*link_get_all) (NMPlatform *);
|
GArray *(*link_get_all) (NMPlatform *);
|
||||||
gboolean (*link_add) (NMPlatform *, const char *name, NMLinkType type);
|
gboolean (*link_add) (NMPlatform *, const char *name, NMLinkType type);
|
||||||
@@ -369,7 +369,7 @@ const char *nm_platform_get_error_msg (void);
|
|||||||
void nm_platform_query_devices (void);
|
void nm_platform_query_devices (void);
|
||||||
|
|
||||||
gboolean nm_platform_sysctl_set (const char *path, const char *value);
|
gboolean nm_platform_sysctl_set (const char *path, const char *value);
|
||||||
char *nm_platform_sysctl_get (const char *path);
|
char *nm_platform_sysctl_get (const char *path, gboolean silent_on_error);
|
||||||
gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback);
|
gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback);
|
||||||
|
|
||||||
GArray *nm_platform_link_get_all (void);
|
GArray *nm_platform_link_get_all (void);
|
||||||
|
@@ -47,7 +47,7 @@ do_sysctl_set (char **argv)
|
|||||||
static gboolean
|
static gboolean
|
||||||
do_sysctl_get (char **argv)
|
do_sysctl_get (char **argv)
|
||||||
{
|
{
|
||||||
auto_g_free char *value = nm_platform_sysctl_get (argv[0]);
|
auto_g_free char *value = nm_platform_sysctl_get (argv[0], FALSE);
|
||||||
|
|
||||||
printf ("%s\n", value);
|
printf ("%s\n", value);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user