On Sun, 2022-10-09 at 00:13 +0200, Francesco Poli wrote:

> Control: tags -1 - wontfix
> OK, I see.
> This looks much more feasible.

Thanks!

> I cannot promise that I will get around to it before bookworm freezes,
> but I think it can be done (sooner or later).

There is no rush, this is just a very minor feature request.

> As far as the requester user name is concerned, there's already some
> code in apt-listbugs which tries to determine it.

Great.

> It uses the output from the "logname" command. This works with "su" and
> "sudo". I don't know about "pkexec", I will have to test it.

logname works correctly with pkexec too, nice!

> For the command line, reading from /proc/${PPID}/cmdline seems to be a
> little tricky.

It is a NUL separated list of strings, should be easy?

> Also, I wonder how portable it is. Is it a Linux-specific thing, or
> is it mandated by POSIX? Is it supported by non-Linux kernels (GNU
> Hurd, FreeBSD kernel, ...)?

It works on the porterboxes for the Debian ports to Hurd and kFreeBSD.

Apparently listing processes is not part of POSIX except for the ps
command, so getting process metadata is operating-system-specific.

https://stackoverflow.com/questions/3667486/display-all-process-using-a-posix-function
https://www.unix.com/man-page/posix/1posix/ps/

> Is there a better or more convenient way?

The native Ruby way to do this seems to be ruby-sys-proctable.

   irb(main):023:0> ProcTable.ps(pid: 1).cmdline
   => "/lib/systemd/systemd --system --deserialize 42"

That works on Windows/Solaris/Linux/FreeBSD/macOS:

   https://github.com/djberg96/sys-proctable

Unfortunately it depends on ruby-ffi which is not installable on Hurd
right now due to a build failure.

   https://buildd.debian.org/status/package.php?p=ruby%2dffi#problem-14

ruby-sys-proctable also does mean an additional dependency, but you
could make it optional by falling back on /proc/$PID/cmdline instead.

On Linux ProcTable just uses the /proc/$PID/cmdline file anyway:

        # Get /proc/<pid>/cmdline information. Strip out embedded nulls.
        begin
          data = IO.read("/proc/#{file}/cmdline").tr("\000", ' ').strip
          struct.cmdline = data
        rescue
          next # Process terminated, on to the next process
        end

The other ports of ProcTable do different things though and
there is currently no POSIX port that just runs `ps` either.

You could either fix that upstream or fallback on this command:

   ps -o cmd= $PPID

-- 
bye,
pabs

https://wiki.debian.org/PaulWise

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to