public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Implement jni/Status.cxx.
Date: Tue, 20 May 2008 18:20:00 -0000	[thread overview]
Message-ID: <20080520182005.19166.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  c578532603748f8d4b4de3f5b6ada6daeaba5f03 (commit)
      from  e3e3774f9865d9c6e7a94fc53b60ab5c0a5a96aa (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit c578532603748f8d4b4de3f5b6ada6daeaba5f03
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue May 20 14:19:26 2008 -0400

    Implement jni/Status.cxx.
    
    frysk-sys/frysk/sys/proc/ChangeLog
    2008-05-20  Andrew Cagney  <cagney@redhat.com>
    
    	* jni/Status.cxx: Implement.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/sys/proc/ChangeLog      |    2 +
 frysk-sys/frysk/sys/proc/jni/Status.cxx |   94 ++++++++++++++++++++++++++++++-
 2 files changed, 95 insertions(+), 1 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/sys/proc/ChangeLog b/frysk-sys/frysk/sys/proc/ChangeLog
index a2a3c3a..c88c933 100644
--- a/frysk-sys/frysk/sys/proc/ChangeLog
+++ b/frysk-sys/frysk/sys/proc/ChangeLog
@@ -1,5 +1,7 @@
 2008-05-20  Andrew Cagney  <cagney@redhat.com>
 
+	* jni/Status.cxx: Implement.
+
 	* jni/Stat.cxx: Delete stray print statements.
 	
 	* jni/Stat.cxx: Implement.
diff --git a/frysk-sys/frysk/sys/proc/jni/Status.cxx b/frysk-sys/frysk/sys/proc/jni/Status.cxx
index b358932..8aae8d4 100644
--- a/frysk-sys/frysk/sys/proc/jni/Status.cxx
+++ b/frysk-sys/frysk/sys/proc/jni/Status.cxx
@@ -1,6 +1,6 @@
 // This file is part of the program FRYSK.
 //
-// Copyright 2008, 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,4 +37,96 @@
 // version and license this file solely under the GPL without
 // exception.
 
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <string.h>
+
 #include "jni.hxx"
+
+#include "jnixx/exceptions.hxx"
+#include "jnixx/logging.hxx"
+#include "jnixx/elements.hxx"
+
+using namespace java::lang;
+using namespace frysk::sys::proc;
+
+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 Status
+scan(jnixx::env env, const char *p, Status status, frysk::rsl::Log fine) {
+  // Clear everything
+  status.SetState(env, '\0');
+  status.SetStoppedState(env, false);
+  status.SetUid(env, -1);
+  status.SetGid(env, -1);
+
+  // STATE (SUBSTATE)
+  const char *state = "\nState:";
+  p = strstr(p, state);
+  if (p == NULL)
+    return Status(env, NULL);
+  p += strlen(state);
+  for (; (*p) != '\r' && (*p) != '\0'; p++) {
+    char c = (*p);
+    if (isspace(c))
+      continue;
+    if (strchr("RSDZTW", c) != NULL) {
+      logf(env, fine, "state '%c'", c);
+      status.SetState(env, c);
+      const char *stopped = " (stopped)";
+      bool isStopped = (strncmp(p + 1, stopped, strlen(stopped)) == 0);
+      logf(env, fine, "stopped %s", isStopped ? "true" : "false");
+      status.SetStoppedState(env, isStopped);
+      break;
+    }
+  }
+  if (state == '\0')
+    return Status(env, NULL);
+
+  // UID
+  int uid;
+  if (!scan(&p, &uid, "\nUid:"))
+    return Status(env, NULL);
+  logf(env, fine, "uid %d", uid);
+  status.SetUid(env, uid);
+
+  // GID
+  int gid;
+  if (!scan(&p, &gid, "\nGid:"))
+    return Status(env, NULL);
+  logf(env, fine, "gid %d", gid);
+  status.SetGid(env, gid);
+
+  return status;
+}
+
+Status
+Status::scan(jnixx::env env, jint pid) {
+  FileBytes bytes = FileBytes(env, pid, "status");
+  if (bytes.elements == NULL)
+    return Status(env, NULL);
+  Status s = ::scan(env, (const char*)bytes.elements, *this, GetFine(env));
+  bytes.release();
+  return s;
+}
+
+Status
+Status::scan(jnixx::env env, jnixx::byteArray buf) {
+  ArrayBytes bytes = ArrayBytes(env, buf);
+  Status s = ::scan(env, (const char*)bytes.elements, *this, GetFine(env));
+  bytes.release();
+  return s;
+}
+


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-05-20 18:20 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=20080520182005.19166.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: link
Be 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).