refactored ps data.

This commit is contained in:
Harald Hope 2023-12-12 15:03:08 -08:00
parent 7e23475333
commit 963673ace6
2 changed files with 104 additions and 111 deletions

205
pinxi
View file

@ -50,8 +50,8 @@ use POSIX qw(ceil uname strftime ttyname);
## INXI INFO ##
my $self_name='pinxi';
my $self_version='3.3.31';
my $self_date='2023-12-10';
my $self_patch='24';
my $self_date='2023-12-12';
my $self_patch='25';
## END INXI INFO ##
my ($b_pledge,@pledges);
@ -74,7 +74,7 @@ my ($fake_data_dir,$self_path,$user_config_dir,$user_config_file,$user_data_dir)
## Hashes
my (%alerts,%build_prop,%client,%colors,,%cpuinfo_machine,%disks_bsd,
%dboot,%devices,%dl,%dmmapper,%force,%loaded,%mapper,%program_values,%risc,
%dboot,%devices,%dl,%dmmapper,%force,%gui,%loaded,%mapper,%program_values,%risc,
%service_tool,%show,%sysctl,%system_files,%usb,%windows);
## System Arrays
@ -107,7 +107,7 @@ my ($b_admin,$b_android,$b_display,$b_irc,$b_root);
## System
my ($bsd_type,$device_vm,$language,$os,$pci_tool) = ('','','','','');
my ($wan_url,$wl_compositors) = ('','');
my ($wan_url) = ('');
my ($bits_sys,$cpu_arch,$ppid);
my ($cpu_sleep,$dl_timeout,$limit,$ps_cols,$ps_count) = (0.35,4,10,0,5);
my $sensors_cpu_nu = 0;
@ -4289,6 +4289,7 @@ sub set_program_values {
'cdm' => ['^cdm',0,'0','CDM',0,1,0,'',''],
# might be xlogin, unknown output for -V
'clogin' => ['^clogin',0,'-V','clogin',0,1,0,'',''], # unverified, maybe xlogin
'elogind' => ['^elogind',0,'0','elogind',0,1,0,'',''],
'emptty' => ['^emptty',0,'0','EMPTTY',0,1,0,'',''], # unverified
'entrance' => ['^entrance',0,'0','Entrance',0,1,0,'',''],
'gdm' => ['^gdm',2,'--version','GDM',0,1,0,'',''],
@ -4306,6 +4307,7 @@ sub set_program_values {
'nodm' => ['^nodm',0,'0','nodm',0,1,0,'',''],
'pcdm' => ['^pcdm',0,'0','PCDM',0,1,0,'',''],
'qingy' => ['^qingy',0,'0','qingy',0,1,0,'',''], # unverified
'seatd' => ['^seatd',3,'-v','seatd',0,1,0,'',''],
'sddm' => ['^sddm',0,'0','SDDM',0,1,0,'',''],
'slim' => ['slim version',3,'-v','SLiM',0,1,0,'',''],
'slimski' => ['slimski version',3,'-v','slimski',0,1,0,'',''], # slim fork
@ -6398,7 +6400,7 @@ my $pppid = '';
sub set {
eval $start if $b_log;
main::set_ps_aux() if !$loaded{'ps-aux'};
PsData::set_cmd() if !$loaded{'ps-cmd'};
# $b_irc = 1; # for testing, like cli konvi start which shows as tty
if (!$b_irc){
# we'll run ShellData::set() for -I, but only then
@ -19185,7 +19187,7 @@ sub set_compositor_data {
sub get_compositors {
eval $start if $b_log;
my $found = [];
main::set_ps_gui() if !$loaded{'ps-gui'};
PsData::set_gui() if !$loaded{'ps-gui'};
if (@ps_gui){
# ORDER MATTERS!
# notes: compiz: debian package compiz-core;
@ -19196,7 +19198,7 @@ sub get_compositors {
push (@compositors,qw(3dwm cosmic-comp dcompmgr gala kmscon
metisse mir moblin monsterwm picom ukwm unagi unity-system-compositor
xcompmgr xfwm4 xfwm5 xfwm));
my $matches = join('|',@compositors) . $wl_compositors;
my $matches = join('|',@compositors) . $gui{'wl-comp'};
foreach my $psg (@ps_gui){
if ($psg =~ /^($matches)$/){
push(@$found,$1);
@ -19602,7 +19604,7 @@ sub component_recursive_data {
}
## MachineItem
# Public: get(), is_vm()
# public subs: get(); is_vm()
{
my $b_vm;
package MachineItem;
@ -29067,7 +29069,7 @@ my $desktop = [];
sub get {
eval $start if $b_log;
set_desktop_values();
main::set_ps_gui() if !$loaded{'ps-gui'};
PsData::set_gui() if !$loaded{'ps-gui'};
get_kde_trinity_data();
if (!@$desktop){
get_env_de_data();
@ -29085,7 +29087,7 @@ sub get {
get_ps_de_data();
}
if ($extra > 2 && @$desktop){
set_info_data();
set_info_data(); # panels, docks, bars, etc
set_screensaver_data(); # and lockers
}
if ($b_display && !$force{'display'} && $extra > 1){
@ -29475,7 +29477,6 @@ sub get_env_xprop_misc_data {
sub get_ps_de_data {
eval $start if $b_log;
my ($program,@version_data,@wms);
main::set_ps_gui() if !$loaded{'ps-gui'};
if (@ps_gui){
# order matters, these have alternate search patterns from default name
# 0: check program; 1: ps_gui search; 2: data; 3: trigger alternate values/version
@ -29521,7 +29522,7 @@ sub get_ps_de_data {
nawm notion nscde openbox pekwm penrose qtile qvwm ratpoison
sawfish scrotwm snapwm spectrwm stumpwm tinywm tvtwm twm uwm
windowlab wmfs wmfs2 wingo wmii2 wmii wmx xmonad yeahwm);
my $matches = join('|',@wms) . $wl_compositors;
my $matches = join('|',@wms) . $gui{'wl-comp'};
# note: use my $psg to avoid bizarre return from program_data to ps_gui write
foreach my $psg (@ps_gui){
# no need to use check program with short list of ps_gui
@ -29611,7 +29612,6 @@ sub get_wm_main {
}
}
if (!$desktop->[5]){
main::set_ps_gui() if !$loaded{'ps-gui'};
# order matters, see above logic
# due to lisp/python starters, clfswm/stumpwm/qtile need the starter filters
my @wms = qw(2bwm 9wm aewm aewm\+\+ afterstep amiwm antiwm awesome blackbox
@ -29623,7 +29623,7 @@ sub get_wm_main {
mvwm mwm nawm notion openbox qtile qvwm penrose ratpoison sawfish scrotwm
snapwm spectrwm stumpwm tinywm tvtwm twm ukwm windowlab WindowMaker wingo
wmfs2? wmii2? wmx xfwm[45]? xmonad yeahwm);
my $wms = join('|',@wms) . $wl_compositors;
my $wms = join('|',@wms) . $gui{'wl-comp'};
foreach my $psg (@ps_gui){
if ($psg =~ /^($wms)$/){
$working = $1;
@ -29681,63 +29681,36 @@ sub get_wm_version {
sub set_info_data {
eval $start if $b_log;
main::set_ps_gui() if !$loaded{'ps-gui'};
my (@data,@info,$item);
my $pattern = 'alltray|awn|awesomebar|bar|bmpanel|bmpanel2|budgie-panel|';
$pattern .= 'cairo-dock|dde-dock|dmenu|dockbarx|docker|docky|dzen|dzen2|';
$pattern .= 'fancybar|fbpanel|fspanel|glx-dock|gnome-panel|hpanel|';
$pattern .= 'i3bar|i3status|i3-status-rs|icewmtray|';
$pattern .= 'kdocker|kicker|';
$pattern .= 'latte|latte-dock|lemonbar|ltpanel|luastatus|lxpanel|lxqt-panel|';
$pattern .= 'matchbox-panel|mate-panel|nwg-bar|nwg-dock|nwg-panel|ourico|';
$pattern .= 'perlpanel|plank|plasma-desktop|plasma-netbook|polybar|pypanel|';
$pattern .= 'razor-panel|razorqt-panel|rootbar|sfwbar|stalonetray|swaybar|';
$pattern .= 'taskbar|tint2|trayer|';
$pattern .= 'ukui-panel|vala-panel|wapanel|waybar|wbar|wharf|wingpanel|witray|';
$pattern .= 'xfce4-panel|xfce5-panel|xmobar|yabar|yambar';
if (@data = grep {/^($pattern)$/} @ps_gui){
# only one entry per type, can be multiple
foreach $item (@data){
if (! grep {$item =~ /$_/} @info){
$item = main::trimmer($item);
$item =~ s/.*\///;
push(@info, (split(/\s+/, $item))[0]);
}
}
}
if (@info){
main::uniq(\@info);
$desktop->[4] = join(', ', @info);
if (@{$gui{'info-active'}}){
$desktop->[4] = join(', ', @{$gui{'info-active'}});
}
eval $end if $b_log;
}
sub set_screensaver_data {
eval $start if $b_log;
my (@installed,@running);
# make sure these are the same as in set_ps_gui() list.
my @items = qw(away boinc-screensaver budgie-screensaver cinnamon-screensaver
gnome-screensaver gsd-screensaver-proxy gtklock i3lock kscreenlocker
light-locker lockscreen lxlock mate-screensaver nwg-lock physlock
rss-glx slock swayidle swaylock ukui-screensaver unicode-screensaver
xautolock xfce4-screensaver xlock xlockmore xscreensaver
xsecurelock xss-lock xtrlock);
foreach my $item (@items){
if (grep {$_ eq $item} @ps_gui){
push(@running,$item);
# these are running/active
if (@{$gui{'tools-active'}}){
$desktop->[7] = join(',', @{$gui{'tools-active'}});
}
elsif ($b_admin && main::check_program($item)){
# now check if any are available but not running/services
if ($b_admin){
my (@installed,%test);
if ($desktop->[7]){
foreach my $tool (@{$gui{'tools-active'}}){
$test{$tool} = 1;
}
}
foreach my $item (@{$gui{'tools-test'}}){
next if $test{$item};
if (main::check_program($item)){
push(@installed,$item);
}
}
if (@running){
main::uniq(\@running);
$desktop->[7] = join(',', @running);
}
if (@installed){
main::uniq(\@installed);
$desktop->[8] = join(',', @installed);
}
}
eval $end if $b_log;
}
@ -30879,9 +30852,9 @@ sub get_display_manager {
# greetd-684.sock if no .run seen. Add Ly in case they add run file/directory.
# greetd frontends: agreety dlm gtkgreet qtgreet tuigreet wlgreet
# mlogin may be mlogind, not verified
my @dms = qw(brzdm cdm clogin emptty entranced gdm gdm3 greetd kdm kdm3 kdmctl
ldm lightdm lxdm ly mdm mlogin nodm pcdm qingy sddm slim slimski tbsm tdm
udm wdm xdm xdmctl xenodm xlogin);
my @dms = qw(brzdm cdm clogin elogind emptty entranced
gdm gdm3 greetd kdm kdm3 kdmctl ldm lightdm lxdm ly mdm mlogin nodm
pcdm qingy sddm seatd slim slimski tbsm tdm udm wdm xdm xdmctl xenodm xlogin);
# these are the only one I know of so far that have version info. xlogin /
# clogin do, -V, brzdm -v, but syntax not verified.
my @dms_version = qw(gdm gdm3 lightdm ly slim);
@ -34443,28 +34416,37 @@ sub sys_data {
}
}
sub set_ps_aux {
## PsData
# public subs: set_cmd(); set_gui()
{
package PsData;
sub set_cmd {
eval $start if $b_log;
my ($header,$ps,@temp);
# note: some ps cut off output based on terminal width
# ww sets width unlimited
$loaded{'ps-aux'} = 1;
$ps = grabber("ps wwaux 2>/dev/null",'','strip','ref');
my ($b_busybox,$header,$ps,@temp);
$loaded{'ps-cmd'} = 1;
my $args = 'wwaux';
my $path = main::check_program('ps');
my $link = readlink($path);
if ($link && $link =~ /busybox/i){
$b_busybox = 1;
$args = '';
}
# note: some ps cut output based on terminal width, ww sets width unlimited
# old busybox returns error with args, new busybox ignores auxww
$ps = main::grabber("$path $args 2>/dev/null",'','strip','ref');
if (@$ps){
$header = shift @$ps; # get rid of header row
# handle busy box, which has 3 columns, regular ps aux has 11
# avoid deprecated implicit split error in older Perls
@temp = split(/\s+/, $header);
}
else {
return;
}
$ps_cols = $#temp; # the indexes, not the scalar count
# we want more data from ps busybox
my $cols_use = ($ps_cols < 4) ? 7 : 2;
# not used, $b_busybox_ps was global
# if ($ps_cols < 10){
# my $version = qx(ps --version 2>&1);
# $b_busybox_ps = 1 if $version =~ /busybox/i;
# }
return if !@$ps; # note: mips/openwrt ps has no 'a'
# we want more data from ps busybox, to get TinyX screen res
my $cols_use = ($b_busybox) ? 7 : 2;
for (@$ps){
next if !$_;
next if $self_name eq 'inxi' && /\/$self_name\b/;
@ -34483,11 +34465,11 @@ sub set_ps_aux {
}
}
# never prints with 5, because ps loaded before option handler
# print 'ps main: ', Dumper \@ps_cmd; # if $dbg[5];
# print 'ps main: ', Data::Dumper::Dumper \@ps_cmd; # if $dbg[5];
eval $end if $b_log;
}
sub set_ps_gui {
sub set_gui {
eval $start if $b_log;
$loaded{'ps-gui'} = 1;
my ($b_wl,$working,@match,@temp);
@ -34518,30 +34500,29 @@ sub set_ps_gui {
ukwm xfwm[45]?);
push(@match,@temp);
# startx: /bin/sh /usr/bin/startx
@temp=qw(ly .*startx xinit); # possible dm values
@temp=qw(ly startx xinit); # possible dm values
push(@match,@temp);
}
# info: NOTE: glx-dock is cairo-dock
if ($show{'system'} && $extra > 2){
@temp=qw(alltray awesomebar awn bar bmpanel bmpanel2 budgie-panel
cairo-dock dde-dock dmenu dockbarx docker docky dzen dzen2
fbpanel fspanel glx-dock gnome-panel hpanel i3bar i3-status(-rs)? icewmtray
kdocker kicker latte latte-dock lemonbar ltpanel luastatus lxpanel lxqt-panel
process_gui(\@{$gui{'info-active'}},join('|', qw(
alltray awesomebar awn bar bmpanel bmpanel2 budgie-panel cairo-dock
dde-dock dmenu dockbarx docker docky dzen dzen2 fbpanel fspanel
glx-dock gnome-panel hpanel i3bar i3-status(-rs)? icewmtray kdocker kicker
latte latte-dock lemonbar ltpanel luastatus lxpanel lxqt-panel
matchbox-panel mate-panel nwg-bar nwg-dock nwg-panel ourico
perlpanel plank plasma-desktop plasma-netbook polybar pypanel
razor-panel razorqt-panel rootbar
sfwbar stalonetray swaybar taskbar tint2 trayer
ukui-panel vala-panel wapanel waybar wbar wharf wingpanel witray
xfce[45]?-panel xmobar yambar yabar);
push(@match,@temp);
# then the screensavers/lockers. Note that many lockers may not be services
@temp=qw(away boinc-screensaver budgie-screensaver cinnamon-screensaver
gnome-screensaver gsd-screensaver-proxy gtklock i3lock kscreenlocker
light-locker lockscreen lxlock mate-screensaver nwg-lock physlock
rss-glx slock swayidle swaylock ukui-screensaver unicode-screensaver
razor-panel razorqt-panel rootbar sfwbar stalonetray swaybar
taskbar tint2 trayer ukui-panel vala-panel wapanel waybar wbar wharf
wingpanel witray xfce[45]?-panel xmobar yambar yabar)));
# Generate tools: screensavers/lockers. Note that many lockers may not be services
@{$gui{'tools-test'}}=qw(away boinc-screensaver budgie-screensaver
cinnamon-screensaver gnome-screensaver gsd-screensaver-proxy gtklock i3lock
kscreenlocker light-locker lockscreen lxlock mate-screensaver nwg-lock
physlock rss-glx slock swayidle swaylock ukui-screensaver unicode-screensaver
xautolock xfce4-screensaver xlock xlockmore xscreensaver
xsecurelock xss-lock xtrlock);
push(@match,@temp);
process_gui(\@{$gui{'tools-active'}},join('|',@{$gui{'tools-test'}}));
}
# compositors (for wayland these are also the server, note).
# for wayland always show, so always load these
@ -34553,12 +34534,12 @@ sub set_ps_gui {
push(@match,@temp);
$b_wl = 1;
}
uniq(\@match);
main::uniq(\@match);
my $matches = join('|', @match);
if ($b_wl){
# wayland compositors generally are compositors and wm.
# These will be used globally to avoid having to redo it over and over.
$wl_compositors = '|' . join('|',qw(asc awc
$gui{'wl-comp'} = '|' . join('|',qw(asc awc
cage cagebreak cardboard chameleonwm clayland comfc
dwc dwl epd-wm fireplace feathers fenestra glass gamescope greenfield grefson
hikari hopalong [Hh]yprland inaban japokwm kiwmi labwc laikawm lipstick liri
@ -34568,23 +34549,35 @@ sub set_ps_gui {
tabby taiwins tinybox tinywl trinkster velox vimway vivarium
wavy waybox way-?cooler wayfire wayhouse waymonad westeros westford
weston wio\+? wxr[cd] xuake));
$matches .= $wl_compositors;
$matches .= $gui{'wl-comp'};
}
$matches = qr/$matches/; # remember qr/../i only added perl 5.014
process_gui(\@ps_gui,$matches);
# print "$matches\n";
foreach (@ps_cmd){
# strip out python/lisp/sh starters
if (/^(\/\S+\/(c?lisp|perl|python|sh)\s+)?(|[\S]*\/)($matches)(\/|\s|$)/){
push(@ps_gui, $4); # deal with duplicates with uniq
}
}
# print Dumper \@ps_gui if $dbg[5];
uniq(\@ps_gui) if @ps_gui;
print 'ps_gui: ', Dumper \@ps_gui if $dbg[5];
log_data('dump','@ps_gui',\@ps_gui) if $b_log;
main::uniq(\@ps_gui) if @ps_gui;
if ($dbg[5]){
print 'ps_gui: ', Data::Dumper::Dumper \@ps_gui;
print '%gui: ', Data::Dumper::Dumper \%gui;
}
if ($b_log){
main::log_data('dump','@ps_gui',\@ps_gui);
main::log_data('dump','%gui',\%gui);
}
eval $end if $b_log;
}
# args: 0: array ref or scalar to become ref; 1: 1: matches pattern
sub process_gui {
foreach (@ps_cmd){
# strip out python/lisp/*sh starters
if (/^(\/\S+\/(c?lisp|perl|python|[a-z]{0,3}sh)\s+)?(|[\S]*\/)($_[1])(\/|\s|$)/){
push(@{$_[0]}, $4); # deal with duplicates with uniq
}
}
}
}
sub get_self_version {
eval $start if $b_log;
my $patch = $self_patch;
@ -36439,7 +36432,7 @@ my ($items,$subs);
sub generate {
eval $start if $b_log;
my ($item,%checks);
main::set_ps_aux() if !$loaded{'ps-aux'};
PsData::set_cmd() if !$loaded{'ps-cmd'};
main::set_sysctl_data() if $use{'sysctl'};
main::set_dboot_data() if $bsd_type && !$loaded{'dboot'};
# note: ps aux loads before logging starts, so create debugger data here

View file

@ -15,7 +15,7 @@
.\" with this program; if not, write to the Free Software Foundation, Inc.,
.\" 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
.\"
.TH INXI 1 "2023\-12\-09" "inxi" "inxi manual"
.TH INXI 1 "2023\-12\-12" "inxi" "inxi manual"
.SH NAME
inxi \- Command line system information script for console and IRC