After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752857 - [review] add "nm-default.h" header and order destruction of singleton instances [th/nm-default-bgo752857]
[review] add "nm-default.h" header and order destruction of singleton instanc...
Status: RESOLVED FIXED
Product: NetworkManager
Classification: Platform
Component: general
git master
Other Linux
: Normal normal
: ---
Assigned To: NetworkManager maintainer(s)
NetworkManager maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-07-25 09:56 UTC by Thomas Haller
Modified: 2015-08-05 13:43 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[PATCH] fixup! all: include internal headers with quotes (3.17 KB, patch)
2015-07-29 13:06 UTC, Beniamino Galvani
none Details | Review

Description Thomas Haller 2015-07-25 09:56:58 UTC
please review
Comment 1 Thomas Haller 2015-07-25 09:57:33 UTC
th/nm-default-bgo752857
Comment 2 Beniamino Galvani 2015-07-29 13:06:37 UTC
Created attachment 308391 [details] [review]
[PATCH] fixup! all: include internal headers with quotes

Looks good to me, only some nitpicks:

> core: order destruction of singleton instances

    This is only a crude method to get the lifetime of singleton instances
    right by default. Having singeltons ref other singletons to keep them

s/singeltons/singletons/

+inline void __attribute__((destructor))
+_nm_singleton_instance_destroy (void)

static void? or is inline needed in this case?

