Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
What's reponsible of creating /run/user/<UID>
View unanswered posts
View posts from last 24 hours

Goto page 1, 2  Next  
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Sat Jun 12, 2021 3:29 pm    Post subject: What's reponsible of creating /run/user/<UID> Reply with quote

On my OpenRC based system I only have directory 0 for root, but nothing for other users.
Which program is responsible for creating all the user directories under /run/user/? Some programs assume those user directories are created and will fail if there's none.

Do others have similar problems?
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6335
Location: Dallas area

PostPosted: Sat Jun 12, 2021 3:44 pm    Post subject: Reply with quote

Nope. :lol:

Edit to add: but then again I'm running an old (ancient?) version of openrc.

As far as the run dir, gnome takes care of it when it's running, I believe that kde does also, and maybe some of the dm's might.

Me, I just manually created mine over in /tmp, not /run (personal choice) and set XDG_RUNTIME_DIR=<dir name> appropriately.
_________________
UM780, 6.14 zen kernel, gcc 13, openrc, wayland


Last edited by Anon-E-moose on Sat Jun 12, 2021 3:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1924
Location: South America

PostPosted: Sat Jun 12, 2021 3:48 pm    Post subject: Re: What's reponsible of creating /run/user/<UID> Reply with quote

Zucca wrote:
Which program is responsible for creating all the user directories under /run/user/?

elogind, through PAM, when the corresponding user logs in.


Last edited by GDH-gentoo on Sat Jun 12, 2021 3:49 pm; edited 1 time in total
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6335
Location: Dallas area

PostPosted: Sat Jun 12, 2021 3:49 pm    Post subject: Re: What's reponsible of creating /run/user/<UID> Reply with quote

GDH-gentoo wrote:
Zucca wrote:
Which program is responsible for creating all the user directories under /run/user/?
elogind, through PAM, when the corresponding user logs in.


Nice to know. Not that I'm running *logind :lol:
_________________
UM780, 6.14 zen kernel, gcc 13, openrc, wayland
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Sun Jun 13, 2021 12:13 pm    Post subject: Reply with quote

Hm... The program I have problems with is dte. It tries to create lock file under /run/user/$UID and if the directory is missing then it opes files ro.

I smell a bug.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!


Last edited by Zucca on Sun Jun 13, 2021 1:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6082
Location: Removed by Neddy

PostPosted: Sun Jun 13, 2021 12:20 pm    Post subject: Reply with quote

Quote:
export XDG_RUNTIME_DIR=$(mktemp -d /tmp/$(id -u)-runtime-dir.XXX)


it will be a program explicitly wanting to write to XDG_RUNTIME_DIR with no ~/ fallback.
_________________
#define HelloWorld int
#define Int main()
#define Return printf
#define Print return
#include <stdio>
HelloWorld Int {
Return("Hello, world!\n");
Print 0;
Back to top
View user's profile Send private message
javeree
Guru
Guru


Joined: 29 Jan 2006
Posts: 461

PostPosted: Sun Jun 13, 2021 3:14 pm    Post subject: Reply with quote

@GDH-gentoo

Does that mean
* you login, this calls pam and pam calls logind
or
* you login, logind gets called (how?) and logind calls pam
?

I don't quite understand the role of logind, neither in what exactly it does nor whwhat it gets triggered by.
Back to top
View user's profile Send private message
Hu
Administrator
Administrator


Joined: 06 Mar 2007
Posts: 23629

PostPosted: Sun Jun 13, 2021 4:15 pm    Post subject: Reply with quote

When you log in, PAM is triggered. If so configured, PAM will load the pam_elogind.so module (or equivalent for systemd users). That PAM module will notify the running logind of your existence, and logind will do various privileged things on your behalf. According to one of the posts here (which I am taking on faith and not checking), one of those privileged things is creating the /run/user directory for you.
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1924
Location: South America

PostPosted: Sun Jun 13, 2021 7:43 pm    Post subject: Reply with quote

javeree wrote:
I don't quite understand the role of logind, neither in what exactly it does nor whwhat it gets triggered by.

What Hu said, but here's some more detail. For example, for a text UI login on some tty:

1) User logs in, program involved in that login (/bin/login) links to PAM libraries.
Code:
$ ldd /bin/login | grep pam
   libpam.so.0 => /lib64/libpam.so.0 (0x00007fd7cab1c000)
   libpam_misc.so.0 => /lib64/libpam_misc.so.0 (0x00007fd7cab17000)

