~network-manager/network-manager/ubuntu.hardy.07

« back to all changes in this revision

Viewing changes to debian/patches/002-IFUPDOWN-hostname.loom.patch

* merge RELEASE 0.7~~svn20081008t224042-0ubuntu1 to ubuntu/intrepid

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
=== modified file 'ChangeLog'
2
 
--- a/ChangeLog 2008-10-03 21:51:57 +0000
3
 
+++ b/ChangeLog 2008-10-06 08:22:23 +0000
4
 
@@ -1,8 +1,36 @@
5
 
+2008-10-03  Alexander Sack  <asac@ubuntu.com>
6
 
+
7
 
+       Implement system hostname support for debian/ubuntu
8
 
+
9
 
+       * system-settings/plugins/ifupdown/plugin.c
10
 
+               - (GObject__set_property, GObject__get_property, SCPluginIfupdown_init, update_system_hostname, get_hostname):
11
 
+                       implement hostname property that watches and
12
 
+                       parses /etc/hostname
13
 
+
14
 
+
15
 
+       Make nm-inotify-helper from ifcfg-fedora plugin usable
16
 
+       for other plugins too
17
 
+
18
 
+       * system-settings/plugins/ifcfg-fedora/nm-inotify-helper.c (deleted)
19
 
+         system-settings/plugins/ifcfg-fedora/nm-inotify-helper.h (deleted)
20
 
+         system-settings/src/nm-inotify-helper.c (NEW)
21
 
+         system-settings/src/nm-inotify-helper.h (NEW)
22
 
+         system-settings/plugins/ifcfg-fedora/Makefile.am
23
 
+         system-settings/src/Makefile.am
24
 
+               - make inotify available for all system plugins and
25
 
+                       adjust ifcfg-fedora build accordingly
26
 
+
27
 
+       * system-settings/plugins/ifupdown/plugin.c
28
 
+               - (GObject__get_property): extend announced capabilities; add
29
 
+                       NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME support
30
 
+               - (GObject__set_property,write_system_hostname): implement
31
 
+                       NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME capability.
32
 
+
33
 
 2008-10-02  Alexander Sack  <asac@ubuntu.com>
34
 
 
35
 
        Implement support for wep-tx-keyidx in ifupdown system
36
 
        config plugin.
37
 
 
38
 
        * system-settings/plugins/ifupdown/parser.c
39
 
                - (update_wireless_security_setting_from_if_block): introduce
40
 
                        free_type_mapping func table; rename a few local
41
 
 
42
 
=== modified file 'system-settings/plugins/ifcfg-fedora/Makefile.am'
43
 
--- a/system-settings/plugins/ifcfg-fedora/Makefile.am  2008-05-13 16:53:50 +0000
44
 
+++ b/system-settings/plugins/ifcfg-fedora/Makefile.am  2008-10-02 22:32:18 +0000
45
 
@@ -5,19 +5,17 @@ libnm_settings_plugin_ifcfg_fedora_la_SO
46
 
        shvar.c \
47
 
        shvar.h \
48
 
        plugin.c \
49
 
        plugin.h \
50
 
        nm-ifcfg-connection.c \
51
 
        nm-ifcfg-connection.h \
52
 
        reader.c \
53
 
        reader.h \
54
 
-       common.h \
55
 
-       nm-inotify-helper.c \
56
 
-       nm-inotify-helper.h
57
 
+       common.h
58
 
 
59
 
 libnm_settings_plugin_ifcfg_fedora_la_CPPFLAGS = \
60
 
        $(GLIB_CFLAGS) \
61
 
        $(GMODULE_CFLAGS) \
62
 
        $(DBUS_CFLAGS) \
63
 
        -DG_DISABLE_DEPRECATED \
64
 
        -I${top_srcdir}/system-settings/src \
65
 
        -I$(top_srcdir)/include \
66
 
 
67
 
=== removed file 'system-settings/plugins/ifcfg-fedora/nm-inotify-helper.c'
68
 
--- a/system-settings/plugins/ifcfg-fedora/nm-inotify-helper.c  2008-08-26 09:34:31 +0000
69
 
+++ b/system-settings/plugins/ifcfg-fedora/nm-inotify-helper.c  1970-01-01 00:00:00 +0000
70
 
@@ -1,211 +0,0 @@
71
 
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
72
 
-/* NetworkManager system settings service
73
 
- *
74
 
- * This program is free software; you can redistribute it and/or modify
75
 
- * it under the terms of the GNU General Public License as published by
76
 
- * the Free Software Foundation; either version 2 of the License, or
77
 
- * (at your option) any later version.
78
 
- *
79
 
- * This program is distributed in the hope that it will be useful,
80
 
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
81
 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
82
 
- * GNU General Public License for more details.
83
 
- *
84
 
- * You should have received a copy of the GNU General Public License along
85
 
- * with this program; if not, write to the Free Software Foundation, Inc.,
86
 
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
87
 
- *
88
 
- * (C) Copyright 2008 Red Hat, Inc.
89
 
- */
90
 
-
91
 
-#include <unistd.h>
92
 
-#include <string.h>
93
 
-#include <sys/inotify.h>
94
 
-#include <glib.h>
95
 
-
96
 
-#include "nm-marshal.h"
97
 
