Added darwin port. Patch by Benjamin Reed <ranger@befunk.com>. Closes

Added darwin port.
Patch by Benjamin Reed <ranger@befunk.com>.
Closes #481068.

Bumped version number to 2.21.1.

svn path=/trunk/; revision=2666
This commit is contained in:
Benoît Dejean
2007-09-28 17:36:48 +00:00
parent 8a0a3632ac
commit 3529a1b59f
36 changed files with 2506 additions and 3 deletions

View File

@@ -3,8 +3,8 @@ dnl Configure script for the Gnome library
dnl
m4_define([libgtop_major_version], [2])
m4_define([libgtop_minor_version], [20])
m4_define([libgtop_micro_version], [0])
m4_define([libgtop_minor_version], [21])
m4_define([libgtop_micro_version], [1])
m4_define([libgtop_version], [libgtop_major_version.libgtop_minor_version.libgtop_micro_version])
dnl increment if the interface has additions, changes, removals.
@@ -380,6 +380,7 @@ sysdeps/freebsd/Makefile
sysdeps/solaris/Makefile
sysdeps/aix/Makefile
sysdeps/bsd/Makefile
sysdeps/darwin/Makefile
src/Makefile
src/daemon/Makefile
lib/Makefile

View File

@@ -92,6 +92,13 @@ AC_DEFUN([GNOME_LIBGTOP_SYSDEPS],[
libgtop_have_sysinfo=yes
libgtop_postinstall='chgrp system $(bindir)/libgtop_server && chmod g+s $(bindir)/libgtop_server2'
;;
darwin*)
libgtop_sysdeps_dir=darwin
libgtop_use_machine_h=yes
libgtop_need_server=yes
libgtop_have_sysinfo=yes
libgtop_postinstall='chgrp kmem $(bindir)/libgtop_server && chmod g+s $(bindir)/libgtop_server2'
;;
*)
if test x$hacker_mode = xyes ; then
case "$host_os" in

View File

@@ -2,4 +2,4 @@
SUBDIRS = common @sysdeps_dir@
DIST_SUBDIRS = bsd common linux osf1 \
stub stub_suid sun4 freebsd solaris aix
stub stub_suid sun4 freebsd solaris aix darwin

View File

@@ -0,0 +1,16 @@
INCLUDES = @INCLUDES@ @LIBGTOP_INCS@
noinst_LTLIBRARIES = libgtop_sysdeps-2.0.la libgtop_sysdeps_suid-2.0.la
libgtop_sysdeps_2_0_la_SOURCES = nosuid.c siglist.c sysinfo.c
libgtop_sysdeps_suid_2_0_la_SOURCES = open.c close.c \
cpu.c mem.c swap.c uptime.c loadavg.c shm_limits.c msg_limits.c \
sem_limits.c proclist.c procstate.c procuid.c proctime.c \
procmem.c procsignal.c prockernel.c procsegment.c procargs.c \
procmap.c netload.c ppp.c netlist.c procopenfiles.c procwd.c
libgtopinclude_HEADERS = glibtop_server.h glibtop_machine.h
libgtopincludedir = $(includedir)/libgtop-2.0
noinst_HEADERS = glibtop_suid.h

27
sysdeps/darwin/close.c Normal file
View File

@@ -0,0 +1,27 @@
/*
This file is part of LibGTop 2.0.
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/close.h>
/* Closes pipe to gtop server. */
void
glibtop_close_p (glibtop *server)
{ }

View File

@@ -0,0 +1,26 @@
/*
This file is part of LibGTop 2.0.
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 <glibtop/close.h>
/* Closes pipe to gtop server. */
void
glibtop_close_p (glibtop *server)
{ }

91
sysdeps/darwin/cpu.c Normal file
View File

@@ -0,0 +1,91 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/cpu.h>
#include <glibtop_suid.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>
#include <mach/vm_map.h>
static const unsigned long _glibtop_sysdeps_cpu =
(1L << GLIBTOP_CPU_TOTAL) + (1L << GLIBTOP_CPU_USER) +
(1L << GLIBTOP_CPU_NICE) + (1L << GLIBTOP_CPU_SYS) +
(1L << GLIBTOP_CPU_IDLE) + (1L << GLIBTOP_CPU_FREQUENCY) +
(1L << GLIBTOP_XCPU_TOTAL) + (1L << GLIBTOP_XCPU_USER) +
(1L << GLIBTOP_XCPU_NICE) + (1L << GLIBTOP_XCPU_SYS) +
(1L << GLIBTOP_XCPU_IDLE);
/* Init function. */
void
_glibtop_init_cpu_p (glibtop *server)
{
server->sysdeps.cpu = _glibtop_sysdeps_cpu;
}
/* Provides information about cpu usage. */
void
glibtop_get_cpu_p (glibtop *server, glibtop_cpu *buf)
{
processor_cpu_load_info_data_t *pinfo;
mach_msg_type_number_t info_count;
natural_t processor_count;
int i;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_CPU), 0);
memset (buf, 0, sizeof (glibtop_cpu));
if (host_processor_info (mach_host_self (),
PROCESSOR_CPU_LOAD_INFO,
&processor_count,
(processor_info_array_t*)&pinfo,
&info_count)) {
glibtop_warn_io_r (server, "host_processor_info (cpu)");
return;
}
for (i = 0; i < server->ncpu; i++) {
buf->xcpu_user [i] = pinfo[i].cpu_ticks [CPU_STATE_USER];
buf->xcpu_sys [i] = pinfo[i].cpu_ticks [CPU_STATE_SYSTEM];
buf->xcpu_idle [i] = pinfo[i].cpu_ticks [CPU_STATE_IDLE];
buf->xcpu_nice [i] = pinfo[i].cpu_ticks [CPU_STATE_NICE];
buf->xcpu_total[i] = buf->xcpu_user [i] + buf->xcpu_sys [i] +
buf->xcpu_idle [i] + buf->xcpu_nice [i];
buf->user += buf->xcpu_user [i];
buf->sys += buf->xcpu_sys [i];
buf->idle += buf->xcpu_idle [i];
buf->nice += buf->xcpu_nice [i];
buf->total += buf->xcpu_total[i];
}
vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count);
buf->frequency = 100;
buf->flags = _glibtop_sysdeps_cpu;
}

View File

@@ -0,0 +1,35 @@
/*
This file is part of LibGTop 2.0.
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_MACHINE_H__
#define __GLIBTOP_MACHINE_H__
G_BEGIN_DECLS
typedef struct _glibtop_machine glibtop_machine;
struct _glibtop_machine
{
uid_t uid, euid; /* Real and effective user id */
gid_t gid, egid; /* Real and effective group id */
};
G_END_DECLS
#endif

View File

