public inbox for frysk-cvs@sourceware.org help / color / mirror / Atom feed
From: cagney@sourceware.org To: frysk-cvs@sourceware.org Subject: [SCM] master: Change Status to a scanner class like Stat; update. Date: Thu, 14 Feb 2008 16:38:00 -0000 [thread overview] Message-ID: <20080214163835.31532.qmail@sourceware.org> (raw) The branch, master has been updated via e5a826018181d156023024ce27a707bbfb62c0a0 (commit) from 6f90ccc376e5bc50e2ad3a6cd97f1424660d6329 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email. - Log ----------------------------------------------------------------- commit e5a826018181d156023024ce27a707bbfb62c0a0 Author: Andrew Cagney <cagney@redhat.com> Date: Thu Feb 14 11:38:11 2008 -0500 Change Status to a scanner class like Stat; update. frysk-core/frysk/isa/corefiles/ChangeLog 2008-02-14 Andrew Cagney <cagney@redhat.com> * IA32LinuxElfCorefile.java: Delete use of Status. * PPC64LinuxElfCorefile.java: Ditto. * PPC32LinuxElfCorefile.java: Ditto. * X8664LinuxElfCorefile.java: Ditto. frysk-core/frysk/proc/live/ChangeLog 2008-02-14 Andrew Cagney <cagney@redhat.com> * LinuxPtraceProc.java: Update to match Status. * LinuxPtraceTaskState.java: Ditto. frysk-sys/frysk/sys/proc/ChangeLog 2008-02-14 Andrew Cagney <cagney@redhat.com> * Status.java: Rewrite. * TestStatus.java: Update. * cni/Status.cxx (Status::scan): Update. ----------------------------------------------------------------------- Summary of changes: frysk-core/frysk/isa/corefiles/ChangeLog | 7 + .../frysk/isa/corefiles/IA32LinuxElfCorefile.java | 5 +- .../frysk/isa/corefiles/PPC32LinuxElfCorefile.java | 5 +- .../frysk/isa/corefiles/PPC64LinuxElfCorefile.java | 5 +- .../frysk/isa/corefiles/X8664LinuxElfCorefile.java | 5 +- frysk-core/frysk/proc/live/ChangeLog | 3 + frysk-core/frysk/proc/live/LinuxPtraceProc.java | 8 +- .../frysk/proc/live/LinuxPtraceTaskState.java | 6 +- frysk-sys/frysk/sys/proc/ChangeLog | 6 + frysk-sys/frysk/sys/proc/Status.java | 116 ++++++-------------- frysk-sys/frysk/sys/proc/TestStatus.java | 55 ++++----- frysk-sys/frysk/sys/proc/cni/Status.cxx | 82 +++++++++++++- 12 files changed, 168 insertions(+), 135 deletions(-) First 500 lines of diff: diff --git a/frysk-core/frysk/isa/corefiles/ChangeLog b/frysk-core/frysk/isa/corefiles/ChangeLog index da92ce7..086d81c 100644 --- a/frysk-core/frysk/isa/corefiles/ChangeLog +++ b/frysk-core/frysk/isa/corefiles/ChangeLog @@ -1,3 +1,10 @@ +2008-02-14 Andrew Cagney <cagney@redhat.com> + + * IA32LinuxElfCorefile.java: Delete use of Status. + * PPC64LinuxElfCorefile.java: Ditto. + * PPC32LinuxElfCorefile.java: Ditto. + * X8664LinuxElfCorefile.java: Ditto. + 2008-02-13 Andrew Cagney <cagney@redhat.com> * IA32LinuxElfCorefile.java: Update to match Status. diff --git a/frysk-core/frysk/isa/corefiles/IA32LinuxElfCorefile.java b/frysk-core/frysk/isa/corefiles/IA32LinuxElfCorefile.java index fd2fe28..7fc5bcc 100644 --- a/frysk-core/frysk/isa/corefiles/IA32LinuxElfCorefile.java +++ b/frysk-core/frysk/isa/corefiles/IA32LinuxElfCorefile.java @@ -61,7 +61,6 @@ import frysk.proc.Task; import frysk.sys.proc.AuxvBuilder; import frysk.sys.proc.CmdLineBuilder; import frysk.sys.proc.Stat; -import frysk.sys.proc.Status; /** * LinuxElfCorefilex86. Extends LinuxCorefile. Fill in @@ -120,8 +119,8 @@ public class IA32LinuxElfCorefile extends LinuxElfCorefile { // Set rest of prpsinfo prpsInfo.setPrFlag(processStat.flags); - prpsInfo.setPrUid(Status.getUID(ProcessIdentifierFactory.create(pid))); - prpsInfo.setPrGid(Status.getGID(ProcessIdentifierFactory.create(pid))); + prpsInfo.setPrUid(process.getUID()); + prpsInfo.setPrGid(process.getGID()); prpsInfo.setPrPid(pid); prpsInfo.setPrPpid(processStat.ppid.intValue()); diff --git a/frysk-core/frysk/isa/corefiles/PPC32LinuxElfCorefile.java b/frysk-core/frysk/isa/corefiles/PPC32LinuxElfCorefile.java index 93cc4e0..e418179 100644 --- a/frysk-core/frysk/isa/corefiles/PPC32LinuxElfCorefile.java +++ b/frysk-core/frysk/isa/corefiles/PPC32LinuxElfCorefile.java @@ -65,7 +65,6 @@ import frysk.proc.Task; import frysk.sys.proc.AuxvBuilder; import frysk.sys.proc.CmdLineBuilder; import frysk.sys.proc.Stat; -import frysk.sys.proc.Status; /** * PPC32LinuxElfCorefile. Extends LinuxCorefile. Fill in @@ -125,8 +124,8 @@ public class PPC32LinuxElfCorefile extends LinuxElfCorefile { // Set rest of prpsinfo prpsInfo.setPrFlag(processStat.flags); - prpsInfo.setPrUid(Status.getUID(ProcessIdentifierFactory.create(pid))); - prpsInfo.setPrGid(Status.getGID(ProcessIdentifierFactory.create(pid))); + prpsInfo.setPrUid(process.getUID()); + prpsInfo.setPrGid(process.getGID()); prpsInfo.setPrPid(pid); prpsInfo.setPrPpid(processStat.ppid.intValue()); diff --git a/frysk-core/frysk/isa/corefiles/PPC64LinuxElfCorefile.java b/frysk-core/frysk/isa/corefiles/PPC64LinuxElfCorefile.java index 7fc9005..cf31acf 100644 --- a/frysk-core/frysk/isa/corefiles/PPC64LinuxElfCorefile.java +++ b/frysk-core/frysk/isa/corefiles/PPC64LinuxElfCorefile.java @@ -64,7 +64,6 @@ import frysk.proc.Task; import frysk.sys.proc.AuxvBuilder; import frysk.sys.proc.CmdLineBuilder; import frysk.sys.proc.Stat; -import frysk.sys.proc.Status; /** * PPC64LinuxElfCorefile. Extends LinuxCorefile. Fill in @@ -124,8 +123,8 @@ public class PPC64LinuxElfCorefile extends LinuxElfCorefile { // Set rest of prpsinfo prpsInfo.setPrFlag(processStat.flags); - prpsInfo.setPrUid(Status.getUID(ProcessIdentifierFactory.create(pid))); - prpsInfo.setPrGid(Status.getGID(ProcessIdentifierFactory.create(pid))); + prpsInfo.setPrUid(process.getUID()); + prpsInfo.setPrGid(process.getGID()); prpsInfo.setPrPid(pid); prpsInfo.setPrPpid(processStat.ppid.intValue()); diff --git a/frysk-core/frysk/isa/corefiles/X8664LinuxElfCorefile.java b/frysk-core/frysk/isa/corefiles/X8664LinuxElfCorefile.java index 6197f31..2a27a1b 100644 --- a/frysk-core/frysk/isa/corefiles/X8664LinuxElfCorefile.java +++ b/frysk-core/frysk/isa/corefiles/X8664LinuxElfCorefile.java @@ -60,7 +60,6 @@ import frysk.proc.Task; import frysk.sys.proc.AuxvBuilder; import frysk.sys.proc.CmdLineBuilder; import frysk.sys.proc.Stat; -import frysk.sys.proc.Status; /** * X8664LinuxElfCorefile. Extends LinuxCorefile. Fill in @@ -120,8 +119,8 @@ public class X8664LinuxElfCorefile extends LinuxElfCorefile { // Set rest of prpsinfo prpsInfo.setPrFlag(processStat.flags); - prpsInfo.setPrUid(Status.getUID(ProcessIdentifierFactory.create(pid))); - prpsInfo.setPrGid(Status.getGID(ProcessIdentifierFactory.create(pid))); + prpsInfo.setPrUid(process.getUID()); + prpsInfo.setPrGid(process.getGID()); prpsInfo.setPrPid(pid); prpsInfo.setPrPpid(processStat.ppid.intValue()); diff --git a/frysk-core/frysk/proc/live/ChangeLog b/frysk-core/frysk/proc/live/ChangeLog index 0cec713..d370c3e 100644 --- a/frysk-core/frysk/proc/live/ChangeLog +++ b/frysk-core/frysk/proc/live/ChangeLog @@ -1,5 +1,8 @@ 2008-02-14 Andrew Cagney <cagney@redhat.com> + * LinuxPtraceProc.java: Update to match Status. + * LinuxPtraceTaskState.java: Ditto. + * LiveTask.java: Update to match Task. * LinuxPtraceProc.java: Ditto. * LinuxPtraceHost.java: Ditto. diff --git a/frysk-core/frysk/proc/live/LinuxPtraceProc.java b/frysk-core/frysk/proc/live/LinuxPtraceProc.java index 2c179c3..e5808f5 100644 --- a/frysk-core/frysk/proc/live/LinuxPtraceProc.java +++ b/frysk-core/frysk/proc/live/LinuxPtraceProc.java @@ -176,11 +176,15 @@ public class LinuxPtraceProc extends LiveProc { } public int getUID() { - return Status.getUID(ProcessIdentifierFactory.create(getPid())); + Status status = new Status(); + status.scan(ProcessIdentifierFactory.create(getPid())); + return status.uid; } public int getGID() { - return Status.getGID(ProcessIdentifierFactory.create(getPid())); + Status status = new Status(); + status.scan(ProcessIdentifierFactory.create(getPid())); + return status.gid; } /** diff --git a/frysk-core/frysk/proc/live/LinuxPtraceTaskState.java b/frysk-core/frysk/proc/live/LinuxPtraceTaskState.java index ff60e45..f84ab24 100644 --- a/frysk-core/frysk/proc/live/LinuxPtraceTaskState.java +++ b/frysk-core/frysk/proc/live/LinuxPtraceTaskState.java @@ -181,13 +181,15 @@ class LinuxPtraceTaskState extends State { LinuxPtraceTaskState handleAttach(LinuxPtraceTask task) { logger.log(Level.FINE, "{0} handleAttach\n", task); task.sendAttach(); + Status status = new Status(); + status.scan(task.tid); if (task.getProc().getMainTask() == task - && Status.isStopped(task.tid)) { + && status.stoppedState) { // The attach has been initiated on the main // task of the process; the process state // should transition to (T) TRACED. If it is // instead (T) STOPPED then the process is - // stuck (suspended), send it a SIGSTOP to + // stuck (suspended), send it a SIGCONT to // unwedge it. /proc/status is used as that // differentiates between STOPPED an TRACED. logger.log(Level.FINE, diff --git a/frysk-sys/frysk/sys/proc/ChangeLog b/frysk-sys/frysk/sys/proc/ChangeLog index 4ebb3a3..0ba620c 100644 --- a/frysk-sys/frysk/sys/proc/ChangeLog +++ b/frysk-sys/frysk/sys/proc/ChangeLog @@ -1,3 +1,9 @@ +2008-02-14 Andrew Cagney <cagney@redhat.com> + + * Status.java: Rewrite. + * TestStatus.java: Update. + * cni/Status.cxx (Status::scan): Update. + 2008-02-13 Andrew Cagney <cagney@redhat.com> * Status.java (getGID(ProcessIdentifier)): Replace getGID(int). diff --git a/frysk-sys/frysk/sys/proc/Status.java b/frysk-sys/frysk/sys/proc/Status.java index d3414e7..0590f4e 100644 --- a/frysk-sys/frysk/sys/proc/Status.java +++ b/frysk-sys/frysk/sys/proc/Status.java @@ -39,6 +39,7 @@ package frysk.sys.proc; +import frysk.rsl.Log; import frysk.sys.ProcessIdentifier; /** @@ -52,107 +53,56 @@ import frysk.sys.ProcessIdentifier; */ public class Status { + private static final Log fine = Log.fine(Status.class); - private native static byte[] statusSlurp (int pid); - - /** - * Converts a byte[] data structure to a - * String[] data structure - * @param byteBuffer[] - source byte byffer - * @return String[] - converted String buffer - */ - private static String[] byteBuffertoStringbuffer(byte[] byteBuffer) { - String byteString = new String(byteBuffer); - return byteString.split("\n"); + public Status() { } + public String toString() { + if (pid != null) + return "/proc/" + pid + "/status"; + else + return super.toString(); + } + + public Status scan(ProcessIdentifier pid) { + fine.log(this, "stan", pid); + this.pid = pid; + return scan(pid.intValue()); + } + private native Status scan(int pid); /** - * Given a byte[] buffer from /proc/$$/status - * find and return either GID or UID. - * @param idType - Type to return. Accepts Gid or Uid - * @param byteidBuffer - buffer to search. - * @return int either GID or UID of process, or -1 on error. + * For testing only; package private. */ - private static int getID(String idType, byte[] byteidBuffer) { - // As fetching a GID/UID are very similar we just pass of the - // search code to a simple lookup method - String[] idBuffer = byteBuffertoStringbuffer(byteidBuffer); - int idIndex = 5; - int idIndexEnd = 0; - for (int i=0; i<idBuffer.length; i++) { - if (idBuffer[i].startsWith(idType)) { - idIndexEnd = idIndex; - for (int j=idIndex; j<idBuffer[i].length(); j++) - if (idBuffer[i].charAt(j)=='\t') - break; - else - idIndexEnd++; - if (idIndex == idIndexEnd) - return -1; - else - return Integer.parseInt(idBuffer[i].substring(idIndex,idIndexEnd)); - } - } - // if we get here, id not found in status - return -1; - } + native Status scan(byte[] buffer); /** - * Return the UID from a given buffer. Buffer - * has to follow format of /proc/$$/status. - * @param buffer - buffer search. - * @return int - UID in buffer. + * Re-scan /proc/$$/status using the previous pid. */ - public static int getUID(byte[] buffer) { - if (buffer != null) - return getID("Uid", buffer); - else - return -1; + public Status rescan() { + return scan(pid.intValue()); } + public ProcessIdentifier pid; + /** - * Return the UID from the /proc/$$/status - * file according to the PID passed. - * @param spid - PID of process to search. - * @return int - UID of process PID. + * The UID from the /proc/$$/status file. */ - public static int getUID(ProcessIdentifier pid) { - byte[] buffer = statusSlurp(pid.intValue()); - return getUID(buffer); - } + public int uid; /** - * Return the GID from a given buffer. Buffer - * has to follow format of /proc/$$/status. - * @param buffer - buffer search. - * @return int - GID in buffer. + * Return the GID from the /proc/$$/status file according to the + * PID passed. */ - public static int getGID(byte[] buffer) { - if (buffer != null) - return getID("Gid", buffer); - else - return -1; - } - + public int gid; + /** - * Return the GID from the /proc/$$/status - * file according to the PID passed. - * @param spid - PID of process to search. - * @return int - GID of process PID. + * The state from /proc/$$/status file. */ - public static int getGID(ProcessIdentifier pid) { - byte[] buffer = statusSlurp(pid.intValue()); - return getGID(buffer); - } + public char state; /** - * Returns true if the PID is in a stopped state. + * True if the PID is in a stopped state. */ - public static boolean isStopped(ProcessIdentifier pid) { - byte[] buf = statusSlurp(pid.intValue()); - if (buf == null) - return false; // lost task? - String status = new String(buf); - return status.indexOf("T (stopped)") >= 0; - } + public boolean stoppedState; } diff --git a/frysk-sys/frysk/sys/proc/TestStatus.java b/frysk-sys/frysk/sys/proc/TestStatus.java index e855a82..e826c64 100644 --- a/frysk-sys/frysk/sys/proc/TestStatus.java +++ b/frysk-sys/frysk/sys/proc/TestStatus.java @@ -40,21 +40,19 @@ package frysk.sys.proc; import frysk.junit.TestCase; +import frysk.sys.Pid; /** * Test the Status getUID() and getGID() a predefined set of * <tt>/proc$$/status</tt> buffer. */ -public class TestStatus - extends TestCase -{ - public void testParseStatusGetID() - { +public class TestStatus extends TestCase { + public void testParseStatusGetID() { // Construct valid status buffer - String[] status = new String[] { + String[] statusBuf = new String[] { "Name:\tgaim\n", - "State:\tS (sleeping)\n", + "State:\tT (stopped)\n", "SleepAVG:\t88%\n", "Tgid:\t2765\n", "Pid:\t2765\n", @@ -87,31 +85,20 @@ public class TestStatus "SigCgt:\t0000000180014407\n", "CapInh:\t0000000000000000\n", "CapPrm:\t0000000000000000\n", - "CapEff:\t0000000000000000"}; + "CapEff:\t0000000000000000\n" + }; - byte[] buf = TestLib.stringsToBytes (status); + byte[] buf = TestLib.stringsToBytes(statusBuf); + Status status = new Status().scan(buf); + assertNotNull("status", status); // Test normal-expected results from a valid status buffer - assertEquals ("Normal Process UID", 500, Status.getUID(buf)); - assertEquals ("Normal Process GID", 500, Status.getGID(buf)); + assertEquals("Process UID", 500, status.uid); + assertEquals("Process GID", 500, status.gid); + assertEquals("Process Stopped State", true, status.stoppedState); } - public void testParseStatusNullBufferGetID() - { - // Test abnormal-expected results from invald status buffers - - // Test null buffer - - assertEquals("Null Buffer Process UID", -1, - Status.getUID((byte[])null)); - assertEquals("Null Buffer Process GID", -1, - Status.getGID((byte[])null)); - - } - - - public void testParseStatusInvalidBufferGetID() - { + public void testParseStatusInvalidBufferGetID() { // Test abnormal-expected results from invald status buffers // Test non-null but invalid buffer @@ -121,10 +108,18 @@ public class TestStatus "We stuck, nor breath nor motion;\n", "As idle as a painted ship\n", "Upon a painted ocean."}; - byte[] buf = TestLib.stringsToBytes(randomText); + Status status = new Status(); + assertNull("scan", status.scan(buf)); + + assertEquals("Non null Buffer, invalid text Process UID", -1, + status.uid); + assertEquals("Non null Buffer, invalid text Process GID", -1, + status.gid); + } - assertEquals("Non null Buffer, invalid text Process UID", -1, Status.getUID(buf)); - assertEquals("Non null Buffer, invalid text Process GID", -1, Status.getGID(buf)); + public void testSelf() { + Status status = new Status(); + assertNotNull("status value", status.scan(Pid.get())); } } diff --git a/frysk-sys/frysk/sys/proc/cni/Status.cxx b/frysk-sys/frysk/sys/proc/cni/Status.cxx index 62c4911..9cb6813 100644 --- a/frysk-sys/frysk/sys/proc/cni/Status.cxx +++ b/frysk-sys/frysk/sys/proc/cni/Status.cxx @@ -1,6 +1,6 @@ // This file is part of the program FRYSK. // -// Copyright 2006, Red Hat Inc. +// Copyright 2006, 2008, Red Hat Inc. // // FRYSK is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by @@ -37,17 +37,87 @@ // version and license this file solely under the GPL without // exception. +#include <stdlib.h> +#include <ctype.h> +#include <stdio.h> + #include <gcj/cni.h> #include "frysk/sys/proc/cni/slurp.hxx" #include "frysk/sys/cni/Errno.hxx" #include "frysk/sys/proc/Status.h" +#include "frysk/rsl/Log.h" +#include "frysk/rsl/cni/Log.hxx" #include "java/lang/String.h" -jbyteArray -frysk::sys::proc::Status::statusSlurp (jint pid) -{ - jbyteArray buf = slurp (pid, "status"); - return buf; +static bool +scan(const char** p, jint* val, const char* prefix) { + (*p) = strstr((*p), prefix); + if ((*p) == NULL) + return false; + (*p) += strlen(prefix); + char *endp; + (*val) = strtol((*p), &endp, 10); + if ((*p) == endp) + return false; + return true; +} + +static frysk::sys::proc::Status* +scan(const char *p, frysk::sys::proc::Status* const status, + frysk::rsl::Log* const fine) { + // Clear everything + status->state = '\0'; + status->stoppedState = false; + status->uid = -1; + status->gid = -1; + + // STATE (SUBSTATE) + const char *state = "\nState:"; + p = strstr(p, state); + if (p == NULL) + return NULL; + p += strlen(state); + for (; (*p) != '\r' && (*p) != '\0'; p++) { + char c = (*p); + if (isspace(c)) + continue; + if (strchr("RSDZTW", c) != NULL) { + status->state = c; + logf(fine, "state '%c'", c); + const char *stopped = " (stopped)"; + status->stoppedState = strncmp(p + 1, stopped, strlen(stopped)) == 0; + logf(fine, "stopped %s", status->stoppedState ? "true" : "false"); + break; + } + } + if (state == '\0') hooks/post-receive -- frysk system monitor/debugger
reply other threads:[~2008-02-14 16:38 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20080214163835.31532.qmail@sourceware.org \ --to=cagney@sourceware.org \ --cc=frysk-cvs@sourceware.org \ --cc=frysk@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).