public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM] master: Don't copy FileBytes.
Date: Tue, 20 May 2008 18:01:00 -0000 [thread overview]
Message-ID: <20080520180123.25285.qmail@sourceware.org> (raw)
The branch, master has been updated
via e3e3774f9865d9c6e7a94fc53b60ab5c0a5a96aa (commit)
from 73d257dda14d543954b156e4b5ecbb20312cc0b0 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email.
- Log -----------------------------------------------------------------
commit e3e3774f9865d9c6e7a94fc53b60ab5c0a5a96aa
Author: Andrew Cagney <cagney@redhat.com>
Date: Tue May 20 13:59:50 2008 -0400
Don't copy FileBytes.
frysk-sys/frysk/sys/proc/ChangeLog
2008-05-20 Andrew Cagney <cagney@redhat.com>
* jni/Stat.cxx: Delete stray print statements.
frysk-sys/jnixx/ChangeLog
2008-05-20 Andrew Cagney <cagney@redhat.com>
* elements.hxx (class FileBytes): Add pid/tid method.
* elements.cxx (FileBytes::FileBytes): Implement.
(slurp): Refactor out of FileBytes constructor; include NUL in
length.
-----------------------------------------------------------------------
Summary of changes:
frysk-sys/frysk/sys/proc/ChangeLog | 2 +
frysk-sys/frysk/sys/proc/jni/Stat.cxx | 2 -
frysk-sys/jnixx/ChangeLog | 5 ++
frysk-sys/jnixx/elements.cxx | 68 ++++++++++++++++++++++-----------
frysk-sys/jnixx/elements.hxx | 1 +
5 files changed, 53 insertions(+), 25 deletions(-)
First 500 lines of diff:
diff --git a/frysk-sys/frysk/sys/proc/ChangeLog b/frysk-sys/frysk/sys/proc/ChangeLog
index dc6accf..a2a3c3a 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/Stat.cxx: Delete stray print statements.
+
* jni/Stat.cxx: Implement.
* jni/MapsBuilder.cxx: Implement.
diff --git a/frysk-sys/frysk/sys/proc/jni/Stat.cxx b/frysk-sys/frysk/sys/proc/jni/Stat.cxx
index d4135bb..df0e85a 100644
--- a/frysk-sys/frysk/sys/proc/jni/Stat.cxx
+++ b/frysk-sys/frysk/sys/proc/jni/Stat.cxx
@@ -130,9 +130,7 @@ frysk::sys::proc::Stat::scan(jnixx::env env, jint procPid, jint threadTid) {
frysk::sys::proc::Stat
frysk::sys::proc::Stat::scan(jnixx::env env, jint procPid) {
- fprintf(stderr, "opening %d\n", procPid);
FileBytes bytes = FileBytes(env, procPid, "stat");
- fprintf(stderr, "elements %s\n", bytes.elements);
if (bytes.elements == NULL)
return Stat(env, NULL);
::scan(env, (const char*) bytes.elements, *this, GetFine(env));
diff --git a/frysk-sys/jnixx/ChangeLog b/frysk-sys/jnixx/ChangeLog
index ed3049d..fb7e090 100644
--- a/frysk-sys/jnixx/ChangeLog
+++ b/frysk-sys/jnixx/ChangeLog
@@ -1,5 +1,10 @@
2008-05-20 Andrew Cagney <cagney@redhat.com>
+ * elements.hxx (class FileBytes): Add pid/tid method.
+ * elements.cxx (FileBytes::FileBytes): Implement.
+ (slurp): Refactor out of FileBytes constructor; include NUL in
+ length.
+
* scan.hxx: New.
* scan.cxx: New.
diff --git a/frysk-sys/jnixx/elements.cxx b/frysk-sys/jnixx/elements.cxx
index 937609c..65b3315 100644
--- a/frysk-sys/jnixx/elements.cxx
+++ b/frysk-sys/jnixx/elements.cxx
@@ -101,16 +101,8 @@ chars2strings(::jnixx::env env, char** argv) {
return strings;
}
-FileBytes::FileBytes(jnixx::env env, const char* fmt, ...) {
- // Convert the string into a file.
- char file[FILENAME_MAX];
- va_list ap;
- va_start(ap, fmt);
- if (::vsnprintf(file, sizeof file, fmt, ap) >= FILENAME_MAX) {
- errnoException(env, errno, "snprintf");
- }
- va_end(ap);
-
+void
+slurp(jnixx::env env, FileBytes& bytes, const char* file) {
// Attempt to open the file.
int fd = ::open(file, O_RDONLY);
if (fd < 0) {
@@ -124,49 +116,79 @@ FileBytes::FileBytes(jnixx::env env, const char* fmt, ...) {
// reads are needed to confirm EOF. Allocating 2&BUFSIZE ensures
// that there's always space for at least two reads. Ref SW #3370
jsize allocated = BUFSIZ * 2 + 1;
- elements = (jbyte*) ::malloc(allocated);
- if (elements == NULL) {
+ bytes.elements = (jbyte*) ::malloc(allocated);
+ if (bytes.elements == NULL) {
errnoException(env, errno, "malloc");
}
- length = 0;
+ bytes.length = 0;
while (true) {
// Attempt to fill the remaining buffer; less space for a
// terminating NUL character.
- int size = ::read(fd, elements + length, allocated - length - 1);
+ int size = ::read(fd, bytes.elements + bytes.length,
+ allocated - bytes.length - 1);
if (size < 0) {
::close(fd);
- release();
+ bytes.release();
+ // Abandon the read with elements == NULL.
return;
} else if (size == 0) {
break;
}
- length += size;
+ bytes.length += size;
- if (length + BUFSIZ >= allocated) {
+ if (bytes.length + BUFSIZ >= allocated) {
// Not enough space for the next ~BUFSIZ'd read; expand the
// buffer. Don't trust realloc with the pointer; will need to
// free the old buffer if something goes wrong.
allocated += BUFSIZ;
- jbyte *tmp = (jbyte*)::realloc(elements, allocated);
+ jbyte *tmp = (jbyte*)::realloc(bytes.elements, allocated);
if (tmp == NULL) {
int err = errno;
::close(fd);
- release();
+ bytes.release();
errnoException(env, err, "realloc");
}
- elements = tmp;
+ bytes.elements = tmp;
}
}
::close(fd);
// Null terminate the buffer.
- elements[length] = '\0';
+ bytes.elements[bytes.length] = '\0';
+ bytes.length++; // count the trailing NUL
}
-FileBytes::FileBytes(jnixx::env env, jint pid, const char* name) {
- FileBytes(env, "/proc/%d/%s", (int) pid, name);
+FileBytes::FileBytes(jnixx::env env, const char* fmt, ...) {
+ // Convert the string into a file.
+ char file[FILENAME_MAX];
+ va_list ap;
+ va_start(ap, fmt);
+ if (::vsnprintf(file, sizeof file, fmt, ap) >= FILENAME_MAX) {
+ errnoException(env, errno, "vsnprintf");
+ }
+ va_end(ap);
+ slurp(env, *this, file);
+}
+
+FileBytes::FileBytes(jnixx::env env, int pid, const char* name) {
+ // Convert the string into a file.
+ char file[FILENAME_MAX];
+ if (::snprintf(file, sizeof file, "/proc/%d/%s", pid, name) >= FILENAME_MAX) {
+ errnoException(env, errno, "snprintf");
+ }
+ slurp(env, *this, file);
+}
+
+FileBytes::FileBytes(jnixx::env env, int pid, int tid, const char* name) {
+ // Convert the string into a file.
+ char file[FILENAME_MAX];
+ if (::snprintf(file, sizeof file, "/proc/%d/task/%d/%s", pid, tid, name)
+ >= FILENAME_MAX) {
+ errnoException(env, errno, "snprintf");
+ }
+ slurp(env, *this, file);
}
void
diff --git a/frysk-sys/jnixx/elements.hxx b/frysk-sys/jnixx/elements.hxx
index ebaad34..28b41f8 100644
--- a/frysk-sys/jnixx/elements.hxx
+++ b/frysk-sys/jnixx/elements.hxx
@@ -100,6 +100,7 @@ public:
FileBytes(jnixx::env, const char* fmt, ...)
__attribute__((format(printf, 3, 4)));
FileBytes(jnixx::env, int pid, const char* name);
+ FileBytes(jnixx::env, int pid, int tid, const char* name);
void release();
~FileBytes() {
release();
hooks/post-receive
--
frysk system monitor/debugger
reply other threads:[~2008-05-20 18:01 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=20080520180123.25285.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).