@@ -0,0 +1,50 @@
/*
This file is part of LibGTop 2.0.
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_SERVER_H__
#define __GLIBTOP_SERVER_H__
G_BEGIN_DECLS
#define GLIBTOP_SUID_CPU (1 << GLIBTOP_SYSDEPS_CPU)
#define GLIBTOP_SUID_MEM (1 << GLIBTOP_SYSDEPS_MEM)
#define GLIBTOP_SUID_SWAP (1 << GLIBTOP_SYSDEPS_SWAP)
#define GLIBTOP_SUID_UPTIME (1 << GLIBTOP_SYSDEPS_UPTIME)
#define GLIBTOP_SUID_LOADAVG (1 << GLIBTOP_SYSDEPS_LOADAVG)
#define GLIBTOP_SUID_SHM_LIMITS (1 << GLIBTOP_SYSDEPS_SHM_LIMITS)
#define GLIBTOP_SUID_MSG_LIMITS (1 << GLIBTOP_SYSDEPS_MSG_LIMITS)
#define GLIBTOP_SUID_SEM_LIMITS (1 << GLIBTOP_SYSDEPS_SEM_LIMITS)
#define GLIBTOP_SUID_PROCLIST (1 << GLIBTOP_SYSDEPS_PROCLIST)
#define GLIBTOP_SUID_PROC_STATE (1 << GLIBTOP_SYSDEPS_PROC_STATE)
#define GLIBTOP_SUID_PROC_UID (1 << GLIBTOP_SYSDEPS_PROC_UID)
#define GLIBTOP_SUID_PROC_MEM (1 << GLIBTOP_SYSDEPS_PROC_MEM)
#define GLIBTOP_SUID_PROC_TIME (1 << GLIBTOP_SYSDEPS_PROC_TIME)
#define GLIBTOP_SUID_PROC_SIGNAL (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL)
#define GLIBTOP_SUID_PROC_KERNEL (1 << GLIBTOP_SYSDEPS_PROC_KERNEL)
#define GLIBTOP_SUID_PROC_SEGMENT (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT)
#define GLIBTOP_SUID_PROC_ARGS (1 << GLIBTOP_SYSDEPS_PROC_ARGS)
#define GLIBTOP_SUID_PROC_MAP (1 << GLIBTOP_SYSDEPS_PROC_MAP)
#define GLIBTOP_SUID_NETLOAD (1 << GLIBTOP_SYSDEPS_NETLOAD)
#define GLIBTOP_SUID_NETLIST 0
#define GLIBTOP_SUID_PPP (1 << GLIBTOP_SYSDEPS_PPP)
#define GLIBTOP_SUID_PROC_WD (1 << GLIBTOP_SYSDEPS_PROC_WD)
G_END_DECLS
#endif

View File

@@ -0,0 +1,44 @@
/*
This file is part of LibGTop 2.0.
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_SUID_H__
#define __GLIBTOP_SUID_H__
G_BEGIN_DECLS
static inline void glibtop_suid_enter (glibtop *server) {
setreuid (server->machine.uid, server->machine.euid);
};
static inline void glibtop_suid_leave (glibtop *server) {
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
};
void
glibtop_init_p (glibtop *server, const unsigned long features,
const unsigned flags);
void
glibtop_open_p (glibtop *server, const char *program_name,
const unsigned long features,
const unsigned flags);
G_END_DECLS
#endif

65
sysdeps/darwin/loadavg.c Normal file
View File

@@ -0,0 +1,65 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/loadavg.h>
#include <glibtop_suid.h>
#include <stdlib.h>
static const unsigned long _glibtop_sysdeps_loadavg =
(1L << GLIBTOP_LOADAVG_LOADAVG);
/* Init function. */
void
_glibtop_init_loadavg_p (glibtop *server)
{
server->sysdeps.loadavg = _glibtop_sysdeps_loadavg;
}
/* Provides load averange. */
void
glibtop_get_loadavg_p (glibtop *server, glibtop_loadavg *buf)
{
double ldavg[3];
int i;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_LOADAVG), 0);
memset (buf, 0, sizeof (glibtop_loadavg));
if (getloadavg (ldavg, 3) != 3) {
glibtop_warn_io_r (server, "getloadavg");
return;
}
/* fill in the struct */
buf->flags = _glibtop_sysdeps_loadavg;
for (i = 0; i < 3; i++) {
buf->loadavg [i] = ldavg [i];
}
}

70
sysdeps/darwin/mem.c Normal file
View File

@@ -0,0 +1,70 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/mem.h>
#include <glibtop_suid.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
static const unsigned long _glibtop_sysdeps_mem =
(1L << GLIBTOP_MEM_TOTAL) + (1L << GLIBTOP_MEM_USED) +
(1L << GLIBTOP_MEM_FREE);
/* Init function. */
void
_glibtop_init_mem_p (glibtop *server)
{
server->sysdeps.mem = _glibtop_sysdeps_mem;
}
/* Provides information about memory usage. */
void
glibtop_get_mem_p (glibtop *server, glibtop_mem *buf)
{
vm_statistics_data_t vm_info;
mach_msg_type_number_t info_count;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MEM), 0);
memset (buf, 0, sizeof (glibtop_mem));
info_count = HOST_VM_INFO_COUNT;
if (host_statistics (mach_host_self (), HOST_VM_INFO,
(host_info_t)&vm_info, &info_count)) {
glibtop_warn_io_r (server, "host_statistics (vm_statistics)");
return;
}
buf->total = (vm_info.active_count + vm_info.inactive_count +
vm_info.free_count + vm_info.wire_count) * vm_page_size;
buf->free = vm_info.free_count * vm_page_size;
buf->used = buf->total - buf->free;
buf->flags = _glibtop_sysdeps_mem;
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/msg_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_msg_limits = 0;
/* Init function. */
void
_glibtop_init_msg_limits_p (glibtop *server)
{
server->sysdeps.msg_limits = _glibtop_sysdeps_msg_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_msg_limits_p (glibtop *server, glibtop_msg_limits *buf)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_MSG_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_msg_limits));
}

66
sysdeps/darwin/netlist.c Normal file
View File

@@ -0,0 +1,66 @@
/*
This file is part of LibGTop 2.0.
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/netlist.h>
#include <glibtop/error.h>
#include <net/if.h>
static const unsigned long _glibtop_sysdeps_netlist = (1 << GLIBTOP_NETLIST_NUMBER);
/* Init function. */
void
_glibtop_init_netlist_s (glibtop *server)
{
server->sysdeps.netlist = _glibtop_sysdeps_netlist;
}
char**
glibtop_get_netlist_s (glibtop *server, glibtop_netlist *buf)
{
struct if_nameindex *ifstart, *ifs;
GPtrArray *devices;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_NETLIST, 0);
memset (buf, 0, sizeof (glibtop_netlist));
ifs = ifstart = if_nameindex();
devices = g_ptr_array_new();
while(ifs && ifs->if_name) {
g_ptr_array_add(devices, g_strdup(ifs->if_name));
buf->number++;
ifs++;
}
if_freenameindex(ifstart);
buf->flags = _glibtop_sysdeps_netlist;
g_ptr_array_add(devices, NULL);
return (char **) g_ptr_array_free(devices, FALSE);
}

165
sysdeps/darwin/netload.c Normal file
View File

