Compare commits
60
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
907fe7a87f | ||
|
|
83fbcbeb4e | ||
|
|
a20ec372b7 | ||
|
|
91aead2fd3 | ||
|
|
965051cdcf | ||
|
|
67b476efe0 | ||
|
|
edf041dc7a | ||
|
|
a04f46a647 | ||
|
|
d83284613b | ||
|
|
012dcef75d | ||
|
|
f21897f93b | ||
|
|
710a3f791b | ||
|
|
b88fb7c0c7 | ||
|
|
510a4b5c89 | ||
|
|
4c76ea27c5 | ||
|
|
44a4062111 | ||
|
|
8bd48cc477 | ||
|
|
ce23dbeec7 | ||
|
|
5619873f02 | ||
|
|
73b0850a52 | ||
|
|
129062d9cd | ||
|
|
cb1e4f491d | ||
|
|
de81b90497 | ||
|
|
fde00170d7 | ||
|
|
e0ef7a3616 | ||
|
|
2f8090559e | ||
|
|
1f15289d75 | ||
|
|
7acf88a0bf | ||
|
|
fcdf809ef5 | ||
|
|
dd8d2355cc | ||
|
|
c1ee0a18b9 | ||
|
|
0a3f546638 | ||
|
|
58097d9743 | ||
|
|
b44692d8e6 | ||
|
|
a693ebce90 | ||
|
|
216a2df541 | ||
|
|
2d2c4c996d | ||
|
|
e09ad13a16 | ||
|
|
59aeadaef2 | ||
|
|
73c3c287f7 | ||
|
|
4655d5e3df | ||
|
|
cef810dafb | ||
|
|
240649b925 | ||
|
|
7041d070f1 | ||
|
|
8337f13d6c | ||
|
|
9b8ec6ec5a | ||
|
|
639169e9cc | ||
|
|
adfb6d4d0a | ||
|
|
e0c289a34c | ||
|
|
436ceb351a | ||
|
|
8a4c9f6eb0 | ||
|
|
87f0aa7f6f | ||
|
|
692f5a43ea | ||
|
|
f2aef38d02 | ||
|
|
833ca18ecf | ||
|
|
b8c6325123 | ||
|
|
78f5683bfc | ||
|
|
619e639eca | ||
|
|
d20d75908d | ||
|
|
642df76807 |
No files matched your search
+17
@@ -22,3 +22,20 @@ missing
|
||||
src/sigar_version_autoconf.c
|
||||
examples/cpuinfo
|
||||
examples/sigar_ps
|
||||
debian/*.log
|
||||
debian/stamp-*
|
||||
debian/tmp
|
||||
m4/
|
||||
debian/python-sigar*
|
||||
debian/python-module-stampdir
|
||||
debian/*.debhelper
|
||||
debian/*.substvars
|
||||
debian/libsigar1/
|
||||
debian/libsigar1-dev/
|
||||
debian/libsigar-java-doc/
|
||||
debian/libsigar-java/
|
||||
debian/files
|
||||
config.sub*
|
||||
config.guess*
|
||||
bindings/java/${dist}
|
||||
bindings/python/build
|
||||
@@ -1,10 +1,29 @@
|
||||
Copyright (c) 2004-2011 VMware, Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
|
||||
ADDITIONAL LICENSE INFORMATION:
|
||||
|
||||
Hyperic SIGAR includes some third-party open source components
|
||||
in its distribution. The list below identifies the community or
|
||||
organization and links to their appropriate license terms.
|
||||
|
||||
The Hyperic team would like to thank all the communities
|
||||
of the projects listed below for their contributions.
|
||||
---------------------------------------------------------------------
|
||||
|
||||
----------------------------------------------------------
|
||||
Components under the Apache License 2.0:
|
||||
----------------------------------------------------------
|
||||
|
||||
The following components are included without modification:
|
||||
|
||||
@@ -16,20 +35,83 @@ The following components are included with modification:
|
||||
|
||||
- cpptasks -
|
||||
Information: http://ant-contrib.sourceforge.net/
|
||||
License: http://ant-contrib.sourceforge.net/LICENSE.txt
|
||||
License: http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
- (portions of) APR -
|
||||
Information: http://apr.apache.org/
|
||||
License: http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
----------------------------------------------------------
|
||||
Components under BSD/MIT Style Licenses:
|
||||
----------------------------------------------------------
|
||||
|
||||
The following components are included with modification:
|
||||
|
||||
- solaris get_mib2 -
|
||||
Information: ftp://vic.cc.purdue.edu/pub/tools/unix/solaris/get_mib2/
|
||||
License: within src/os/solaris/get_mib2.[ch]
|
||||
|
||||
Copyright 1995 Purdue Research Foundation, West Lafayette, Indiana
|
||||
47907. All rights reserved.
|
||||
|
||||
Written by Victor A. Abell <abe@cc.purdue.edu>
|
||||
|
||||
This software is not subject to any license of the American Telephone
|
||||
and Telegraph Company or the Regents of the University of California.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose on
|
||||
any computer system, and to alter it and redistribute it freely, subject
|
||||
to the following restrictions:
|
||||
|
||||
1. Neither Victor A Abell nor Purdue University are responsible for
|
||||
any consequences of the use of this software.
|
||||
|
||||
2. The origin of this software must not be misrepresented, either by
|
||||
explicit claim or by omission. Credit to Victor A. Abell and Purdue
|
||||
University must appear in documentation and sources.
|
||||
|
||||
3. Altered versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
|
||||
4. This notice may not be removed or altered.
|
||||
|
||||
- getline by Chris Thewalt -
|
||||
Information: http://tinyurl.com/r438r
|
||||
License: within src/sigar_getline.c
|
||||
|
||||
Copyright (C) 1991, 1992 by Chris Thewalt (thewalt@ce.berkeley.edu)
|
||||
|
||||
Permission to use, copy, modify, and distribute this software
|
||||
for any purpose and without fee is hereby granted, provided
|
||||
that the above copyright notices appear in all copies and that both the
|
||||
copyright notice and this permission notice appear in supporting
|
||||
documentation. This software is provided "as is" without express or
|
||||
implied warranty.
|
||||
|
||||
- PrintfFormat.java -
|
||||
Information: http://java.sun.com/developer/technicalArticles/Programming/sprintf/PrintfFormat.java
|
||||
License: within bindings/java/src/org/hyperic/sigar/util/PrintfFormat.java
|
||||
|
||||
(c) 2000 Sun Microsystems, Inc.
|
||||
ALL RIGHTS RESERVED
|
||||
|
||||
License Grant-
|
||||
|
||||
Permission to use, copy, modify, and distribute this Software and its
|
||||
documentation for NON-COMMERCIAL or COMMERCIAL purposes and without fee is
|
||||
hereby granted.
|
||||
|
||||
This Software is provided "AS IS". All express warranties, including any
|
||||
implied warranty of merchantability, satisfactory quality, fitness for a
|
||||
particular purpose, or non-infringement, are disclaimed, except to the extent
|
||||
that such disclaimers are held to be legally invalid.
|
||||
|
||||
You acknowledge that Software is not designed, licensed or intended for use in
|
||||
the design, construction, operation or maintenance of any nuclear facility
|
||||
("High Risk Activities"). Sun disclaims any express or implied warranty of
|
||||
fitness for such uses.
|
||||
|
||||
Please refer to the file http://www.sun.com/policies/trademarks/ for further
|
||||
important trademark information and to
|
||||
http://java.sun.com/nav/business/index.html for further important licensing
|
||||
information for the Java Technology.
|
||||
@@ -22,7 +22,7 @@ spec = Gem::Specification.new do |s|
|
||||
s.name = GEM
|
||||
# s.version = props['version.major'] + '.' + props['version.minor'] + '.' + props['version.maint']
|
||||
# '0.7.x' until the sigar-1.7.0 release
|
||||
s.version = '0' + '.' + props['version.minor'] + '.' + '0'
|
||||
s.version = '0' + '.' + props['version.minor'] + '.' + '2'
|
||||
s.summary = props['project.summary']
|
||||
s.description = s.summary
|
||||
s.author = props['project.author']
|
||||
@@ -32,9 +32,9 @@ spec = Gem::Specification.new do |s|
|
||||
s.has_rdoc = false
|
||||
s.extensions = 'bindings/ruby/extconf.rb'
|
||||
s.files =
|
||||
%w(COPYING EXCEPTIONS README Rakefile version.properties) +
|
||||
%w(LICENSE NOTICE README Rakefile version.properties) +
|
||||
%w(bindings/SigarWrapper.pm bindings/SigarBuild.pm) +
|
||||
Dir.glob("bindings/ruby/**/*") +
|
||||
`git ls-files -- bindings/ruby/*.*`.split("\n") +
|
||||
Dir.glob("include/*.h") +
|
||||
Dir.glob("src/**/*.[ch]") +
|
||||
Dir.glob("src/**/*.in")
|
||||
|
||||
+2
-1
@@ -2,7 +2,8 @@
|
||||
|
||||
set -x
|
||||
|
||||
rm -f INSTALL NEWS AUTHORS \
|
||||
rm -f INSTALL NEWS \
|
||||
&& rm -f -r m4 \
|
||||
&& rm -f aclocal.m4 \
|
||||
&& rm -f -r autom4te.cache \
|
||||
&& rm -f compile \
|
||||
|
||||
+8
-17
@@ -28,7 +28,7 @@ use POSIX ();
|
||||
|
||||
use vars qw(@ISA @EXPORT);
|
||||
@ISA = qw(Exporter);
|
||||
@EXPORT = qw(cppflags ldflags libs os src inline_src version_file);
|
||||
@EXPORT = qw(cppflags ldflags libs os src inline_src version_file resource_file);
|
||||
|
||||
sub archname {
|
||||
my $os = lc $^O;
|
||||
@@ -108,22 +108,8 @@ sub flags {
|
||||
}
|
||||
elsif ($os =~ /(darwin)/) {
|
||||
$os = $1;
|
||||
my(@sdks) = reverse sort </Developer/SDKs/MacOSX10.*.sdk>;
|
||||
my $sdk;
|
||||
if (@sdks == 0) {
|
||||
die
|
||||
"Xcode Developer Tools not installed\n".
|
||||
"Download from http://developer.apple.com/technology/xcode.html";
|
||||
}
|
||||
else {
|
||||
#print "Available SDKs...\n(*) " . join("\n ", @sdks) . "\n";
|
||||
$sdk = $sdks[0];
|
||||
}
|
||||
@cppflags = ('-DDARWIN',
|
||||
"-I/Developer/Headers/FlatCarbon -isysroot $sdk");
|
||||
@ldflags = ("-Wl,-syslibroot,$sdk",
|
||||
'-framework CoreServices',
|
||||
'-framework IOKit');
|
||||
@cppflags = ('-DDARWIN');
|
||||
@ldflags = ('-framework CoreServices', '-framework IOKit');
|
||||
if (-e "/usr/local/libproc.h") {
|
||||
push @cppflags, '-DDARWIN_HAS_LIBPROC_H';
|
||||
}
|
||||
@@ -261,6 +247,11 @@ sub version_properties {
|
||||
return $props;
|
||||
}
|
||||
|
||||
sub resource_file {
|
||||
my(@args) = @_ ? @_ : @ARGV;
|
||||
version_file(find_file("src/os/win32/sigar.rc.in"), "sigar.rc", @args);
|
||||
}
|
||||
|
||||
sub version_file {
|
||||
local $_;
|
||||
my($source, $dest, %filters);
|
||||
|
||||
@@ -508,6 +508,7 @@
|
||||
<include name="bindings/java/**/*.java"/>
|
||||
<include name="bindings/java/**/*.java.in"/>
|
||||
<include name="bindings/java/**/*.c"/>
|
||||
<include name="bindings/java/**/*.cpp"/>
|
||||
<include name="bindings/java/**/*.h"/>
|
||||
<include name="bindings/java/**/*.pl"/>
|
||||
<include name="bindings/java/**/build.xml"/>
|
||||
|
||||
@@ -356,8 +356,6 @@
|
||||
<compilerarg value="${uni.arch}"/>
|
||||
<compilerarg value="-mmacosx-version-min=${osx.min}"/>
|
||||
|
||||
<sysincludepath location="/Developer/Headers/FlatCarbon"/>
|
||||
|
||||
<defineset>
|
||||
<define name="DARWIN"/>
|
||||
<define name="DARWIN_HAS_LIBPROC_H" if="libproc.h"/>
|
||||
|
||||
@@ -90,8 +90,12 @@ public class ArchNameTask extends Task {
|
||||
if (ArchLoader.IS_DARWIN) {
|
||||
//default to most recent SDK
|
||||
//MacOSX10.3.9.sdk, MacOSX10.4u.sdk, MacOSX10.5.sdk,etc.
|
||||
String sdkRoot = "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs";
|
||||
if (new File(sdkRoot).exists() == false) {
|
||||
sdkRoot = "/Developer/SDKs";
|
||||
}
|
||||
File[] sdks =
|
||||
new File("/Developer/SDKs").listFiles(new FileFilter() {
|
||||
new File(sdkRoot).listFiles(new FileFilter() {
|
||||
public boolean accept(File file) {
|
||||
String name = file.getName();
|
||||
return
|
||||
@@ -99,6 +103,7 @@ public class ArchNameTask extends Task {
|
||||
name.endsWith(".sdk");
|
||||
}
|
||||
});
|
||||
|
||||
if (sdks != null) {
|
||||
Arrays.sort(sdks);
|
||||
String prop = "uni.sdk";
|
||||
|
||||
Binary file not shown.
@@ -23,6 +23,8 @@ import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
public abstract class FileWatcher {
|
||||
|
||||
private Sigar sigar;
|
||||
@@ -31,6 +33,9 @@ public abstract class FileWatcher {
|
||||
private Set files =
|
||||
Collections.synchronizedSet(new HashSet());
|
||||
|
||||
private static final Logger log =
|
||||
SigarLog.getLogger(FileWatcher.class.getName());
|
||||
|
||||
public abstract void onChange(FileInfo info);
|
||||
|
||||
public void onNotFound(FileInfo info) {
|
||||
@@ -66,14 +71,22 @@ public abstract class FileWatcher {
|
||||
public void add(File[] files)
|
||||
throws SigarException {
|
||||
for (int i=0; i<files.length; i++) {
|
||||
try {
|
||||
add(files[i]);
|
||||
} catch (SigarFileNotFoundException e) {
|
||||
log.error("Cannot add file: " + files[i].getAbsolutePath(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void add(String[] files)
|
||||
throws SigarException {
|
||||
for (int i=0; i<files.length; i++) {
|
||||
try {
|
||||
add(files[i]);
|
||||
} catch (SigarFileNotFoundException e) {
|
||||
log.error("Cannot add file: " + files[i], e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class ProcUtil {
|
||||
|
||||
for (int i=0; i<len; i++) {
|
||||
char c = name.charAt(i);
|
||||
if (!((c == '.') || Character.isLetter(c))) {
|
||||
if (!((c == '.') || Character.isJavaIdentifierPart(c))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ public class SigarLog {
|
||||
private static final int LOG_INFO = 3;
|
||||
private static final int LOG_DEBUG = 4;
|
||||
|
||||
private static final boolean enableLogFallbackConf = ! Boolean.getBoolean("sigar.noLog4jDefaultConfig");
|
||||
|
||||
private static native void setLogger(Sigar sigar, Logger log);
|
||||
|
||||
public static native void setLevel(Sigar sigar, int level);
|
||||
@@ -46,7 +48,7 @@ public class SigarLog {
|
||||
|
||||
public static Logger getLogger(String name) {
|
||||
Logger log = Logger.getLogger(name);
|
||||
if (!isLogConfigured()) {
|
||||
if (enableLogFallbackConf && !isLogConfigured()) {
|
||||
BasicConfigurator.configure();
|
||||
}
|
||||
return log;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class SigarProcess implements SigarProcessMBean {
|
||||
|
||||
public String getObjectName() throws SigarException {
|
||||
long pid = getPid();
|
||||
String name = this.sigar.getProcState(pid).getName();
|
||||
String name = this.sigar.getProcState(pid).getName().replaceAll(":", "_");
|
||||
String cls = "unknown";
|
||||
if (name.startsWith("java")) {
|
||||
try {
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.hyperic.sigar.test;
|
||||
import java.util.Date;
|
||||
|
||||
import org.hyperic.sigar.SigarException;
|
||||
import org.hyperic.sigar.SigarLoader;
|
||||
import org.hyperic.sigar.Who;
|
||||
|
||||
public class TestWho extends SigarTestCase {
|
||||
@@ -39,7 +40,9 @@ public class TestWho extends SigarTestCase {
|
||||
who[i].getDevice() + "\t" +
|
||||
new Date(who[i].getTime() * 1000) + "\t" +
|
||||
host);
|
||||
if (!SigarLoader.IS_WIN32) {
|
||||
assertLengthTrace("user", who[i].getUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+423
-2
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2007 Hyperic, Inc.
|
||||
* Copyright (c) 2010 VMware, Inc.
|
||||
* Copyright (c) 2010-2011 VMware, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,13 +19,14 @@
|
||||
#include "sigar.h"
|
||||
#include "sigar_fileinfo.h"
|
||||
#include "sigar_format.h"
|
||||
#include "sigar_ptql.h"
|
||||
|
||||
#define PySigarString_FromNetAddr(a) pysigar_net_address_to_string(&a)
|
||||
|
||||
#define PySigarInt_FromChar(c) PyInt_FromLong((int)c)
|
||||
|
||||
#define PySigar_ParsePID \
|
||||
if (!PyArg_ParseTuple(args, "i", &pid)) return NULL
|
||||
if (pysigar_parse_pid(sigar, args, &pid) != SIGAR_OK) return NULL
|
||||
|
||||
#define PySigar_ParseName \
|
||||
if (!PyArg_ParseTuple(args, "s", &name, &name_len)) return NULL
|
||||
@@ -68,6 +69,103 @@ static void pysigar_free(PyObject *self)
|
||||
self->ob_type->tp_free((PyObject *)self);
|
||||
}
|
||||
|
||||
static int pysigar_ptql_re_impl(void *data,
|
||||
char *haystack, char *needle)
|
||||
{
|
||||
PyObject *name = PyString_FromString("sigar");
|
||||
PyObject *module = PyImport_Import(name);
|
||||
PyObject *match, *args, *source, *regex, *result;
|
||||
int matches = 0;
|
||||
|
||||
match = PyObject_GetAttrString(module, "string_matches");
|
||||
|
||||
source = PyString_FromString(haystack);
|
||||
regex = PyString_FromString(needle);
|
||||
args = PyTuple_New(2);
|
||||
PyTuple_SetItem(args, 0, source); /* steals source reference */
|
||||
PyTuple_SetItem(args, 1, regex); /* steals regex reference */
|
||||
|
||||
result = PyObject_CallObject(match, args);
|
||||
|
||||
Py_DECREF(name);
|
||||
Py_DECREF(module);
|
||||
Py_DECREF(args);
|
||||
Py_DECREF(match);
|
||||
|
||||
if (result == NULL) {
|
||||
if (PyErr_Occurred()) {
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
else {
|
||||
matches = (result == Py_True);
|
||||
Py_DECREF(result);
|
||||
}
|
||||
|
||||
return matches;
|
||||
}
|
||||
|
||||
#define sigar_isdigit(c) \
|
||||
(isdigit(((unsigned char)(c))))
|
||||
|
||||
static int pysigar_parse_pid(sigar_t *sigar, PyObject *args, long *pid)
|
||||
{
|
||||
if ((PyTuple_Size(args) >= 1) && PyString_Check(PyTuple_GetItem(args, 0))) {
|
||||
char *ptql;
|
||||
int ptql_len;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#", &ptql, &ptql_len)) {
|
||||
return !SIGAR_OK;
|
||||
}
|
||||
|
||||
if (sigar_isdigit(*ptql)) {
|
||||
/* XXX pluck strtoull define from sigar_ptql.c */
|
||||
PyObject *obj = PyLong_FromString(ptql, &ptql, 10);
|
||||
*pid = PyLong_AsLong(obj);
|
||||
Py_DECREF(obj);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
else if ((ptql_len == 2) &&
|
||||
(*ptql == '$') && (*(ptql + 1) == '$'))
|
||||
{
|
||||
*pid = sigar_pid_get(sigar);
|
||||
return SIGAR_OK;
|
||||
}
|
||||
else {
|
||||
/* XXX cache queries */
|
||||
sigar_ptql_query_t *query;
|
||||
sigar_ptql_error_t error;
|
||||
int status;
|
||||
|
||||
status = sigar_ptql_query_create(&query, ptql, &error);
|
||||
if (status == SIGAR_OK) {
|
||||
sigar_ptql_re_impl_set(sigar, NULL, pysigar_ptql_re_impl);
|
||||
status = sigar_ptql_query_find_process(sigar, query, (sigar_pid_t *)pid);
|
||||
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
||||
sigar_ptql_query_destroy(query);
|
||||
|
||||
if (status == SIGAR_OK) {
|
||||
return SIGAR_OK;
|
||||
}
|
||||
else {
|
||||
PySigar_Croak();
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(PyExc_ValueError, error.message);
|
||||
return !SIGAR_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (PyArg_ParseTuple(args, "i", pid)) {
|
||||
return SIGAR_OK;
|
||||
}
|
||||
else {
|
||||
return !SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *pysigar_net_address_to_string(sigar_net_address_t *address)
|
||||
{
|
||||
char addr_str[SIGAR_INET6_ADDRSTRLEN];
|
||||
@@ -131,6 +229,38 @@ static PyObject *pysigar_new_strlist(char **data, unsigned long number)
|
||||
return av;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_new_doublelist(double *data, unsigned long number)
|
||||
{
|
||||
unsigned long i;
|
||||
PyObject *av;
|
||||
|
||||
if (!(av = PyTuple_New(number))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<number; i++) {
|
||||
PyTuple_SET_ITEM(av, i, PyFloat_FromDouble(data[i]));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_new_intlist(int *data, unsigned long number)
|
||||
{
|
||||
unsigned long i;
|
||||
PyObject *av;
|
||||
|
||||
if (!(av = PyTuple_New(number))) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i=0; i<number; i++) {
|
||||
PyTuple_SET_ITEM(av, i, PyInt_FromLong(data[i]));
|
||||
}
|
||||
|
||||
return av;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_new_list(char *data, unsigned long number,
|
||||
int size, PyTypeObject *type)
|
||||
{
|
||||
@@ -191,6 +321,57 @@ static PyObject *pysigar_net_interface_list(PyObject *self, PyObject *args)
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_net_connection_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status, flags;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_net_connection_list_t connlist;
|
||||
PyObject *RETVAL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &flags)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
status = sigar_net_connection_list_get(sigar, &connlist, flags);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_list((char *)&connlist.data[0],
|
||||
connlist.number,
|
||||
sizeof(*connlist.data),
|
||||
&pysigar_PySigarNetConnectionType);
|
||||
|
||||
sigar_net_connection_list_destroy(sigar, &connlist);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_net_route_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_net_route_list_t net_routelist;
|
||||
PyObject *RETVAL;
|
||||
|
||||
status = sigar_net_route_list_get(sigar, &net_routelist);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_list((char *)&net_routelist.data[0],
|
||||
net_routelist.number,
|
||||
sizeof(*net_routelist.data),
|
||||
&pysigar_PySigarNetRouteType);
|
||||
|
||||
sigar_net_route_list_destroy(sigar, &net_routelist);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_arp_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
@@ -214,6 +395,222 @@ static PyObject *pysigar_arp_list(PyObject *self, PyObject *args)
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_net_stat(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status, flags;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_net_stat_t *RETVAL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "i", &flags)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = malloc(sizeof(*RETVAL));
|
||||
if ((status = sigar_net_stat_get(sigar, RETVAL, flags)) != SIGAR_OK) {
|
||||
free(RETVAL);
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
PyObject *self = PySigar_new(pysigar_PySigarNetStatType);
|
||||
PySIGAR_OBJ->ptr = RETVAL;
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *pysigar_cpu_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_cpu_list_t cpus;
|
||||
PyObject *RETVAL;
|
||||
|
||||
status = sigar_cpu_list_get(sigar, &cpus);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_list((char *)&cpus.data[0],
|
||||
cpus.number,
|
||||
sizeof(*cpus.data),
|
||||
&pysigar_PySigarCpuType);
|
||||
|
||||
sigar_cpu_list_destroy(sigar, &cpus);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_cpu_info_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_cpu_info_list_t cpu_infos;
|
||||
PyObject *RETVAL;
|
||||
|
||||
status = sigar_cpu_info_list_get(sigar, &cpu_infos);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_list((char *)&cpu_infos.data[0],
|
||||
cpu_infos.number,
|
||||
sizeof(*cpu_infos.data),
|
||||
&pysigar_PySigarCpuInfoType);
|
||||
|
||||
sigar_cpu_info_list_destroy(sigar, &cpu_infos);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_loadavg(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_loadavg_t loadavg;
|
||||
|
||||
status = sigar_loadavg_get(sigar, &loadavg);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pysigar_new_doublelist(loadavg.loadavg, 3);
|
||||
}
|
||||
|
||||
static PyObject *pysigar_who_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_who_list_t wholist;
|
||||
PyObject *RETVAL;
|
||||
|
||||
status = sigar_who_list_get(sigar, &wholist);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_list((char *)&wholist.data[0],
|
||||
wholist.number,
|
||||
sizeof(*wholist.data),
|
||||
&pysigar_PySigarWhoType);
|
||||
|
||||
sigar_who_list_destroy(sigar, &wholist);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_proc_list(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_proc_list_t list;
|
||||
|
||||
PyObject *RETVAL;
|
||||
|
||||
if (PyTuple_Size(args) == 0) {
|
||||
status = sigar_proc_list_get(sigar, &list);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sigar_ptql_query_t *query;
|
||||
sigar_ptql_error_t error;
|
||||
char *ptql;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s", &ptql)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
status = sigar_ptql_query_create(&query, ptql, &error);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
PyErr_SetString(PyExc_ValueError, error.message);
|
||||
return NULL;
|
||||
}
|
||||
sigar_ptql_re_impl_set(sigar, NULL, pysigar_ptql_re_impl);
|
||||
status = sigar_ptql_query_find(sigar, query, &list);
|
||||
sigar_ptql_re_impl_set(sigar, NULL, NULL);
|
||||
sigar_ptql_query_destroy(query);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_intlist(&list.data[0], list.number);
|
||||
|
||||
sigar_proc_list_destroy(sigar, &list);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_proc_args(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_proc_args_t proc_args;
|
||||
long pid;
|
||||
|
||||
PyObject *RETVAL;
|
||||
|
||||
PySigar_ParsePID;
|
||||
|
||||
status = sigar_proc_args_get(sigar, pid, &proc_args);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
RETVAL = pysigar_new_strlist(proc_args.data, proc_args.number);
|
||||
|
||||
sigar_proc_args_destroy(sigar, &proc_args);
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static int pysigar_env_getall(void *data,
|
||||
const char *key, int klen,
|
||||
char *val, int vlen)
|
||||
{
|
||||
PyDict_SetItem((PyObject *)data,
|
||||
PyString_FromStringAndSize(key, klen),
|
||||
PyString_FromStringAndSize(val, vlen));
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_proc_env(PyObject *self, PyObject *args)
|
||||
{
|
||||
int status;
|
||||
sigar_t *sigar = PySIGAR;
|
||||
sigar_proc_env_t procenv;
|
||||
long pid;
|
||||
|
||||
PyObject *RETVAL;
|
||||
|
||||
PySigar_ParsePID;
|
||||
|
||||
RETVAL = PyDict_New();
|
||||
|
||||
procenv.type = SIGAR_PROC_ENV_ALL;
|
||||
procenv.env_getter = pysigar_env_getall;
|
||||
procenv.data = RETVAL;
|
||||
|
||||
status = sigar_proc_env_get(sigar, pid, &procenv);
|
||||
if (status != SIGAR_OK) {
|
||||
PySigar_Croak();
|
||||
}
|
||||
|
||||
return RETVAL;
|
||||
}
|
||||
|
||||
static PyObject *pysigar_format_size(PyObject *self, PyObject *args)
|
||||
{
|
||||
char buffer[56];
|
||||
@@ -230,8 +627,18 @@ static PyObject *pysigar_format_size(PyObject *self, PyObject *args)
|
||||
static PyMethodDef pysigar_methods[] = {
|
||||
{ "close", pysigar_close, METH_NOARGS, NULL },
|
||||
{ "net_interface_list", pysigar_net_interface_list, METH_NOARGS, NULL },
|
||||
{ "net_connection_list", pysigar_net_connection_list, METH_VARARGS, NULL },
|
||||
{ "net_route_list", pysigar_net_route_list, METH_NOARGS, NULL },
|
||||
{ "file_system_list", pysigar_file_system_list, METH_NOARGS, NULL },
|
||||
{ "arp_list", pysigar_arp_list, METH_NOARGS, NULL },
|
||||
{ "net_stat", pysigar_net_stat, METH_VARARGS, NULL },
|
||||
{ "cpu_list", pysigar_cpu_list, METH_NOARGS, NULL },
|
||||
{ "cpu_info_list", pysigar_cpu_info_list, METH_NOARGS, NULL },
|
||||
{ "loadavg", pysigar_loadavg, METH_NOARGS, NULL },
|
||||
{ "who_list", pysigar_who_list, METH_NOARGS, NULL },
|
||||
{ "proc_list", pysigar_proc_list, METH_VARARGS, NULL },
|
||||
{ "proc_args", pysigar_proc_args, METH_VARARGS, NULL },
|
||||
{ "proc_env", pysigar_proc_env, METH_VARARGS, NULL },
|
||||
PY_SIGAR_METHODS
|
||||
{NULL}
|
||||
};
|
||||
@@ -290,10 +697,24 @@ static PyMethodDef pysigar_module_methods[] = {
|
||||
#define PY_SIGAR_CONST_STR(name) \
|
||||
PyDict_SetItemString(dict, #name, o=PyString_FromString(SIGAR_##name)); Py_DECREF(o)
|
||||
|
||||
#define PY_SIGAR_DEFINE_CONST_STR(name, value) \
|
||||
PyDict_SetItemString(dict, name, o=PyString_FromString(value)); Py_DECREF(o)
|
||||
|
||||
static void init_pysigar_version(PyObject *dict)
|
||||
{
|
||||
PyObject *o;
|
||||
sigar_version_t *sv = sigar_version_get();
|
||||
PY_SIGAR_DEFINE_CONST_STR("BUILD_DATE", sv->build_date);
|
||||
PY_SIGAR_DEFINE_CONST_STR("SCM_REVISION", sv->scm_revision);
|
||||
PY_SIGAR_DEFINE_CONST_STR("VERSION", sv->version);
|
||||
}
|
||||
|
||||
static void init_pysigar_constants(PyObject *dict)
|
||||
{
|
||||
PyObject *o;
|
||||
|
||||
init_pysigar_version(dict);
|
||||
|
||||
PY_SIGAR_CONST_INT(FIELD_NOTIMPL);
|
||||
|
||||
PY_SIGAR_CONST_INT(IFF_UP);
|
||||
|
||||
@@ -17,11 +17,14 @@
|
||||
#
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
from os import system, mkdir, path, popen
|
||||
from distutils.util import get_platform
|
||||
from distutils.sysconfig import get_config_var, get_python_version
|
||||
from os import system, mkdir, path, popen, rename
|
||||
import sys
|
||||
|
||||
build = 'build'
|
||||
options = {'perl':'perl'}
|
||||
deps = [build + '/_sigar_generated.c']
|
||||
|
||||
def parse_args():
|
||||
global options
|
||||
@@ -59,6 +62,7 @@ if 'sigar' in options:
|
||||
_sigar = Extension(
|
||||
"_sigar",
|
||||
["_sigar.c"],
|
||||
depends = deps,
|
||||
include_dirs = [sigar + '/include', build],
|
||||
extra_compile_args = ['-Wall'],
|
||||
libraries=['sigar'],
|
||||
@@ -67,11 +71,24 @@ else :
|
||||
print "Inlining libsigar sources"
|
||||
src = sargs('inline_src -- ' + build)
|
||||
src.append('_sigar.c')
|
||||
|
||||
version_file = "sigar_version.c"
|
||||
build_version_file = build + "/" + version_file
|
||||
libname = "_sigar" + get_config_var("SO")
|
||||
filters = \
|
||||
'ARCHNAME=' + get_platform() + '-' + get_python_version() + ' ' + \
|
||||
'ARCHLIB=' + libname + ' ' + \
|
||||
'BINNAME=' + libname
|
||||
system(options['perl'] + ' -Mlib=.. -MSigarBuild -e version_file ' + filters)
|
||||
rename(version_file, build_version_file)
|
||||
src.append(build_version_file)
|
||||
|
||||
cppflags = sargs('cppflags')
|
||||
cppflags.append('-Wall')
|
||||
_sigar = Extension(
|
||||
"_sigar",
|
||||
src,
|
||||
depends = deps,
|
||||
include_dirs = [build],
|
||||
extra_compile_args = cppflags,
|
||||
extra_link_args = sargs('ldflags'),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#
|
||||
# Copyright (c) 2007 Hyperic, Inc.
|
||||
# Copyright (c) 2011 VMware, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -15,3 +16,8 @@
|
||||
#
|
||||
|
||||
from _sigar import *
|
||||
|
||||
import re
|
||||
#wrapper for pysigar_ptql_re_impl
|
||||
def string_matches(source, regex):
|
||||
return re.compile(regex).match(source) != None
|
||||
Executable
+123
@@ -0,0 +1,123 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) 2011 VMware, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
import unittest
|
||||
import os
|
||||
import sys
|
||||
|
||||
#prepend PYTHONPATH to find sigar in build/
|
||||
from distutils.util import get_platform
|
||||
from distutils.sysconfig import get_python_version
|
||||
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)) + \
|
||||
"/../build/lib." + get_platform() + "-" + get_python_version())
|
||||
|
||||
import sigar
|
||||
|
||||
class SigarTest(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.sigar = sigar.open()
|
||||
|
||||
def tearDown(self):
|
||||
self.sigar.close()
|
||||
self.sigar = None
|
||||
|
||||
def is_type(self, obj, cls):
|
||||
return obj.__class__.__name__ == cls
|
||||
|
||||
def testCpuList(self):
|
||||
retval = self.sigar.cpu_list()
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
for cpu in retval:
|
||||
self.assertTrue(self.is_type(cpu, "Cpu"))
|
||||
|
||||
def testCpuInfoList(self):
|
||||
retval = self.sigar.cpu_info_list()
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
for cpu in retval:
|
||||
self.assertTrue(self.is_type(cpu, "CpuInfo"))
|
||||
|
||||
def testWhoList(self):
|
||||
retval = self.sigar.who_list()
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
for who in retval:
|
||||
self.assertTrue(self.is_type(who, "Who"))
|
||||
|
||||
def testNetRouteList(self):
|
||||
retval = self.sigar.net_connection_list(0)
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
for conn in retval:
|
||||
self.assertTrue(self.is_type(conn, "NetConnection"))
|
||||
|
||||
def testNetStat(self):
|
||||
retval = self.sigar.net_stat(0)
|
||||
self.assertTrue(self.is_type(retval, "NetStat"))
|
||||
|
||||
def testNetRoute(self):
|
||||
retval = self.sigar.net_route_list()
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
for route in retval:
|
||||
self.assertTrue(self.is_type(route, "NetRoute"))
|
||||
|
||||
def testProcArgs(self):
|
||||
retval = self.sigar.proc_args(os.getpid())
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
self.assertTrue(retval > 1)
|
||||
for arg in retval:
|
||||
self.assertTrue(isinstance(arg, str))
|
||||
|
||||
self.assertEquals(retval, self.sigar.proc_args(str(os.getpid())))
|
||||
|
||||
self.assertEquals(retval, self.sigar.proc_args("$$"))
|
||||
|
||||
retval = self.sigar.proc_args("Pid.Pid.eq=" + str(os.getpid()))
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
|
||||
def testProcEnv(self):
|
||||
retval = self.sigar.proc_env(os.getpid())
|
||||
for k, v in os.environ.items():
|
||||
self.assertEquals(v, retval[k])
|
||||
for pid in self.sigar.proc_list("State.Name.eq=python"):
|
||||
self.sigar.proc_env(pid)
|
||||
|
||||
def testProcList(self):
|
||||
retval = self.sigar.proc_list()
|
||||
self.assertTrue(isinstance(retval, tuple))
|
||||
self.assertTrue(len(retval) > 1)
|
||||
self.assertTrue(os.getpid() in retval)
|
||||
self.assertTrue(os.getpid() in self.sigar.proc_list("State.Name.eq=python"))
|
||||
self.assertTrue(os.getpid() in self.sigar.proc_list("State.Name.re=.*ython"))
|
||||
self.assertFalse(os.getpid() in self.sigar.proc_list("State.Name.eq=ruby"))
|
||||
try:
|
||||
self.sigar.proc_list("Invalid.Query.xe=.*ython")
|
||||
self.assertTrue(False)
|
||||
except ValueError:
|
||||
self.assertTrue(True)
|
||||
|
||||
def testPtql(self):
|
||||
try:
|
||||
self.sigar.proc_args("Invalid.Query.xe=.*ython")
|
||||
self.assertTrue(False)
|
||||
except ValueError:
|
||||
self.assertTrue(True)
|
||||
|
||||
def testConstants(self):
|
||||
self.assertEquals(sigar.IFF_UP, 0x1)
|
||||
self.assertTrue(len(sigar.VERSION) >= 7)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
+18
-15
@@ -1,7 +1,7 @@
|
||||
#
|
||||
# Copyright (c) 2007, 2009 Hyperic, Inc.
|
||||
# Copyright (c) 2009 SpringSource, Inc.
|
||||
# Copyright (c) 2010 VMware, Inc.
|
||||
# Copyright (c) 2010-2012 VMware, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
@@ -26,20 +26,11 @@ print 'Ruby platform=' + RUBY_PLATFORM + "\n"
|
||||
case RUBY_PLATFORM
|
||||
when /darwin/
|
||||
os = 'darwin'
|
||||
sdks = Dir.glob('/Developer/SDKs/MacOSX10.*.sdk').sort.reverse
|
||||
if sdks.length == 0
|
||||
print "Xcode Developer Tools not installed\n"
|
||||
print "Download from http://developer.apple.com/technology/xcode.html\n"
|
||||
exit 1
|
||||
else
|
||||
print "Available SDKs...\n(*) " + sdks.join("\n ") + "\n"
|
||||
sdk = sdks[0]
|
||||
end
|
||||
if File.file?("/usr/include/libproc.h")
|
||||
$CPPFLAGS += ' -DDARWIN_HAS_LIBPROC_H'
|
||||
end
|
||||
$CPPFLAGS += ' -DDARWIN -I/Developer/Headers/FlatCarbon -isysroot ' + sdk
|
||||
$LDFLAGS += ' -Wl,-syslibroot,' + sdk + ' -framework CoreServices -framework IOKit'
|
||||
$CPPFLAGS += ' -DDARWIN'
|
||||
$LDFLAGS += ' -framework CoreServices -framework IOKit'
|
||||
when /bsd/
|
||||
os = 'darwin'
|
||||
have_library("kvm")
|
||||
@@ -102,14 +93,26 @@ unless is_win32
|
||||
end
|
||||
end
|
||||
|
||||
$distcleanfiles = ['rbsigar_generated.rx','sigar_version.c']
|
||||
|
||||
system('perl -Mlib=.. -MSigarWrapper -e generate Ruby .')
|
||||
libname = extension_name + '.' + CONFIG['DLEXT']
|
||||
system('perl -Mlib=.. -MSigarBuild -e version_file ' +
|
||||
filters =
|
||||
'ARCHNAME=' + RUBY_PLATFORM + ' ' +
|
||||
'ARCHLIB=' + libname + ' ' +
|
||||
'BINNAME=' + libname)
|
||||
'BINNAME=' + libname
|
||||
|
||||
system('perl -Mlib=.. -MSigarBuild -e version_file ' + filters)
|
||||
|
||||
if is_win32
|
||||
system('perl -Mlib=.. -MSigarBuild -e resource_file ' + filters)
|
||||
system('rc /r sigar.rc')
|
||||
$LDFLAGS += ' sigar.res'
|
||||
$distcleanfiles << ['sigar.rc', 'sigar.res']
|
||||
#do not want dynamic runtime else "MSVCR80.dll was not found"
|
||||
$CFLAGS = $CFLAGS.gsub('-MD', '')
|
||||
end
|
||||
|
||||
$distcleanfiles = ['rbsigar_generated.rx','sigar_version.c']
|
||||
#XXX seems mkmf forces basename on srcs
|
||||
#XXX should be linking against libsigar anyhow
|
||||
(Dir["../../src/*.c"] + Dir["#{osdir}/*.c"] + Dir["#{osdir}/*.cpp"]).each do |file|
|
||||
|
||||
@@ -30,7 +30,7 @@ class FileSystemTest < Test::Unit::TestCase
|
||||
|
||||
begin
|
||||
usage = sigar.file_system_usage fs.dir_name
|
||||
rescue err
|
||||
rescue => err
|
||||
if fs.type == Sigar::FSTYPE_LOCAL_DISK
|
||||
raise err
|
||||
end
|
||||
|
||||
+2
-5
@@ -21,6 +21,7 @@ AC_PROG_LN_S
|
||||
AC_PROG_INSTALL
|
||||
AC_PROG_MAKE_SET
|
||||
AC_PROG_LIBTOOL
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
AC_MSG_CHECKING([for os type ($host_os)])
|
||||
FRAMEWORK=
|
||||
@@ -34,7 +35,6 @@ case $host_os in
|
||||
SRC_OS="darwin"
|
||||
AC_DEFINE(DARWIN,[],[running on MacOS X])
|
||||
AC_DEFINE(SIGAR_TEST_OS_DARWIN, [1], [for the tests])
|
||||
SIGAR_INCLUDES="-I /Developer/Headers/FlatCarbon/"
|
||||
SIGAR_LIBS="-framework IOKit -framework CoreServices"
|
||||
;;
|
||||
*netbsd*)
|
||||
@@ -73,7 +73,7 @@ case $host_os in
|
||||
esac
|
||||
AC_MSG_RESULT([$SRC_OS])
|
||||
|
||||
AC_CHECK_HEADERS(libproc.h valgrind/valgrind.h)
|
||||
AC_CHECK_HEADERS(utmp.h utmpx.h libproc.h valgrind/valgrind.h)
|
||||
if test $ac_cv_header_libproc_h = yes; then
|
||||
AC_DEFINE(DARWIN_HAS_LIBPROC_H, [1], [sigar named them DARWIN_HAS_... instead of HAVE_])
|
||||
fi
|
||||
@@ -148,10 +148,7 @@ src/os/darwin/Makefile
|
||||
src/os/freebsd/Makefile
|
||||
src/os/hpux/Makefile
|
||||
src/os/linux/Makefile
|
||||
src/os/netware/Makefile
|
||||
src/os/osf1/Makefile
|
||||
src/os/solaris/Makefile
|
||||
src/os/stub/Makefile
|
||||
src/os/win32/Makefile
|
||||
examples/Makefile
|
||||
src/sigar_version_autoconf.c
|
||||
|
||||
+8
-4
@@ -23,6 +23,10 @@
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef MAX_INTERFACE_NAME_LEN
|
||||
#define MAX_INTERFACE_NAME_LEN 256
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -529,7 +533,7 @@ typedef struct {
|
||||
|
||||
typedef struct {
|
||||
char default_gateway[SIGAR_INET6_ADDRSTRLEN];
|
||||
char default_gateway_interface[16];
|
||||
char default_gateway_interface[MAX_INTERFACE_NAME_LEN];
|
||||
char host_name[SIGAR_MAXHOSTNAMELEN];
|
||||
char domain_name[SIGAR_MAXDOMAINNAMELEN];
|
||||
char primary_dns[SIGAR_INET6_ADDRSTRLEN];
|
||||
@@ -556,7 +560,7 @@ typedef struct {
|
||||
mtu,
|
||||
window,
|
||||
irtt;
|
||||
char ifname[16];
|
||||
char ifname[MAX_INTERFACE_NAME_LEN];
|
||||
} sigar_net_route_t;
|
||||
|
||||
typedef struct {
|
||||
@@ -602,7 +606,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
|
||||
#define SIGAR_IPV6_ADDR_COMPATv4 0x0080
|
||||
|
||||
typedef struct {
|
||||
char name[16];
|
||||
char name[MAX_INTERFACE_NAME_LEN];
|
||||
char type[64];
|
||||
char description[256];
|
||||
sigar_net_address_t hwaddr;
|
||||
@@ -847,7 +851,7 @@ sigar_net_listen_address_get(sigar_t *sigar,
|
||||
sigar_net_address_t *address);
|
||||
|
||||
typedef struct {
|
||||
char ifname[16];
|
||||
char ifname[MAX_INTERFACE_NAME_LEN];
|
||||
char type[64];
|
||||
sigar_net_address_t hwaddr;
|
||||
sigar_net_address_t address;
|
||||
|
||||
@@ -403,7 +403,7 @@ int sigar_get_iftype(const char *name, int *type, int *inst);
|
||||
#include <netdb.h>
|
||||
#endif
|
||||
|
||||
#define SIGAR_HOSTENT_LEN 512
|
||||
#define SIGAR_HOSTENT_LEN 1024
|
||||
#if defined(_AIX)
|
||||
#define SIGAR_HAS_HOSTENT_DATA
|
||||
#endif
|
||||
|
||||
+25
-1
@@ -4,6 +4,29 @@ MESSAGE(STATUS "CMAKE_SYSTEM_NAME is ${CMAKE_SYSTEM_NAME}")
|
||||
|
||||
INCLUDE_DIRECTORIES(../include/)
|
||||
|
||||
INCLUDE(CheckCSourceCompiles)
|
||||
|
||||
MACRO (CHECK_STRUCT_MEMBER _STRUCT _MEMBER _HEADER _RESULT)
|
||||
SET(_INCLUDE_FILES)
|
||||
FOREACH (it ${_HEADER})
|
||||
SET(_INCLUDE_FILES "${_INCLUDE_FILES}#include <${it}>\n")
|
||||
ENDFOREACH (it)
|
||||
|
||||
SET(_CHECK_STRUCT_MEMBER_SOURCE_CODE "
|
||||
${_INCLUDE_FILES}
|
||||
int main()
|
||||
{
|
||||
static ${_STRUCT} tmp;
|
||||
if (sizeof(tmp.${_MEMBER}))
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
")
|
||||
CHECK_C_SOURCE_COMPILES("${_CHECK_STRUCT_MEMBER_SOURCE_CODE}" ${_RESULT})
|
||||
|
||||
ENDMACRO (CHECK_STRUCT_MEMBER)
|
||||
|
||||
|
||||
## linux
|
||||
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
SET(SIGAR_SRC os/linux/linux_sigar.c)
|
||||
@@ -17,7 +40,6 @@ IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin|FreeBSD)")
|
||||
|
||||
INCLUDE_DIRECTORIES(os/darwin/)
|
||||
IF(CMAKE_SYSTEM_NAME MATCHES "(Darwin)")
|
||||
INCLUDE_DIRECTORIES(/Developer/Headers/FlatCarbon/)
|
||||
ADD_DEFINITIONS(-DDARWIN)
|
||||
SET(SIGAR_LINK_FLAGS "-framework CoreServices -framework IOKit")
|
||||
ELSE(CMAKE_SYSTEM_NAME MATCHES "(Darwin)")
|
||||
@@ -60,6 +82,8 @@ IF(WIN32)
|
||||
ADD_DEFINITIONS(-DSIGAR_SHARED)
|
||||
SET(SIGAR_SRC os/win32/peb.c os/win32/win32_sigar.c)
|
||||
INCLUDE_DIRECTORIES(os/win32)
|
||||
CHECK_STRUCT_MEMBER(MIB_IPADDRROW wType "windows.h;iphlpapi.h" wType_in_MIB_IPADDRROW)
|
||||
add_definitions(-DHAVE_MIB_IPADDRROW_WTYPE=${wType_in_MIB_IPADDRROW})
|
||||
ENDIF(WIN32)
|
||||
|
||||
SET(SIGAR_SRC ${SIGAR_SRC}
|
||||
|
||||
@@ -4,8 +4,5 @@ SUBDIRS = \
|
||||
freebsd \
|
||||
hpux \
|
||||
linux \
|
||||
netware \
|
||||
osf1 \
|
||||
solaris \
|
||||
stub \
|
||||
win32
|
||||
@@ -50,8 +50,7 @@
|
||||
#endif
|
||||
#include <mach-o/dyld.h>
|
||||
#define __OPENTRANSPORTPROVIDERS__
|
||||
#include <Gestalt.h>
|
||||
#include <CFString.h>
|
||||
#include <CoreServices/CoreServices.h>
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <IOKit/IOBSD.h>
|
||||
#include <IOKit/IOKitLib.h>
|
||||
@@ -3661,6 +3660,9 @@ int sigar_os_sys_info_get(sigar_t *sigar,
|
||||
case 6:
|
||||
codename = "Snow Leopard";
|
||||
break;
|
||||
case 7:
|
||||
codename = "Lion";
|
||||
break;
|
||||
default:
|
||||
codename = "Unknown";
|
||||
break;
|
||||
|
||||
+33
-10
@@ -19,11 +19,24 @@
|
||||
#ifndef SIGAR_OS_H
|
||||
#define SIGAR_OS_H
|
||||
|
||||
#if _MSC_VER <= 1200
|
||||
#define SIGAR_USING_MSC6 /* Visual Studio version 6 */
|
||||
#if !defined(MSVC) && defined(_MSC_VER)
|
||||
#define MSVC
|
||||
#endif
|
||||
|
||||
#ifdef MSVC
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define snprintf _snprintf
|
||||
#if _MSC_VER <= 1200
|
||||
#define SIGAR_USING_MSC6 /* Visual Studio version 6 */
|
||||
#define HAVE_MIB_IPADDRROW_WTYPE 0
|
||||
#else
|
||||
#define HAVE_MIB_IPADDRROW_WTYPE 1
|
||||
#endif
|
||||
#else
|
||||
/* Cross compiling */
|
||||
#define _WIN32_WINNT 0x0501
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#include <winreg.h>
|
||||
#include <winperf.h>
|
||||
@@ -38,12 +51,27 @@
|
||||
|
||||
#include "sigar_util.h"
|
||||
|
||||
#define INT64_C(val) val##i64
|
||||
#ifdef MSVC
|
||||
# define INT64_C(val) val##i64
|
||||
# define SIGAR_DLLFUNC(api, name) \
|
||||
struct { \
|
||||
const char *name; \
|
||||
##api##_##name func; \
|
||||
} ##name
|
||||
#else
|
||||
/* The GCC compiler doesn't require/accept the ## prefix */
|
||||
# define INT64_C(val) val##L
|
||||
# define SIGAR_DLLFUNC(api, name) \
|
||||
struct { \
|
||||
const char *name; \
|
||||
api##_##name func; \
|
||||
} name
|
||||
#endif
|
||||
|
||||
/* see apr/include/arch/win32/atime.h */
|
||||
#define EPOCH_DELTA INT64_C(11644473600000000)
|
||||
|
||||
#define SIGAR_CMDLINE_MAX 4096
|
||||
#define SIGAR_CMDLINE_MAX 4096<<2
|
||||
|
||||
/* XXX: support CP_UTF8 ? */
|
||||
|
||||
@@ -457,12 +485,6 @@ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
|
||||
LPTSTR,
|
||||
LPDWORD);
|
||||
|
||||
#define SIGAR_DLLFUNC(api, name) \
|
||||
struct { \
|
||||
const char *name; \
|
||||
##api##_##name func; \
|
||||
} ##name
|
||||
|
||||
typedef struct {
|
||||
sigar_dll_handle_t handle;
|
||||
|
||||
@@ -567,6 +589,7 @@ struct sigar_t {
|
||||
sigar_cache_t *netif_mib_rows;
|
||||
sigar_cache_t *netif_addr_rows;
|
||||
sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */
|
||||
int netif_name_short;
|
||||
|
||||
WORD ws_version;
|
||||
int ws_error;
|
||||
|
||||
+106
-25
@@ -23,6 +23,9 @@
|
||||
#include "sigar_util.h"
|
||||
#include "sigar_format.h"
|
||||
#include <shellapi.h>
|
||||
#ifndef MSVC
|
||||
#include <iphlpapi.h>
|
||||
#endif
|
||||
|
||||
#define USING_WIDE_S(s) (s)->using_wide
|
||||
#define USING_WIDE() USING_WIDE_S(sigar)
|
||||
@@ -124,6 +127,9 @@ typedef enum {
|
||||
#define MS_LOOPBACK_ADAPTER "Microsoft Loopback Adapter"
|
||||
#define NETIF_LA "la"
|
||||
|
||||
static int get_proc_info(sigar_t *sigar, sigar_pid_t pid);
|
||||
static int netif_hash(char *s);
|
||||
|
||||
sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft)
|
||||
{
|
||||
sigar_uint64_t time;
|
||||
@@ -375,13 +381,13 @@ static sigar_mpr_t sigar_mpr = {
|
||||
};
|
||||
|
||||
#define DLLMOD_COPY(name) \
|
||||
memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name))
|
||||
memcpy(&(sigar->name), &sigar_##name, sizeof(sigar_##name))
|
||||
|
||||
#define DLLMOD_INIT(name, all) \
|
||||
sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->##name), all)
|
||||
sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->name), all)
|
||||
|
||||
#define DLLMOD_FREE(name) \
|
||||
sigar_dllmod_free((sigar_dll_module_t *)&(sigar->##name))
|
||||
sigar_dllmod_free((sigar_dll_module_t *)&(sigar->name))
|
||||
|
||||
static void sigar_dllmod_free(sigar_dll_module_t *module)
|
||||
{
|
||||
@@ -507,6 +513,19 @@ static int sigar_enable_privilege(char *name)
|
||||
return status;
|
||||
}
|
||||
|
||||
static int netif_name_short(void)
|
||||
{
|
||||
char value[32767]; /* max size from msdn docs */
|
||||
DWORD retval =
|
||||
GetEnvironmentVariable("SIGAR_NETIF_NAME_SHORT", value, sizeof(value));
|
||||
if ((retval > 0) && (strEQ(value, "1") || (strEQ(value, "true")))) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int sigar_os_open(sigar_t **sigar_ptr)
|
||||
{
|
||||
LONG result;
|
||||
@@ -567,6 +586,8 @@ int sigar_os_open(sigar_t **sigar_ptr)
|
||||
sigar->netif_addr_rows = NULL;
|
||||
sigar->netif_adapters = NULL;
|
||||
sigar->netif_names = NULL;
|
||||
sigar->netif_name_short = netif_name_short();
|
||||
|
||||
sigar->pinfo.pid = -1;
|
||||
sigar->ws_version = 0;
|
||||
sigar->lcpu = -1;
|
||||
@@ -1470,7 +1491,9 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
}
|
||||
|
||||
/* likely we are 32-bit, pid process is 64-bit */
|
||||
#ifdef MSVC
|
||||
status = sigar_proc_args_wmi_get(sigar, pid, procargs);
|
||||
#endif
|
||||
if (status == ERROR_NOT_FOUND) {
|
||||
status = SIGAR_NO_SUCH_PROCESS;
|
||||
}
|
||||
@@ -1507,7 +1530,7 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
|
||||
break; /*XXX*/
|
||||
}
|
||||
|
||||
klen = val - ptr;
|
||||
klen = val - (char*)ptr;
|
||||
SIGAR_SSTRCPY(key, ptr);
|
||||
key[klen] = '\0';
|
||||
++val;
|
||||
@@ -1640,6 +1663,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
}
|
||||
|
||||
status = sigar_proc_exe_peb_get(sigar, proc, procexe);
|
||||
#ifdef MSVC
|
||||
if (procexe->name[0] == '\0') {
|
||||
/* likely we are 32-bit, pid process is 64-bit */
|
||||
/* procexe->cwd[0] = XXX where else can we try? */
|
||||
@@ -1648,7 +1672,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
|
||||
status = SIGAR_NO_SUCH_PROCESS;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
if (procexe->cwd[0] != '\0') {
|
||||
/* strip trailing '\' */
|
||||
int len = strlen(procexe->cwd);
|
||||
@@ -2279,9 +2303,9 @@ static int sigar_get_adapter_info(sigar_t *sigar,
|
||||
|
||||
static int sigar_get_adapters_addresses(sigar_t *sigar,
|
||||
ULONG family, ULONG flags,
|
||||
PIP_ADAPTER_ADDRESSES *addrs)
|
||||
PIP_ADAPTER_ADDRESSES *addrs,
|
||||
ULONG *size)
|
||||
{
|
||||
ULONG size = sigar->ifconf_len;
|
||||
ULONG rc;
|
||||
|
||||
DLLMOD_INIT(iphlpapi, FALSE);
|
||||
@@ -2290,28 +2314,23 @@ static int sigar_get_adapters_addresses(sigar_t *sigar,
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
*addrs = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf;
|
||||
rc = sigar_GetAdaptersAddresses(family,
|
||||
flags,
|
||||
NULL,
|
||||
*addrs,
|
||||
&size);
|
||||
size);
|
||||
|
||||
if (rc == ERROR_BUFFER_OVERFLOW) {
|
||||
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
|
||||
"GetAdaptersAddresses "
|
||||
"realloc ifconf_buf old=%d, new=%d",
|
||||
sigar->ifconf_len, size);
|
||||
sigar->ifconf_len = size;
|
||||
sigar->ifconf_buf = realloc(sigar->ifconf_buf,
|
||||
sigar->ifconf_len);
|
||||
"GetAdaptersAddresses realloc to %d", size);
|
||||
|
||||
*addrs = realloc(*addrs, *size);
|
||||
|
||||
*addrs = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf;
|
||||
rc = sigar_GetAdaptersAddresses(family,
|
||||
flags,
|
||||
NULL,
|
||||
*addrs,
|
||||
&size);
|
||||
(PIP_ADAPTER_ADDRESSES)*addrs,
|
||||
size);
|
||||
}
|
||||
|
||||
if (rc != ERROR_SUCCESS) {
|
||||
@@ -2394,10 +2413,10 @@ static int sigar_get_netif_ipaddr(sigar_t *sigar,
|
||||
MIB_IPADDRROW *row = &mib->table[i];
|
||||
short type;
|
||||
|
||||
#ifdef SIGAR_USING_MSC6
|
||||
type = row->unused2;
|
||||
#else
|
||||
#if HAVE_MIB_IPADDRROW_WTYPE
|
||||
type = row->wType;
|
||||
#else
|
||||
type = row->unused2;
|
||||
#endif
|
||||
if (!(type & MIB_IPADDR_PRIMARY)) {
|
||||
continue;
|
||||
@@ -2651,6 +2670,33 @@ static int netif_hash(char *s)
|
||||
#define IF_TYPE_IEEE80211 71
|
||||
#endif
|
||||
|
||||
static int
|
||||
sigar_net_interface_name_get(sigar_t *sigar, MIB_IFROW *ifr, PIP_ADAPTER_ADDRESSES address_list, char *name)
|
||||
{
|
||||
PIP_ADAPTER_ADDRESSES iter;
|
||||
int lpc = 0;
|
||||
|
||||
if (address_list == NULL) {
|
||||
return SIGAR_ENOTIMPL;
|
||||
}
|
||||
|
||||
for (iter = address_list; iter != NULL; iter = iter->Next) {
|
||||
for (lpc = 0; lpc < iter->PhysicalAddressLength; lpc++) {
|
||||
if (iter->PhysicalAddress[lpc] != ifr->bPhysAddr[lpc]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lpc == iter->PhysicalAddressLength) {
|
||||
wcstombs(name, iter->FriendlyName, MAX_INTERFACE_NAME_LEN);
|
||||
name[MAX_INTERFACE_NAME_LEN-1] = '\0';
|
||||
return SIGAR_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return SIGAR_ENOENT;
|
||||
}
|
||||
|
||||
SIGAR_DECLARE(int)
|
||||
sigar_net_interface_list_get(sigar_t *sigar,
|
||||
sigar_net_interface_list_t *iflist)
|
||||
@@ -2658,6 +2704,14 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||
MIB_IFTABLE *ift;
|
||||
int i, status;
|
||||
int lo=0, eth=0, la=0;
|
||||
PIP_ADAPTER_ADDRESSES address_list = NULL;
|
||||
ULONG size = 0;
|
||||
|
||||
status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, &address_list, &size);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
address_list = NULL;
|
||||
}
|
||||
|
||||
if (!sigar->netif_mib_rows) {
|
||||
sigar->netif_mib_rows =
|
||||
@@ -2670,6 +2724,9 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||
}
|
||||
|
||||
if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) {
|
||||
if (address_list) {
|
||||
free(address_list);
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -2681,23 +2738,44 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||
}
|
||||
|
||||
for (i=0; i<ift->dwNumEntries; i++) {
|
||||
char name[16];
|
||||
char name[MAX_INTERFACE_NAME_LEN];
|
||||
int key;
|
||||
MIB_IFROW *ifr = ift->table + i;
|
||||
sigar_cache_entry_t *entry;
|
||||
|
||||
status = SIGAR_ENOENT;
|
||||
|
||||
if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
|
||||
/* special-case */
|
||||
sprintf(name, NETIF_LA "%d", la++);
|
||||
}
|
||||
else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
|
||||
if (!sigar->netif_name_short) {
|
||||
status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
|
||||
}
|
||||
if (status != SIGAR_OK) {
|
||||
sprintf(name, "lo%d", lo++);
|
||||
}
|
||||
}
|
||||
else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
|
||||
(ifr->dwType == IF_TYPE_IEEE80211))
|
||||
{
|
||||
if (!sigar->netif_name_short &&
|
||||
(strstr(ifr->bDescr, "Scheduler") == NULL) &&
|
||||
(strstr(ifr->bDescr, "Filter") == NULL))
|
||||
{
|
||||
status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
|
||||
}
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
if (sigar->netif_name_short) {
|
||||
sprintf(name, "eth%d", eth++);
|
||||
}
|
||||
else {
|
||||
snprintf(name, ifr->dwDescrLen, "%s", ifr->bDescr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
continue; /*XXX*/
|
||||
}
|
||||
@@ -2720,6 +2798,10 @@ sigar_net_interface_list_get(sigar_t *sigar,
|
||||
}
|
||||
}
|
||||
|
||||
if (address_list != NULL) {
|
||||
free(address_list);
|
||||
}
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
@@ -2730,10 +2812,9 @@ static int sigar_net_interface_ipv6_config_find(sigar_t *sigar, int index,
|
||||
return SIGAR_ENOTIMPL;
|
||||
#else
|
||||
int status;
|
||||
PIP_ADAPTER_ADDRESSES aa, addrs;
|
||||
PIP_ADAPTER_ADDRESSES aa = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf, addrs;
|
||||
ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
|
||||
|
||||
status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, flags, &aa);
|
||||
status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, flags, &aa, &sigar->ifconf_len);
|
||||
|
||||
if (status != SIGAR_OK) {
|
||||
return status;
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#pragma comment(lib, "wbemuuid.lib")
|
||||
|
||||
#ifndef SIGAR_CMDLINE_MAX
|
||||
#define SIGAR_CMDLINE_MAX 4096
|
||||
#define SIGAR_CMDLINE_MAX 4096<<2
|
||||
#endif
|
||||
|
||||
class WMI {
|
||||
|
||||
+24
-114
@@ -30,6 +30,11 @@
|
||||
#ifndef WIN32
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
#if defined(HAVE_UTMPX_H)
|
||||
# include <utmpx.h>
|
||||
#elif defined(HAVE_UTMP_H)
|
||||
# include <utmp.h>
|
||||
#endif
|
||||
|
||||
#include "sigar.h"
|
||||
#include "sigar_private.h"
|
||||
@@ -412,7 +417,7 @@ static int sigar_common_fs_type_get(sigar_file_system_t *fsp)
|
||||
|
||||
switch (*type) {
|
||||
case 'n':
|
||||
if (strEQ(type, "nfs")) {
|
||||
if (strnEQ(type, "nfs", 3)) {
|
||||
fsp->type = SIGAR_FSTYPE_NETWORK;
|
||||
}
|
||||
break;
|
||||
@@ -1024,40 +1029,7 @@ SIGAR_DECLARE(int) sigar_who_list_destroy(sigar_t *sigar,
|
||||
return SIGAR_OK;
|
||||
}
|
||||
|
||||
#ifdef DARWIN
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
#ifdef MAC_OS_X_VERSION_10_5
|
||||
# if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
|
||||
# define SIGAR_NO_UTMP
|
||||
# endif
|
||||
/* else 10.4 and earlier or compiled with -mmacosx-version-min=10.3 */
|
||||
#endif
|
||||
|
||||
#if defined(__sun)
|
||||
# include <utmpx.h>
|
||||
# define SIGAR_UTMP_FILE _UTMPX_FILE
|
||||
# define ut_time ut_tv.tv_sec
|
||||
#elif defined(WIN32)
|
||||
/* XXX may not be the default */
|
||||
#define SIGAR_UTMP_FILE "C:\\cygwin\\var\\run\\utmp"
|
||||
#define UT_LINESIZE 16
|
||||
#define UT_NAMESIZE 16
|
||||
#define UT_HOSTSIZE 256
|
||||
#define UT_IDLEN 2
|
||||
#define ut_name ut_user
|
||||
|
||||
struct utmp {
|
||||
short ut_type;
|
||||
int ut_pid;
|
||||
char ut_line[UT_LINESIZE];
|
||||
char ut_id[UT_IDLEN];
|
||||
time_t ut_time;
|
||||
char ut_user[UT_NAMESIZE];
|
||||
char ut_host[UT_HOSTSIZE];
|
||||
long ut_addr;
|
||||
};
|
||||
#elif defined(NETWARE)
|
||||
#if defined(NETWARE)
|
||||
static char *getpass(const char *prompt)
|
||||
{
|
||||
static char password[BUFSIZ];
|
||||
@@ -1067,109 +1039,48 @@ static char *getpass(const char *prompt)
|
||||
|
||||
return (char *)&password;
|
||||
}
|
||||
#elif !defined(SIGAR_NO_UTMP)
|
||||
# include <utmp.h>
|
||||
# ifdef UTMP_FILE
|
||||
# define SIGAR_UTMP_FILE UTMP_FILE
|
||||
# else
|
||||
# define SIGAR_UTMP_FILE _PATH_UTMP
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(DARWIN)
|
||||
# define ut_user ut_name
|
||||
#endif
|
||||
|
||||
#ifdef DARWIN
|
||||
/* XXX from utmpx.h; sizeof changed in 10.5 */
|
||||
/* additionally, utmpx does not work on 10.4 */
|
||||
#define SIGAR_HAS_UTMPX
|
||||
#define _PATH_UTMPX "/var/run/utmpx"
|
||||
#define _UTX_USERSIZE 256 /* matches MAXLOGNAME */
|
||||
#define _UTX_LINESIZE 32
|
||||
#define _UTX_IDSIZE 4
|
||||
#define _UTX_HOSTSIZE 256
|
||||
struct utmpx {
|
||||
char ut_user[_UTX_USERSIZE]; /* login name */
|
||||
char ut_id[_UTX_IDSIZE]; /* id */
|
||||
char ut_line[_UTX_LINESIZE]; /* tty name */
|
||||
pid_t ut_pid; /* process id creating the entry */
|
||||
short ut_type; /* type of this entry */
|
||||
struct timeval ut_tv; /* time entry was created */
|
||||
char ut_host[_UTX_HOSTSIZE]; /* host name */
|
||||
__uint32_t ut_pad[16]; /* reserved for future use */
|
||||
};
|
||||
#define ut_xtime ut_tv.tv_sec
|
||||
#define UTMPX_USER_PROCESS 7
|
||||
/* end utmpx.h */
|
||||
#define SIGAR_UTMPX_FILE _PATH_UTMPX
|
||||
#endif
|
||||
|
||||
#if !defined(NETWARE) && !defined(_AIX)
|
||||
|
||||
#define WHOCPY(dest, src) \
|
||||
SIGAR_SSTRCPY(dest, src); \
|
||||
if (sizeof(src) < sizeof(dest)) \
|
||||
dest[sizeof(src)] = '\0'
|
||||
|
||||
#ifdef SIGAR_HAS_UTMPX
|
||||
static int sigar_who_utmpx(sigar_t *sigar,
|
||||
static int sigar_who_utmp(sigar_t *sigar,
|
||||
sigar_who_list_t *wholist)
|
||||
{
|
||||
FILE *fp;
|
||||
struct utmpx ut;
|
||||
#if defined(HAVE_UTMPX_H)
|
||||
struct utmpx *ut;
|
||||
|
||||
if (!(fp = fopen(SIGAR_UTMPX_FILE, "r"))) {
|
||||
return errno;
|
||||
}
|
||||
setutxent();
|
||||
|
||||
while (fread(&ut, sizeof(ut), 1, fp) == 1) {
|
||||
while ((ut = getutxent()) != NULL) {
|
||||
sigar_who_t *who;
|
||||
|
||||
if (*ut.ut_user == '\0') {
|
||||
if (*ut->ut_user == '\0') {
|
||||
continue;
|
||||
}
|
||||
|
||||
#ifdef UTMPX_USER_PROCESS
|
||||
if (ut.ut_type != UTMPX_USER_PROCESS) {
|
||||
if (ut->ut_type != USER_PROCESS) {
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
|
||||
SIGAR_WHO_LIST_GROW(wholist);
|
||||
who = &wholist->data[wholist->number++];
|
||||
|
||||
WHOCPY(who->user, ut.ut_user);
|
||||
WHOCPY(who->device, ut.ut_line);
|
||||
WHOCPY(who->host, ut.ut_host);
|
||||
WHOCPY(who->user, ut->ut_user);
|
||||
WHOCPY(who->device, ut->ut_line);
|
||||
WHOCPY(who->host, ut->ut_host);
|
||||
|
||||
who->time = ut.ut_xtime;
|
||||
who->time = ut->ut_tv.tv_sec;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SIGAR_NO_UTMP) && defined(SIGAR_HAS_UTMPX)
|
||||
#define sigar_who_utmp sigar_who_utmpx
|
||||
#else
|
||||
static int sigar_who_utmp(sigar_t *sigar,
|
||||
sigar_who_list_t *wholist)
|
||||
{
|
||||
endutxent();
|
||||
#elif defined(HAVE_UTMP_H)
|
||||
FILE *fp;
|
||||
#ifdef __sun
|
||||
/* use futmpx w/ pid32_t for sparc64 */
|
||||
struct futmpx ut;
|
||||
#else
|
||||
struct utmp ut;
|
||||
#endif
|
||||
if (!(fp = fopen(SIGAR_UTMP_FILE, "r"))) {
|
||||
#ifdef SIGAR_HAS_UTMPX
|
||||
/* Darwin 10.5 */
|
||||
return sigar_who_utmpx(sigar, wholist);
|
||||
#endif
|
||||
|
||||
if (!(fp = fopen(_PATH_UTMP, "r"))) {
|
||||
return errno;
|
||||
}
|
||||
|
||||
@@ -1189,7 +1100,7 @@ static int sigar_who_utmp(sigar_t *sigar,
|
||||
SIGAR_WHO_LIST_GROW(wholist);
|
||||
who = &wholist->data[wholist->number++];
|
||||
|
||||
WHOCPY(who->user, ut.ut_user);
|
||||
WHOCPY(who->user, ut.ut_name);
|
||||
WHOCPY(who->device, ut.ut_line);
|
||||
WHOCPY(who->host, ut.ut_host);
|
||||
|
||||
@@ -1197,11 +1108,10 @@ static int sigar_who_utmp(sigar_t *sigar,
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
#endif
|
||||
|
||||
return SIGAR_OK;
|
||||
}
|
||||
#endif /* SIGAR_NO_UTMP */
|
||||
#endif /* NETWARE */
|
||||
|
||||
#if defined(WIN32)
|
||||
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@
|
||||
#include <grp.h>
|
||||
|
||||
/* sysconf(_SC_GET{PW,GR}_R_SIZE_MAX) */
|
||||
#define R_SIZE_MAX 1024
|
||||
#define R_SIZE_MAX 2048
|
||||
|
||||
int sigar_user_name_get(sigar_t *sigar, int uid, char *buf, int buflen)
|
||||
{
|
||||
|
||||
+2
-2
@@ -39,7 +39,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#if defined(_WIN32)
|
||||
#if defined(MSVC)
|
||||
#include <WinError.h>
|
||||
#endif
|
||||
|
||||
@@ -85,7 +85,7 @@ TEST(test_sigar_file_system_list_get) {
|
||||
} else {
|
||||
switch (ret) {
|
||||
/* track the expected error code */
|
||||
#if defined(_WIN32)
|
||||
#if defined(MSVC)
|
||||
case ERROR_NOT_READY:
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#if defined(_WIN32)
|
||||
#if defined(MSVC)
|
||||
#include <WinError.h>
|
||||
#endif
|
||||
|
||||
@@ -127,7 +127,7 @@ TEST(test_sigar_proc_list_get) {
|
||||
switch (ret) {
|
||||
case EPERM:
|
||||
case ESRCH:
|
||||
#if (defined(_WIN32))
|
||||
#if (defined(MSVC))
|
||||
/* OpenProcess() may return ERROR_ACCESS_DENIED */
|
||||
case ERROR_ACCESS_DENIED:
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
copyright.year=2004-2009
|
||||
copyright.year=2004-2011
|
||||
version.major=1
|
||||
version.minor=7
|
||||
version.maint=0
|
||||
|
||||
Reference in new issue
Block a user