Also pushed a trivial fixup and added a patch as attachment (I didn't push a fixup for it because it has conflicts with following commits).
Comment 3 Thomas Haller 2015-07-29 18:33:51 UTC
(In reply to Beniamino Galvani from comment #2)
> Created attachment 308391 [details] [review] [review]
> [PATCH] fixup! all: include internal headers with quotes
> 
> Looks good to me, only some nitpicks:
> 

Thanks. Fixed after your comments and included attachment 308391 [details] [review].

Rebased and repushed.
Comment 4 Dan Winship 2015-08-03 12:57:11 UTC
>+		if (instance->ref_count > 1)
>+			nm_log_dbg (LOGD_CORE, "disown %s singleton (%p)", G_OBJECT_TYPE_NAME (instance), instance);

I know this is in the old code too, but I'm not sure why; what is it supposed to be telling you?

>+#define NM_DEFINE_SINGLETON_REGISTER_DESTRUCTION TRUE

This seems unnecessary...

And I don't think you actually need nm_singleton_instance_register_destruction(). (Eg, compare against my version in bug 622927; though I should have made nm_singletons_destroy() be a destructor rather than being called explicitly.)



>+#if defined (NETWORKMANAGER_COMPILATION) && NETWORKMANAGER_COMPILATION == 2
>+
>+/* the header is used inside src/, where additional
>+ * headers are available. */

That's non-obvious. It might be better to have a different or additional define...

Related to that; if you knew whether the current directory was a library directory or a daemon/client directory, then you could automatically include either <glib/gi18n-lib.h> or <glib/gi18n.h> as appropriate.
Comment 5 Dan Williams 2015-08-03 13:37:50 UTC
(In reply to Dan Winship from comment #4)
> >+#define NM_DEFINE_SINGLETON_REGISTER_DESTRUCTION TRUE
> 
> This seems unnecessary...

Yeah, I don't see why we'd need both ways?

> And I don't think you actually need
> nm_singleton_instance_register_destruction(). (Eg, compare against my
> version in bug 622927; though I should have made nm_singletons_destroy() be
> a destructor rather than being called explicitly.)

Agreed; shouldn't we just be destroying all the singletons we create at exit, instead of having them register themselves?

> >+#if defined (NETWORKMANAGER_COMPILATION) && NETWORKMANAGER_COMPILATION == 2
> >+
> >+/* the header is used inside src/, where additional
> >+ * headers are available. */
> 
> That's non-obvious. It might be better to have a different or additional
> define...

How about NETWORKMANAGER_DAEMON_COMPILATION?  I'd rather have a different/additional define than overloading this one.

The rest of the patches LGTM.
Comment 6 Thomas Haller 2015-08-04 10:42:55 UTC
(In reply to Dan Winship from comment #4)
> >+		if (instance->ref_count > 1)
> >+			nm_log_dbg (LOGD_CORE, "disown %s singleton (%p)", G_OBJECT_TYPE_NAME (instance), instance);
> 
> I know this is in the old code too, but I'm not sure why; what is it
> supposed to be telling you?

The "destructor" only unrefs the singleton. Previously, without ordering of destruction, it was not at all uncommon, that this does not yet drop the ref-count to zero.
So, you sould first see a "disown" message and later "destroy" (which is ok).
OTOH, some singletons were leaked, so we would not actually ever see the "destroy" message.

Now with ordering the destruction of singletons, we would even more expect that the singletons shut down in the right order and the last reference gets droped.

If you now see the message, something is odd.


> >+#define NM_DEFINE_SINGLETON_REGISTER_DESTRUCTION TRUE
> 
> This seems unnecessary...

Dropped.


> And I don't think you actually need
> nm_singleton_instance_register_destruction(). (Eg, compare against my
> version in bug 622927; though I should have made nm_singletons_destroy() be
> a destructor rather than being called explicitly.)

You basically merged the singleton for destruction into _singleton_instance_weak_ref_cb(). I did that now too (see fixup!) and renamed the function.

Note that NMPlatform does not get registered for destruction -- as before.

How is this?


> >+#if defined (NETWORKMANAGER_COMPILATION) && NETWORKMANAGER_COMPILATION == 2
> >+
> >+/* the header is used inside src/, where additional
> >+ * headers are available. */
> 
> That's non-obvious. It might be better to have a different or additional
> define...

How about the fixup! that adds NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON ?



> Related to that; if you knew whether the current directory was a library
> directory or a daemon/client directory, then you could automatically include
> either <glib/gi18n-lib.h> or <glib/gi18n.h> as appropriate.

Added commit "nm-default: include i18n headers via "nm-default.h""




Repushed.
Comment 7 Thomas Haller 2015-08-04 10:44:35 UTC
(In reply to Dan Williams from comment #5)
> (In reply to Dan Winship from comment #4)
> > >+#define NM_DEFINE_SINGLETON_REGISTER_DESTRUCTION TRUE
> > 
> > This seems unnecessary...
> 
> Yeah, I don't see why we'd need both ways?

Dropped.

> > And I don't think you actually need
> > nm_singleton_instance_register_destruction(). (Eg, compare against my
> > version in bug 622927; though I should have made nm_singletons_destroy() be
> > a destructor rather than being called explicitly.)
> 
> Agreed; shouldn't we just be destroying all the singletons we create at
> exit, instead of having them register themselves?

Addressed in fixup commit? Better?

> > >+#if defined (NETWORKMANAGER_COMPILATION) && NETWORKMANAGER_COMPILATION == 2
> > >+
> > >+/* the header is used inside src/, where additional
> > >+ * headers are available. */
> > 
> > That's non-obvious. It might be better to have a different or additional
> > define...
> 
> How about NETWORKMANAGER_DAEMON_COMPILATION?  I'd rather have a
> different/additional define than overloading this one.

It's still only one define, with named flags. How is that?
Comment 8 Dan Winship 2015-08-04 17:11:04 UTC
(In reply to Thomas Haller from comment #6)
> (In reply to Dan Winship from comment #4)
> > >+		if (instance->ref_count > 1)
> > >+			nm_log_dbg (LOGD_CORE, "disown %s singleton (%p)", G_OBJECT_TYPE_NAME (instance), instance);

> If you now see the message, something is odd.

OK, so it should probably be reworded to indicate that?

>+#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON

That looks weird...

I don't think you need a bitfield. At the moment, we only want to distinguish daemon, libraries, and "other", which are mutually exclusive.

> nm-default: include i18n headers via "nm-default.h"

pushed three fixups to danw/nm-default-bgo752857
Comment 9 Dan Williams 2015-08-04 18:12:23 UTC
Why aren't we destroying the NMPlatform instance on exit?  That seems to be the only reason for the register_destruction() stuff.  From a quick look NMPlatform itself doesn't care about destruction, and NMLinuxPlatform doesn't care much.  By this point all listeners should have unregistered their signal handlers, and the Platform should probably be the last thing destroyed since it doesn't depend on any other objects.

danw's fixups look OK to me.
Comment 10 Thomas Haller 2015-08-05 09:55:14 UTC
(In reply to Dan Winship from comment #8)
> (In reply to Thomas Haller from comment #6)
> > (In reply to Dan Winship from comment #4)
> > > >+		if (instance->ref_count > 1)
> > > >+			nm_log_dbg (LOGD_CORE, "disown %s singleton (%p)", G_OBJECT_TYPE_NAME (instance), instance);
> 
> > If you now see the message, something is odd.
> 
> OK, so it should probably be reworded to indicate that?

Reworded.


> >+#if (NETWORKMANAGER_COMPILATION) & NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON
> 
> That looks weird...

Changed to ==


> I don't think you need a bitfield. At the moment, we only want to
> distinguish daemon, libraries, and "other", which are mutually exclusive.
> 
> > nm-default: include i18n headers via "nm-default.h"
> 
> pushed three fixups to danw/nm-default-bgo752857

Thanks, I took them, and removed your branch. Rebased all to master.



(In reply to Dan Williams from comment #9)
> Why aren't we destroying the NMPlatform instance on exit?

Correct, when unifying several singleton implementations (by adding NM_SINGLETON_DEFINE_GETTER()), we did not do everything.
 - NMManager is still defined differently
 - we leak several singletons, although we defined a destructor.
 - NMPlatform is known not to destroy.

It's todo, but not that urgent either.


> That seems to be
> the only reason for the register_destruction() stuff. 

Not really. It is the reason for the "gboolean register_destruction" argument of nm_singleton_instance_register().

Do you want to drop _nm_singleton_instance_register_destruction() altogether? How should that be? 



> From a quick look
> NMPlatform itself doesn't care about destruction, and NMLinuxPlatform
> doesn't care much.  By this point all listeners should have unregistered
> their signal handlers, and the Platform should probably be the last thing
> destroyed since it doesn't depend on any other objects.

We still leak some singletons. Let's fix that first, before destroying NMPlatform too. danw/gdbus-bgo622927 has some relevant changes for NMManager there...
Comment 11 Dan Winship 2015-08-05 12:23:45 UTC
lgtm
Comment 12 Thomas Haller 2015-08-05 12:44:15 UTC
> Correct, when unifying several singleton implementations (by adding
> NM_SINGLETON_DEFINE_GETTER()), we did not do everything.
>  - NMManager is still defined differently
>  - we leak several singletons, although we defined a destructor.
>  - NMPlatform is known not to destroy.
> 
> It's todo, but not that urgent either.
> 
> 
> > That seems to be
> > the only reason for the register_destruction() stuff. 
> 
> Not really. It is the reason for the "gboolean register_destruction"
> argument of nm_singleton_instance_register().
> 
> Do you want to drop _nm_singleton_instance_register_destruction()
> altogether? How should that be? 
> 
> 
> 
> > From a quick look
> > NMPlatform itself doesn't care about destruction, and NMLinuxPlatform
> > doesn't care much.  By this point all listeners should have unregistered
> > their signal handlers, and the Platform should probably be the last thing
> > destroyed since it doesn't depend on any other objects.
> 
> We still leak some singletons. Let's fix that first, before destroying
> NMPlatform too. danw/gdbus-bgo622927 has some relevant changes for NMManager
> there...

Added another fixup, removing the @register_destruction singleton. NMPlatform is still leaked, but there is a FIXME comment.
Other advantage: we log now a line: "disown NMPlatform instance" which indicates the leakage too.
Comment 13 Dan Williams 2015-08-05 13:24:09 UTC
LGTM