ubase

mirror of https://git.suckless.org/ubase
Log | Files | Refs | README | LICENSE

commit f606172e5551744a70a4d537488e1d08f6ca9f08
parent a570a80ed1606bed43118cb148fc83c3ac22b5c1
Author: mrgrouse <mrgrouse@mrgrouse.com>
Date:   Fri,  5 Dec 2025 15:36:00 -0500

login.c: create XDG_RUNTIME_DIR on login

Diffstat:
Mlogin.c | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/login.c b/login.c @@ -12,6 +12,8 @@ #include <unistd.h> #include <utmp.h> +#include <sys/stat.h> + #include "config.h" #include "passwd.h" #include "util.h" @@ -119,6 +121,27 @@ main(int argc, char *argv[]) writeutmp(user, tty); + /* === begin our compensations === */ + + // Source - https://stackoverflow.com/a + // Posted by user2622016, modified by community. See post 'Timeline' for change history + // Retrieved 2025-11-28, License - CC BY-SA 4.0 + int length = snprintf( NULL, 0, "%d", uid); + char* str = malloc( length + 1 ); + snprintf( str, length + 1, "%d", uid); + + char rtdir[] = "/run/user/"; // prefix to our XDG_RUNTIME_DIR + + strcat(rtdir, str); // concatenating our uid onto the prefix + + if (mkdir(rtdir, 0755) < 0) + eprintf("mkdir:"); + if (chown(rtdir, uid, gid) < 0) + eprintf("chown:"); + free(str); + + /* === end our compensations === */ + if (initgroups(user, gid) < 0) eprintf("initgroups:"); if (setgid(gid) < 0)