Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

The XDG Base Directory Specification is a very interesting spec for user directories. It also provides good default values, except for XDG_RUNTIME_DIR.

Now I am writing a software that needs to create named pipes. It is a per-user client-server framework (there is a FIFO for the server and a FIFO per client).

If XDG_RUNTIME_DIR is not defined, I am currently using a per-user subdirectory in /tmp — but it does not ensure all the specified conditions (viz. the paragraph starting with "The lifetime of the directory MUST be bound to the user being logged in…")

Is /tmp/myserver-$USER good enough?

Edit

I saw elsewhere a few suggestions:

  • . is quite unsatisfactory (at least because it is not an absolute path).
  • I also saw /var/run/user/$USER — not bad, but that directory does not exist (at least on my box running a Debian testing)
share|improve this question

2 Answers 2

up vote 2 down vote accepted

/tmp is used by plenty of programs in a similar way already. On my system I can see the /tmp/orbit-$USER (used by Gnome's ORBit2) and /tmp/.X11-unix/ (Xorg and X11) directories with plenty of pipes, ehm, sockets, in them. I am sure there are also others, so I see nothing wrong with what you are doing. Just be prepared that since it is a world writeable location a malicious process can hijack the location (verify the permissions before you write to it).

I can also recommend $TMPDIR for those who use pam_mktemp, as this directory is only accessible by the user.

share|improve this answer
    
PAM is the right solution, thanks! On Debian it is called libpam-tmpdir –  cadrian Jun 3 '12 at 7:23
    
sorry for the lost bounty... :-( –  cadrian Jun 3 '12 at 7:23

Create directory /tmp/service-$USER.id with unique id. For exsmple, in shell:

mktemp -d /tmp/service-"$USER".XXX
share|improve this answer
1  
How do you ensure the requirement that the same directory is used from the first login to the last logout of the user? –  cadrian Jun 1 '12 at 13:10
    
Hmmm... create symlink ~user/.service/tmp_dir. If linked directory does not exist, create new –  Selivanov Pavel Jun 2 '12 at 1:05

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.