-#include "nm-inotify-helper.h"
98
 
-
99
 
-G_DEFINE_TYPE (NMInotifyHelper, nm_inotify_helper, G_TYPE_OBJECT)
100
 
-
101
 
-#define NM_INOTIFY_HELPER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperPrivate))
102
 
-
103
 
-typedef struct {
104
 
-       int ifd;
105
 
-
106
 
-       GHashTable *wd_refs;
107
 
-} NMInotifyHelperPrivate;
108
 
-
109
 
-/* Signals */
110
 
-enum {
111
 
-       EVENT,
112
 
-       LAST_SIGNAL
113
 
-};
114
 
-
115
 
-static guint signals[LAST_SIGNAL] = { 0 };
116
 
-
117
 
-int
118
 
-nm_inotify_helper_add_watch (NMInotifyHelper *self, const char *path)
119
 
-{
120
 
-       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
121
 
-       int wd;
122
 
-       guint32 refcount;
123
 
-
124
 
-       g_return_val_if_fail (priv->ifd >= 0, -1);
125
 
-
126
 
-       /* We only care about modifications since we're just trying to get change
127
 
-        * notifications on hardlinks.
128
 
-        */
129
 
-
130
 
-       wd = inotify_add_watch (priv->ifd, path, IN_CLOSE_WRITE);
131
 
-       if (wd < 0)
132
 
-               return -1;
133
 
-
134
 
-       refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
135
 
-       refcount++;
136
 
-       g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
137
 
-
138
 
-       return wd;
139
 
-}
140
 
-
141
 
-void
142
 
-nm_inotify_helper_remove_watch (NMInotifyHelper *self, int wd)
143
 
-{
144
 
-       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
145
 
-       guint32 refcount;
146
 
-
147
 
-       g_return_if_fail (priv->ifd >= 0);
148
 
-
149
 
-       refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
150
 
-       if (!refcount)
151
 
-               return;
152
 
-
153
 
-       refcount--;
154
 
-       if (!refcount) {
155
 
-               g_hash_table_remove (priv->wd_refs, GINT_TO_POINTER (wd));
156
 
-               inotify_rm_watch (priv->ifd, wd);
157
 
-       } else
158
 
-               g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
159
 
-}
160
 
-
161
 
-static gboolean
162
 
-inotify_event_handler (GIOChannel *channel, GIOCondition cond, gpointer user_data)
163
 
-{
164
 
-       NMInotifyHelper *self = NM_INOTIFY_HELPER (user_data);
165
 
-       struct inotify_event evt;
166
 
-
167
 
-       /* read the notifications from the watch descriptor */
168
 
-       while (g_io_channel_read_chars (channel, (gchar *) &evt, sizeof (struct inotify_event), NULL, NULL) == G_IO_STATUS_NORMAL) {
169
 
-               gchar filename[PATH_MAX + 1];
170
 
-
171
 
-               filename[0] = '\0';
172
 
-               if (evt.len > 0) {
173
 
-                       g_io_channel_read_chars (channel,
174
 
-                                               filename,
175
 
-                                               evt.len > PATH_MAX ? PATH_MAX : evt.len,
176
 
-                                               NULL, NULL);
177
 
-               }
178
 
-
179
 
-               if (!(evt.mask & IN_IGNORED))
180
 
-                       g_signal_emit (self, signals[EVENT], 0, &evt, &filename[0]);
181
 
-       }
182
 
-
183
 
-       return TRUE;
184
 
-}
185
 
-
186
 
-static gboolean
187
 
-init_inotify (NMInotifyHelper *self)
188
 
-{
189
 
-       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
190
 
-       GIOChannel *channel;
191
 
-       guint source_id;
192
 
-
193
 
-       priv->ifd = inotify_init ();
194
 
-       if (priv->ifd == -1) {
195
 
-               g_warning ("%s: couldn't initialize inotify", __func__);
196
 
-               return FALSE;
197
 
-       }
198
 
-
199
 
-       /* Watch the inotify descriptor for file/directory change events */
200
 
-       channel = g_io_channel_unix_new (priv->ifd);
201
 
-       if (!channel) {
202
 
-               g_warning ("%s: couldn't create new GIOChannel", __func__);
203
 
-               close (priv->ifd);
204
 
-               priv->ifd = -1;
205
 
-               return FALSE;
206
 
-       }
207
 
-
208
 
-       g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
209
 
-       g_io_channel_set_encoding (channel, NULL, NULL); 
210
 
-
211
 
-       source_id = g_io_add_watch (channel,
212
 
-                                   G_IO_IN | G_IO_ERR,
213
 
-                                   (GIOFunc) inotify_event_handler,
214
 
-                                   (gpointer) self);
215
 
-       g_io_channel_unref (channel);
216
 
-       return TRUE;
217
 
-}
218
 
-
219
 
-NMInotifyHelper *
220
 
-nm_inotify_helper_get (void)
221
 
-{
222
 
-       static NMInotifyHelper *singleton = NULL;
223
 
-
224
 
-       if (!singleton) {
225
 
-               singleton = (NMInotifyHelper *) g_object_new (NM_TYPE_INOTIFY_HELPER, NULL);
226
 
-               if (!singleton)
227
 
-                       return NULL;
228
 
-
229
 
-               if (!init_inotify (singleton)) {
230
 
-                       g_object_unref (singleton);
231
 
-                       return NULL;
232
 
-               }
233
 
-       } else
234
 
-               g_object_ref (singleton);
235
 
-
236
 
-       g_assert (singleton);
237
 
-       return singleton;
238
 
-}
239
 
-
240
 
-static void
241
 
-nm_inotify_helper_init (NMInotifyHelper *self)
242
 
-{
243
 
-       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
244
 
-
245
 
-       priv->wd_refs = g_hash_table_new (g_direct_hash, g_direct_equal);
246
 
-}
247
 
-
248
 
-static void
249
 
-finalize (GObject *object)
250
 
-{
251
 
-       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (object);
252
 
-
253
 
-       if (priv->ifd >= 0)
254
 
-               close (priv->ifd);
255
 
-
256
 
-       g_hash_table_destroy (priv->wd_refs);
257
 
-
258
 
-       G_OBJECT_CLASS (nm_inotify_helper_parent_class)->finalize (object);
259
 
-}
260
 
-
261
 
-static void
262
 
-nm_inotify_helper_class_init (NMInotifyHelperClass *klass)
263
 
-{
264
 
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
265
 
-
266
 
-       g_type_class_add_private (klass, sizeof (NMInotifyHelperPrivate));
267
 
-
268
 
-       /* Virtual methods */
269
 
-       object_class->finalize = finalize;
270
 
-
271
 
-       /* Signals */
272
 
-       signals[EVENT] =
273
 
-               g_signal_new ("event",
274
 
-                             G_OBJECT_CLASS_TYPE (object_class),
275
 
-                             G_SIGNAL_RUN_LAST,
276
 
-                             G_STRUCT_OFFSET (NMInotifyHelperClass, event),
277
 
-                             NULL, NULL,
278
 
-                             _nm_marshal_VOID__POINTER_STRING,
279
 
-                             G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_STRING);
280
 
-}
281
 
-
282
 
 
283
 
=== removed file 'system-settings/plugins/ifcfg-fedora/nm-inotify-helper.h'
284
 
--- a/system-settings/plugins/ifcfg-fedora/nm-inotify-helper.h  2008-06-26 18:31:52 +0000
285
 
+++ b/system-settings/plugins/ifcfg-fedora/nm-inotify-helper.h  1970-01-01 00:00:00 +0000
286
 
@@ -1,54 +0,0 @@
287
 
-/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
288
 
-/* NetworkManager system settings service
289
 
- *
290
 
- * This program is free software; you can redistribute it and/or modify
291
 
- * it under the terms of the GNU General Public License as published by
292
 
- * the Free Software Foundation; either version 2 of the License, or
293
 
- * (at your option) any later version.
294
 
- *
295
 
- * This program is distributed in the hope that it will be useful,
296
 
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
297
 
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
298
 
- * GNU General Public License for more details.
299
 
- *
300
 
- * You should have received a copy of the GNU General Public License along
301
 
- * with this program; if not, write to the Free Software Foundation, Inc.,
302
 
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
303
 
- *
304
 
- * (C) Copyright 2008 Red Hat, Inc.
305
 
- */
306
 
-
307
 
-#ifndef __INOTIFY_HELPER_H__
308
 
-#define __INOTIFY_HELPER_H__
309
 
-
310
 
-#include <glib.h>
311
 
-#include <glib-object.h>
312
 
-#include <sys/inotify.h>
313
 
-
314
 
-#define NM_TYPE_INOTIFY_HELPER            (nm_inotify_helper_get_type ())
315
 
-#define NM_INOTIFY_HELPER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelper))
316
 
-#define NM_INOTIFY_HELPER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
317
 
-#define NM_IS_INOTIFY_HELPER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_INOTIFY_HELPER))
318
 
-#define NM_IS_INOTIFY_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_INOTIFY_HELPER))
319
 
-#define NM_INOTIFY_HELPER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
320
 
-
321
 
-typedef struct {
322
 
-       GObject parent;
323
 
-} NMInotifyHelper;
324
 
-
325
 
-typedef struct {
326
 
-       GObjectClass parent;
327
 
-
328
 
-       /* signals */
329
 
-       void (* event) (NMInotifyHelper *helper, struct inotify_event *evt, const char *filename);
330
 
-} NMInotifyHelperClass;
331
 
-
332
 
-GType nm_inotify_helper_get_type (void);
333
 
-
334
 
-NMInotifyHelper * nm_inotify_helper_get (void);
335
 
-
336
 
-int nm_inotify_helper_add_watch (NMInotifyHelper *helper, const char *path);
337
 
-
338
 
-void nm_inotify_helper_remove_watch (NMInotifyHelper *helper, int wd);
339
 
-
340
 
-#endif  /* __INOTIFY_HELPER_H__ */
341
 
 
342
 
=== modified file 'system-settings/plugins/ifupdown/plugin.c'
343
 
--- a/system-settings/plugins/ifupdown/plugin.c 2008-09-18 15:29:59 +0000
344
 
+++ b/system-settings/plugins/ifupdown/plugin.c 2008-10-04 17:09:53 +0000
345
 
@@ -36,32 +36,37 @@
346
 
 #include "nm-setting-ip4-config.h"
347
 
 #include "nm-setting-wireless.h"
