public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Implement jni/Status.cxx.
@ 2008-05-20 18:20 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-05-20 18:20 UTC (permalink / raw)
  To: frysk-cvs

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-05-20 18:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-20 18:20 [SCM] master: Implement jni/Status.cxx cagney

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).