# HG changeset patch # User František Kučera # Date 1409609164 -7200 # Node ID c6688467d03c93bc0535c970b097ed11c053c724 # Parent 9ff9cd2d677a22d0120cae10eb0e82c4a7da69e5 prototyp: processes – parse null-byte separated files from /proc diff -r 9ff9cd2d677a -r c6688467d03c prototyp/prototyp.sql --- a/prototyp/prototyp.sql Mon Sep 01 22:47:19 2014 +0200 +++ b/prototyp/prototyp.sql Tue Sep 02 00:06:04 2014 +0200 @@ -213,8 +213,17 @@ use strict; use warnings; + # There is a library… # aptitude install libproc-processtable-perl - # TODO: use Proc::ProcessTable::Process; + # use Proc::ProcessTable::Process; + # But there can be found: + # /* replace all '\0' with spaces (except for the last one */ + # for (cur = cmndline_text; cur < cmndline_text + cmndline_off - 1; cur++) { + # if (*cur == '\0') + # *cur = ' '; + # } + # which wipes boundaries between arguments (that can also contain spaces) + # So wait until the patch https://rt.cpan.org/Public/Bug/Display.html?id=52442 will be integrated my $dir = "/proc"; @@ -227,16 +236,13 @@ open(CMDLINE, "<$dir/$pid/cmdline"); binmode CMDLINE; - my $cmdline; - read(CMDLINE, $cmdline, 65536); - - my @cmdline_parts = split(0x00, $cmdline); + my @cmdline = split("\x00", ); return_next({ id => $pid, owner => $uid, - command => readlink("$dir/$pid/exe"), - arguments => ["xxx"], + command => shift(@cmdline), + arguments => [@cmdline], working_dir => readlink("$dir/$pid/cwd") }); }