[MONGOCRYPT-115] Expose a default system dependent PID file + domain socket location for mongocryptd Created: 29/Jul/19  Updated: 30/Mar/22

Status: Backlog
Project: Libmongocrypt
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Kevin Albertson Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by DRIVERS-2113 [FLE] Have drivers choose a default P... Backlog

 Description   

Expose functions like:

const char*
mongocrypt_default_pid_file_path (void);
 
const char*
mongocrypt_default_domain_socket_path (void);

Which returns the default PID file path a driver should use to spawn and connect to mongocryptd.

mark.benvenuto helpfully suggested the base logic per system:

MacOS

NSTemporaryDirectory()/mongocryptd.pid
https://developer.apple.com/documentation/foundation/1409211-nstemporarydirectory  

Linux

if $XDG_RUNTIME_DIR set:
   $XDG_RUNTIME_DIR/mongocryptd.pid
else if $XDG_DATA_HOME is set
  $XDG_DATA_HOME/mongocryptd.pid
else if $HOME
    $HOME/.local/share/mongocryptd.pid
else
   abort
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html  

Windows

%LOCALAPPDATA%\Temp\mongocryptd.pid 
 
Via FOLDERID_LocalAppData i.e. (%LOCALAPPDATA% (%USERPROFILE%\AppData\Local))
https://docs.microsoft.com/en-us/windows/desktop/shell/knownfolderid



 Comments   
Comment by Oleg Pudeyev (Inactive) [ 30/Jul/19 ]

For Linux, I don't think $XDG_DATA_HOME/mongocryptd.pid and $HOME/.local/share/mongocryptd.pid are appropriate. The "data" and "share" subdirectories are for immutable data like icons, fonts, readme files and such, not for sockets and pid files. These directories may also be read-only.

`/var/run` is the systemwide location for pid files, and https://www.freedesktop.org/software/systemd/man/file-hierarchy.html#Home%20Directory interestingly does not define `~/.local/var` at all. Therefore I would suggest:

if $XDG_RUNTIME_DIR set:
   $XDG_RUNTIME_DIR/mongocryptd.pid
else if $TMPDIR is set
  $TMPDIR/mongocryptd-$uid/mongocryptd.pid
else
    /tmp/mongocryptd-$uid/mongocryptd.pid

... where $uid is the user id of the logged in user. Note that this may yield two instances of mongocryptd if a user sometimes uses MongoDB drivers from within an X session and sometimes not, such as via an SSH login to the same machine.

Generated at Thu Feb 08 09:08:00 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.