r50148 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r50147‎ | r50148 | r50149 >
Date:05:22, 3 May 2009
Author:nicdumz
Status:deferred
Tags:
Comment:
Adding full commandline with arguments from /proc/pid/cmdline to email.
Modified paths:
  • /trunk/tools/slayerd/slayerd.cc (modified) (history)

Diff [purge]

Index: trunk/tools/slayerd/slayerd.cc
@@ -70,7 +70,10 @@
7171 process(fs::path const &pth);
7272
7373 pid_t _pid;
 74+ /* short command from /proc/{pid}/stat */
7475 std::string _comm;
 76+ /* fulll command from /proc/{pid}/cmdline */
 77+ std::string _fullcomm;
7578 char _state;
7679 pid_t _ppid;
7780 pid_t _pgrp;
@@ -163,6 +166,17 @@
164167 if (!(f >> _msize >> _mres >> _mshare >> _mtext >> _mlib >> _mdata))
165168 throw std::runtime_error("could not parse statm line");
166169 }
 170+
 171+ {
 172+ std::ifstream f((pth / "cmdline").native_file_string().c_str());
 173+ std::string sline;
 174+
 175+ if (!f)
 176+ throw std::runtime_error("could not read line from cmdline");
 177+
 178+ if (!(f >> _fullcomm))
 179+ throw std::runtime_error("could not parse cmdline");
 180+ }
167181 }
168182
169183 std::string
@@ -629,9 +643,14 @@
630644
631645 while (bytes >= config.thresh && !u.processes.empty()) {
632646 process &p = u.processes[0];
 647+
 648+ /* command is (%s) formatted, strip parentheses. */
633649 std::string comm = p._comm.substr(1);
634650 comm.resize(comm.size() - 1);
635651
 652+ /* arguments are \0 separated, use spaces for display */
 653+ std::replace(p._fullcomm.begin(), p._fullcomm.end(), '\0', ' ');
 654+
636655 if (!config.debug)
637656 kill(p._pid, SIGKILL);
638657
@@ -642,8 +661,8 @@
643662 % (thissize / 1024 / 1024)
644663 % ((bytes - thissize) / 1024 / 1024)));
645664
646 - process_list += str(boost::format(" %s (pid %d), using %d megabyte(s)\n")
647 - % comm % p._pid % (thissize / 1024 / 1024));
 665+ process_list += str(boost::format(" %s (pid %d), using %d megabyte(s). Command was:\n \"%s\"\n")
 666+ % comm % p._pid % (thissize / 1024 / 1024) % p._fullcomm);
648667
649668 bytes -= thissize;
650669 u.processes.erase(u.processes.begin());

Status & tagging log