tools.ps.linux: recover from missing file in ps-cmdline, fixes #1120

db4
Björn Lindqvist 2015-10-20 16:55:48 +02:00
parent 8bb96cbfd1
commit 9b5cb445ee
1 changed files with 10 additions and 9 deletions

View File

@ -1,23 +1,24 @@
! Copyright (C) 2012 Doug Coleman. ! Copyright (C) 2012 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs io.directories io.pathnames kernel USING: accessors arrays assocs continuations io.directories kernel
math.parser prettyprint sequences splitting system math.parser sequences splitting system tools.ps unix.linux.proc ;
tools.ps unix.linux.proc ;
IN: tools.ps.linux IN: tools.ps.linux
! If cmdline is empty, read the filename from /proc/pid/stat ! If cmdline is empty, read the filename from /proc/pid/stat
: ps-cmdline ( path -- path string ) : ps-cmdline ( path -- string )
dup parse-proc-pid-cmdline [ dup parse-proc-pid-cmdline [
dup parse-proc-pid-stat filename>> parse-proc-pid-stat filename>>
[ "()" member? ] trim [ "()" member? ] trim
"[" "]" surround "[" "]" surround
] [ ] [
"\0" split " " join nip "\0" split harvest " " join
] if-empty ; ] if-empty ;
: safe-ps-cmdline ( path -- string/f )
[ ps-cmdline ] [ 2drop f ] recover ;
M: linux ps ( -- assoc ) M: linux ps ( -- assoc )
"/proc" [ "/proc" [
"." directory-files "." directory-files [ string>number ] filter
[ file-name string>number ] filter [ dup safe-ps-cmdline 2array ] map sift-values
[ ps-cmdline ] { } map>assoc
] with-directory ; ] with-directory ;