@@ -0,0 +1,165 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/netload.h>
#include <glibtop_suid.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <net/if_dl.h>
#include <net/route.h>
static const unsigned long _glibtop_sysdeps_netload =
(1L << GLIBTOP_NETLOAD_IF_FLAGS) +
(1L << GLIBTOP_NETLOAD_MTU) +
/* (1L << GLIBTOP_NETLOAD_SUBNET) + */
/* (1L << GLIBTOP_NETLOAD_ADDRESS) + */
(1L << GLIBTOP_NETLOAD_PACKETS_IN) +
(1L << GLIBTOP_NETLOAD_PACKETS_OUT) +
(1L << GLIBTOP_NETLOAD_PACKETS_TOTAL) +
(1L << GLIBTOP_NETLOAD_BYTES_IN) +
(1L << GLIBTOP_NETLOAD_BYTES_OUT) +
(1L << GLIBTOP_NETLOAD_BYTES_TOTAL) +
(1L << GLIBTOP_NETLOAD_ERRORS_IN) +
(1L << GLIBTOP_NETLOAD_ERRORS_OUT) +
(1L << GLIBTOP_NETLOAD_ERRORS_TOTAL) +
(1L << GLIBTOP_NETLOAD_COLLISIONS);
/* Init function. */
void
_glibtop_init_netload_p (glibtop *server)
{
server->sysdeps.netload = _glibtop_sysdeps_netload;
}
/* Provides Network statistics. */
void
glibtop_get_netload_p (glibtop *server, glibtop_netload *buf,
const char *interface)
{
int mib[] = { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST, 0 };
size_t bufsize;
char *rtbuf, *ptr, *eob;
struct if_msghdr *ifm;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_NETLOAD), 0);
memset (buf, 0, sizeof (glibtop_netload));
if (sysctl (mib, 6, NULL, &bufsize, NULL, 0) < 0)
return;
rtbuf = (char*)g_malloc (bufsize);
if (rtbuf == NULL)
return;
if (sysctl (mib, 6, rtbuf, &bufsize, NULL, 0) < 0) {
g_free (rtbuf);
return;
}
eob = rtbuf + bufsize;
ptr = rtbuf;
while (ptr < eob) {
struct sockaddr_dl *sdl;
ifm = (struct if_msghdr*) ptr;
if (ifm->ifm_type != RTM_IFINFO)
break;
ptr += ifm->ifm_msglen;
while (ptr < eob) {
struct if_msghdr *nextifm = (struct if_msghdr*) ptr;
if (nextifm->ifm_type != RTM_NEWADDR)
break;
ptr += nextifm->ifm_msglen;
}
sdl = (struct sockaddr_dl*) (ifm + 1);
if (sdl->sdl_family != AF_LINK)
continue;
if (strlen (interface) != sdl->sdl_nlen)
continue;
if (strcmp (interface, sdl->sdl_data) == 0)
goto FOUND;
}
g_free (rtbuf);
return;
FOUND:
if (ifm->ifm_flags & IFF_UP)
buf->if_flags |= GLIBTOP_IF_FLAGS_UP;
if (ifm->ifm_flags & IFF_BROADCAST)
buf->if_flags |= GLIBTOP_IF_FLAGS_BROADCAST;
if (ifm->ifm_flags & IFF_DEBUG)
buf->if_flags |= GLIBTOP_IF_FLAGS_DEBUG;
if (ifm->ifm_flags & IFF_LOOPBACK)
buf->if_flags |= GLIBTOP_IF_FLAGS_LOOPBACK;
if (ifm->ifm_flags & IFF_POINTOPOINT)
buf->if_flags |= GLIBTOP_IF_FLAGS_POINTOPOINT;
if (ifm->ifm_flags & IFF_RUNNING)
buf->if_flags |= GLIBTOP_IF_FLAGS_RUNNING;
if (ifm->ifm_flags & IFF_NOARP)
buf->if_flags |= GLIBTOP_IF_FLAGS_NOARP;
if (ifm->ifm_flags & IFF_NOARP)
buf->if_flags |= GLIBTOP_IF_FLAGS_PROMISC;
if (ifm->ifm_flags & IFF_ALLMULTI)
buf->if_flags |= GLIBTOP_IF_FLAGS_ALLMULTI;
if (ifm->ifm_flags & IFF_OACTIVE)
buf->if_flags |= GLIBTOP_IF_FLAGS_OACTIVE;
if (ifm->ifm_flags & IFF_SIMPLEX)
buf->if_flags |= GLIBTOP_IF_FLAGS_SIMPLEX;
if (ifm->ifm_flags & IFF_LINK0)
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK0;
if (ifm->ifm_flags & IFF_LINK1)
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK1;
if (ifm->ifm_flags & IFF_LINK2)
buf->if_flags |= GLIBTOP_IF_FLAGS_LINK2;
if (ifm->ifm_flags & IFF_ALTPHYS)
buf->if_flags |= GLIBTOP_IF_FLAGS_ALTPHYS;
if (ifm->ifm_flags & IFF_MULTICAST)
buf->if_flags |= GLIBTOP_IF_FLAGS_MULTICAST;
buf->mtu = ifm->ifm_data.ifi_mtu;
buf->subnet = 0; /* FIXME */
buf->address = 0; /* FIXME */
buf->packets_in = ifm->ifm_data.ifi_ipackets;
buf->packets_out = ifm->ifm_data.ifi_opackets;
buf->packets_total = buf->packets_in + buf->packets_out;
buf->bytes_in = ifm->ifm_data.ifi_ibytes;
buf->bytes_out = ifm->ifm_data.ifi_obytes;
buf->bytes_total = buf->bytes_in + buf->bytes_out;
buf->errors_in = ifm->ifm_data.ifi_ierrors;
buf->errors_out = ifm->ifm_data.ifi_oerrors;
buf->errors_total = buf->errors_in + buf->errors_out;
buf->collisions = ifm->ifm_data.ifi_collisions;
buf->flags = _glibtop_sysdeps_netload;
g_free (buf);
}

55
sysdeps/darwin/nosuid.c Normal file
View File

@@ -0,0 +1,55 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/cpu.h>
#include <glibtop/open.h>
#include <mach/mach_host.h>
#include <mach/mach_init.h>
#include <mach/mach_interface.h>
#include <glibtop/error.h>
void
glibtop_open_s (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
processor_cpu_load_info_data_t *pinfo;
mach_msg_type_number_t info_count;
natural_t processor_count;
if (host_processor_info (mach_host_self (),
PROCESSOR_CPU_LOAD_INFO,
&processor_count,
(processor_info_array_t*)&pinfo,
&info_count)) {
glibtop_error_io_r (server, "host_processor_info");
}
server->ncpu = (processor_count <= GLIBTOP_NCPU) ?
processor_count : GLIBTOP_NCPU;
vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count);
}
void
glibtop_close_s (glibtop *server)
{ }

98
sysdeps/darwin/open.c Normal file
View File

