C Testers wanted for new "ps" command for pkg(8)

I added functionality to list processes using deleted binaries & libraries after a system update. As this feature is present in openSUSE's zypper and Debian's apt (through the needrestart plugin), I decided to add it to pkg(8).


To test:

Bash:
git clone --depth 1 https://github.com/freebsd/pkg
cd pkg
fetch https://github.com/freebsd/pkg/pull/2290.diff
patch -p1 < 2290.diff
./configure
make
# Optional:
doas make install

Do some pkg stuff or system update and run `pkg ps [-v]`

Thanks in advance.
 
Last edited:
Hi,

It may sound stupid, but what is the purpose of this feature? Can you, please, try to explain it in a different way from what is already explained in GitHub.
I read up the the description few times, as well as the given example with the sleep command, but I still fail to understand how ps and pkg are related.
Note that it may be one of this case when "if you don't understand that's because you don't need it", probably yes but I'll try to comprehend just a bit in which case this feature can be useful.

A quick note about the instructions, I think a cd pkg/ is missing after the git clone.
So I've installed it in a VM, tried few things(install packages mostly) with pkg like you said and then enter pkg ps -v but while the header appears it basically remains empty, meaning nothing happens, so I think I don't use it correctly or not in the right context, hence my initial question.

Thank you.
 
Hi,

It may sound stupid, but what is the purpose of this feature? Can you, please, try to explain it in a different way from what is already explained in GitHub.
I read up the the description few times, as well as the given example with the sleep command, but I still fail to understand how ps and pkg are related.
Note that it may be one of this case when "if you don't understand that's because you don't need it", probably yes but I'll try to comprehend just a bit in which case this feature can be useful.

A quick note about the instructions, I think a cd pkg/ is missing after the git clone.
So I've installed it in a VM, tried few things(install packages mostly) with pkg like you said and then enter pkg ps -v but while the header appears it basically remains empty, meaning nothing happens, so I think I don't use it correctly or not in the right context, hence my initial question.

Thank you.
When you upgrade a bunch of packages, you may have to restart your shell or system daemons because they're using obsolete libraries or binaries. This command makes those evident. The sleep test is just to show the sample output and to make sure that scanning void executable mappings works.

In openSUSE Tumbleweed I get:

Bash:
$ sudo zypper ps -s
The following running processes use deleted files:

PID   | PPID  | UID | User | Command           | Service
------+-------+-----+------+-------------------+--------
27316 | 27301 | 458 | gdm  | gnome-shell       | 
27370 | 27316 | 458 | gdm  | Xwayland          | 
27643 | 27316 | 458 | gdm  | mutter-x11-frames | 

You may wish to restart these processes.
See 'man zypper' for information about the meaning of values in the above table.

No core libraries or services have been updated since the last system boot.
Reboot is probably not necessary.
 
Only a plugin? How about putting it into the base pkg functionality. If pkg replaces an executable that is currently running somewhere in the system, or a shared library that is currently loaded, it should warn. This should be possible to implement (probably a lot of work), since it is possible to find out what executables are running, and which libraries they are using.
 
This should be possible to implement (probably a lot of work), since it is possible to find out what executables are running, and which libraries they are using.
This part is not easy. Linux appends ` (deleted)` to the name of the deleted files in `/proc/<pid>/maps` but *BSD shows a void path.
 
When you upgrade a bunch of packages, you may have to restart your shell or system daemons because they're using obsolete libraries or binaries. This command makes those evident. The sleep test is just to show the sample output and to make sure that scanning void executable mappings works.

In openSUSE Tumbleweed I get:

Bash:
$ sudo zypper ps -s
The following running processes use deleted files:

PID   | PPID  | UID | User | Command           | Service
------+-------+-----+------+-------------------+--------
27316 | 27301 | 458 | gdm  | gnome-shell       |
27370 | 27316 | 458 | gdm  | Xwayland          |
27643 | 27316 | 458 | gdm  | mutter-x11-frames |

You may wish to restart these processes.
See 'man zypper' for information about the meaning of values in the above table.

No core libraries or services have been updated since the last system boot.
Reboot is probably not necessary.
Thank you for the explanation I have now a better comprehension of what you've done, it seems to be a nice feature to have.
To summarize, please correct me if I am wrong, the final goal is to identify the services that require a restart.
In this case, I don't know if it's feasible, from an user perspective it would be simpler to list them at the end of a pkg's transaction, something like "Following services need to be restarted:" and then put just below the said services identified by pkg ps -v.
It would be easier than running the command manually after a pkg upgrade.
 
Thank you for the explanation I have now a better comprehension of what you've done, it seems to be a nice feature to have.
To summarize, please correct me if I am wrong, the final goal is to identify the services that require a restart.
In this case, I don't know if it's feasible, from an user perspective it would be simpler to list them at the end of a pkg's transaction, something like "Following services need to be restarted:" and then put just below the said services identified by pkg ps -v.
It would be easier than running the command manually after a pkg upgrade.
Identifying the services is a different beast. With Linux, both systemd & OpenRC export the service name to `/proc/<pid>/cgroup` because they create a cgroup with the service name. With FreeBSD there's no obvious mapping between a process and a service, and there's no service manager to get this information. And then comes jails, which introduces another thing to be aware of.
 
Okay I see they work differently, well it was just an idea, I can run things manually it doesn't bother me that much ;)
Thank you for the reply.
 
adding libxo for JSON output and filtering is a bit excessive for pkg

FreeBSD seems to be implementing xo wherever it can, and that's very useful. I think including it in pkg would be excellent. Packages are foundational to most useful FreeBSD systems, so being able to query package information with JSON output would let higher-level languages work with that data in a trivial way.
 
Sorry, I don't see what you mean I don't find that comment.

1723867437164.pngIt's in the PR that was linked from the opening post here:
 
Ho I see, I didn't think you were talking about this git repository.

BTW thank you for the effort with the screenshots posted every time, I appreciate it because that's convenient and quicker to follow the current discussion, I don't know if it was said before but I think it makes everybody happy about it :)
Thank you.
 
FreeBSD seems to be implementing xo wherever it can, and that's very useful. I think including it in pkg would be excellent. Packages are foundational to most useful FreeBSD systems, so being able to query package information with JSON output would let higher-level languages work with that data in a trivial way.
That would need a PR on its own to add this support for all pkg commands as well. It makes no sense to add yet another dependency to support JSON output for only this command. IIRC one command supports JSON but uses another library for that.
 
Last edited:
Back
Top