2) Code in PAM libraries does what configuration files tell it to. Configuration files tell it to load module pam_elogind.so.

/etc/pam.d/login
Code:
session      include      system-local-login
/etc/pam.d/system-local-login
Code:
session      include      system-login
/etc/pam.d/system-login
Code:
-session        optional        pam_elogind.so

3) Code in PAM libraries calls function pam_sm_open_session() of pam_elogind.so:
Code:
$ nm -D --defined-only /lib64/security/pam_elogind.so
000000000000cf80 T pam_sm_close_session
000000000000b6c0 T pam_sm_open_session

4) Code in pam_elogind.so makes login connect to system-wide message bus and request elogind to create a session for the logged-in user:

Syslog:
Code:
authpriv.info: Jun 13 15:32:55 login[519]: pam_unix(login:session): session opened for user <my user> (uid=1000) by LOGIN(uid=0)
auth.info: Jun 13 15:32:55 elogind-daemon[462]: New session c3 of user <my user>.
dbus-monitor:
Code:
method call time=1623609175.560833 sender=:1.10 -> destination=org.freedesktop.login1 serial=2 path=/org/freedesktop/login1; interface=org.freedesktop.login1.Manager; member=CreateSession
   uint32 1000
   uint32 0
   string "login"
   string "tty"
   string "user"
   string ""
   string ""
   uint32 0
   string "tty1"
   string ""
   boolean false
   string ""
   string ""
   array [
   ]
signal time=1623609175.562498 sender=:1.1 -> destination=(null destination) serial=44 path=/org/freedesktop/login1; interface=org.freedesktop.login1.Manager; member=SessionNew
   string "c3"
   object path "/org/freedesktop/login1/session/c3"

5) As part of session creation, elogind creates the subdirectory of /run/user and mounts a tmpfs on it.

elogind-246.9.2/src/login/logind-user.c
Code:
int user_new(User **ret,
             Manager *m,
             UserRecord *ur) {
// ...
        if (asprintf(&u->runtime_path, "/run/user/" UID_FMT, ur->uid) < 0)
                return -ENOMEM;
// ...
}
elogind-246.9.2/src/login/user-runtime-dir.c
Code:
static int do_mount(const char *runtime_path, size_t runtime_dir_size, size_t runtime_dir_inodes, uid_t uid, gid_t gid) {
// ...
        return user_mkdir_runtime_path(runtime_path, uid, gid, runtime_dir_size, runtime_dir_inodes);
}
// ...
int user_runtime_dir(const char *verb, User *u) {
        int r = 0;
// ...
        if (streq(verb, "start"))
                r = do_mount(u->runtime_path, u->manager->runtime_dir_size, u->manager->runtime_dir_inodes,
                             u->user_record->uid, u->user_record->gid);
// ...
}
Back to top
View user's profile Send private message
javeree
Guru
Guru


Joined: 29 Jan 2006
Posts: 461

PostPosted: Sun Jun 13, 2021 10:27 pm    Post subject: Reply with quote

@GDH-gentoo

Thanks for that great rundown of what happens. this makes so much sense !
I wish many more topics were explained in this kind of fashion.
Kudos
Back to top
View user's profile Send private message
Goverp
Advocate
Advocate


Joined: 07 Mar 2007
Posts: 2276

PostPosted: Mon Jun 14, 2021 8:30 am    Post subject: Reply with quote

FWIW, here's a script I use for creating tempfiles, using /run/user/... or /tmp or whatever, as available:
Code:
### Print a temp filename, using $XDG_RUNTIME_DIR if poss, /run if root, else /tmp
Tempfile()
{       local id me dir
        id="$(id -n -u)"
        me="${0##*/}"

        if      [ "$id" = "root" ]
        then
                dir="${XDG_RUNTIME_DIR:-/run}"
                [ -d "$dir" ] || dir=""
                mktemp -p "$dir" "tmp.$me.XXXXXXXXXX"
        else    mktemp -p "${XDG_RUNTIME_DIR}" "tmp.$id.$me.XXXXXXXXXX"
        fi
}