@@ -0,0 +1,98 @@
/*
This file is part of LibGTop 2.0.
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/cpu.h>
#include <glibtop/open.h>
#include <mach/mach_host.h>
#include <mach/mach_init.h>
#include <mach/mach_interface.h>
#include <glibtop/init_hooks.h>
#include <glibtop/error.h>
#include <unistd.h>
/* !!! THIS FUNCTION RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
void
glibtop_init_p (glibtop *server, const unsigned long features,
const unsigned flags)
{
const _glibtop_init_func_t *init_fkt;
if (server == NULL)
glibtop_error_r (NULL, "glibtop_init_p (server == NULL)");
/* Do the initialization, but only if not already initialized. */
if ((server->flags & _GLIBTOP_INIT_STATE_INIT) == 0) {
glibtop_open_p (server, "glibtop", features, flags);
for (init_fkt = _glibtop_init_hook_p; *init_fkt; init_fkt++)
(*init_fkt) (server);
server->flags |= _GLIBTOP_INIT_STATE_INIT;
}
}
void
glibtop_open_p (glibtop *server, const char *program_name,
const unsigned long features, const unsigned flags)
{
processor_cpu_load_info_data_t *pinfo;
mach_msg_type_number_t info_count;
natural_t processor_count;
/* !!! WE ARE ROOT HERE - CHANGE WITH CAUTION !!! */
server->name = program_name;
server->machine.uid = getuid ();
server->machine.euid = geteuid ();
server->machine.gid = getgid ();
server->machine.egid = getegid ();
/* Drop priviledges. */
if (setreuid (server->machine.euid, server->machine.uid))
_exit (1);
if (setregid (server->machine.egid, server->machine.gid))
_exit (1);
/* !!! END OF SUID ROOT PART !!! */
/* Our effective uid is now those of the user invoking the server,
* so we do no longer have any priviledges. */
if (host_processor_info (mach_host_self (),
PROCESSOR_CPU_LOAD_INFO,
&processor_count,
(processor_info_array_t*)&pinfo,
&info_count)) {
glibtop_error_io_r (server, "host_processor_info");
}
server->ncpu = (processor_count <= GLIBTOP_NCPU) ?
processor_count : GLIBTOP_NCPU;
vm_deallocate (mach_task_self (), (vm_address_t) pinfo, info_count);
}

47
sysdeps/darwin/ppp.c Normal file
View File

@@ -0,0 +1,47 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/ppp.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_ppp = 0;
/* Init function. */
void
_glibtop_init_ppp_p (glibtop *server)
{
server->sysdeps.ppp = _glibtop_sysdeps_ppp;
}
/* Provides PPP/ISDN information. */
void
glibtop_get_ppp_p (glibtop *server, glibtop_ppp *buf, unsigned short device)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PPP), 0);
memset (buf, 0, sizeof (glibtop_ppp));
}

130
sysdeps/darwin/procargs.c Normal file
View File

@@ -0,0 +1,130 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procargs.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <limits.h>
static const unsigned long _glibtop_sysdeps_proc_args =
(1L << GLIBTOP_PROC_ARGS_SIZE);
/* Init function. */
void
_glibtop_init_proc_args_p (glibtop *server)
{
server->sysdeps.proc_args = _glibtop_sysdeps_proc_args;
}
/* Provides detailed information about a process. */
char *
glibtop_get_proc_args_p (glibtop *server, glibtop_proc_args *buf,
pid_t pid, unsigned max_len)
{
char argbuf[4096];
char *start, *end, *str;
size_t bufsize = 4096;
int mib [3];
unsigned length;
char *args;
int *ip;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_ARGS), 0);
memset (buf, 0, sizeof (glibtop_proc_args));
mib [0] = CTL_KERN;
mib [1] = KERN_PROCARGS;
mib [2] = pid;
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
if (sysctl (mib, 3, argbuf, &bufsize, NULL, 0) < 0) {
glibtop_suid_leave (server);
return NULL;
}
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
end = &argbuf[bufsize];
ip = (int *)end - 2;
while (*--ip) {
if (ip == (int *)argbuf) {
return NULL;
}
}
start = (char *)(ip + 1);
while (*--ip) {
if (ip == (int *)argbuf) {
return NULL;
}
}
ip++;
if ((ip[0] & 0xbfff0000) == 0xbfff0000) {
ip += 2;
start = (char*)(ip + (strlen ((char*)ip) + 3) / 4);
while (!*start)
start++;
}
for (str = start + strlen (start); str < end - 1; str++) {
if (*str == '=') {
while (*str != '\0' && str > start)
str--;
break;
}
}
end = str;
if (start[0] == '-' || start[0] == '?' || start[0] <= ' ') {
return NULL;
}
length = end - start;
if (max_len != 0 && length > max_len)
length = max_len;
args = g_malloc(length + 1);
if (args == NULL) {
glibtop_warn_io_r (server, "malloc(procargs)");
return NULL;
}
memcpy (args, start, length);
args [length] = '\0';
buf->size = length;
buf->flags = _glibtop_sysdeps_proc_args;
return args;
}

View File

@@ -0,0 +1,48 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/prockernel.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_kernel = 0;
/* Init function. */
void
_glibtop_init_proc_kernel_p (glibtop *server)
{
server->sysdeps.proc_kernel = _glibtop_sysdeps_proc_kernel;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_kernel_p (glibtop *server, glibtop_proc_kernel *buf,
pid_t pid)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_KERNEL), 0);
memset (buf, 0, sizeof (glibtop_proc_kernel));
}

104
sysdeps/darwin/proclist.c Normal file
View File

