[haiku-bugs] Re: [Haiku] #18130: XDG_* variables: getenv() gets different results if app is run from a console or from GUI

  • From: "Haiku" <trac@xxxxxxxxxxxx>
  • To: undisclosed-recipients: ;
  • Date: Sun, 11 Dec 2022 21:36:42 -0000

#18130: XDG_* variables: getenv() gets different results if app is run from a
console or from GUI
------------------------+-------------------------
  Reporter:  bipolar    |      Owner:  nobody
      Type:  bug        |     Status:  new
  Priority:  normal     |  Milestone:  Unscheduled
 Component:  - General  |    Version:  R1/beta4
Resolution:             |   Keywords:
Blocked By:             |   Blocking:
  Platform:  All        |
------------------------+-------------------------
Description changed by bipolar:

Old description:

Many ported software makes use of the XDG_* variables ("XDG_CONFIG_HOME",
"XDG_DATA_DIRS", etc).

Haiku currently exports those from `etc/profile.d/xdg_basedirs.sh`.

The problem is that `getenv()` gives different results if the app is
launched from a Terminal window, or by double clicking in it, for
example. It gets the proper values in the first case, and NULL on the
latter.

Will attach a very basic example app (please excuse the poor code) that
exhibits this behavior.

Over haikuports this is currently fixed for many apps by directly
patching them, but the fix seems to be simpler... as hinted by Pulkomandy
[https://github.com/haikuports/haikuports/commit/655df3db34b268cb4b2c5947f1dfe323d9a7a1d6
here]:

just source `etc/profile.d/xdg_basedirs.sh` from, for example,
`~/config/settings/boot/UserSetupEnvironment`.

To be explicit, adding the following on said file:

{{{
source /boot/system/settings/etc/profile.d/xdg_basedirs.sh
}}}

After doing that, and a reboot, the attached test case app shows the
expected/correct behavior.

Should this be enough/valid for ported apps (instead of individual app
patching), or am I missing something else?

Should `/system/boot/SetupEnvironment` contain a similar line, or the
"exports" should be moved there from the `xdg_basedirs.sh` file?

New description:

 Many ported software makes use of the XDG_* variables ("XDG_CONFIG_HOME",
 "XDG_DATA_DIRS", etc).

 Haiku currently exports those from `etc/profile.d/xdg_basedirs.sh`.

 The problem is that `getenv()` gives different results if the app is
 launched from a Terminal window, or by double clicking in it, for example.
 It gets the proper values in the first case, and NULL on the latter.

 Will attach a very basic example app (please excuse the poor code) that
 exhibits this behavior.

 Over haikuports this is currently fixed for many apps by directly patching
 them, but the fix seems to be simpler... as hinted by PulkoMandy
 
[https://github.com/haikuports/haikuports/commit/655df3db34b268cb4b2c5947f1dfe323d9a7a1d6#commitcomment-92156775
 here]:

 just source `etc/profile.d/xdg_basedirs.sh` from, for example,
 `~/config/settings/boot/UserSetupEnvironment`.

 To be explicit, adding the following on said file:

 {{{
 source /boot/system/settings/etc/profile.d/xdg_basedirs.sh
 }}}

 After doing that, and a reboot, the attached test case app shows the
 expected/correct behavior.

 Should this be enough/valid for ported apps (instead of individual app
 patching), or am I missing something else?

 Should `/system/boot/SetupEnvironment` contain a similar line, or the
 "exports" should be moved there from the `xdg_basedirs.sh` file?

--
-- 
Ticket URL: <https://dev.haiku-os.org/ticket/18130#comment:5>
Haiku <https://dev.haiku-os.org>
The Haiku operating system.

Other related posts: