backends: clean them up somewhat

Put the two functions they provide into their own header so
places that need them don't have to include nm-system.h.
This commit is contained in:
Dan Williams 2011-11-17 18:51:33 -06:00
parent 9dd270966e
commit 2ea0f3e9c2
18 changed files with 96 additions and 271 deletions

View file

@ -7,8 +7,10 @@ INCLUDES = \
noinst_LTLIBRARIES = libnmbackend.la
libnmbackend_la_SOURCES = NetworkManagerGeneric.c \
NetworkManagerGeneric.h
libnmbackend_la_SOURCES = \
NetworkManagerGeneric.c \
NetworkManagerGeneric.h \
nm-backend.h
libnmbackend_la_LIBADD =

View file

@ -35,35 +35,20 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Check if the daemon was already running - do not start a new instance */
/* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd; check if the daemon was already running - do not
* start a new instance
*/
if (g_file_test("/var/run/daemons/nscd", G_FILE_TEST_EXISTS))
nm_spawn_process ("/etc/rc.d/nscd restart");
}

View file

@ -28,22 +28,11 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
/* ifupdown isn't always installed (bgo #625427) */
if (g_file_test ("/sbin/ifup", G_FILE_TEST_EXISTS))
@ -52,15 +41,9 @@ void nm_system_enable_loopback (void)
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Invalidate the nscd host cache since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -27,35 +27,20 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd. Only restart if already running.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd. Only restart if already running.
*/
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -23,35 +23,15 @@
* (C) Copyright 2006 Alex Smith
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "nm-system.h"
/* Provided by the frugalwareutils package on Frugalware */
#include <libfwnetconfig.h>
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
fwnet_loup ();
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* I'm not running nscd */
}

View file

@ -18,13 +18,15 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2004 Red Hat, Inc.
* (C) Copyright 2004 - 2011 Red Hat, Inc.
*/
#ifndef NETWORK_MANAGER_GENERIC_H
#define NETWORK_MANAGER_GENERIC_H
#ifndef NM_GENERIC_H
#define NM_GENERIC_H
void nm_generic_enable_loopback (void);
void nm_generic_update_dns (void);
#include "nm-backend.h"
#endif
void nm_generic_enable_loopback (void);
void nm_generic_update_dns (void);
#endif /* NM_GENERIC_H */

View file

@ -27,18 +27,12 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gio/gio.h>
#include <glib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
#define BUFFER_SIZE 512
static void openrc_start_lo_if_necessary()
{
/* No need to run net.lo if it is already running */
@ -46,18 +40,11 @@ static void openrc_start_lo_if_necessary()
nm_spawn_process ("/etc/init.d/net.lo start");
}
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
gchar *comm;
/* If anything goes wrong trying to open /proc/1/comm, we will assume
OpenRC. */
/* If anything goes wrong trying to open /proc/1/comm, we will assume OpenRC */
if (!g_file_get_contents ("/proc/1/comm", &comm, NULL, NULL)) {
nm_log_info (LOGD_CORE, "NetworkManager is running with OpenRC...");
openrc_start_lo_if_necessary ();
@ -77,15 +64,11 @@ void nm_system_enable_loopback (void)
g_free (comm);
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd. Only restart if already running.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd. Only restart if already running.
*/
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -28,35 +28,18 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Invalidate the nscd host cache, if it exists, since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -25,34 +25,17 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Invalidate the nscd host cache, if it exists, since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE | G_FILE_TEST_IS_REGULAR)) {
nm_spawn_process ("/etc/init.d/nscd condrestart");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -26,36 +26,21 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");
/* Invalidate the nscd host cache, if it exists, since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");
}
}

View file

@ -24,34 +24,14 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* I'm not running nscd */
}

View file

@ -16,41 +16,24 @@
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* (C) Copyright 2004 Red Hat, Inc.
* (C) Copyright 2004 - 2011 Red Hat, Inc.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* Invalidate the nscd host cache since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_EXISTS | G_FILE_TEST_IS_EXECUTABLE | G_FILE_TEST_IS_REGULAR)) {
nm_spawn_process ("/etc/init.d/nscd condrestart");
nm_spawn_process ("/usr/sbin/nscd -i hosts");

View file

@ -24,34 +24,14 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Make glibc/nscd aware of any changes to the resolv.conf file by
* restarting nscd.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
/* I'm not running nscd */
}

View file

@ -27,36 +27,21 @@
#include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "NetworkManagerGeneric.h"
#include "nm-system.h"
#include "NetworkManagerUtils.h"
#include "nm-logging.h"
/*
* nm_system_enable_loopback
*
* Bring up the loopback interface
*
*/
void nm_system_enable_loopback (void)
void nm_backend_enable_loopback (void)
{
nm_generic_enable_loopback ();
}
/*
* nm_system_update_dns
*
* Invalidate the nscd host cache, if it exists, since
* we changed resolv.conf.
*
*/
void nm_system_update_dns (void)
void nm_backend_update_dns (void)
{
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");
/* Invalidate the nscd host cache, if it exists, since we changed resolv.conf */
if (g_file_test ("/usr/sbin/nscd", G_FILE_TEST_IS_EXECUTABLE)) {
nm_log_info (LOGD_DNS, "Clearing nscd hosts cache.");
nm_spawn_process ("/usr/sbin/nscd -i hosts");
}
}

29
src/backends/nm-backend.h Normal file
View file

@ -0,0 +1,29 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2011 Red Hat, Inc.
*/
#ifndef NM_BACKEND_H
#define NM_BACKEND_H
/* Random disto-specific stuff */
void nm_backend_enable_loopback (void);
void nm_backend_update_dns (void);
#endif /* NM_BACKEND_H */

View file

@ -40,7 +40,7 @@
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-logging.h"
#include "nm-system.h"
#include "backends/nm-backend.h"
#include "NetworkManagerUtils.h"
#include "nm-dns-plugin.h"
@ -752,7 +752,7 @@ update_dns (NMDnsManager *self,
success = update_resolv_conf (domain, searches, nameservers, iface, error);
if (success)
nm_system_update_dns ();
nm_backend_update_dns ();
if (searches)
g_strfreev (searches);

View file

@ -40,7 +40,7 @@
#include "NetworkManagerUtils.h"
#include "nm-manager.h"
#include "nm-policy.h"
#include "nm-system.h"
#include "backends/nm-backend.h"
#include "nm-dns-manager.h"
#include "nm-dbus-manager.h"
#include "nm-supplicant-manager.h"
@ -685,7 +685,7 @@ main (int argc, char *argv[])
nm_manager_start (manager);
/* Bring up the loopback interface. */
nm_system_enable_loopback ();
nm_backend_enable_loopback ();
success = TRUE;

View file

@ -57,9 +57,6 @@ struct rtnl_route *nm_system_add_ip4_vpn_gateway_route (NMDevice *parent_device,
gboolean nm_system_iface_flush_addresses (int ifindex, int family);
void nm_system_enable_loopback (void);
void nm_system_update_dns (void);
gboolean nm_system_apply_ip4_config (int ifindex,
NMIP4Config *config,
int priority,