@@ -0,0 +1,104 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proclist.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_proclist =
(1L << GLIBTOP_PROCLIST_TOTAL) + (1L << GLIBTOP_PROCLIST_NUMBER) +
(1L << GLIBTOP_PROCLIST_SIZE);
/* Init function. */
void
_glibtop_init_proclist_p (glibtop *server)
{
server->sysdeps.proclist = _glibtop_sysdeps_proclist;
}
pid_t *
glibtop_get_proclist_p (glibtop *server, glibtop_proclist *buf,
int64_t which, int64_t arg)
{
unsigned count, total, i;
pid_t *pids_chain;
int mib[4];
struct kinfo_proc *kp;
size_t length;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROCLIST), 0);
memset (buf, 0, sizeof (glibtop_proclist));
mib [0] = CTL_KERN;
mib [1] = KERN_PROC;
mib [2] = (int)(which & GLIBTOP_KERN_PROC_MASK);
mib [3] = (int)arg;
if (sysctl (mib, 4, NULL, &length, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (proclist)");
return NULL;
}
if ((kp = (struct kinfo_proc *) g_malloc(length)) == NULL) {
glibtop_warn_io_r (server, "malloc (proclist)");
return NULL;
}
if (sysctl (mib, 4, kp, &length, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (proclist)");
g_free (kp);
return NULL;
}
count = length / sizeof (struct kinfo_proc);
pids_chain = g_malloc(count * sizeof (unsigned));
if (pids_chain == NULL) {
glibtop_warn_io_r (server, "g_realloc (proclist)");
g_free (kp);
return NULL;
}
for (total = 0, i = 0; i < count; i++) {
if ((which & GLIBTOP_EXCLUDE_IDLE) &&
(kp [i].kp_proc.p_stat != SRUN))
continue;
if ((which & GLIBTOP_EXCLUDE_SYSTEM) &&
(kp [i].kp_eproc.e_pcred.p_ruid == 0))
continue;
pids_chain [total++] = (unsigned) kp [i].kp_proc.p_pid;
}
g_free (kp);
buf->number = total;
buf->size = sizeof (unsigned);
buf->total = total * sizeof (unsigned);
buf->flags = _glibtop_sysdeps_proclist;
return pids_chain;
}

134
sysdeps/darwin/procmap.c Normal file
View File

@@ -0,0 +1,134 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procmap.h>
#include <glibtop_suid.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>
#include <mach/vm_map.h>
static const unsigned long _glibtop_sysdeps_proc_map =
(1L << GLIBTOP_PROC_MAP_TOTAL) + (1L << GLIBTOP_PROC_MAP_NUMBER) +
(1L << GLIBTOP_PROC_MAP_SIZE);
static const unsigned long _glibtop_sysdeps_proc_map_entry =
(1L << GLIBTOP_MAP_ENTRY_START) + (1L << GLIBTOP_MAP_ENTRY_END) +
(1L << GLIBTOP_MAP_ENTRY_OFFSET) + (1L << GLIBTOP_MAP_ENTRY_PERM);
/* Init function. */
void
_glibtop_init_proc_map_p (glibtop *server)
{
server->sysdeps.proc_map = _glibtop_sysdeps_proc_map;
}
/* Provides detailed information about a process. */
glibtop_map_entry *
glibtop_get_proc_map_p (glibtop *server, glibtop_proc_map *buf, pid_t pid)
{
glibtop_map_entry *maps;
mach_port_t task;
vm_address_t address;
natural_t nesting_depth;
int n;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_MAP), 0);
memset (buf, 0, sizeof (glibtop_proc_map));
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
if (task_for_pid (mach_task_self (), pid, &task) != KERN_SUCCESS) {
glibtop_suid_leave (server);
glibtop_warn_io_r (server, "task_for_pid (procmap)");
return NULL;
}
maps = NULL;
n = 0;
address = 0;
nesting_depth = 0;
while (1) {
vm_region_submap_info_data_64_t info;
mach_msg_type_number_t info_count;
vm_size_t size;
info_count = VM_REGION_SUBMAP_INFO_COUNT_64;
if (vm_region_recurse_64 (task, &address, &size, &nesting_depth,
(vm_region_recurse_info_64_t)&info, &info_count))
break;
if (info.is_submap) {
nesting_depth++;
continue;
}
maps = g_realloc (maps, (n + 1) * sizeof (glibtop_map_entry));
if (!maps) {
glibtop_suid_leave (server);
return NULL;
}
memset (maps + n, 0, sizeof (glibtop_map_entry));
maps[n].start = address;
maps[n].end = address + size - 1;
maps[n].offset = info.offset;
if (info.protection & VM_PROT_READ)
maps[n].perm |= GLIBTOP_MAP_PERM_READ;
if (info.protection & VM_PROT_WRITE)
maps[n].perm |= GLIBTOP_MAP_PERM_WRITE;
if (info.protection & VM_PROT_EXECUTE)
maps[n].perm |= GLIBTOP_MAP_PERM_EXECUTE;
if (info.share_mode == SM_PRIVATE ||
info.share_mode == SM_PRIVATE_ALIASED)
maps[n].perm |= GLIBTOP_MAP_PERM_PRIVATE;
if (info.share_mode == SM_SHARED ||
info.share_mode == SM_TRUESHARED ||
info.share_mode == SM_SHARED_ALIASED)
maps[n].perm |= GLIBTOP_MAP_PERM_SHARED;
maps[n].flags = _glibtop_sysdeps_proc_map_entry;
address += size;
n++;
}
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
buf->number = n;
buf->size = sizeof (glibtop_map_entry);
buf->total = n * sizeof (glibtop_map_entry);
buf->flags = _glibtop_sysdeps_proc_map;
return maps;
}

245
sysdeps/darwin/procmem.c Normal file
View File

@@ -0,0 +1,245 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procmem.h>
#include <glibtop_suid.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>
#include <mach/mach_traps.h>
#include <mach/task.h>
#include <mach/vm_map.h>
#include <mach/shared_memory_server.h>
static const unsigned long _glibtop_sysdeps_proc_mem =
(1L << GLIBTOP_PROC_MEM_SIZE) + (1L << GLIBTOP_PROC_MEM_VSIZE) +
(1L << GLIBTOP_PROC_MEM_RESIDENT) + (1L << GLIBTOP_PROC_MEM_SHARE) +
(1L << GLIBTOP_PROC_MEM_RSS);
/* Init function. */
void
_glibtop_init_proc_mem_p (glibtop *server)
{
server->sysdeps.proc_mem = _glibtop_sysdeps_proc_mem;
}
#define SHARED_TABLE_SIZE 137
#define TEXT_SEGMENT_START (GLOBAL_SHARED_TEXT_SEGMENT)
#define TEXT_SEGMENT_END (GLOBAL_SHARED_TEXT_SEGMENT + SHARED_TEXT_REGION_SIZE)
#define DATA_SEGMENT_START (GLOBAL_SHARED_DATA_SEGMENT)
#define DATA_SEGMENT_END (GLOBAL_SHARED_DATA_SEGMENT + SHARED_DATA_REGION_SIZE)
struct shared_info {
unsigned obj_id;
unsigned share_mode;
unsigned page_count;
unsigned ref_count;
unsigned task_ref_count;
vm_size_t size;
struct shared_info *next;
};
typedef struct shared_info shared_table[SHARED_TABLE_SIZE];
typedef struct shared_info shared_info;
static void
shared_table_init (shared_table table)
{
memset (table, 0, sizeof (shared_table));
}
static void
shared_table_free (glibtop *server, shared_table table)
{
int i;
for (i = 0; i < SHARED_TABLE_SIZE; i++) {
shared_info *info = table [i].next;
while (info) {
shared_info *next = info->next;
g_free (info);
info = next;
}
}
}
static void
shared_table_register (glibtop *server, shared_table table,
vm_region_top_info_data_t *top, vm_size_t size)
{
shared_info *info, *last;
info = last = &table [top->obj_id % SHARED_TABLE_SIZE];
while (info) {
if (info->obj_id == top->obj_id) {
info->task_ref_count++;
return;
}
last = info;
info = info->next;
}
info = g_malloc (sizeof (shared_info));
if (info) {
info->obj_id = top->obj_id;
info->share_mode = top->share_mode;
info->page_count = top->shared_pages_resident;
info->ref_count = top->ref_count;
info->task_ref_count = 1;
info->size = size;
info->next = NULL;
last->next = info;
}
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_mem_p (glibtop *server, glibtop_proc_mem *buf,
pid_t pid)
{
task_basic_info_data_t tinfo;
mach_msg_type_number_t info_count;
vm_size_t vsize, resident, private, vprivate, shared;
kern_return_t retval;
shared_table stable;
vm_address_t address;
mach_port_t task;
int i, split;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_MEM), 0);
memset (buf, 0, sizeof (glibtop_proc_mem));
address = 0;
split = 0;
vsize = resident = private = vprivate = shared = 0;
shared_table_init (stable);
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
retval = task_for_pid (mach_task_self (), pid, &task);
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
if (retval)
return;
info_count = TASK_BASIC_INFO_COUNT;
if (task_info (task, TASK_BASIC_INFO, (task_info_t)&tinfo, &info_count)) {
glibtop_warn_io_r (server, "task_info (procmem)");
return;
}
vsize = tinfo.virtual_size;
resident = tinfo.resident_size;
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
while (1) {
vm_region_basic_info_data_64_t basic;
vm_region_top_info_data_t top;
mach_port_t object_name;
vm_size_t size;
info_count = VM_REGION_BASIC_INFO_COUNT_64;
if (vm_region_64 (task, &address, &size, VM_REGION_BASIC_INFO,
(vm_region_info_t)&basic,
&info_count, &object_name))
break;
info_count = VM_REGION_TOP_INFO_COUNT;
if (vm_region_64 (task, &address, &size, VM_REGION_TOP_INFO,
(vm_region_info_t)&top,
&info_count, &object_name))
break;
if (address >= TEXT_SEGMENT_START && address < DATA_SEGMENT_END) {
if (!split && top.share_mode == SM_EMPTY) {
if (basic.reserved)
split = 1;
}
if (top.share_mode != SM_PRIVATE) {
address += size;
continue;
}
}
switch (top.share_mode) {
case SM_COW:
if (top.ref_count == 1) {
private += top.private_pages_resident * vm_page_size;
private += top.shared_pages_resident * vm_page_size;
vprivate += size;
} else {
shared_table_register (server, stable, &top, size);
vprivate += top.private_pages_resident * vm_page_size;
}
break;
case SM_PRIVATE:
private += top.private_pages_resident * vm_page_size;
vprivate += size;
break;
case SM_SHARED:
shared_table_register (server, stable, &top, size);
break;
}
address += size;
}
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
for (i = 0; i < SHARED_TABLE_SIZE; i++) {
shared_info *sinfo = &stable[i];
while (sinfo) {
if (sinfo->share_mode == SM_SHARED &&
sinfo->ref_count == sinfo->task_ref_count) {
private += sinfo->page_count * vm_page_size;
vprivate += sinfo->size;
} else {
shared += sinfo->page_count * vm_page_size;
}
sinfo = sinfo->next;
}
}
shared_table_free (server, stable);
if (split)
vsize -= DATA_SEGMENT_END - TEXT_SEGMENT_START;
buf->size = vprivate;
buf->vsize = vsize;
buf->resident = resident;
buf->share = shared;
buf->rss = private;
buf->flags = _glibtop_sysdeps_proc_mem;
}

