Commit 2b87dbb2 authored by Thomas Haller's avatar Thomas Haller

core: cleanup data types for nm_platform_sysctl_get_int32()

The sysctl values in the kernel (for those values for which
nm_platform_sysctl_get_uint() is currently used) are defined as s32.
Change nm_platform_sysctl_get_uint() to nm_platform_sysctl_get_int32()
and ensure, that a matching integer type is used thoroughly.
Signed-off-by: Thomas Haller's avatarThomas Haller <thaller@redhat.com>
parent 63075d98
......@@ -281,7 +281,7 @@ typedef struct {
guint linklocal6_timeout_id;
char * ip6_disable_ipv6_path;
gint ip6_disable_ipv6_save;
gint32 ip6_disable_ipv6_save;
char * ip6_accept_ra_path;
gint32 ip6_accept_ra_save;
......@@ -441,16 +441,16 @@ save_ip6_properties (NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
priv->ip6_accept_ra_save = nm_platform_sysctl_get_uint (priv->ip6_accept_ra_path);
if (priv->ip6_accept_ra_save > 2)
priv->ip6_accept_ra_save = nm_platform_sysctl_get_int32 (priv->ip6_accept_ra_path, -1);
if (priv->ip6_accept_ra_save > 2 || priv->ip6_accept_ra_save < -1)
priv->ip6_accept_ra_save = -1;
priv->ip6_use_tempaddr_save = nm_platform_sysctl_get_uint (priv->ip6_use_tempaddr_path);
if (priv->ip6_use_tempaddr_save > 2)
priv->ip6_use_tempaddr_save = nm_platform_sysctl_get_int32 (priv->ip6_use_tempaddr_path, -1);
if (priv->ip6_use_tempaddr_save > 2 || priv->ip6_use_tempaddr_save < -1)
priv->ip6_use_tempaddr_save = -1;
priv->ip6_disable_ipv6_save = nm_platform_sysctl_get_uint (priv->ip6_disable_ipv6_path);
if (priv->ip6_disable_ipv6_save > 1)
priv->ip6_disable_ipv6_save = nm_platform_sysctl_get_int32 (priv->ip6_disable_ipv6_path, -1);
if (priv->ip6_disable_ipv6_save > 1 || priv->ip6_disable_ipv6_save < -1)
priv->ip6_disable_ipv6_save = -1;
}
......
......@@ -27,6 +27,7 @@
#include <netlink/route/addr.h>
#include "nm-platform.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
#include "nm-enum-types.h"
......@@ -244,27 +245,33 @@ nm_platform_sysctl_get (const char *path)
}
/**
* nm_platform_sysctl_get_uint:
* nm_platform_sysctl_get_int32:
* @path: Absolute path to sysctl
* @fallback: default value, if the content of path could not be read
* as decimal integer.
*
* Returns: (unsigned integer) contents of the sysctl file, or -1 on error
* Returns: contents of the sysctl file parsed as s32 integer, or
* @fallback on error. Also, on error, @errno will be set to a non-zero
* value.
*/
int
nm_platform_sysctl_get_uint (const char *path)
gint32
nm_platform_sysctl_get_int32 (const char *path, gint32 fallback)
{
char *value, *end;
long tmp;
int ret = -1;
char *value = NULL;
gint32 ret;
value = nm_platform_sysctl_get (path);
if (!value)
return ret;
g_return_val_if_fail (path, fallback);
tmp = strtoul (value, &end, 10);
if (!*end)
ret = tmp;
g_free (value);
if (path)
value = nm_platform_sysctl_get (path);
if (!value) {
errno = EINVAL;
return fallback;
}
ret = nm_utils_ascii_str_to_int64 (value, 10, G_MININT32, G_MAXINT32, fallback);
g_free (value);
return ret;
}
......
......@@ -350,7 +350,7 @@ void nm_platform_query_devices (void);
gboolean nm_platform_sysctl_set (const char *path, const char *value);
char *nm_platform_sysctl_get (const char *path);
int nm_platform_sysctl_get_uint (const char *path);
gint32 nm_platform_sysctl_get_int32 (const char *path, gint32 fallback);
GArray *nm_platform_link_get_all (void);
gboolean nm_platform_dummy_add (const char *name);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment