gamemode/data/gamemodelist
Reilly Brogan 9646f2bd93 gamemodelist: Fix unreadable process maps
Systemd commit [bf1b9ae487b65b1cb1639b222724fab95e508cf5](bf1b9ae487) (present in Systemd v254 and later) effectively broke gamemodelist as the process map for the `systemd --user` process became unreadable. After this change gamemodelist would exit with an error like the following:

```
awk: fatal: cannot open file `/proc/2281/maps' for reading: Permission denied
```

To work around this let's add a hook to the awk statement to skip any files that can't be read.

Closes FeralInteractive/gamemode#456
2024-03-27 10:16:28 +00:00

33 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
# Created by Sam Gleske
# Created Sat Jan 1 16:56:54 EST 2022
# MIT License - https://github.com/samrocketman/home
# DESCRIPTION
# Find all running processes which have loaded Feral Interactive gamemode
# via libgamemodeauto.so. This script will not detect processes which load
# gamemode without libgamemodeauto.so.
# DEVELOPMENT ENVIRONMENT
# Ubuntu 18.04.6 LTS
# Linux 5.4.0-91-generic x86_64
# GNU bash, version 4.4.20(1)-release (x86_64-pc-linux-gnu)
# find (GNU findutils) 4.7.0-git
# GNU Awk 4.1.4, API: 1.1 (GNU MPFR 4.0.1, GNU MP 6.1.2)
# xargs (GNU findutils) 4.7.0-git
# ps from procps-ng 3.3.12
if [ -z "${USER:-}" ]; then
echo '$USER variable not defined.' >&2
exit 1
fi
if [ ! -d /proc ]; then
echo 'ERROR: /proc filesystem missing. We do not appear to be running on Linux.' >&2
exit 1
fi
find /proc -maxdepth 2 -type f -user "${USER}" -readable -name maps -exec \
awk -- 'BEGINFILE { if (ERRNO) nextfile } $0 ~ /libgamemodeauto\.so\.0/ {pid=FILENAME; gsub("[^0-9]", "", pid); print pid;nextfile}' {} + \
| xargs | xargs -I{} -- ps -o pid,ppid,user,ni,psr,comm --pid '{}'