Hello,

Please find below a proposal to add a configuration package to centralize environment variables definitions (and a little more).

Best Regards,

Stéphane

--
Stéphane Desneux
Intel OTC - Vannes/FR





Tizen 3.x: per-profile paths/environment configuration
======================================================

This is a proposal to have a unique package that defines how the environment 
variables are made available to an application running in userland.

* 1 source package per profile 
  - naming proposal: 'tizen-env-$profile' (ex: tizen-env-mobile, tizen-env-ivi 
...)
  - could be made updatable by an oem for device customization

* 1 main source file (in any convenient format: sh-like, yaml, xml, json, ini 
...)
  2 kinds of variables reserved for Tizen:
  - system variables (paths are absolute here): TZ_SYS_XXXXX
  - user variables (relative to user home dir at definition time): 
TZ_USER_REL_XXXXXX

  other user/system variables not related to paths could be defined too...
  
  Example:
     TZ_SYS_DB="/var/db" for global databases dir
     TZ_USER_REL_DB=".tizen/db" for user database dir (relative to user home 
dir)
     TZ_USER_DB="/home/<username>/.config/db" : the user variable not defined 
but resolved at runtime

* 2 generated binary packages:
  - binary package tizen-env-$profile-devel would contain:
    => /usr/include/tizen-env.h
       ...
       /* for global static paths: */
       static const char *TZ_SYS_DB="/var/db";
       ...
       /* for user specific paths, use TZ_USER_REL_XXXXX naming: */
       static const char* TZ_USER_REL_DB="db"; 
       ...
       /* no expanded user varisbles TZ_USER_XXX as they will be resolved at 
runtime with getenv() */

    => /usr/share/pkgconfig/tizen-env.pc
       allows the use of system paths at build time (without using the header)

    => do we add a helper that could be used in other source files ? For 
example, a wrapper around getenv() that would do the job in particular for user 
variables to be resolved at runtime (depends on uid, username, home dir etc.):
       const char* tzgetenv(const char* name) {
          ... if name is a TZ_XXX variable, resolve it with tizen-env.h header 
definitions (use the real env variable or not)
          ... else return getenv() result
       }
    => the same helper can be coded in python, javascript ... or any language 
which has a way to access to environment variables

  - binary package tizen-env-$profile containing "sourceable" files which could 
be located in different places:
    => /etc/environment (sourced by pam)
    => /etc/profile.d/tizen-env.sh (sourced by any login shell)
    => /etc/tizen-env.py
    => /etc/tizen-env.ini (section [system], [user] ...)
    => ... other suitable formats (json, XML, ...) and places if needed


Variables to be set in app environment
--------------------------------------
* Historical vars: HOME, TERM, SHELL, USER, LOGNAME, LANG, PATH ...
* XDG variables:
    - XDG_SESSION_ID
    - XDG_RUNTIME_DIR
    - XDG_CONFIG_DIRS
    - XDG_DATA_DIRS
    - ...
* daemon specific vars:
    - DISPLAY
    - WAYLAND_DISPLAY
    - DBUS_SESSION_BUS_ADDRESS
    - ...
* "Tizen vars" set by a file installed by tizen-env-$profile:
  - global static paths
    . TZ_SYS_HOME : the directory containing the home dirs
    . TZ_SYS_DB: database directory
    . TZ_SYS_CONFIG: vconf directory
    . TZ_SYS_CONFIG_VOLATILE: vconf directory (for volatile files AKA 'memory' 
vconf)
    . TZ_SYS_APP: applications install dir
    . TZ_SYS_DESKTOP_APP: desktop files dir
  - user paths, resolved as relative to user home dir
    . TZ_USER_DB: user database dir
    . TZ_USER_CONFIG: user vconf dir
    . TZ_USER_APP: user applications dir
    . TZ_USER_DESKTOP_APP: user desktop files dir
    . TZ_USER_DOCUMENTS: user documents dir
    . TZ_USER_PICTURES: user pictures dir
    . TZ_USER_VIDEOS ...
    . TZ_USER_MUSIC
    . TZ_USER_DOWNLOADS
    . TZ_USER_PUBLIC: shared content
    . ...
   - other global variables TZ_SYS_???
   - other user variables TZ_USER_???

