2005-01-14 Colin Walters <walters@redhat.com>
Patch from ed@catmur.co.uk (Ed Catmur) * named/nm-named-manager.c: Add "context" property. Use it to add child watch source in specific GMainContext. * src/NetworkManager.c (nm_data_new): Initialize named with correct main context. Start named only after forking. git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@377 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
This commit is contained in:

committed by
Colin Walters

parent
0229295c83
commit
f9d46351f6
11
ChangeLog
11
ChangeLog
@@ -1,3 +1,14 @@
|
|||||||
|
2005-01-14 Colin Walters <walters@redhat.com>
|
||||||
|
|
||||||
|
Patch from ed@catmur.co.uk (Ed Catmur)
|
||||||
|
|
||||||
|
* named/nm-named-manager.c: Add "context" property.
|
||||||
|
Use it to add child watch source in specific GMainContext.
|
||||||
|
|
||||||
|
* src/NetworkManager.c (nm_data_new): Initialize
|
||||||
|
named with correct main context. Start named only
|
||||||
|
after forking.
|
||||||
|
|
||||||
2005-01-14 Colin Walters <walters@redhat.com>
|
2005-01-14 Colin Walters <walters@redhat.com>
|
||||||
|
|
||||||
* named/nm-named-manager.c (generate_named_conf): Write config
|
* named/nm-named-manager.c (generate_named_conf): Write config
|
||||||
|
@@ -41,12 +41,26 @@
|
|||||||
#define RESOLV_CONF "/etc/resolv.conf"
|
#define RESOLV_CONF "/etc/resolv.conf"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
PROP_0,
|
||||||
|
PROP_CONTEXT,
|
||||||
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(NMNamedManager, nm_named_manager, G_TYPE_OBJECT)
|
G_DEFINE_TYPE(NMNamedManager, nm_named_manager, G_TYPE_OBJECT)
|
||||||
|
|
||||||
static void nm_named_manager_finalize (GObject *object);
|
static void nm_named_manager_finalize (GObject *object);
|
||||||
static void nm_named_manager_dispose (GObject *object);
|
static void nm_named_manager_dispose (GObject *object);
|
||||||
static GObject *nm_named_manager_constructor (GType type, guint n_construct_properties,
|
static GObject *nm_named_manager_constructor (GType type, guint n_construct_properties,
|
||||||
GObjectConstructParam *construct_properties);
|
GObjectConstructParam *construct_properties);
|
||||||
|
static void nm_named_manager_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec);
|
||||||
|
static void nm_named_manager_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec);
|
||||||
static gboolean rewrite_resolv_conf (NMNamedManager *mgr, GError **error);
|
static gboolean rewrite_resolv_conf (NMNamedManager *mgr, GError **error);
|
||||||
static int safer_kill (const char *path, pid_t pid, int signum);
|
static int safer_kill (const char *path, pid_t pid, int signum);
|
||||||
|
|
||||||
@@ -55,8 +69,9 @@ struct NMNamedManagerPrivate
|
|||||||
char *named_realpath_binary;
|
char *named_realpath_binary;
|
||||||
GPid named_pid;
|
GPid named_pid;
|
||||||
guint spawn_count;
|
guint spawn_count;
|
||||||
guint child_watch_id;
|
GMainContext *main_context;
|
||||||
guint queued_reload_id;
|
GSource *child_watch;
|
||||||
|
GSource *queued_reload;
|
||||||
|
|
||||||
guint id_serial;
|
guint id_serial;
|
||||||
GHashTable *domain_searches; /* guint -> char * */
|
GHashTable *domain_searches; /* guint -> char * */
|
||||||
@@ -77,6 +92,15 @@ nm_named_manager_class_init (NMNamedManagerClass *klass)
|
|||||||
object_class->dispose = nm_named_manager_dispose;
|
object_class->dispose = nm_named_manager_dispose;
|
||||||
object_class->finalize = nm_named_manager_finalize;
|
object_class->finalize = nm_named_manager_finalize;
|
||||||
object_class->constructor = nm_named_manager_constructor;
|
object_class->constructor = nm_named_manager_constructor;
|
||||||
|
object_class->set_property = nm_named_manager_set_property;
|
||||||
|
object_class->get_property = nm_named_manager_get_property;
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_CONTEXT,
|
||||||
|
g_param_spec_pointer ("context",
|
||||||
|
"GMainContext",
|
||||||
|
"Main context",
|
||||||
|
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -93,6 +117,44 @@ nm_named_manager_init (NMNamedManager *mgr)
|
|||||||
(GDestroyNotify) g_hash_table_destroy);
|
(GDestroyNotify) g_hash_table_destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_named_manager_set_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
const GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
NMNamedManager *mgr = NM_NAMED_MANAGER (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_CONTEXT:
|
||||||
|
mgr->priv->main_context = g_value_get_pointer (value);
|
||||||
|
g_main_context_ref (mgr->priv->main_context);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
nm_named_manager_get_property (GObject *object,
|
||||||
|
guint prop_id,
|
||||||
|
GValue *value,
|
||||||
|
GParamSpec *pspec)
|
||||||
|
{
|
||||||
|
NMNamedManager *mgr = NM_NAMED_MANAGER (object);
|
||||||
|
|
||||||
|
switch (prop_id)
|
||||||
|
{
|
||||||
|
case PROP_CONTEXT:
|
||||||
|
g_value_set_pointer (value, mgr->priv->main_context);
|
||||||
|
default:
|
||||||
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
nm_named_manager_dispose (GObject *object)
|
nm_named_manager_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
@@ -108,8 +170,10 @@ nm_named_manager_dispose (GObject *object)
|
|||||||
unlink (mgr->priv->named_pid_file);
|
unlink (mgr->priv->named_pid_file);
|
||||||
if (mgr->priv->named_realpath_binary)
|
if (mgr->priv->named_realpath_binary)
|
||||||
safer_kill (mgr->priv->named_realpath_binary, mgr->priv->named_pid, SIGTERM);
|
safer_kill (mgr->priv->named_realpath_binary, mgr->priv->named_pid, SIGTERM);
|
||||||
if (mgr->priv->child_watch_id)
|
if (mgr->priv->child_watch)
|
||||||
g_source_remove (mgr->priv->child_watch_id);
|
g_source_destroy (mgr->priv->child_watch);
|
||||||
|
if (mgr->priv->main_context)
|
||||||
|
g_main_context_unref (mgr->priv->main_context);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,6 +207,7 @@ nm_named_manager_constructor (GType type, guint n_construct_properties,
|
|||||||
klass = NM_NAMED_MANAGER_CLASS (g_type_class_peek (NM_TYPE_NAMED_MANAGER));
|
klass = NM_NAMED_MANAGER_CLASS (g_type_class_peek (NM_TYPE_NAMED_MANAGER));
|
||||||
|
|
||||||
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
|
||||||
|
|
||||||
mgr = NM_NAMED_MANAGER (parent_class->constructor (type, n_construct_properties,
|
mgr = NM_NAMED_MANAGER (parent_class->constructor (type, n_construct_properties,
|
||||||
construct_properties));
|
construct_properties));
|
||||||
|
|
||||||
@@ -151,9 +216,12 @@ nm_named_manager_constructor (GType type, guint n_construct_properties,
|
|||||||
}
|
}
|
||||||
|
|
||||||
NMNamedManager *
|
NMNamedManager *
|
||||||
nm_named_manager_new (void)
|
nm_named_manager_new (GMainContext *main_context)
|
||||||
{
|
{
|
||||||
return NM_NAMED_MANAGER (g_object_new (NM_TYPE_NAMED_MANAGER, NULL));
|
return NM_NAMED_MANAGER (g_object_new (NM_TYPE_NAMED_MANAGER,
|
||||||
|
"context",
|
||||||
|
main_context,
|
||||||
|
NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
GQuark
|
GQuark
|
||||||
@@ -386,8 +454,10 @@ watch_cb (GPid pid, gint status, gpointer data)
|
|||||||
else
|
else
|
||||||
syslog (LOG_WARNING, "named died from an unknown cause");
|
syslog (LOG_WARNING, "named died from an unknown cause");
|
||||||
|
|
||||||
if (mgr->priv->queued_reload_id > 0)
|
if (mgr->priv->queued_reload) {
|
||||||
g_source_remove (mgr->priv->queued_reload_id);
|
g_source_destroy (mgr->priv->queued_reload);
|
||||||
|
mgr->priv->queued_reload = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* FIXME - do something with error; need to handle failure to
|
/* FIXME - do something with error; need to handle failure to
|
||||||
* respawn */
|
* respawn */
|
||||||
@@ -440,10 +510,14 @@ nm_named_manager_start (NMNamedManager *mgr, GError **error)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
g_ptr_array_free (named_argv, TRUE);
|
g_ptr_array_free (named_argv, TRUE);
|
||||||
|
syslog (LOG_INFO, "named started with pid %d", pid);
|
||||||
mgr->priv->named_pid = pid;
|
mgr->priv->named_pid = pid;
|
||||||
if (mgr->priv->child_watch_id)
|
if (mgr->priv->child_watch)
|
||||||
g_source_remove (mgr->priv->child_watch_id);
|
g_source_destroy (mgr->priv->child_watch);
|
||||||
mgr->priv->child_watch_id = g_child_watch_add (pid, watch_cb, mgr);
|
mgr->priv->child_watch = g_child_watch_source_new (pid);
|
||||||
|
g_source_set_callback (mgr->priv->child_watch, (GSourceFunc) watch_cb, mgr, NULL);
|
||||||
|
g_source_attach (mgr->priv->child_watch, mgr->priv->main_context);
|
||||||
|
g_source_unref (mgr->priv->child_watch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
if (!rewrite_resolv_conf (mgr, error))
|
if (!rewrite_resolv_conf (mgr, error))
|
||||||
@@ -540,7 +614,7 @@ rewrite_resolv_conf (NMNamedManager *mgr, GError **error)
|
|||||||
goto lose;
|
goto lose;
|
||||||
|
|
||||||
searches = compute_domain_searches (mgr);
|
searches = compute_domain_searches (mgr);
|
||||||
if (fprintf (f, "%s"," ; generated by NetworkManager, do not edit!\n") < 0) {
|
if (fprintf (f, "%s","; generated by NetworkManager, do not edit!\n") < 0) {
|
||||||
g_free (searches);
|
g_free (searches);
|
||||||
goto lose;
|
goto lose;
|
||||||
}
|
}
|
||||||
|
@@ -63,7 +63,7 @@ typedef struct
|
|||||||
|
|
||||||
GType nm_named_manager_get_type (void);
|
GType nm_named_manager_get_type (void);
|
||||||
|
|
||||||
NMNamedManager * nm_named_manager_new (void);
|
NMNamedManager * nm_named_manager_new (GMainContext *main_context);
|
||||||
|
|
||||||
gboolean nm_named_manager_start (NMNamedManager *mgr, GError **error);
|
gboolean nm_named_manager_start (NMNamedManager *mgr, GError **error);
|
||||||
|
|
||||||
|
@@ -553,12 +553,7 @@ static NMData *nm_data_new (gboolean enable_test_devices)
|
|||||||
sigaction (SIGINT, &action, NULL);
|
sigaction (SIGINT, &action, NULL);
|
||||||
sigaction (SIGTERM, &action, NULL);
|
sigaction (SIGTERM, &action, NULL);
|
||||||
|
|
||||||
data->named = nm_named_manager_new ();
|
data->named = nm_named_manager_new (data->main_context);
|
||||||
if (!nm_named_manager_start (data->named, &error))
|
|
||||||
{
|
|
||||||
syslog (LOG_CRIT, "Couldn't initialize nameserver: %s", error->message);
|
|
||||||
exit (EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Initialize the device list mutex to protect additions/deletions to it. */
|
/* Initialize the device list mutex to protect additions/deletions to it. */
|
||||||
data->dev_list_mutex = g_mutex_new ();
|
data->dev_list_mutex = g_mutex_new ();
|
||||||
@@ -818,6 +813,12 @@ int main( int argc, char *argv[] )
|
|||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!nm_named_manager_start (nm_data->named, &error))
|
||||||
|
{
|
||||||
|
syslog (LOG_CRIT, "Couldn't initialize nameserver: %s", error->message);
|
||||||
|
exit (EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
/* Start the wireless scanning thread and timeout */
|
/* Start the wireless scanning thread and timeout */
|
||||||
if (!g_thread_create (nm_wireless_scan_worker, nm_data, FALSE, &error))
|
if (!g_thread_create (nm_wireless_scan_worker, nm_data, FALSE, &error))
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user