core: remove redundant sysctl utilities

NMDevice was still using the old sysctl functions from
NetworkManagerUtils rather than the new NMPlatform ones. Fix it, and
remove the old functions.
This commit is contained in:
Dan Winship
2013-11-08 08:49:06 -05:00
parent 1981323b19
commit 7bc7da83ec
6 changed files with 43 additions and 142 deletions

View File

@@ -408,116 +408,6 @@ value_hash_add_object_property (GHashTable *hash,
value_hash_add (hash, key, value);
}
/**
* nm_utils_do_sysctl:
* @path: path to write @value to
* @value: value to write to @path
*
* Writes @value to the file at @path, trying 3 times on failure.
*
* Returns: %TRUE on success. On failure, returns %FALSE and sets errno.
*/
gboolean
nm_utils_do_sysctl (const char *path, const char *value)
{
int fd, len, nwrote, tries, saved_errno = 0;
char *actual;
g_return_val_if_fail (path != NULL, FALSE);
g_return_val_if_fail (value != NULL, FALSE);
fd = open (path, O_WRONLY | O_TRUNC);
if (fd == -1) {
saved_errno = errno;
nm_log_warn (LOGD_CORE, "sysctl: failed to open '%s': (%d) %s",
path, saved_errno, strerror (saved_errno));
errno = saved_errno;
return FALSE;
}
nm_log_dbg (LOGD_CORE, "sysctl: setting '%s' to '%s'", path, value);
/* Most sysfs and sysctl options don't care about a trailing CR, while some
* (like infiniband) do. So always add the CR. Also, neither sysfs nor
* sysctl support partial writes so the CR must be added to the string we're
* about to write.
*/
actual = g_strdup_printf ("%s\n", value);
/* Try to write the entire value three times if a partial write occurs */
len = strlen (actual);
for (tries = 0, nwrote = 0; tries < 3 && nwrote != len; tries++) {
errno = 0;
nwrote = write (fd, actual, len);
if (nwrote == -1) {
if (errno == EINTR)
continue;
saved_errno = errno;
break;
}
}
g_free (actual);
close (fd);
if (nwrote != len && saved_errno != EEXIST) {
nm_log_warn (LOGD_CORE, "sysctl: failed to set '%s' to '%s': (%d) %s",
path, value, saved_errno, strerror (saved_errno));
}
errno = saved_errno;
return (nwrote == len);
}
gboolean
nm_utils_get_proc_sys_net_value (const char *path,
const char *iface,
gint32 *out_value)
{
GError *error = NULL;
char *contents = NULL;
gboolean success = FALSE;
long int tmp;
if (!g_file_get_contents (path, &contents, NULL, &error)) {
nm_log_dbg (LOGD_DEVICE, "(%s): error reading %s: (%d) %s",
iface, path,
error ? error->code : -1,
error && error->message ? error->message : "(unknown)");
g_clear_error (&error);
} else {
errno = 0;
tmp = strtol (contents, NULL, 10);
if (errno == 0) {
*out_value = (gint32) tmp;
success = TRUE;
}
g_free (contents);
}
return success;
}
gboolean
nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
const char *iface,
gint32 *out_value,
gint32 valid_min,
gint32 valid_max)
{
gboolean result;
gint32 val;
result = nm_utils_get_proc_sys_net_value (path, iface, &val);
if (result) {
if (val >= valid_min && val <= valid_max)
*out_value = val;
else
result = FALSE;
}
return result;
}
static char *
get_new_connection_name (const GSList *existing,