View File

@@ -0,0 +1,43 @@
/*
This file is part of LibGTop 2.0.
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>
/* Init function. */
void
_glibtop_init_proc_open_files_s (glibtop *server)
{
server->sysdeps.proc_open_files = 0;
}
/* Provides detailed information about a process. */
glibtop_open_files_entry *
glibtop_get_proc_open_files_s (glibtop *server, glibtop_proc_open_files *buf, pid_t pid)
{
glibtop_init_s (&server, GLIBTOP_SYSDEPS_PROC_MAP, 0);
memset (buf, 0, sizeof (glibtop_proc_open_files));
return NULL;
}

View File

@@ -0,0 +1,48 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procsegment.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_proc_segment = 0;
/* Init function. */
void
_glibtop_init_proc_segment_p (glibtop *server)
{
server->sysdeps.proc_segment = _glibtop_sysdeps_proc_segment;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_segment_p (glibtop *server, glibtop_proc_segment *buf,
pid_t pid)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SEGMENT), 0);
memset (buf, 0, sizeof (glibtop_proc_segment));
}

View File

@@ -0,0 +1,76 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procsignal.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_proc_signal =
(1L << GLIBTOP_PROC_SIGNAL_SIGNAL) +
(1L << GLIBTOP_PROC_SIGNAL_BLOCKED) +
(1L << GLIBTOP_PROC_SIGNAL_SIGIGNORE) +
(1L << GLIBTOP_PROC_SIGNAL_SIGCATCH);
/* Init function. */
void
_glibtop_init_proc_signal_p (glibtop *server)
{
server->sysdeps.proc_signal = _glibtop_sysdeps_proc_signal;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_signal_p (glibtop *server, glibtop_proc_signal *buf,
pid_t pid)
{
int mib[4];
size_t length;
struct kinfo_proc kinfo;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_SIGNAL), 0);
memset (buf, 0, sizeof (glibtop_proc_signal));
mib [0] = CTL_KERN;
mib [1] = KERN_PROC;
mib [2] = KERN_PROC_PID;
mib [3] = pid;
length = sizeof (struct kinfo_proc);
if (sysctl (mib, 4, &kinfo, &length, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (procuid)");
return;
}
buf->signal[0] = kinfo.kp_proc.p_siglist;
buf->blocked[0] = kinfo.kp_proc.p_sigmask;
buf->sigignore[0] = kinfo.kp_proc.p_sigignore;
buf->sigcatch[0] = kinfo.kp_proc.p_sigcatch;
buf->flags = _glibtop_sysdeps_proc_signal;
}

View File

@@ -0,0 +1,94 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procstate.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_proc_state =
(1L << GLIBTOP_PROC_STATE_CMD) + (1L << GLIBTOP_PROC_STATE_STATE) +
(1L << GLIBTOP_PROC_STATE_UID) + (1L << GLIBTOP_PROC_STATE_GID);
/* Init function. */
void
_glibtop_init_proc_state_p (glibtop *server)
{
server->sysdeps.proc_state = _glibtop_sysdeps_proc_state;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_state_p (glibtop *server, glibtop_proc_state *buf,
pid_t pid)
{
int mib[4];
size_t length;
struct kinfo_proc kinfo;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_STATE), 0);
memset (buf, 0, sizeof (glibtop_proc_state));
mib [0] = CTL_KERN;
mib [1] = KERN_PROC;
mib [2] = KERN_PROC_PID;
mib [3] = pid;
length = sizeof (struct kinfo_proc);
if (sysctl (mib, 4, &kinfo, &length, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (procstat)");
return;
}
strncpy (buf->cmd, kinfo.kp_proc.p_comm, sizeof (buf->cmd) - 1);
buf->cmd [sizeof (buf->cmd) - 1] = 0;
buf->uid = kinfo.kp_eproc.e_pcred.p_svuid;
buf->gid = kinfo.kp_eproc.e_pcred.p_svgid;
switch (kinfo.kp_proc.p_stat) {
case SIDL:
buf->state = 0;
break;
case SRUN:
buf->state = 'R';
break;
case SSLEEP:
buf->state = 'S';
break;
case SSTOP:
buf->state = 'T';
break;
case SZOMB:
buf->state = 'Z';
break;
default:
return;
}
buf->flags = _glibtop_sysdeps_proc_state;
}

118
sysdeps/darwin/proctime.c Normal file
View File