348
 
 #include "nm-setting-wired.h"
349
 
 #include "nm-setting-ppp.h"
350
 
 
351
 
 #include "nm-ifupdown-connection.h"
352
 
 #include "plugin.h"
353
 
 #include "parser.h"
354
 
+#include "nm-inotify-helper.h"
355
 
 
356
 
 #include <nm-utils.h>
357
 
 #include <sha1.h>
358
 
 
359
 
 #include <arpa/inet.h>
360
 
 
361
 
 #define IFUPDOWN_PLUGIN_NAME "ifupdown"
362
 
 #define IFUPDOWN_PLUGIN_INFO "(C) 2008 Canonical Ltd.  To report bugs please use the NetworkManager mailing list."
363
 
+#define IFUPDOWN_SYSTEM_HOSTNAME_FILE "/etc/hostname"
364
 
 
365
 
 typedef struct {
366
 
 
367
 
        DBusGConnection *g_connection;
368
 
        NMSystemConfigHalManager *hal_mgr;
369
 
 
370
 
        GHashTable *iface_connections;
371
 
-       
372
 
+       gchar* hostname;
373
 
+
374
 
+       gulong inotify_event_id;
375
 
+       int inotify_system_hostname_wd;
376
 
 } SCPluginIfupdownPrivate;
377
 
 
378
 
 static void
379
 
 system_config_interface_init (NMSystemConfigInterface *system_config_interface_class);
380
 
 
381
 
 G_DEFINE_TYPE_EXTENDED (SCPluginIfupdown, sc_plugin_ifupdown, G_TYPE_OBJECT, 0,
382
 
                                    G_IMPLEMENT_INTERFACE (NM_TYPE_SYSTEM_CONFIG_INTERFACE,
383
 
                                                                          system_config_interface_init))
384
 
