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 563627 - g_get_prgname() threadsafety
g_get_prgname() threadsafety
Status: RESOLVED WONTFIX
Product: glib
Classification: Platform
Component: general
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Sven Herzberg
gtkdev
Depends on:
Blocks: 603774
 
 
Reported: 2008-12-08 03:12 UTC by Behdad Esfahbod
Modified: 2010-02-02 17:40 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed patch v1 (1.26 KB, patch)
2009-10-23 12:51 UTC, Sven Herzberg
none Details | Review

Description Behdad Esfahbod 2008-12-08 03:12:48 UTC
The docs for g_set_prgname() say: "Note that for thread-safety reasons this function can only be called once."   However, the code doesn't enforce that.  So a string obtained using g_get_prgname() can later be freed if g_set_prgname() is called again.

I suggest g_set_prgname() do a g_return_if_fail (prgname == NULL);
Comment 1 Sven Herzberg 2009-10-23 12:34:14 UTC
We should use something like g_once() actually, to make sure we don't introduce a race condition as described by your proposal.
Comment 2 Sven Herzberg 2009-10-23 12:51:38 UTC
Created attachment 146099 [details] [review]
proposed patch v1
Comment 3 Tim Janik 2009-10-23 13:04:24 UTC
(In reply to comment #2)
> Created an attachment (id=146099) [details] [review]
> proposed patch v1

Looks good Sven, please apply.
Comment 5 Benjamin Otte (Company) 2009-10-28 20:11:39 UTC
make check fails in glib/tests/option-context now.
Comment 6 Tim Janik 2009-10-29 12:33:39 UTC
(In reply to comment #5)
> make check fails in glib/tests/option-context now.

Thanks Benjamin, seems g_option_context_parse() calls g_set_prgname() unconditionally. This needs to be fixed as well, i.e.:
- g_option_context_parse shouldn't override a prgname if has been previously set by an applicaiton (i.e. it should only set the prgname if it's unset).
- programs might validly change the prgname that has been set by g_option_context_parse, which means that g_set_prgname() needs to be callable more than once. So we'll have to revert the patch. Please note that because g_option_context_parse() calls g_set_prgname(), we have also broken applications that currently do:
main() {
  g_option_context_parse (...);
  g_set_prgname (...);
Comment 7 Andrew Cowie 2009-12-04 09:04:19 UTC
The check inhibiting use of g_set_prgname() just turned up in Glib 2.22.3; but Tim's suggestion that 

> - programs might validly change the prgname that has been set by
> g_option_context_parse, which means that g_set_prgname() needs to be callable
> more than once.

seems not to work anymore. Does that mean that the only correct behaviour is to call g_set_prgname() before [say] gtk_init()?

AfC
Comment 8 Benjamin Otte (Company) 2009-12-04 09:08:30 UTC
We likely need to back out the current patch because it's causing warnings in too many programs and breaks the testsuite.
And apparently there hasn't been any progress to resolve the issue otherwise.
Comment 9 Tim Janik 2009-12-04 10:23:50 UTC
(In reply to comment #8)
> We likely need to back out the current patch because it's causing warnings in
> too many programs and breaks the testsuite.

It should simply be backed out to fix those cases.

> And apparently there hasn't been any progress to resolve the issue otherwise.

There's really no alternative to unbreak our API again.
Comment 10 Jan D. 2009-12-04 13:32:01 UTC
I don't know if you have taken this into account, but note that any gtk-program that has --name <name> in its argument list will get the warning about g_set_prgname() called multiple times when gtk_init is called.

And this is all inside gtk_init, I don't know what an app should do to get around it.  Apparently Gdk has an option callback for --name that does g_set_progname.
Comment 11 Matthias Clasen 2009-12-04 22:47:26 UTC
Fwiw, I agree. I was quite surprised when I had to disable one of the option-context tests to fix make check, due to this change.
Comment 12 Matthias Clasen 2009-12-21 14:27:39 UTC
Reverted now.
Comment 13 Tim Janik 2009-12-22 09:28:57 UTC
(In reply to comment #12)
> Reverted now.

Thanks a lot, WONTFIXing this, since due to technical reasons we need g_get_prgname() to be callable multiple times.