![]() |
Paths, directories and settings at boot time | ![]() |
The order of the boot steps is described in the main program and crash handling. This page describes what the steps which concern the system layer do: finding the installation, setting the environment variables which all search paths are built from, creating the user directories, managing temporary directories, and keeping the settings file. The code is in
System/Boot/init_texmacs.cpp
,
init_upgrade.cpp
,
Texmacs/Texmacs/texmacs.cpp
and the entry points of the platform layers.
$TEXMACS_PATH is the directory with the Scheme code, styles, fonts and documentation of the installation (in the source tree,
src/TeXmacs
). It is determined in two places:
The main functions of
Plugins/Unix
and
Plugins/Windows64
call setup_texmacs_path. If TEXMACS_PATH is set and valid, it is kept. Otherwise the function tries directories relative to the executable (texmacs_get_application_directory): on macOS ../Resources/share/TeXmacs inside a bundle, then TeXmacs next to the executable, the parent directory, and (on Unix) usr/share/TeXmacs, usr/local/share/TeXmacs, ../usr/share/TeXmacs, /usr/share/TeXmacs and /usr/local/share/TeXmacs. The first valid one becomes TEXMACS_PATH. A directory is valid for test_texmacs_path if it contains doc, fonts, progs, styles and a file SVNREV whose contents equal ALTERNATIVE_VERSION (the version series, such as 2.1., read from src/TeXmacs/SVNREV at build time). This prevents an executable from silently running with the files of another TeXmacs version.
TeXmacs_init_paths in
texmacs.cpp
then handles bundles: on macOS it sets TEXMACS_PATH to ../Resources/share/TeXmacs if it is still unset, adds the bundle's Plugins, Frameworks and Resources/lib directories to the Qt plug-in path and the dynamic library paths, and appends the PATH of a login shell (obtained by running $SHELL -l -c 'echo $PATH') and the bundle's bin directory to PATH; on Windows it uses the parent of the executable's directory and sets PWD if it is missing or comes from a Unix environment (Wine); on Haiku it uses ../data/TeXmacs. If TEXMACS_PATH still does not exist, the program exits.
The shell script misc/scripts/texmacs used by Unix installations sets TEXMACS_PATH and TEXMACS_BIN_PATH before starting texmacs.bin, and puts $TEXMACS_BIN_PATH/bin and $TEXMACS_BIN_PATH/lib in front of the search paths.
$TEXMACS_HOME_PATH is the user's directory: it defaults to ~/.TeXmacs, to %APPDATA%\TeXmacs on Windows and to ~/config/settings/TeXmacs on Haiku, and is set by immediate_options if it is not set in the environment (init_main_paths repeats the test later). The server certificates directory TEXMACS_SERVER_CERT_DIR defaults to $TEXMACS_HOME_PATH/server.
Most search paths of TeXmacs are environment variables, so that they can be overridden from outside and are inherited by plug-ins. init_guile and init_env_vars set them, keeping the value given in the environment where noted. Each path includes the corresponding directory of every installed plug-in, as computed by plugin_path (sub), which searches $TEXMACS_HOME_PATH, /etc/TeXmacs, $TEXMACS_PATH and /usr/share/TeXmacs for plugins/*/sub.
$TEXMACS_PATH/progs, the previous value, $TEXMACS_HOME_PATH/progs and the progs directories of plug-ins.
init-texmacs.scm
must be found in the first two, or the boot fails.
The previous value followed by the plug-ins' bin and lib directories; on Windows and macOS also $TEXMACS_PATH/bin; the manual path preference is put in front.
The roots for style files and packages (user directory, installation, plug-ins), and all their subdirectories. Kept if set.
The same for the texts directories. Kept if set.
The text and style paths. Kept if set.
The previous value followed by $TEXMACS_HOME_PATH/doc, $TEXMACS_PATH/doc and the plug-ins' doc directories.
The previous value followed by $TEXMACS_PATH and $TEXMACS_HOME_PATH; see is_secure in URLs.
Background patterns, icons, dictionaries and themes. Kept if set.
The source directory given at build time (empty on Windows).
Because URLs expand environment variables when they are constructed (URLs), code which builds search paths must run after init_env_vars. init_misc finally checks whether the shell command which works (use_which), which resolve_in_path relies on.
init_user_dirs creates the directory tree of $TEXMACS_HOME_PATH if needed: bin, doc, fonts (with subdirectories for the various font formats and for fonts that failed to load), langs, misc, packages, plugins, progs, server, styles, system (with bib, cache, certificates, database, make and tmp), texts (with backup and scratch) and users. The directories server, system and users are made accessible to the user only (mode 0700). The other files in system include settings.scm (below), preferences.scm (see preferences) and the boot lock.
Each process uses its own temporary directory, $TEXMACS_HOME_PATH/system/tmp/pid, returned by url_temp_dir. At the end of init_user_dirs, clean_temp_dirs removes the directories of processes which are no longer running: for every numeric entry of system/tmp, it runs ps -p pid and deletes the directory with rm -rf unless the output mentions both texmacs and the process number (process_running). On 32-bit Windows the directories are named after the start time instead, and are removed after seven days. Other entries of system/tmp, such as tree_cache (the cache of the remote file system) or the previews of the print dialog, are left alone.
$TEXMACS_HOME_PATH/system/settings.scm holds the tuple texmacs_settings of pairs (variable, value), read and written with get_setting and set_setting. Its only systematic entry is VERSION. init_plugins (called from TeXmacs_main) reads it:
If there is neither settings.scm nor the file TEX_PATHS of very old versions, this is a first run: setup_texmacs creates the settings file (also running the TeX font setup setup_tex) and install_status is set to 1, which makes the welcome message appear.
If the recorded version differs from the current one, init_upgrade recreates the settings, renames the user initialization files of very old versions, removes the style, file, documentation, directory and attribute caches, the font database files and the font error files, and reloads the cache. For upgrades from versions up to 1.0.7.9 it also assembles a document with the list of changes, in which case install_status is 2.
The boot lock, system/boot_lock, is created by acquire_boot_lock during init_texmacs and removed by release_boot_lock just before the event loop starts. If it is found at startup, the previous run crashed while booting, and the settings, the setup file, the caches and the font error files are removed.
process_running looks for the lower case word texmacs in the output of ps (
System/Boot/init_texmacs.cpp:151
). The executable of the macOS bundle is …/TeXmacs.app/Contents/MacOS/TeXmacs, which does not contain it. A running bundled instance is therefore considered dead, and any other instance which starts later (another bundle instance, or a texmacs.bin -headless run sharing the same $TEXMACS_HOME_PATH) deletes its temporary directory, and with it the temporary files it is using (downloads, conversions, previews). For example, with the bundle running as process 1665, ps -p 1665 prints /Applications/TeXmacs.app/Contents/MacOS/TeXmacs.
On Unix, texmacs_get_application_directory returns the directory of the executable, except when TEXMACS_BIN_PATH is set: then it returns the parent of $TEXMACS_BIN_PATH, which the launcher script sets to the installation directory (the one containing bin), so the two cases differ by two levels. On Unix systems other than Linux and macOS, without TEXMACS_BIN_PATH, the function reaches its end without a return statement (Plugins/Unix/unix_system.cpp:210-230), which is undefined behaviour.
On macOS, every start runs a login shell to obtain the user's PATH; a slow shell initialization slows down the start of TeXmacs accordingly.
setup_texmacs_home_path in
Plugins/Windows64/windows64_entrypoint.cpp
(which would use the local application data directory) is never called; the home directory on Windows is the roaming %APPDATA%\TeXmacs set by immediate_options.