summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoît Dejean <benoit@placenet.org>2006-09-19 14:38:14 +0000
committerBenoît Dejean <bdejean@src.gnome.org>2006-09-19 14:38:14 +0000
commit1ca0e5c5e763c408cf9e3904cca0fb6968b7145d (patch)
tree58e16d5205d53e62f91e21e615a353f7e0879e86
parent537bf34f9425768167c7e165fa23a167fb75e179 (diff)
downloadlibgtop-1ca0e5c5e763c408cf9e3904cca0fb6968b7145d.tar.gz
Added glibtop_get_proc_open_files implementation by Henry Zhang
2006-09-19 Benoît Dejean <benoit@placenet.org> * Makefile.am: * procopenfiles.c: (glibtop_init_proc_open_files_s), (glibtop_get_proc_open_files_s): Added glibtop_get_proc_open_files implementation by Henry Zhang <hua.zhang@sun.com>. Closes #346174.
-rw-r--r--sysdeps/solaris/ChangeLog10
-rw-r--r--sysdeps/solaris/Makefile.am1
-rw-r--r--sysdeps/solaris/procopenfiles.c130
3 files changed, 141 insertions, 0 deletions
diff --git a/sysdeps/solaris/ChangeLog b/sysdeps/solaris/ChangeLog
index dff4595c..3f4159ed 100644
--- a/sysdeps/solaris/ChangeLog
+++ b/sysdeps/solaris/ChangeLog
@@ -1,3 +1,13 @@
+2006-09-19 Benoît Dejean <benoit@placenet.org>
+
+ * Makefile.am:
+ * procopenfiles.c: (glibtop_init_proc_open_files_s),
+ (glibtop_get_proc_open_files_s):
+
+ Added glibtop_get_proc_open_files implementation by
+ Henry Zhang <hua.zhang@sun.com>.
+ Closes #346174.
+
2006-06-24 Benoît Dejean <benoit@placenet.org>
* proctime.c: (glibtop_get_proc_time_s):
diff --git a/sysdeps/solaris/Makefile.am b/sysdeps/solaris/Makefile.am
index 181111f5..3f43e69f 100644
--- a/sysdeps/solaris/Makefile.am
+++ b/sysdeps/solaris/Makefile.am
@@ -8,6 +8,7 @@ libgtop_sysdeps_2_0_la_SOURCES = open.c close.c siglist.c cpu.c mem.c \
proclist.c procstate.c procuid.c \
proctime.c procmem.c procsignal.c \
prockernel.c procsegment.c procargs.c \
+ procopenfiles.c \
procmap.c netload.c ppp.c procdata.c netlist.c
libgtop_sysdeps_2_0_la_LDFLAGS = $(LT_VERSION_INFO)
diff --git a/sysdeps/solaris/procopenfiles.c b/sysdeps/solaris/procopenfiles.c
new file mode 100644
index 00000000..cf24b0c2
--- /dev/null
+++ b/sysdeps/solaris/procopenfiles.c
@@ -0,0 +1,130 @@
+/* $Id$ */
+
+/* Copyright (C) 2006 Henry Zhang
+ This file is part of LibGTop 2.14.
+
+ Contributed by Henry Zhang <hua.zhang@sun.com>, July 2006.
+
+ LibGTop is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License,
+ or (at your option) any later version.
+
+ LibGTop is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with LibGTop; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+*/
+
+#include <config.h>
+#include <glibtop.h>
+#include <glibtop/error.h>
+#include <glibtop/procopenfiles.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdio.h>
+
+#include "glibtop_private.h"
+
+static const unsigned long _glibtop_sysdeps_proc_open_files =
+(1L << GLIBTOP_PROC_OPEN_FILES_NUMBER)|
+(1L << GLIBTOP_PROC_OPEN_FILES_TOTAL)|
+(1L << GLIBTOP_PROC_OPEN_FILES_SIZE);
+
+/* Init function. */
+
+void
+glibtop_init_proc_open_files_s (glibtop *server)
+{
+ server->sysdeps.proc_open_files = _glibtop_sysdeps_proc_open_files;
+}
+
+
+
+/* Provides detailed information about a process' open files */
+
+glibtop_open_files_entry *
+glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid)
+{
+ char filename [BUFSIZ];
+ GArray *entries;
+ struct dirent *direntry;
+ DIR *dir;
+ int errno;
+
+ glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_OPEN_FILES, 0);
+
+ memset (buf, 0, sizeof (glibtop_proc_open_files));
+
+ sprintf (filename, "/proc/%d/fd", pid);
+
+ dir = opendir (filename);
+ if (!dir) return NULL;
+
+ entries = g_array_new(FALSE, FALSE, sizeof(glibtop_open_files_entry));
+
+ while((direntry = readdir(dir))) {
+ char tgt [BUFSIZ];
+ int rv;
+ glibtop_open_files_entry entry = {0};
+ struct stat statbuf;
+
+ if(direntry->d_name[0] == '.')
+ continue;
+
+ if ((entry.fd = (int) g_ascii_strtoull(direntry->d_name, NULL, 10)) == 0)
+ continue;
+
+ /* from /path get object name */
+ g_snprintf(filename, sizeof filename, "/proc/%d/path/%s",
+ pid, direntry->d_name);
+
+ rv = readlink(filename, tgt, sizeof(tgt) - 1);
+ /* read object, if not have, set it as NULL, but this fd still need to insert into the array */
+ if(rv < 0)
+ rv = 0;
+ tgt[rv] = '\0';
+
+ /* from /fd get the stat data */
+ g_snprintf(filename, sizeof filename, "/proc/%d/fd/%s",
+ pid, direntry->d_name);
+
+ if(stat (filename, &statbuf))
+ statbuf.st_mode = 0;
+
+ switch (statbuf.st_mode & S_IFMT) {
+ case S_IFIFO: /* pipe */
+ entry.type = GLIBTOP_FILE_TYPE_PIPE;
+ break;
+ case S_IFSOCK: /* socket */
+ /* at solaris, now a little difficult to tell the Socket type, so here I
+ give the type 0, it will not impact the existed code. Later will provide
+ a patch to tell the type, and get the object name */
+ entry.type = 0;
+ break;
+ default:
+ entry.type = GLIBTOP_FILE_TYPE_FILE;
+ }
+
+ g_strlcpy(entry.info.file.name, tgt, sizeof entry.info.file.name);
+
+ g_array_append_val(entries, entry);
+ }
+
+ closedir (dir);
+
+ buf->flags = _glibtop_sysdeps_proc_open_files;
+ buf->number = entries->len;
+ buf->size = sizeof(glibtop_open_files_entry);
+ buf->total = buf->number * buf->size;
+
+ return (glibtop_open_files_entry*)g_array_free(entries, FALSE);
+}