Added missing files
svn path=/trunk/; revision=2580
This commit is contained in:
31
examples/wd.c
Normal file
31
examples/wd.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/procwd.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
pid_t pid;
|
||||
glibtop_proc_wd buf;
|
||||
char **dirs, **dir;
|
||||
|
||||
if (argc < 2 || !(pid = strtoul(argv[1], NULL, 0)))
|
||||
pid = getpid();
|
||||
|
||||
dirs = glibtop_get_proc_wd(&buf, pid);
|
||||
|
||||
g_print("Process %u:\n"
|
||||
" - root: '%s'\n"
|
||||
" - exe: '%s'\n"
|
||||
" - working directories:\n",
|
||||
(unsigned)pid, buf.root, buf.exe);
|
||||
|
||||
for (dir = dirs; *dir; ++dir)
|
||||
g_print(" - '%s'\n", *dir);
|
||||
|
||||
g_strfreev(dirs);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
69
include/glibtop/procwd.h
Normal file
69
include/glibtop/procwd.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* Copyright (C) 2007 Benoît Dejean
|
||||
This file is part of LibGTop 2.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
#ifndef __GLIBTOP_PROCWD_H__
|
||||
#define __GLIBTOP_PROCWD_H__
|
||||
|
||||
#include <glibtop.h>
|
||||
#include <glibtop/global.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _glibtop_proc_wd glibtop_proc_wd;
|
||||
|
||||
#define GLIBTOP_PROC_WD_NUMBER 0
|
||||
#define GLIBTOP_PROC_WD_ROOT 1
|
||||
#define GLIBTOP_PROC_WD_EXE 2
|
||||
#define GLIBTOP_PROC_WD_MAX 3
|
||||
|
||||
#define GLIBTOP_PROC_WD_ROOT_LEN 215
|
||||
#define GLIBTOP_PROC_WD_EXE_LEN 215
|
||||
|
||||
struct _glibtop_proc_wd
|
||||
{
|
||||
guint64 flags;
|
||||
guint32 number;
|
||||
char root[GLIBTOP_PROC_WD_ROOT_LEN+1];
|
||||
char exe[GLIBTOP_PROC_WD_EXE_LEN+1];
|
||||
};
|
||||
|
||||
|
||||
char ** glibtop_get_proc_wd(glibtop_proc_wd *buf, pid_t pid);
|
||||
char ** glibtop_get_proc_wd_l(glibtop *server, glibtop_proc_wd *buf, pid_t pid);
|
||||
|
||||
|
||||
#if GLIBTOP_SUID_PROC_WD
|
||||
|
||||
#define glibtop_get_proc_wd_r glibtop_get_proc_wd_p
|
||||
void _glibtop_init_proc_wd_p(glibtop *server);
|
||||
char ** glibtop_get_proc_wd_p(glibtop *server, glibtop_proc_wd *buf, pid_t pid);
|
||||
|
||||
#else
|
||||
|
||||
#define glibtop_get_proc_wd_r glibtop_get_proc_wd_s
|
||||
void _glibtop_init_proc_wd_s(glibtop *server);
|
||||
char ** glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
130
lib/libgtop.sym
Normal file
130
lib/libgtop.sym
Normal file
@@ -0,0 +1,130 @@
|
||||
glibtop_call_l
|
||||
glibtop_call_p
|
||||
glibtop_close
|
||||
glibtop_close_p
|
||||
glibtop_close_r
|
||||
glibtop_close_s
|
||||
glibtop_get_cpu
|
||||
glibtop_get_cpu_l
|
||||
glibtop_get_cpu_p
|
||||
glibtop_get_cpu_s
|
||||
glibtop_get_fsusage
|
||||
glibtop_get_fsusage_l
|
||||
glibtop_get_fsusage_p
|
||||
glibtop_get_fsusage_s
|
||||
glibtop_get_loadavg
|
||||
glibtop_get_loadavg_l
|
||||
glibtop_get_loadavg_p
|
||||
glibtop_get_loadavg_s
|
||||
glibtop_get_mem
|
||||
glibtop_get_mem_l
|
||||
glibtop_get_mem_p
|
||||
glibtop_get_mem_s
|
||||
glibtop_get_mountlist
|
||||
glibtop_get_mountlist_l
|
||||
glibtop_get_mountlist_p
|
||||
glibtop_get_mountlist_s
|
||||
glibtop_get_msg_limits
|
||||
glibtop_get_msg_limits_l
|
||||
glibtop_get_msg_limits_p
|
||||
glibtop_get_msg_limits_s
|
||||
glibtop_get_netlist
|
||||
glibtop_get_netlist_l
|
||||
glibtop_get_netlist_p
|
||||
glibtop_get_netlist_s
|
||||
glibtop_get_netload
|
||||
glibtop_get_netload_l
|
||||
glibtop_get_netload_p
|
||||
glibtop_get_netload_s
|
||||
glibtop_get_parameter_l
|
||||
glibtop_get_parameter_p
|
||||
glibtop_get_ppp
|
||||
glibtop_get_ppp_l
|
||||
glibtop_get_ppp_p
|
||||
glibtop_get_ppp_s
|
||||
glibtop_get_proc_args
|
||||
glibtop_get_proc_args_l
|
||||
glibtop_get_proc_args_p
|
||||
glibtop_get_proc_args_s
|
||||
glibtop_get_proc_argv
|
||||
glibtop_get_proc_argv_l
|
||||
glibtop_get_proc_argv_p
|
||||
glibtop_get_proc_kernel
|
||||
glibtop_get_proc_kernel_l
|
||||
glibtop_get_proc_kernel_p
|
||||
glibtop_get_proc_kernel_s
|
||||
glibtop_get_proclist
|
||||
glibtop_get_proclist_l
|
||||
glibtop_get_proclist_p
|
||||
glibtop_get_proclist_s
|
||||
glibtop_get_proc_map
|
||||
glibtop_get_proc_map_l
|
||||
glibtop_get_proc_map_p
|
||||
glibtop_get_proc_map_s
|
||||
glibtop_get_proc_mem
|
||||
glibtop_get_proc_mem_l
|
||||
glibtop_get_proc_mem_p
|
||||
glibtop_get_proc_mem_s
|
||||
glibtop_get_proc_open_files
|
||||
glibtop_get_proc_open_files_l
|
||||
glibtop_get_proc_open_files_p
|
||||
glibtop_get_proc_open_files_s
|
||||
glibtop_get_proc_segment
|
||||
glibtop_get_proc_segment_l
|
||||
glibtop_get_proc_segment_p
|
||||
glibtop_get_proc_segment_s
|
||||
glibtop_get_proc_signal
|
||||
glibtop_get_proc_signal_l
|
||||
glibtop_get_proc_signal_p
|
||||
glibtop_get_proc_signal_s
|
||||
glibtop_get_proc_state
|
||||
glibtop_get_proc_state_l
|
||||
glibtop_get_proc_state_p
|
||||
glibtop_get_proc_state_s
|
||||
glibtop_get_proc_time
|
||||
glibtop_get_proc_time_l
|
||||
glibtop_get_proc_time_p
|
||||
glibtop_get_proc_time_s
|
||||
glibtop_get_proc_uid
|
||||
glibtop_get_proc_uid_l
|
||||
glibtop_get_proc_uid_p
|
||||
glibtop_get_proc_uid_s
|
||||
glibtop_get_proc_wd
|
||||
glibtop_get_proc_wd_l
|
||||
glibtop_get_proc_wd_p
|
||||
glibtop_get_proc_wd_s
|
||||
glibtop_get_sem_limits
|
||||
glibtop_get_sem_limits_l
|
||||
glibtop_get_sem_limits_p
|
||||
glibtop_get_sem_limits_s
|
||||
glibtop_get_shm_limits
|
||||
glibtop_get_shm_limits_l
|
||||
glibtop_get_shm_limits_p
|
||||
glibtop_get_shm_limits_s
|
||||
glibtop_get_swap
|
||||
glibtop_get_swap_l
|
||||
glibtop_get_swap_p
|
||||
glibtop_get_swap_s
|
||||
glibtop_get_sysdeps
|
||||
glibtop_get_sysdeps_r
|
||||
glibtop_get_sysinfo
|
||||
glibtop_get_sysinfo_p
|
||||
glibtop_get_sysinfo_s
|
||||
glibtop_get_uptime
|
||||
glibtop_get_uptime_l
|
||||
glibtop_get_uptime_p
|
||||
glibtop_get_uptime_s
|
||||
glibtop_global_server
|
||||
glibtop_init
|
||||
glibtop_init_p
|
||||
glibtop_init_r
|
||||
glibtop_init_s
|
||||
glibtop_internet_addr
|
||||
glibtop_make_connection
|
||||
glibtop_open_l
|
||||
glibtop_open_p
|
||||
glibtop_open_s
|
||||
glibtop_server_features
|
||||
glibtop_set_parameter_l
|
||||
glibtop_set_parameter_p
|
||||
glibtop_sys_siglist
|
98
sysdeps/linux/procwd.c
Normal file
98
sysdeps/linux/procwd.c
Normal file
@@ -0,0 +1,98 @@
|
||||
/* Copyright (C) 2007 Benoît Dejean
|
||||
This file is part of LibGTop 2.
|
||||
|
||||
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/procwd.h>
|
||||
#include <glibtop/error.h>
|
||||
|
||||
#include <glibtop_private.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
void
|
||||
_glibtop_init_proc_wd_s(glibtop *server)
|
||||
{
|
||||
server->sysdeps.proc_wd =
|
||||
(1 << GLIBTOP_PROC_WD_EXE) +
|
||||
(1 << GLIBTOP_PROC_WD_ROOT) +
|
||||
(1 << GLIBTOP_PROC_WD_NUMBER);
|
||||
|
||||
}
|
||||
|
||||
static gboolean is_in(GPtrArray *array, const char *str)
|
||||
{
|
||||
guint i;
|
||||
|
||||
for (i = 0; i != array->len; ++i) {
|
||||
if (strcmp(g_ptr_array_index(array, i), str) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
char**
|
||||
glibtop_get_proc_wd_s(glibtop *server, glibtop_proc_wd *buf, pid_t pid)
|
||||
{
|
||||
GPtrArray *dirs;
|
||||
char path[80];
|
||||
char dir[256];
|
||||
DIR *task;
|
||||
|
||||
glibtop_init_s(&server, GLIBTOP_SYSDEPS_PROC_WD, 0);
|
||||
|
||||
memset(buf, 0, sizeof(glibtop_proc_wd));
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/root", pid);
|
||||
if (safe_readlink(path, buf->root, sizeof buf->root))
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_ROOT);
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/exe", pid);
|
||||
if (safe_readlink(path, buf->exe, sizeof buf->exe))
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_EXE);
|
||||
|
||||
dirs = g_ptr_array_sized_new(2);
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/cwd", pid);
|
||||
if (safe_readlink(path, dir, sizeof dir))
|
||||
g_ptr_array_add(dirs, g_strdup(dir));
|
||||
|
||||
g_snprintf(path, sizeof path, "/proc/%u/task", pid);
|
||||
if ((task = opendir(path)) != NULL) {
|
||||
struct dirent *sub;
|
||||
while ((sub = readdir(task)) != NULL) {
|
||||
g_snprintf(path, sizeof path, "/proc/%u/task/%s/cwd", pid, sub->d_name);
|
||||
if (safe_readlink(path, dir, sizeof dir) && !is_in(dirs, dir))
|
||||
g_ptr_array_add(dirs, g_strdup(dir));
|
||||
}
|
||||
closedir(task);
|
||||
}
|
||||
|
||||
buf->number = dirs->len;
|
||||
buf->flags |= (1 << GLIBTOP_PROC_WD_NUMBER);
|
||||
|
||||
g_ptr_array_add(dirs, NULL);
|
||||
|
||||
return (char**) g_ptr_array_free(dirs, FALSE);
|
||||
}
|
||||
|
Reference in New Issue
Block a user