Bug 907041

Summary: Incomplete tmux path patch
Product: [openSUSE] openSUSE Tumbleweed Reporter: Marcus Rückert <mrueckert>
Component: OtherAssignee: Cristian Rodríguez <crrodriguez>
Status: RESOLVED FIXED QA Contact: E-mail List <qa-bugs>
Severity: Normal    
Priority: P5 - None CC: forgotten_cAXlJ_FoSf
Version: NO 13.2 BUGS!!   
Target Milestone: ---   
Hardware: Other   
OS: Other   
Whiteboard:
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---

Description Marcus Rückert 2014-11-25 10:46:44 UTC
I started a tmux session from the text console and then tried to reattach it with in gnome-terminal:

```
$ pgrep -U darix tmux
2355
$ strace -fF -s 1024 -o tmux.strace.txt tmux attach
no sessions
$ grep -c /run/tmux tmux.strace.txt
0
$ grep -c /tmp/tmux tmux.strace.txt
12
# it cant be environment variables either.
$ env | grep -ci tmux
0
```

To me it looks like your patch is incomplete.
Comment 1 Marcus Rückert 2014-11-25 10:48:58 UTC
export TMUX_TMPDIR="/run/tmux/$(id -u)/"

is a workaround for now.
Comment 2 Cristian Rodríguez 2014-11-25 15:04:02 UTC
reproduced.. what the...
Comment 3 Cristian Rodríguez 2014-11-25 18:36:34 UTC
Hrmmm... looks like we are dealing with a tmux bug triggered by this change...all functions that want the tmux socket call makesocketpath() 

which says..

char *
makesocketpath(const char *label)
{
...
   uid = getuid();
    if ((s = getenv("TMUX_TMPDIR")) != NULL && *s != '\0')
     xsnprintf(base, sizeof base, "%s/", s); 
else if ((s = getenv("TMPDIR")) != NULL && *s != '\0')
xsnprintf(base, sizeof base, "%s/tmux-%u", s, uid);
 else
xsnprintf(base, sizeof base, "%s/tmux-%u", _PATH_TMP, uid);


I only modified the fallback.. case.. to 

xsnprintf(base, sizeof base, "/run/tmux/%u", uid);

But in the case of this bug, the first session (in the real console) is created in /run/tmux/$uid as expected but when you try to attach to the existent session a new one is created in /tmp/tmux-$uid ..this is because in the desktop terminal emulator $TMPDIR is set.. le sigh...
Comment 4 Cristian Rodríguez 2014-11-25 18:50:49 UTC
request id 263031 should address this issue by not taking into consideration TMPDIR environment variable..which may be unset in real console but set in a virtual terminal../run/tmux is always available till the machine is shutdown anyway.
Comment 5 Forgotten User cAXlJ_FoSf 2014-11-25 19:47:48 UTC
I don't really like this, it's even more deviating from upstream behavior and somewhat unexpected for people like me who set TMPDIR and expect tmux to obey that.

@Marcus:
So you have TMPDIR set to /tmp but only for the shell you start in a terminal emulator, and if so why since /tmp should the default anyway? Note that this is documented and expected behavior in tmux and only worked previously by coincidence because TMPDIR and the fallback /tmp were the same.
Comment 6 Marcus Rückert 2014-11-25 20:15:28 UTC
while it might be that it was only working by accident in the past. but the accident were our default settings.
Comment 7 Cristian Rodríguez 2014-11-25 20:42:34 UTC
(In reply to Marcus Rückert from comment #6)
> while it might be that it was only working by accident in the past. but the
> accident were our default settings.

Correct, because in either case the socket was created in /tmp .. as TMPDIR is set to /tmp in the desktop environment.. but if it was not , it used to fallback to /tmp and everything worked by accident..
Comment 8 Forgotten User cAXlJ_FoSf 2014-11-25 20:48:15 UTC
(In reply to Marcus Rückert from comment #6)
> while it might be that it was only working by accident in the past. but the
> accident were our default settings.

Well, it goes both ways, not obeying TMPDIR any more is an unexpected change just as well. My question remains, why would you set TMPDIR differently depending on the login method, that sounds like a recipe for breakage, and why set it at all if it only points to /tmp?
Comment 9 Forgotten User cAXlJ_FoSf 2014-11-25 21:05:34 UTC
OK, I had not noticed that TMPDIR=/tmp is a default because I always override it on all my boxes, it comes from /etc/X11/xdm/Xsession.

@Werner:
Why is TMPDIR actually set to /tmp in /etc/X11/xdm/Xsession? And, if it is actually needed by anything can we move that to /etc/profile so that it is at least consistent independent of the login method?
Comment 10 Dr. Werner Fink 2014-12-03 09:38:03 UTC
(In reply to Guido Berhoerster from comment #9)

> Why is TMPDIR actually set to /tmp in /etc/X11/xdm/Xsession? And, if it is 
> actually needed by anything can we move that to /etc/profile so that it is at 
> least consistent independent of the login method?

TMPDIR is used to make sure that all tools used in /etc/X11/xdm/Xsession do use it. We might reset it before we execute the final user scripts/shell in the shell function exec_login()
Comment 11 Forgotten User cAXlJ_FoSf 2014-12-03 09:46:22 UTC
(In reply to Dr. Werner Fink from comment #10)
> (In reply to Guido Berhoerster from comment #9)
> 
> > Why is TMPDIR actually set to /tmp in /etc/X11/xdm/Xsession? And, if it is 
> > actually needed by anything can we move that to /etc/profile so that it is at 
> > least consistent independent of the login method?
> 
> TMPDIR is used to make sure that all tools used in /etc/X11/xdm/Xsession do
> use it. We might reset it before we execute the final user scripts/shell in
> the shell function exec_login()

OK, I'll take care of that.
Comment 12 Stefan Dirsch 2014-12-15 14:55:57 UTC
SR #263801 accepted.