Use it thus:
Code:
tmp=$(Tempfile)
echo "First line" > $tmp
echo "Second line >> $tmp
rm $tmp

_________________
Greybeard
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1924
Location: South America

PostPosted: Mon Jun 14, 2021 4:19 pm    Post subject: Reply with quote

Zucca wrote:
Hm... The program I have problems with is dte. It tries to create lock file under /run/user/$UID

Looking at the code, it uses:
  • The value of XDG_RUNTIME_DIR if the variable is set, otherwise
  • The value of DTE_HOME if the variable is set, otherwise
  • $HOME/.dte (and HOME better be set).
Is any of those set in the environment?
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Mon Jun 14, 2021 4:51 pm    Post subject: Reply with quote

GDH-gentoo wrote:
Is any of those set in the environment?
Code:
$ env | egrep 'RUNTIME|HOME'
HOME=/home/zucca
XDG_RUNTIME_DIR=/run/user/999
Hmmm...
Code:
ls /run/user/
0
... so something bit deeper is acting flaky.
This is on a "remote" machine aka. home server via ssh/mosh.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
GDH-gentoo
Veteran
Veteran


Joined: 20 Jul 2019
Posts: 1924
Location: South America

PostPosted: Mon Jun 14, 2021 9:23 pm    Post subject: Reply with quote

And does that home server have elogind installed? If yes, that's where I'd start troubleshooting.
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Tue Jun 15, 2021 6:32 am    Post subject: Reply with quote

Yeah. An elogind system.
I'll dig deeper after I get back from work.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Wed Jun 16, 2021 8:25 am    Post subject: Reply with quote

I grepped the logs for logind (in case elogind uses "logind" on logs) and error, warn etc... None.

I guess I'd need to log out from every remote session and try again.
... or create a temp user to debug this.

I'll get back when I have found something or given up if I haven't found anything.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Thu Mar 10, 2022 9:02 am    Post subject: Reply with quote

This came back to bite me. This time on my laptop and is affecting user root.

I could make a workaround in /etc/profile.d, which would check if XDG_RUNTIME_DIR does not exist, then unset XDG_RUNTIME_DIR.
Clearly elogind creates the directory because it sets the variable. But at some point the directory gets deleted. The only point when it should be deleted is when the last logout of the user happens. So maybe elogind falsely detects some logout as the last?
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Thu Mar 10, 2022 10:01 am    Post subject: hack Reply with quote

Ok. Here goes. Seems to be doing the thing. Might also break something. :D
Code:
# cat /etc/profile.d/zz_xdg_fixes.sh
#!/bin/sh

if [ "$XDG_RUNTIME_DIR" ] && [ ! -d "$XDG_RUNTIME_DIR" ]
then
        if tty -s
        then
                # Current terminal is connected to standard input.
                # We can inform the user about what we're doing.
                [ "$RC_GOT_FUNCTIONS" != "yes" ] && source /lib/gentoo/functions.sh
                ewarn "XDG_RUNTIME_DIR (${XDG_RUNTIME_DIR}) doesn't exist."
                einfo "Unsetting XDG_RUNTIME_DIR"
        fi
        unset XDG_RUNTIME_DIR
fi

_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6335
Location: Dallas area

PostPosted: Thu Mar 10, 2022 11:10 am    Post subject: Reply with quote

Wouldn't it be better in your .bash_profile instead of globally?

I use a script to start wayland and at the start I do a simple check and create the dir if needed. This is with openrc, not *logind

It's not the *logind that does the setting it's pam, if I remember correctly.
_________________
UM780, 6.14 zen kernel, gcc 13, openrc, wayland
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Thu Mar 10, 2022 6:17 pm    Post subject: Reply with quote