@@ -100,21 +105,36 @@ SCPluginIfupdown_connection_added (NMSys
385
 
 static void
386
 
 SCPluginIfupdown_unmanaged_devices_changed (NMSystemConfigInterface *config);
387
 
 
388
 
 static void
389
 
 GObject__get_property (GObject *object, guint prop_id,
390
 
                                   GValue *value, GParamSpec *pspec);
391
 
 
392
 
 static void
393
 
+GObject__set_property (GObject *object, guint prop_id,
394
 
+                                  const GValue *value, GParamSpec *pspec);
395
 
+
396
 
+static void
397
 
 GObject__dispose (GObject *object);
398
 
 
399
 
 static void
400
 
 GObject__finalize (GObject *object);
401
 
 
402
 
+/* other helpers */
403
 
+static const char *
404
 
+get_hostname (NMSystemConfigInterface *config);
405
 
+
406
 
+
407
 
+static void
408
 
+update_system_hostname(NMInotifyHelper *inotify_helper,
409
 
+                       struct inotify_event *evt,
410
 
+                       const char *path,
411
 
+                       NMSystemConfigInterface *config);
412
 
+
413
 
 
414
 
 static void
415
 
 system_config_interface_init (NMSystemConfigInterface *system_config_interface_class)
416
 
 {
417
 
        system_config_interface_class->init = SCPluginIfupdown_init;
418
 
        system_config_interface_class->get_connections = SCPluginIfupdown_get_connections;
419
 
        system_config_interface_class->get_unmanaged_devices = SCPluginIfupdown_get_unmanaged_devices;
420
 
        system_config_interface_class->connection_added = SCPluginIfupdown_connection_added;
421
 
@@ -126,16 +146,17 @@ sc_plugin_ifupdown_class_init (SCPluginI
422
 
 {
423
 
        GObjectClass *object_class = G_OBJECT_CLASS (req_class);
424
 
 
425
 
        g_type_class_add_private (req_class, sizeof (SCPluginIfupdownPrivate));
426
 
 
427
 
        object_class->dispose = GObject__dispose;
428
 
        object_class->finalize = GObject__finalize;
429
 
        object_class->get_property = GObject__get_property;
430
 
+       object_class->set_property = GObject__set_property;
431
 
 
432
 
        g_object_class_override_property (object_class,
433
 
                                          NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME,
434
 
                                          NM_SYSTEM_CONFIG_INTERFACE_NAME);
435
 
 
436
 
        g_object_class_override_property (object_class,
437
 
                                          NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO,
438
 
                                          NM_SYSTEM_CONFIG_INTERFACE_INFO);
439
 
@@ -151,23 +172,35 @@ sc_plugin_ifupdown_class_init (SCPluginI
440
 
 
441
 
 static void
442
 
 SCPluginIfupdown_init (NMSystemConfigInterface *config,
443
 
                                   NMSystemConfigHalManager *hal_manager)
444
 
 {
445
 
        SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
446
 
        GHashTable *auto_ifaces = g_hash_table_new (g_str_hash, g_str_equal);
447
 
        if_block *block = NULL;
448
 
+       NMInotifyHelper *inotify_helper;
449
 
 
450
 
        if(!priv->iface_connections)
451
 
                priv->iface_connections = g_hash_table_new (g_str_hash, g_str_equal);
452
 
 
453
 
        PLUGIN_PRINT("SCPlugin-Ifupdown", "init!");
454
 
        priv->hal_mgr = g_object_ref (hal_manager);
455
 
 
456
 
+       inotify_helper = nm_inotify_helper_get ();
457
 
+       priv->inotify_event_id = g_signal_connect (inotify_helper,
458
 
+                                                                          "event",
459
 
+                                                                          G_CALLBACK (update_system_hostname),
460
 
+                                                                          config);
461
 
+
462
 
+       priv->inotify_system_hostname_wd =
463
 
+               nm_inotify_helper_add_watch (inotify_helper, IFUPDOWN_SYSTEM_HOSTNAME_FILE);
464
 
+
465
 
+       update_system_hostname(inotify_helper, NULL, NULL, config);
466
 
+
467
 
        ifparser_init();
468
 
        block = ifparser_getfirst();
469
 
 
470
 
        while(block) {
471
 
                if(!strcmp("auto", block->type)) {
472
 
                        g_hash_table_insert (auto_ifaces, block->name, "auto");
473
 
                } else if (!strcmp ("iface", block->type) && strcmp ("lo", block->name)) {
474
 
                        NMExportedConnection *connection = g_hash_table_lookup(priv->iface_connections, block->name);
475
 
@@ -260,58 +293,153 @@ static void
476
 
 SCPluginIfupdown_unmanaged_devices_changed (NMSystemConfigInterface *config)
477
 
 {
478
 
        PLUGIN_PRINT("SCPlugin-Ifdown", "unmanaged_devices_changed ... started");
479
 
        g_return_if_fail (config != NULL);
480
 
 
481
 
        PLUGIN_PRINT("SCPlugin-Ifdown", "unmanaged_devices_changed ... ended");
482
 
 }
483
 
 
484
 
+static const char *
485
 
+get_hostname (NMSystemConfigInterface *config)
486
 
+{
487
 
+       SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
488
 
+       return priv->hostname;
489
 
+}
490
 
+
491
 
+static void
492
 
+update_system_hostname(NMInotifyHelper *inotify_helper,
493
 
+                       struct inotify_event *evt,
494
 
+                       const char *path,
495
 
+                       NMSystemConfigInterface *config)
496
 
+{
497
 
+       SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
498
 
+       gchar *hostname_file = NULL;
499
 
+       gsize hostname_file_len = 0;
500
 
+       GError *error = NULL;
501
 
+
502
 
+       PLUGIN_PRINT ("SCPlugin-Ifupdown", "update_system_hostname");
503
 
+
504
 
+       if (evt && evt->wd != priv->inotify_system_hostname_wd)
505
 
+               return;
506
 
+
507
 
+       if(!g_file_get_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE,
508
 
+                                                &hostname_file,
509
 
+                                                &hostname_file_len,
510
 
+                                                &error)) {
511
 
+               nm_warning ("update_system_hostname() - couldn't read "
512
 
+                                 IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)",
513
 
+                                 error->code, error->message);
514
 
+               return;
515
 
+       }
516
 
+
517
 
+       if (priv->hostname)
518
 
+               g_free(priv->hostname);
519
 
+
520
 
+       priv->hostname = g_strstrip(hostname_file);
521
 
+
522
 
+       g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
523
 
+}
524
 
+
525
 
+static void
526
 
+write_system_hostname(NMSystemConfigInterface *config,
527
 
+                                 const char *newhostname)
528
 
+{
529
 
+       GError *error = NULL;
530
 
+       SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (config);
531
 
+       PLUGIN_PRINT ("SCPlugin-Ifupdown", "write_system_hostname: %s", newhostname);
532
 
+
533
 
+       g_return_if_fail (newhostname);
534
 
+
535
 
+       if(!g_file_set_contents ( IFUPDOWN_SYSTEM_HOSTNAME_FILE,
536
 
+                                                newhostname,
537
 
+                                                -1,
538
 
+                                                &error)) {
539
 
+               nm_warning ("update_system_hostname() - couldn't write hostname (%s) to "
540
 
+                                 IFUPDOWN_SYSTEM_HOSTNAME_FILE " (%d/%s)",
541
 
+                                 newhostname, error->code, error->message);    
542
 
+       } else {
543
 
+               priv->hostname = g_strdup (newhostname);
544
 
+       }
545
 
+       g_object_notify (G_OBJECT (config), NM_SYSTEM_CONFIG_INTERFACE_HOSTNAME);
546
 
+}
547
 
+
548
 
+
549
 
 static void
550
 
 sc_plugin_ifupdown_init (SCPluginIfupdown *plugin)
551
 
 {
552
 
        SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (plugin);
553
 
        GError *error = NULL;
554
 
 
555
 
        priv->g_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
556
 
        if (!priv->g_connection) {
557
 
-               PLUGIN_PRINT (IFUPDOWN_PLUGIN_NAME, "    dbus-glib error: %s",
558
 
+               PLUGIN_PRINT ("SCPlugin-Ifupdown", "    dbus-glib error: %s",
559
 
                              error->message ? error->message : "(unknown)");
560
 
                g_error_free (error);
561
 
        }
562
 
 }
563
 
 
564
 
 static void
565
 
 GObject__get_property (GObject *object, guint prop_id,
566
 
                                   GValue *value, GParamSpec *pspec)
567
 
 {
568
 
+       NMSystemConfigInterface *self = NM_SYSTEM_CONFIG_INTERFACE (object);
569
 
+
570
 
        switch (prop_id) {
571
 
        case NM_SYSTEM_CONFIG_INTERFACE_PROP_NAME:
572
 
                g_value_set_string (value, IFUPDOWN_PLUGIN_NAME);
573
 
                break;
574
 
        case NM_SYSTEM_CONFIG_INTERFACE_PROP_INFO:
575
 
                g_value_set_string (value, IFUPDOWN_PLUGIN_INFO);
576
 
                break;
577
 
        case NM_SYSTEM_CONFIG_INTERFACE_PROP_CAPABILITIES:
578
 
-               g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_NONE);
579
 
+               g_value_set_uint (value, NM_SYSTEM_CONFIG_INTERFACE_CAP_MODIFY_HOSTNAME);
580
 
                break;
581
 
        case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
582
 
-               g_value_set_string (value, "");
583
 
+               {
584
 
+                       g_value_set_string (value, get_hostname(self));
585
 
+                       break;
586
 
+               }
587
 
+       default:
588
 
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
589
 
                break;
590
 
+       }
591
 
+}
592
 
+
593
 
+static void
594
 
+GObject__set_property (GObject *object, guint prop_id,
595
 
+                                  const GValue *value, GParamSpec *pspec)
596
 
+{
597
 
+       switch (prop_id) {
598
 
+       case NM_SYSTEM_CONFIG_INTERFACE_PROP_HOSTNAME:
599
 
+               {
600
 
+                       const gchar *hostname = g_value_get_string (value);
601
 
+                       if (hostname && strlen (hostname) < 1)
602
 
+                               hostname = NULL;
603
 
+                       write_system_hostname(NM_SYSTEM_CONFIG_INTERFACE(object),
604
 
+                                                         hostname);
605
 
+                       break;
606
 
+               }
607
 
        default:
608
 
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
609
 
                break;
610
 
        }
611
 
 }
612
 
 
613
 
 static void
614
 
 GObject__dispose (GObject *object)
615
 
 {
616
 
        SCPluginIfupdown *plugin = SC_PLUGIN_IFUPDOWN (object);
617
 
        SCPluginIfupdownPrivate *priv = SC_PLUGIN_IFUPDOWN_GET_PRIVATE (plugin);
618
 
+       NMInotifyHelper *inotify_helper = nm_inotify_helper_get ();
619
 
+
620
 
+       g_signal_handler_disconnect (inotify_helper, priv->inotify_event_id);
621
 
+
622
 
+       if (priv->inotify_system_hostname_wd >= 0)
623
 
+               nm_inotify_helper_remove_watch (inotify_helper, priv->inotify_system_hostname_wd);
624
 
 
625
 
        g_object_unref (priv->hal_mgr);
626
 
        G_OBJECT_CLASS (sc_plugin_ifupdown_parent_class)->dispose (object);
627
 
 }
628
 
 
629
 
 static void
630
 
 GObject__finalize (GObject *object)
631
 
 {
632
 
 
633
 
=== modified file 'system-settings/src/Makefile.am'
634
 
--- a/system-settings/src/Makefile.am   2008-07-16 07:37:10 +0000
635
 
+++ b/system-settings/src/Makefile.am   2008-10-02 22:32:18 +0000
636
 
@@ -8,16 +8,18 @@ sbin_PROGRAMS = nm-system-settings
637
 
 
638
 
 BUILT_SOURCES = \
639
 
        nm-settings-system-glue.h
640
 
 
641
 
 nm_system_settings_SOURCES = \
642
 
        dbus-settings.c \
643
 
        dbus-settings.h \
644
 
        main.c \
645
 
+       nm-inotify-helper.c \
646
 
+       nm-inotify-helper.h \
647
 
        nm-polkit-helpers.c \
648
 
        nm-polkit-helpers.h \
649
 
        nm-system-config-error.c \
650
 
        nm-system-config-error.h \
651
 
        nm-system-config-interface.c \
652
 
        nm-system-config-interface.h \
653
 
        nm-system-config-hal-manager.c \
654
 
        nm-system-config-hal-manager.h \
655
 
 
656
 
=== added file 'system-settings/src/nm-inotify-helper.c'
657
 
--- a/system-settings/src/nm-inotify-helper.c   1970-01-01 00:00:00 +0000
658
 
+++ b/system-settings/src/nm-inotify-helper.c   2008-10-02 22:32:18 +0000
659
 
@@ -0,0 +1,211 @@
660
 
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
661
 
+/* NetworkManager system settings service
662
 
+ *
663
 
+ * This program is free software; you can redistribute it and/or modify
664
 
+ * it under the terms of the GNU General Public License as published by
665
 
+ * the Free Software Foundation; either version 2 of the License, or
666
 
+ * (at your option) any later version.
667
 
+ *
668
 
+ * This program is distributed in the hope that it will be useful,
669
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
670
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
671
 
+ * GNU General Public License for more details.
672
 
+ *
673
 
+ * You should have received a copy of the GNU General Public License along
674
 
+ * with this program; if not, write to the Free Software Foundation, Inc.,
675
 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
676
 
+ *
677
 
+ * (C) Copyright 2008 Red Hat, Inc.
678
 
+ */
679
 
+
680
 
+#include <unistd.h>
681
 
+#include <string.h>
682
 
+#include <sys/inotify.h>
683
 
+#include <glib.h>
684
 
+
685
 
+#include "nm-marshal.h"
686
 
+#include "nm-inotify-helper.h"
687
 
+
688
 
+G_DEFINE_TYPE (NMInotifyHelper, nm_inotify_helper, G_TYPE_OBJECT)
689
 
+
690
 
+#define NM_INOTIFY_HELPER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperPrivate))
691
 
+
692
 
+typedef struct {
693
 
+       int ifd;
694
 
+
695
 
+       GHashTable *wd_refs;
696
 
+} NMInotifyHelperPrivate;
697
 
+
698
 
+/* Signals */
699
 
+enum {
700
 
+       EVENT,
701
 
+       LAST_SIGNAL
702
 
+};
703
 
+
704
 
+static guint signals[LAST_SIGNAL] = { 0 };
705
 
+
706
 
+int
707
 
+nm_inotify_helper_add_watch (NMInotifyHelper *self, const char *path)
708
 
+{
709
 
+       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
710
 
+       int wd;
711
 
+       guint32 refcount;
712
 
+
713
 
+       g_return_val_if_fail (priv->ifd >= 0, -1);
714
 
+
715
 
+       /* We only care about modifications since we're just trying to get change
716
 
+        * notifications on hardlinks.
717
 
+        */
718
 
+
719
 
+       wd = inotify_add_watch (priv->ifd, path, IN_CLOSE_WRITE);
720
 
+       if (wd < 0)
721
 
+               return -1;
722
 
+
723
 
+       refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
724
 
+       refcount++;
725
 
+       g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
726
 
+
727
 
+       return wd;
728
 
+}
729
 
+
730
 
+void
731
 
+nm_inotify_helper_remove_watch (NMInotifyHelper *self, int wd)
732
 
+{
733
 
+       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
734
 
+       guint32 refcount;
735
 
+
736
 
+       g_return_if_fail (priv->ifd >= 0);
737
 
+
738
 
+       refcount = GPOINTER_TO_UINT (g_hash_table_lookup (priv->wd_refs, GINT_TO_POINTER (wd)));
739
 
+       if (!refcount)
740
 
+               return;
741
 
+
742
 
+       refcount--;
743
 
+       if (!refcount) {
744
 
+               g_hash_table_remove (priv->wd_refs, GINT_TO_POINTER (wd));
745
 
+               inotify_rm_watch (priv->ifd, wd);
746
 
+       } else
747
 
+               g_hash_table_replace (priv->wd_refs, GINT_TO_POINTER (wd), GUINT_TO_POINTER (refcount));
748
 
+}
749
 
+
750
 
+static gboolean
751
 
+inotify_event_handler (GIOChannel *channel, GIOCondition cond, gpointer user_data)
752
 
+{
753
 
+       NMInotifyHelper *self = NM_INOTIFY_HELPER (user_data);
754
 
+       struct inotify_event evt;
755
 
+
756
 
+       /* read the notifications from the watch descriptor */
757
 
+       while (g_io_channel_read_chars (channel, (gchar *) &evt, sizeof (struct inotify_event), NULL, NULL) == G_IO_STATUS_NORMAL) {
758
 
+               gchar filename[PATH_MAX + 1];
759
 
+
760
 
+               filename[0] = '\0';
761
 
+               if (evt.len > 0) {
762
 
+                       g_io_channel_read_chars (channel,
763
 
+                                               filename,
764
 
+                                               evt.len > PATH_MAX ? PATH_MAX : evt.len,
765
 
+                                               NULL, NULL);
766
 
+               }
767
 
+
768
 
+               if (!(evt.mask & IN_IGNORED))
769
 
+                       g_signal_emit (self, signals[EVENT], 0, &evt, &filename[0]);
770
 
+       }
771
 
+
772
 
+       return TRUE;
773
 
+}
774
 
+
775
 
+static gboolean
776
 
+init_inotify (NMInotifyHelper *self)
777
 
+{
778
 
+       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
779
 
+       GIOChannel *channel;
780
 
+       guint source_id;
781
 
+
782
 
+       priv->ifd = inotify_init ();
783
 
+       if (priv->ifd == -1) {
784
 
+               g_warning ("%s: couldn't initialize inotify", __func__);
785
 
+               return FALSE;
786
 
+       }
787
 
+
788
 
+       /* Watch the inotify descriptor for file/directory change events */
789
 
+       channel = g_io_channel_unix_new (priv->ifd);
790
 
+       if (!channel) {
791
 
+               g_warning ("%s: couldn't create new GIOChannel", __func__);
792
 
+               close (priv->ifd);
793
 
+               priv->ifd = -1;
794
 
+               return FALSE;
795
 
+       }
796
 
+
797
 
+       g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
798
 
+       g_io_channel_set_encoding (channel, NULL, NULL); 
799
 
+
800
 
+       source_id = g_io_add_watch (channel,
801
 
+                                   G_IO_IN | G_IO_ERR,
802
 
+                                   (GIOFunc) inotify_event_handler,
803
 
+                                   (gpointer) self);
804
 
+       g_io_channel_unref (channel);
805
 
+       return TRUE;
806
 
+}
807
 
+
808
 
+NMInotifyHelper *
809
 
+nm_inotify_helper_get (void)
810
 
+{
811
 
+       static NMInotifyHelper *singleton = NULL;
812
 
+
813
 
+       if (!singleton) {
814
 
+               singleton = (NMInotifyHelper *) g_object_new (NM_TYPE_INOTIFY_HELPER, NULL);
815
 
+               if (!singleton)
816
 
+                       return NULL;
817
 
+
818
 
+               if (!init_inotify (singleton)) {
819
 
+                       g_object_unref (singleton);
820
 
+                       return NULL;
821
 
+               }
822
 
+       } else
823
 
+               g_object_ref (singleton);
824
 
+
825
 
+       g_assert (singleton);
826
 
+       return singleton;
827
 
+}
828
 
+
829
 
+static void
830
 
+nm_inotify_helper_init (NMInotifyHelper *self)
831
 
+{
832
 
+       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self);
833
 
+
834
 
+       priv->wd_refs = g_hash_table_new (g_direct_hash, g_direct_equal);
835
 
+}
836
 
+
837
 
+static void
838
 
+finalize (GObject *object)
839
 
+{
840
 
+       NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (object);
841
 
+
842
 
+       if (priv->ifd >= 0)
843
 
+               close (priv->ifd);
844
 
+
845
 
+       g_hash_table_destroy (priv->wd_refs);
846
 
+
847
 
+       G_OBJECT_CLASS (nm_inotify_helper_parent_class)->finalize (object);
848
 
+}
849
 
+
850
 
+static void
851
 
+nm_inotify_helper_class_init (NMInotifyHelperClass *klass)
852
 
+{
853
 
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
854
 
+
855
 
+       g_type_class_add_private (klass, sizeof (NMInotifyHelperPrivate));
856
 
+
857
 
+       /* Virtual methods */
858
 
+       object_class->finalize = finalize;
859
 
+
860
 
+       /* Signals */
861
 
+       signals[EVENT] =
862
 
+               g_signal_new ("event",
863
 
+                             G_OBJECT_CLASS_TYPE (object_class),
864
 
+                             G_SIGNAL_RUN_LAST,
865
 
+                             G_STRUCT_OFFSET (NMInotifyHelperClass, event),
866
 
+                             NULL, NULL,
867
 
+                             _nm_marshal_VOID__POINTER_STRING,
868
 
+                             G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_STRING);
869
 
+}
870
 
+
871
 
 
872
 
=== added file 'system-settings/src/nm-inotify-helper.h'
873
 
--- a/system-settings/src/nm-inotify-helper.h   1970-01-01 00:00:00 +0000
874
 
+++ b/system-settings/src/nm-inotify-helper.h   2008-10-02 22:32:18 +0000
875
 
@@ -0,0 +1,54 @@
876
 
+/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
877
 
+/* NetworkManager system settings service
878
 
+ *
879
 
+ * This program is free software; you can redistribute it and/or modify
880
 
+ * it under the terms of the GNU General Public License as published by
881
 
+ * the Free Software Foundation; either version 2 of the License, or
882
 
+ * (at your option) any later version.
883
 
+ *
884
 
+ * This program is distributed in the hope that it will be useful,
885
 
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
886
 
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
887
 
+ * GNU General Public License for more details.
888
 
+ *
889
 
+ * You should have received a copy of the GNU General Public License along
890
 
+ * with this program; if not, write to the Free Software Foundation, Inc.,
891
 
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
892
 
+ *
893
 
+ * (C) Copyright 2008 Red Hat, Inc.
894
 
+ */
895
 
+
896
 
+#ifndef __INOTIFY_HELPER_H__
897
 
+#define __INOTIFY_HELPER_H__
898
 
+
899
 
+#include <glib.h>
900
 
+#include <glib-object.h>
901
 
+#include <sys/inotify.h>
902
 
+
903
 
+#define NM_TYPE_INOTIFY_HELPER            (nm_inotify_helper_get_type ())
904
 
+#define NM_INOTIFY_HELPER(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelper))
905
 
+#define NM_INOTIFY_HELPER_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
906
 
+#define NM_IS_INOTIFY_HELPER(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_INOTIFY_HELPER))
907
 
+#define NM_IS_INOTIFY_HELPER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), NM_TYPE_INOTIFY_HELPER))
908
 
+#define NM_INOTIFY_HELPER_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_INOTIFY_HELPER, NMInotifyHelperClass))
909
 
+
910
 
+typedef struct {
911
 
+       GObject parent;
912
 
+} NMInotifyHelper;
913
 
+
914
 
+typedef struct {
915
 
+       GObjectClass parent;
916
 
+
917
 
+       /* signals */
918
 
+       void (* event) (NMInotifyHelper *helper, struct inotify_event *evt, const char *filename);
919
 
+} NMInotifyHelperClass;
920
 
+
921
 
+GType nm_inotify_helper_get_type (void);
922
 
+
923
 
+NMInotifyHelper * nm_inotify_helper_get (void);
924
 
+
925
 
+int nm_inotify_helper_add_watch (NMInotifyHelper *helper, const char *path);
926
 
+
927
 
+void nm_inotify_helper_remove_watch (NMInotifyHelper *helper, int wd);
928
 
+
929
 
+#endif  /* __INOTIFY_HELPER_H__ */
930