@@ -0,0 +1,118 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/proctime.h>
#include <glibtop_suid.h>
#include <mach/mach_init.h>
#include <mach/mach_host.h>
#include <mach/mach_port.h>
#include <mach/task.h>
#include <mach/vm_map.h>
#include <sys/types.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_proc_time =
(1L << GLIBTOP_PROC_TIME_UTIME) + (1L << GLIBTOP_PROC_TIME_STIME) +
(1L << GLIBTOP_PROC_TIME_FREQUENCY) + (1L << GLIBTOP_PROC_TIME_START_TIME);
#define tv2sec(tv) (((u_int64_t) tv.seconds * 1000000) + (u_int64_t) tv.microseconds)
/* Init function. */
void
_glibtop_init_proc_time_p (glibtop *server)
{
server->sysdeps.proc_time = _glibtop_sysdeps_proc_time;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_time_p (glibtop *server, glibtop_proc_time *buf,
pid_t pid)
{
unsigned int count;
task_basic_info_data_t ti;
task_thread_times_info_data_t tti;
task_port_t task;
time_value_t utime = {0, 0}, stime = {0, 0};
size_t length;
struct kinfo_proc kinfo;
int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, 0 };
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_TIME), 0);
memset (buf, 0, sizeof (glibtop_proc_time));
mib[3] = pid;
length = sizeof (kinfo);
if (sysctl (mib, 4, &kinfo, &length, NULL, 0) < 0) {
glibtop_suid_leave (server);
return;
}
/* !!! THE FOLLOWING CODE RUNS SUID ROOT - CHANGE WITH CAUTION !!! */
glibtop_suid_enter (server);
if (task_for_pid (mach_task_self(), pid, &task) != KERN_SUCCESS) {
glibtop_suid_leave (server);
return;
}
glibtop_suid_leave (server);
/* !!! END OF SUID ROOT PART !!! */
count = TASK_BASIC_INFO_COUNT;
if (task_info(task, TASK_BASIC_INFO, (task_info_t)&ti, &count) != KERN_SUCCESS) {
glibtop_warn_io_r (server, "task_info (proctime)");
if (task != mach_task_self())
mach_port_deallocate (mach_task_self(), task);
return;
}
count = TASK_THREAD_TIMES_INFO_COUNT;
if (task_info(task, TASK_THREAD_TIMES_INFO, (task_info_t)&tti, &count) != KERN_SUCCESS) {
glibtop_warn_io_r (server, "task_info (proctime)");
if (task != mach_task_self())
mach_port_deallocate (mach_task_self(), task);
return;
}
time_value_add (&utime, &ti.user_time);
time_value_add (&stime, &ti.system_time);
time_value_add (&utime, &tti.user_time);
time_value_add (&stime, &tti.system_time);
/* use the same frequency as cpu.c */
buf->utime = tv2sec (utime) / 10000;
buf->stime = tv2sec (stime) / 10000;
buf->frequency = 1000000 / 10000;
buf->start_time = kinfo.kp_proc.p_starttime.tv_sec;
buf->flags = _glibtop_sysdeps_proc_time;
}

83
sysdeps/darwin/procuid.c Normal file
View File

@@ -0,0 +1,83 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/procuid.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
static const unsigned long _glibtop_sysdeps_proc_uid =
(1L << GLIBTOP_PROC_UID_UID) + (1L << GLIBTOP_PROC_UID_EUID) +
(1L << GLIBTOP_PROC_UID_GID) + (1L << GLIBTOP_PROC_UID_EGID) +
(1L << GLIBTOP_PROC_UID_PID) + (1L << GLIBTOP_PROC_UID_PPID) +
(1L << GLIBTOP_PROC_UID_PGRP) + (1L << GLIBTOP_PROC_UID_TTY) +
(1L << GLIBTOP_PROC_UID_TPGID);
/* Init function. */
void
_glibtop_init_proc_uid_p (glibtop *server)
{
server->sysdeps.proc_uid = _glibtop_sysdeps_proc_uid;
}
/* Provides detailed information about a process. */
void
glibtop_get_proc_uid_p (glibtop *server, glibtop_proc_uid *buf,
pid_t pid)
{
int mib[4];
size_t length;
struct kinfo_proc kinfo;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_PROC_UID), 0);
memset (buf, 0, sizeof (glibtop_proc_uid));
mib [0] = CTL_KERN;
mib [1] = KERN_PROC;
mib [2] = KERN_PROC_PID;
mib [3] = pid;
length = sizeof (struct kinfo_proc);
if (sysctl (mib, 4, &kinfo, &length, NULL, 0) < 0) {
glibtop_warn_io_r (server, "sysctl (procuid)");
return;
}
buf->uid = kinfo.kp_eproc.e_pcred.p_ruid;
buf->euid = kinfo.kp_eproc.e_pcred.p_svuid;
buf->gid = kinfo.kp_eproc.e_pcred.p_rgid;
buf->egid = kinfo.kp_eproc.e_pcred.p_svgid;
buf->ppid = kinfo.kp_eproc.e_ppid;
buf->pgrp = kinfo.kp_eproc.e_pgid;
buf->tpgid = kinfo.kp_eproc.e_tpgid;
buf->nice = kinfo.kp_proc.p_nice;
buf->priority = kinfo.kp_proc.p_priority;
buf->flags = _glibtop_sysdeps_proc_uid;
}

50
sysdeps/darwin/procwd.c Normal file
View File

@@ -0,0 +1,50 @@
/*
This file is part of LibGTop 2.0.
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_suid.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
static const unsigned long _glibtop_sysdeps_proc_wd = 0;
/* Init function. */
void
_glibtop_init_proc_wd_p (glibtop *server)
{
server->sysdeps.proc_wd = _glibtop_sysdeps_proc_wd;
}
/* Provides detailed information about a process. */
char **
glibtop_get_proc_wd_p (glibtop *server, glibtop_proc_wd *buf,
pid_t pid)
{
glibtop_init_p (server, GLIBTOP_SYSDEPS_PROC_WD, 0);
memset (buf, 0, sizeof (glibtop_proc_wd));
return NULL;
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/sem_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_sem_limits = 0;
/* Init function. */
void
_glibtop_init_sem_limits_p (glibtop *server)
{
server->sysdeps.sem_limits = _glibtop_sysdeps_sem_limits;
}
/* Provides information about sysv sem limits. */
void
glibtop_get_sem_limits_p (glibtop *server, glibtop_sem_limits *buf)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SEM_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_sem_limits));
}

View File

@@ -0,0 +1,47 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/shm_limits.h>
#include <glibtop_suid.h>
static const unsigned long _glibtop_sysdeps_shm_limits = 0;
/* Init function. */
void
_glibtop_init_shm_limits_p (glibtop *server)
{
server->sysdeps.shm_limits = _glibtop_sysdeps_shm_limits;
}
/* Provides information about sysv ipc limits. */
void
glibtop_get_shm_limits_p (glibtop *server, glibtop_shm_limits *buf)
{
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SHM_LIMITS), 0);
memset (buf, 0, sizeof (glibtop_shm_limits));
}

60
sysdeps/darwin/siglist.c Normal file
View File

@@ -0,0 +1,60 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/signal.h>
const glibtop_signame glibtop_sys_siglist [] =
{ { 1, "SIGHUP", NULL }, /* hangup */
{ 2, "SIGINT", NULL }, /* interrupt */
{ 3, "SIGQUIT", NULL }, /* quit */
{ 4, "SIGILL", NULL }, /* illegal instruction */
{ 5, "SIGTRAP", NULL }, /* trace trap */
{ 6, "SIGTRAP", NULL }, /* abort */
{ 7, "SIGEMT", NULL }, /* EMT instruction */
{ 8, "SIGFPE", NULL }, /* floating point exception */
{ 9, "SIGKILL", NULL }, /* kill */
{ 10, "SIGBUS", NULL }, /* bus error */
{ 11, "SIGSEGV", NULL }, /* segmentation violation */
{ 12, "SIGSYS", NULL }, /* bad argument to system call */
{ 13, "SIGPIPE", NULL }, /* write on a pipe with no one to read it */
{ 14, "SIGALRM", NULL }, /* alarm clock */
{ 15, "SIGTERM", NULL }, /* software termination signal from kill */
{ 16, "SIGURG", NULL }, /* urgent condition on IO channel */
{ 17, "SIGSTOP", NULL }, /* sendable stop signal not from tty */
{ 18, "SIGTSTP", NULL }, /* stop signal from tty */
{ 19, "SIGCONT", NULL }, /* continue a stopped process */
{ 20, "SIGCHLD", NULL }, /* to parent on child stop or exit */
{ 21, "SIGTTIN", NULL }, /* to readers pgrp upon background tty read */
{ 22, "SIGTTOU", NULL }, /* like TTIN for output */
{ 23, "SIGIO", NULL }, /* input/output possible signal */
{ 24, "SIGXCPU", NULL }, /* exceeded CPU time limit */
{ 25, "SIGXFSZ", NULL }, /* exceeded file size limit */
{ 26, "SIGVTALRM", NULL }, /* virtual time alarm */
{ 27, "SIGPROF", NULL }, /* profiling time alarm */
{ 28, "SIGWINCH", NULL }, /* window size changes */
{ 29, "SIGWINFO", NULL }, /* information request */
{ 30, "SIGUSR1", NULL }, /* user defined signal 1 */
{ 31, "SIGUSR2", NULL }, /* user defined signal 2 */
{ 0, NULL, NULL }
};

