chore: Resolve warning `gtk_disable_setlocale() must be called before gtk_init()`
Description
A warning is logged advising to explicitly opt-out of GTK setting the locale. This is relevant when you manage locale setting yourself (like open-vm-tools appears to):
# Generated service from `vmware-user.desktop` by `systemd-xdg-autostart-generator`:
$ systemctl --user status "app-vmware\[email protected]"
vmtoolsd[947]: gtk_disable_setlocale() must be called before gtk_init()
# CLI command:
$ vmtoolsd -n vmusr --blockFd 3
Gtk-WARNING **: 17:53:50.082: gtk_disable_setlocale() must be called before gtk_init()
Reasoning
GTK docs gtk_disable_setlocale():
Prevents
gtk_init(),gtk_init_check(),gtk_init_with_args()andgtk_parse_args()from automatically callingsetlocale(LC_ALL, ""). You would want to use this function if you wanted to set the locale for your program to something other than the user’s locale, or if you wanted to set different values for different locale categories.Most programs should not need to call this function.
A grep for locale shows quite a bit of explicit handling by open-vm-tools codebase, including setting setlocale(LC_ALL, "") itself. Here's an example for vmtoolsd:
https://github.com/vmware/open-vm-tools/blob/ed34acd62f67aceace5f28d214dc8e47b6e35691/open-vm-tools/services/vmtoolsd/mainPosix.c#L196
NOTE: I've not compiled this change to verify. I've just seen it present over the years and thought I'd look into it and provide a PR that should resolve it. There is no harm with ignoring the warning AFAIK, the PR would just resolve some log noise that I've seen contribute some confusion to users that notice it while troubleshooting.
@polarathene Thanks for your contribution. Your contribution will go through a review process at VMware. An update will be provided once the review is completed.
@jonathanvmw friendly ping. Is a review still in the works?
@polarathene
Thanks for the ping. I'm following up internally to try to get you an update. I'll also follow up on the two other issues you highlighted (#670 and #668) - hope to get you some feedback in the next couple of weeks.
hope to get you some feedback in the next couple of weeks.
Friendly ping @jonathanvmw any updates?
@polarathene Hey, We compiled the change and tried it on Ubuntu focal 20.04, but after that we could see the same warning coming up. So we are suspecting single 1 liner change is not complete fix for this.
So we are suspecting single 1 liner change is not complete fix for this.
That's unfortunate, no worries, should this issue be closed or is it something that'll continue to be looked into?
https://github.com/vmware/open-vm-tools/pull/668 is probably fine to address in the meantime?