Re: XDG_RUNTIME_DIR

2021-04-26 Thread RVP

On Mon, 26 Apr 2021, Steffen Nurpmeso wrote:


RVP wrote in
:
|
|Use POSIX shm_open+sem_open? That should let you do proper reference
|counting w/o a server. You'll have to pull in -lrt on Linux & NetBSD
|for this though...

Well, that module had (file-locked file-based) reference counting.
It will not work with programs backgrounding away, like tmux.
Unless you PAMify them all.  Even then.
Any shell script can background away.
You thus need a global authority collecting all per-user programs
that execve(2) away from a (child of a) program who enabled
a session, which was what i (who never looked into this, being



Yes. Programs which do exec will be a problem with PAM. Worse if
the program does daemon() then exec(). Then, even login won't be
able to keep track of them. It'll have to handled by init itself.
(We haven't even considered X11 programs here...)

We come back full circle to a sort-of systemd impl. it seems...

-RVP


Re: XDG_RUNTIME_DIR

2021-04-26 Thread RVP

On Mon, 26 Apr 2021, Steffen Nurpmeso wrote:


RVP wrote in
:
 ...
|There should be a removal of the dirs. on the user's final session
|logout, I think.

This is impossible to do with pam that i never liked (nor
understood, in FreeBSD ~twenty years ago),



Use POSIX shm_open+sem_open? That should let you do proper reference
counting w/o a server. You'll have to pull in -lrt on Linux & NetBSD
for this though...

-RVP


Re: XDG_RUNTIME_DIR

2021-04-26 Thread Steffen Nurpmeso
RVP wrote in
 :
 |On Mon, 26 Apr 2021, Steffen Nurpmeso wrote:
 |
 |> RVP wrote in
 |> :
 |>  ...
 |>|There should be a removal of the dirs. on the user's final session
 |>|logout, I think.
 |>
 |> This is impossible to do with pam that i never liked (nor
 |> understood, in FreeBSD ~twenty years ago),
 |>
 |
 |Use POSIX shm_open+sem_open? That should let you do proper reference
 |counting w/o a server. You'll have to pull in -lrt on Linux & NetBSD
 |for this though...

Well, that module had (file-locked file-based) reference counting.
It will not work with programs backgrounding away, like tmux.
Unless you PAMify them all.  Even then.
Any shell script can background away.
You thus need a global authority collecting all per-user programs
that execve(2) away from a (child of a) program who enabled
a session, which was what i (who never looked into this, being
a fan of runit or just nothing but SysV init or say OpenBSD, and
who never touched FreeBSD PAM stuff but just used what shipped)
would have expected .. it seems.  Because i was surprised to find
out that was not what was happening (and shouldn't it be nothing
but a single bit and some kind of notification).
I dislike all the people liking systemd for allowing exactly this.

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


Re: XDG_RUNTIME_DIR

2021-04-26 Thread Steffen Nurpmeso
RVP wrote in
 :
 |On Sat, 24 Apr 2021, Steffen Nurpmeso wrote:
 |
 |> If you run Linux you could also use the pam_xdg module i have
 |> written.  For example my /etc/pam.d/common-session is
 |>
 |>  session optional pam_xdg.so notroot
 |>
 |>  session requiredpam_unix.so quiet
 |>
 |> and the stuff is as attached.  It handles the other directories of
 |> the standard as well.
 |>
 |
 |This is, I presume, for Linux systems without systemd and pam_env.so?

systemd yes, pam_env no.  pam_env is pretty fat and does a lot of
things which are not needed here.  And of course it does not
create directories.

  ...
 |There should be a removal of the dirs. on the user's final session
 |logout, I think.

This is impossible to do with pam that i never liked (nor
understood, in FreeBSD ~twenty years ago), but CRUX gained it with
3.6, and i was right when looking from the code side.  'Thing is,
while doing this, i looked at code from login (of shadow) and all
that, and it is a pity if you see all the construction sites ..the
possibilities that have been buried there .. because of pam
.. because of systemd.  You rather look to some BSD with steady
iterations and improvements on login.conf or another mechanism.
I mean there is "finit", but that is a complicated mess also it
seems.  Yeah i mean, all this started because someone here was
using a server (written in R or another new/strange language that
came in as a depency) that was doing pam to do only the RUNDIR
part of the game.  But it is bitter, only the real unshare(1) with
a new PID 1 can do real book keeping, from user space.  I would
have expected actual support for this, yes.  Like it is, PAM
sessions are a gracy thing (imho).  I personally use my
/run/user/UID only for unshare(1) box roots.  I do not have
graphical programs but st(1) and firefox-bin (with audacity still
in the line to come).  But the thing does it and is used.

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)


Re: XDG_RUNTIME_DIR

2021-04-25 Thread Bob Bernstein

Thanks for all the encouragement.

I've decided I don't need lyx running in NetBSD. I was getting 
farther into a rabbit-hole I didn't want to be in to begin with. 
If you know what I mean. And I'm sure you do.


Thank you again to all.

--
RSB


Re: XDG_RUNTIME_DIR

2021-04-25 Thread RVP

On Sat, 24 Apr 2021, Steffen Nurpmeso wrote:


If you run Linux you could also use the pam_xdg module i have
written.  For example my /etc/pam.d/common-session is

 session optional pam_xdg.so notroot

 session requiredpam_unix.so quiet

and the stuff is as attached.  It handles the other directories of
the standard as well.



This is, I presume, for Linux systems without systemd and pam_env.so?
Because, the vast thing that is systemd, takes care of mounting a /run
and creating user dirs. inside it; and pam_env.so can read
/etc/environment{,.d/*} and /etc/security/pam_env.conf files where you
can set these system-wide env. vars.

I haven't gone through your code in detail, but, I noticed these small
issues:

Line 40: a_RUNTIME_DIR_BASE_MODE should be mode 0700. All dirs. under
/run are set that way, I think.

Line 77: That ORing is a bit of an odd way to set that buffer size (if
that isn't a typo). Maybe comment is as such?

There should be a removal of the dirs. on the user's final session
logout, I think.

Thanks,
-RVP


Re: XDG_RUNTIME_DIR

2021-04-25 Thread RVP

On Sun, 25 Apr 2021, RVP wrote:


And,... it worked flawlessly. My recommendation: install the binary
package. :)



Can you add lines like these to /etc/fstab if they're not already
there? They're needed for some large, complex programs--and lyx
seems to fit that category, now.

kernfs  /kern  kernfs  rw
ptyfs   /dev/pts   ptyfs   rw
procfs  /proc  procfs  rw
tmpfs   /var/shm   tmpfs   rw,-m1777,-sram%25

-RVP


Re: XDG_RUNTIME_DIR

2021-04-25 Thread RVP

On Sun, 25 Apr 2021, Bob Bernstein wrote:

dbus is launching via standard rc.conf mechanism, with a 'starting dbus' 
message displayed during boot. Do you suppose I need the 'dbus-launch' 
statement in addition to that?




Strictly speaking: no. Applications which need DBUS will launch a
per-user instance of the daemon, once, when needed. You don't need
to start one. I do it that way, in ~/.xinitrc, because I want it
to _exit_ when I quit X. Else, it persists until I log out.


I now have showing in 'env':

XDG_RUNTIME_DIR=/tmp/runtime-bob



Fine. There is also a XDG_CONFIG_HOME--defaulting to ~/.config


and, fwiw:

QTDIR=/usr/pkg/qt5



This is only needed for compiling, I think.

AT THIS STAGE of the game, at least on launch from the command-line lyx is 
not just crashing and dumping core. 'ps' shows a running lyx process, but it 
doesn't seem able to reach the point whereat it would display itself. I have 
DISPLAY set in the env:


DISPLAY=:0



Right, that last bit about setting DISPLAY worries me. You shouldn't
need to set this at all, normally. What was it before you set it
(i.e. in an xterm window)?

As a test, I just installed lyx from the binary package: After
installing what seemed like everything Knuth wrote going back to
1978, it installed itself fine. Running it produced a missing
library (libmagic.so.6) error. That fixed (I'm on 9.99.81 which
has libmagic.so.7), I unset all XDG-related env. vars (only 2);
stopped running dbus-launch in .xinitrc; logged out; logged-in and
ran lyx.

And,... it worked flawlessly. My recommendation: install the binary
package. :)

-RVP


Re: XDG_RUNTIME_DIR

2021-04-24 Thread Pedro Pinho
Qt-apps can be rather picky regarding XDG, I have the following in .xinitrc
to avoid such issues,

mkdir /tmp/${USER}-runtime && chmod -R 0700 /tmp/${USER}-runtime
export XDG_RUNTIME_DIR=/tmp/${USER}-runtime


Den sön 25 apr. 2021 06:19Bob Bernstein  skrev:

> On Sat, 24 Apr 2021, RVP wrote:
>
> > Correction: On NetBSD that would be:
>
> > if [ -x /usr/pkg/bin/dbus-launch -a -z
> > "${DBUS_SESSION_BUS_ADDRESS}" ];
> >
> > In either ~/.xinitrc or ~/.xsession
>
> dbus is launching via standard rc.conf mechanism, with a
> 'starting dbus' message displayed during boot. Do you suppose I
> need the 'dbus-launch' statement in addition to that?
>
> I now have showing in 'env':
>
> XDG_RUNTIME_DIR=/tmp/runtime-bob
>
> and, fwiw:
>
> QTDIR=/usr/pkg/qt5
>
> AT THIS STAGE of the game, at least on launch from the
> command-line lyx is not just crashing and dumping core. 'ps'
> shows a running lyx process, but it doesn't seem able to reach
> the point whereat it would display itself. I have DISPLAY set in
> the env:
>
> DISPLAY=:0
>
> But the game's afoot!
>
> Thank you.
>
> --
> What's going on with Bob?
> https://zeus.jtan.com/~wingnut
>


Re: XDG_RUNTIME_DIR

2021-04-24 Thread Bob Bernstein

On Sat, 24 Apr 2021, RVP wrote:


Correction: On NetBSD that would be:


if [ -x /usr/pkg/bin/dbus-launch -a -z 
"${DBUS_SESSION_BUS_ADDRESS}" ];


In either ~/.xinitrc or ~/.xsession


dbus is launching via standard rc.conf mechanism, with a 
'starting dbus' message displayed during boot. Do you suppose I 
need the 'dbus-launch' statement in addition to that?


I now have showing in 'env':

XDG_RUNTIME_DIR=/tmp/runtime-bob

and, fwiw:

QTDIR=/usr/pkg/qt5

AT THIS STAGE of the game, at least on launch from the 
command-line lyx is not just crashing and dumping core. 'ps' 
shows a running lyx process, but it doesn't seem able to reach 
the point whereat it would display itself. I have DISPLAY set in 
the env:


DISPLAY=:0

But the game's afoot!

Thank you.

--
What's going on with Bob?
https://zeus.jtan.com/~wingnut


Re: XDG_RUNTIME_DIR

2021-04-24 Thread RVP

On Sat, 24 Apr 2021, RVP wrote:


3. ~/.xinitrc
if [ -x /usr/local/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ];
theneval $(dbus-launch --sh-syntax --exit-with-session)
fi



Correction: On NetBSD that would be:

if [ -x /usr/pkg/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ];

In either ~/.xinitrc or ~/.xsession

-RVP


Re: XDG_RUNTIME_DIR

2021-04-24 Thread Steffen Nurpmeso
RVP wrote in
 :
 |On Sat, 24 Apr 2021, RVP wrote:
 |
 |> 3. ~/.xinitrc
 |> if [ -x /usr/local/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ];
 |> theneval $(dbus-launch --sh-syntax --exit-with-session)
 |> fi
 |>
 |
 |Correction: On NetBSD that would be:

If you run Linux you could also use the pam_xdg module i have
written.  For example my /etc/pam.d/common-session is

  session optional pam_xdg.so notroot

  session requiredpam_unix.so quiet

and the stuff is as attached.  It handles the other directories of
the standard as well.  (Unfortunately i could not subscribe to the
RedHat hosted PAM list for inclusion upstream, i gave up after
trying several times.)
Could be ported to NetBSD with little effort (unfortunately PAM is
not really portable).

--steffen
|
|Der Kragenbaer,The moon bear,
|der holt sich munter   he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)
/*@ pam_xdg - manage XDG Base Directories (runtime dir life time, environment).
 *@ Create /run/user/`id -u` when the first session is opened.
 *@ It also creates according XDG_RUNTIME_DIR etc. environment variables in the
 *@ user sessions, except when given the "runtime" option, in which case it
 *@ only creates XDG_RUNTIME_DIR and not the others.
 *@ Place for example in /etc/pam.d/common-session one of the following:
 *@   session options pam_xdg.so [runtime] [notroot]
 *@ Notes: - according to XDG Base Directory Specification, v0.7.
 *@- Linux-only (i think).
 *
 * Copyright (c) 2021 Steffen Nurpmeso .
 * SPDX-License-Identifier: ISC
 *
 * Permission to use, copy, modify, and/or distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/* For these a leading \1 is replaced with struct passwd::pw_dir.
 * Be aware we use a stack buffer for storage */
#define a_XDG_DATA_HOME_DEF "\1/.local/share"
#define a_XDG_CONFIG_HOME_DEF "\1/.config"
#define a_XDG_DATA_DIRS_DEF "/usr/local/share:/usr/share"
#define a_XDG_CONFIG_DIRS_DEF "/etc/xdg/"
#define a_XDG_CACHE_HOME_DEF "\1/.cache"

/* */
#define a_XDG "pam_xdg"

#define a_RUNTIME_DIR_OUTER "/run" /* This must exist already */
#define a_RUNTIME_DIR_BASE "user" /* We create this as necessary, thus. */
#define a_RUNTIME_DIR_BASE_MODE 0755 /* 0711? */

/* >8 -- 8< */

/*
#define _POSIX_C_SOURCE 200809L
#define _ATFILE_SOURCE
*/
#define _GNU_SOURCE /* Always the same mess */

#include 
#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#include 
#include 

/* _XOPEN_PATH_MAX POSIX 2008/Cor 1-2013 */
#ifndef PATH_MAX
# define PATH_MAX 1024
#endif

static int a_xdg(int isopen, pam_handle_t *pamh, int flags, int argc,
  const char **argv);

static int
a_xdg(int isopen, pam_handle_t *pamh, int flags, int argc, const char **argv){
   char uidbuf[sizeof "18446744073709551615"],
 wbuf[((sizeof("XDG_RUNTIME_DIR=") + sizeof(a_RUNTIME_DIR_OUTER) +
   sizeof(a_RUNTIME_DIR_BASE) + sizeof("18446744073709551615")) |
(sizeof("XDG_CONFIG_DIRS=") + PATH_MAX)
) +1];
   struct stat st;
   struct passwd *pwp;
   char const *emsg;
   int cwdfd, only_runtime, notroot, res, uidbuflen;
   char const *user;
   (void)flags;

   user = "";
   cwdfd = -1;
   only_runtime = notroot = 0;

   /* Command line */
   if(isopen){
  for(; argc > 0; ++argv, --argc){
 if(!strcmp(argv[0], "runtime"))
only_runtime = 1;
 else if(!strcmp(argv[0], "notroot"))
notroot = 1;
 else if(!(flags & PAM_SILENT)){
emsg = "command line";
errno = EINVAL;
goto jerr;
 }
  }
   }else
  goto jok; /* No longer used, session counting does not work */

   /* We need the user we go for */
   if((res = pam_get_item(pamh, PAM_USER, (void const**))
 ) != PAM_SUCCESS){
  user = "";
  emsg = "cannot query PAM_USER name";
  goto jepam;
   }

   if((pwp = getpwnam(user)) == NULL){
  emsg = "host machine does not know about user";
  errno = EINVAL;
  goto jerr;
   }

   if(notroot && pwp->pw_uid == 0)
  goto jok;

   /* I admit all this is overly complicated and expensive */
   if((cwdfd = open(a_RUNTIME_DIR_OUTER, (O_PATH | O_DIRECTORY | O_NOFOLLOW))
 ) == -1){
  emsg = "cannot obtain chdir(2) descriptor to " 

Re: XDG_RUNTIME_DIR

2021-04-24 Thread RVP

On Sat, 24 Apr 2021, Bob Bernstein wrote:

I have built from pkgsrc 'lyx' with the qt5 libs. Typing 'lyx' at a command 
prompt yields:


$ lyx
QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-bob'



That's a harmless notification. If you want to quash it add these lines:

1. /etc/rc.conf:
dbus_enable=YES

2. ~/.profile
export XDG_RUNTIME_DIR=/tmp/runtime-${LOGNAME}
test -d $XDG_RUNTIME_DIR ||
install -d -m 700 -o $(id -u) -g $(id -g) $XDG_RUNTIME_DIR

3. ~/.xinitrc
if [ -x /usr/local/bin/dbus-launch -a -z "${DBUS_SESSION_BUS_ADDRESS}" ];
theneval $(dbus-launch --sh-syntax --exit-with-session)
fi

-RVP


Re: XDG_RUNTIME_DIR

2021-04-24 Thread Bob Bernstein

On Sat, 24 Apr 2021, Rhialto wrote:



Did you ever have LyX installed / running before?


No, not on my NetBSD machine at any rate.


It is just a wild guess, but does it help if you install that?


xdg-utils got installed along with Lyx and the qt5 packages.


Did you install from the latest stable branch (2021Q1)? I have; if you
installed from the -current version, there may be differences. And if
you mixed installs from different point in time of pkgsrc, that may also
confuse things.


I have a tendency to mix 'n match, or, rather, sometimes -- as 
you sagely note -- mix 'n mismatch pkgsrc, which requires me to 
let my NetBSD system from time to time grind through 
pkg_rolling-replace to straighten out the kind of problems to 
which you allude. That task was accomplished as recently as last 
week.


Thank you.

--
RSB


Re: XDG_RUNTIME_DIR

2021-04-24 Thread Rhialto
On Sat 24 Apr 2021 at 13:39:03 -0400, Bob Bernstein wrote:
> I have built from pkgsrc 'lyx' with the qt5 libs. Typing 'lyx' at a command
> prompt yields:
> 
> $ lyx
> QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/runtime-bob'
> 
> I pecked through the qt5 pkgsrc dirs (for the qt5 packages that were built)
> hoping to find a MESSAGE containing instructions for setting
> XDG_RUNTIME_DIR. (Not sure why I suspected qt5 in that connection.)
> 
> Any and all suggestions will be examined.

Did you ever have LyX installed / running before? I used it before, and
checked my version, and I didn't get that. In my ~/.lyx directory I
found a reference to "xdg-open" (in configure.log), which is part of
xdg-utils. It is just a wild guess, but does it help if you install
that?

> > From my 9.99.81 amd64 system with pkgsrc via git 4/15/21.

Did you install from the latest stable branch (2021Q1)? I have; if you
installed from the -current version, there may be differences. And if
you mixed installs from different point in time of pkgsrc, that may also
confuse things.

> Thank youse.
-Olaf.
-- 
___ Q: "What's an anagram of Banach-Tarski?"  -- Olaf "Rhialto" Seibert
\X/ A: "Banach-Tarski Banach-Tarski." -- rhialto at falu dot nl


signature.asc
Description: PGP signature