* to be completed


Tizen variables compatibility
-----------------------------

Initially, when applications won't have migrated yet, we could use Tizen 2.X 
compatible values for smooth transition (*PATHS VALUES MUST BE CONFIRMED FROM 
ACTUAL IMAGES*):
  TZ_SYS_HOME=/opt/home
  TZ_SYS_DB=/opt/dbspace
  TZ_SYS_CONFIG=/opt/var/kdb
  TZ_SYS_CONFIG_VOLATILE=/opt/var/kdb
  TZ_SYS_APP=/opt/apps
  TZ_SYS_DESKTOP_APP=/opt/share/applications
  TS_USER_DB=../../opt/usr/dbspace
  TZ_USER_CONFIG=../../opt/var/kdb 
  TZ_USER_APP=../../opt/usr/apps 
  TZ_USER_DESKTOP_APP=../../usr/share/applications
  TZ_USER_DOCUMENTS=../../opt/home/app/Documents
  TZ_USER_PICTURES=../../opt/home/app/Pictures
  TZ_USER_VIDEOS=../../opt/home/app/Videos
  TZ_USER_MUSIC=../../opt/home/app/Music
  TZ_USER_DOWNLOADS=../../opt/home/app/Downloads
  TZ_USER_PUBLIC=../../opt/home/app/Public
  ...
=> new (migrated) apps will use the variables and old (non-migrated) ones will 
still have their hardcoded paths. As they're identical, this will probably 
ensure a smooth transition.

Tizen 3.x values with multiuser up (*paths are just given as examples, this is 
not a proposal for the paths*):
  TZ_SYS_HOME=/home 
  TZ_SYS_DB=/var/db
  TZ_SYS_CONFIG=/var/kdb
  TZ_SYS_CONFIG_VOLATILE=/run/kdb
  TZ_SYS_APP=/usr/apps
  TZ_SYS_DESKTOP_APP=/usr/share/applications
  TS_USER_DB=<user_homeid>/.tizen/db 
  TZ_USER_CONFIG=<user_home_dir>/.tizen/kdb
  TZ_USER_APP=<user_home_dir>/.tizen/apps
  TZ_USER_DESKTOP_APP=<user_home_dir>/.tizen/desktop
  TZ_USER_DOCUMENTS=<user_home_dir>/Documents
  TZ_USER_PICTURES=<user_home_dir>/Pictures
  TZ_USER_VIDEOS=<user_home_dir>/Videos
  TZ_USER_MUSIC=<user_home_dir>/Music
  TZ_USER_DOWNLOADS=<user_home_dir>/Downloads
  TZ_USER_PUBLIC=<user_home_dir>/Public
  ...
=> when this new configuration will be set up, non-migrated apps will (MUST?) 
fail.


Variables initialization
------------------------

A good place to initialize the environment variables is the PAM session start. 
This could be done by a PAM module I proposed to write (previously this month: 
https://lists.tizen.org/pipermail/dev/2013-October/000363.html).

This module would read the global configuation file containing the definitions 
(TZ_SYS_??? and TZ_USER_REL_??? vars) and create the appropriate env vars in 
the session.

In particular, the TZ_USER_XXX variables are always built from the user home 
dir and the relative variable TZ_USER_REL_XXX. So we have multiple choices to 
build the user vars because we can write our own home and username resolution: 
the user home directoy can be resolved with:
- $HOME (if set)
- $HOME/${getpwent()->pw_name}
- $TZ_SYS_HOME/$USER (if $USER is set)
- $TZ_SYS_HOME/${getpwent()->pw_name}
- ${getpwent()->pw_dir}/${getpwent()->pw_name}

The last one is the most secure, but this supposes that the users will be 
created in the appropriate dir (the user creation module MUST use the tizen-env 
config file and the TZ_SYS_HOME definition, or be compiled with tizen-env-devel 
!).


_______________________________________________
Dev mailing list
[email protected]
https://lists.tizen.org/listinfo/dev

Reply via email to