110
sysdeps/darwin/swap.c Normal file
View File

@@ -0,0 +1,110 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/swap.h>
#include <glibtop_suid.h>
#include <mach/mach_host.h>
#include <mach/host_info.h>
#include <mach/mach_init.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <dirent.h>
static const unsigned long _glibtop_sysdeps_swap =
(1L << GLIBTOP_SWAP_TOTAL) + (1L << GLIBTOP_SWAP_USED) +
(1L << GLIBTOP_SWAP_FREE) + (1L << GLIBTOP_SWAP_PAGEIN) +
(1L << GLIBTOP_SWAP_PAGEOUT);
/* Init function. */
void
_glibtop_init_swap_p (glibtop *server)
{
server->sysdeps.swap = _glibtop_sysdeps_swap;
}
/* Provides information about swap usage. */
void
glibtop_get_swap_p (glibtop *server, glibtop_swap *buf)
{
vm_statistics_data_t vm_info;
mach_msg_type_number_t info_count;
DIR *dirp;
struct dirent *dp;
struct statfs sfs;
u_int64_t total, used;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_SWAP), 0);
memset (buf, 0, sizeof (glibtop_swap));
total = used = 0;
dirp = opendir ("/private/var/vm");
if (!dirp) {
glibtop_warn_io_r (server, "opendir (swap)");
return;
}
while ((dp = readdir (dirp)) != NULL) {
struct stat sb;
char fname [MAXNAMLEN];
if (strncmp (dp->d_name, "swapfile", 8))
continue;
strcpy (fname, "/private/var/vm/");
strcat (fname, dp->d_name);
if (stat (fname, &sb) < 0)
continue;
used += sb.st_size;
}
closedir (dirp);
if (statfs ("/private/var/vm", &sfs) < 0) {
glibtop_warn_io_r (server, "statfs (swap)");
return;
}
total = (u_int64_t)sfs.f_bfree * sfs.f_bsize + used;
info_count = HOST_VM_INFO_COUNT;
if (host_statistics (mach_host_self (), HOST_VM_INFO,
(host_info_t) &vm_info, &info_count)) {
glibtop_warn_io_r (server, "host_statistics (swap)");
return;
}
buf->total = total;
buf->used = used;
buf->free = total - used;
buf->pagein = vm_info.pageins;
buf->pageout = vm_info.pageouts;
buf->flags = _glibtop_sysdeps_swap;
}

90
sysdeps/darwin/sysinfo.c Normal file
View File

@@ -0,0 +1,90 @@
/*
This file is part of LibGTop 2.0.
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 <sys/param.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <glibtop/error.h>
#include <glibtop/cpu.h>
#include <glibtop/sysinfo.h>
static const unsigned long _glibtop_sysdeps_sysinfo =
(1L << GLIBTOP_SYSINFO_CPUINFO);
static glibtop_sysinfo sysinfo = { .flags = 0 };
static void
init_sysinfo (glibtop *server)
{
char *model;
guint64 ncpus = 1;
int mhz = 0;
size_t len;
if (G_LIKELY (sysinfo.flags))
return;
glibtop_init_s (&server, GLIBTOP_SYSDEPS_CPU, 0);
len = sizeof (ncpus);
sysctlbyname ("hw.ncpu", &ncpus, &len, NULL, 0);
len = 0;
sysctlbyname ("hw.model", NULL, &len, NULL, 0);
model = g_malloc (len);
sysctlbyname ("hw.model", model, &len, NULL, 0);
len = sizeof (mhz);
sysctlbyname ("hw.cpufrequency", &mhz, &len, NULL, 0);
mhz = mhz / 1000000;
for (sysinfo.ncpu = 0;
sysinfo.ncpu < GLIBTOP_NCPU && sysinfo.ncpu < ncpus;
sysinfo.ncpu++) {
glibtop_entry * const cpuinfo = &sysinfo.cpuinfo[sysinfo.ncpu];
cpuinfo->labels = g_ptr_array_new ();
cpuinfo->values = g_hash_table_new_full(g_str_hash,
g_str_equal,
NULL, g_free);
g_ptr_array_add (cpuinfo->labels, "processor");
g_hash_table_insert (cpuinfo->values, "processor",
g_strdup_printf("%u", (guint)sysinfo.ncpu));
g_ptr_array_add (cpuinfo->labels, "vendor_id");
g_hash_table_insert (cpuinfo->values, "vendor_id",
g_strdup(model));
g_ptr_array_add (cpuinfo->labels, "cpu MHz");
g_hash_table_insert (cpuinfo->values, "cpu MHz",
g_strdup_printf("%d", mhz));
}
g_free (model);
sysinfo.flags = _glibtop_sysdeps_sysinfo;
}
const glibtop_sysinfo *
glibtop_get_sysinfo_s (glibtop *server)
{
init_sysinfo (server);
return &sysinfo;
}

66
sysdeps/darwin/uptime.c Normal file
View File

@@ -0,0 +1,66 @@
/*
This file is part of LibGTop 2.0.
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 <unistd.h>
#include <glibtop.h>
#include <glibtop/error.h>
#include <glibtop/uptime.h>
#include <glibtop_suid.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#include <time.h>
static const unsigned long _glibtop_sysdeps_uptime =
(1L << GLIBTOP_UPTIME_UPTIME);
/* Init function. */
void
_glibtop_init_uptime_p (glibtop *server)
{
server->sysdeps.uptime = _glibtop_sysdeps_uptime;
}
/* Provides uptime and idle time. */
void
glibtop_get_uptime_p (glibtop *server, glibtop_uptime *buf)
{
int mib [] = { CTL_KERN, KERN_BOOTTIME };
struct timeval boottime;
size_t size = sizeof (boottime);
time_t now;
glibtop_init_p (server, (1 << GLIBTOP_SYSDEPS_UPTIME), 0);
memset (buf, 0, sizeof (glibtop_uptime));
/* copied from gkrellm port */
if (sysctl (mib, 2, &boottime, &size, NULL, 0) == -1)
return;
time (&now);
buf->uptime = now - boottime.tv_sec + 30;
buf->flags = _glibtop_sysdeps_uptime;
}