Anon-E-moose wrote:
Wouldn't it be better in your .bash_profile instead of globally?
XDG_RUNTIME_DIR being set, but the directory missing will cause harm no matter which user encounters it. And I've now witnessed this bug (if you can call it such) with UID 1000+n and 0.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6335
Location: Dallas area

PostPosted: Thu Mar 10, 2022 6:41 pm    Post subject: Reply with quote

Is pam installed, because the XDG_RUNTIME_DIR should be set and created by pam_elogind, if I'm not mistaken.

If you're trying to set it in more than one place, then you might have a problem like you're encountering.

How do you start wayland, script, DM, *-greetd?

What are your useflags for pambase, if installed.
_________________
UM780, 6.14 zen kernel, gcc 13, openrc, wayland
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Thu Mar 10, 2022 8:18 pm    Post subject: Reply with quote

I'm not setting XDG_RUNTIME_DIR in anywhere. The script above is only there for unsetting it is the directory does not exist.

The directories are normally there. For some reason root got its runtime dir deleted.

I'm currently using elogind and greetd+agreety on tty1 and agetty on other vts. I'm planning to write an init script for greetd+agreety for other vts too (display-manager init script doesn't do it).

pambase USE flags:
-caps
-debug
+elogind
+gnome-keyring
-homed
-minimal
-mktemp
+nullok
-pam_krb5
-pam_ssh
+passwdqc
-pwhistory
-pwquality
-securetty
+sha512
-systemd

_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Anon-E-moose
Watchman
Watchman


Joined: 23 May 2008
Posts: 6335
Location: Dallas area

PostPosted: Thu Mar 10, 2022 8:34 pm    Post subject: Reply with quote

Zucca wrote:
I'm not setting XDG_RUNTIME_DIR in anywhere. The script above is only there for unsetting it is the directory does not exist.

The directories are normally there. For some reason root got its runtime dir deleted.


Sounds like whatever starts the process thinks that root logged out and thus cleaned up,
probably something similar for your user, not sure what elogind/pam decides what a "session" truly is.

In my script that I use to start wayland, I had to add env to pass variables, they were being dropped otherwise
Code:
/usr/bin/env dbus-run-session -- /usr/bin/...

just not sure if that would help your case though.

Edit to add: post your config.toml file

ETA2: https://wiki.archlinux.org/title/Greetd might have more hints
or this https://man.sr.ht/~kennylevinsen/greetd/
_________________
UM780, 6.14 zen kernel, gcc 13, openrc, wayland
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Sat Mar 12, 2022 11:01 am    Post subject: Reply with quote

The problem here isn't relataed to greetd (most propably), since this also happened on my server earlier, which was accessed via ssh and locally only used agetty.
Also in this case root was logged in via tty2 using agetty. Then a tmux session was started and via normal user under wayfire I had su'd into the same tmux session. At some point root lost its runtime dir.
My server isn't online and even running atm. I'll try to get things going again during our spring cleanup.

Everything points into direction of elogind and pam.

/etc/greetd/config.toml:
[terminal]
vt = 1
[default_session]
command = "/etc/greetd/greet_wrapper.sh agreety"
user = "greetd"
... the script there basically displays a banner before execing agreety. If something other than agreety is requested, then skip displaying the banner and exec the greeter right away. But as I said before I don't have greetd in use on my server. However I can conduct tests avoiding tty1 where greetd is, but usinf other ttys where agetty runs. This way I can completely rule out greetd.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Zucca
Moderator
Moderator


Joined: 14 Jun 2007
Posts: 4197
Location: Rasi, Finland

PostPosted: Sun Mar 13, 2022 4:50 pm    Post subject: Reply with quote

I managed to reproduce the bug.
  • login as root on (I did on tty2):
    • start tmux session
    • see /run/user/0 being present
    • detach from tmux
    • logout
  • log in as other user:
    • see /run/user/0 gone
    • run su -lc 'tmux attach' and /run/user/0 still doesn't exist
I'd guess this happens also with other users than root too.
_________________
..: Zucca :..

My gentoo installs:
init=/sbin/openrc-init
-systemd -logind -elogind seatd

Quote:
I am NaN! I am a man!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum