prototyp: processes – parse null-byte separated files from /proc
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 02 Sep 2014 00:06:04 +0200
changeset 12c6688467d03c
parent 11 9ff9cd2d677a
child 13 552252ca87db
prototyp: processes – parse null-byte separated files from /proc
prototyp/prototyp.sql
     1.1 --- a/prototyp/prototyp.sql	Mon Sep 01 22:47:19 2014 +0200
     1.2 +++ b/prototyp/prototyp.sql	Tue Sep 02 00:06:04 2014 +0200
     1.3 @@ -213,8 +213,17 @@
     1.4  	use strict;
     1.5  	use warnings;
     1.6  	
     1.7 +	# There is a library…
     1.8  	# aptitude install libproc-processtable-perl
     1.9 -	# TODO: use Proc::ProcessTable::Process;
    1.10 +	# use Proc::ProcessTable::Process;
    1.11 +	# But there can be found:
    1.12 +	# /* replace all '\0' with spaces (except for the last one */
    1.13 +	# for (cur = cmndline_text; cur < cmndline_text + cmndline_off - 1; cur++) {
    1.14 +	# if (*cur == '\0')
    1.15 +	# 	*cur = ' ';
    1.16 +	# }
    1.17 +	# which wipes boundaries between arguments (that can also contain spaces)
    1.18 +	# So wait until the patch https://rt.cpan.org/Public/Bug/Display.html?id=52442 will be integrated
    1.19  	
    1.20  	my $dir = "/proc";
    1.21  	
    1.22 @@ -227,16 +236,13 @@
    1.23  			
    1.24  			open(CMDLINE, "<$dir/$pid/cmdline");
    1.25  			binmode CMDLINE;
    1.26 -			my $cmdline;
    1.27 -			read(CMDLINE, $cmdline, 65536);
    1.28 -			
    1.29 -			my @cmdline_parts = split(0x00, $cmdline);
    1.30 +			my @cmdline = split("\x00", <CMDLINE>);
    1.31  			
    1.32  			return_next({
    1.33  				id => $pid,
    1.34  				owner => $uid,
    1.35 -				command => readlink("$dir/$pid/exe"),
    1.36 -				arguments => ["xxx"],
    1.37 +				command => shift(@cmdline),
    1.38 +				arguments => [@cmdline],
    1.39  				working_dir => readlink("$dir/$pid/cwd")
    1.40  			});
    1.41  		}