sigar 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ #include "sigar.h"
2
+
3
+ static sigar_version_t sigar_version = {
4
+ "03/26/2012 12:16 PM",
5
+ "6e30384",
6
+ "1.7.0.0",
7
+ "x86_64-darwin10.8.0",
8
+ "sigar.bundle",
9
+ "sigar.bundle",
10
+ "SIGAR-1.7.0.0, "
11
+ "SCM revision 6e30384, "
12
+ "built 03/26/2012 12:16 PM as sigar.bundle",
13
+ 1,
14
+ 7,
15
+ 0,
16
+ 0
17
+ };
18
+
19
+ SIGAR_DECLARE(sigar_version_t *) sigar_version_get(void)
20
+ {
21
+ return &sigar_version;
22
+ }
@@ -30,7 +30,7 @@ class FileSystemTest < Test::Unit::TestCase
30
30
 
31
31
  begin
32
32
  usage = sigar.file_system_usage fs.dir_name
33
- rescue err
33
+ rescue => err
34
34
  if fs.type == Sigar::FSTYPE_LOCAL_DISK
35
35
  raise err
36
36
  end
@@ -23,6 +23,10 @@
23
23
 
24
24
  #include <limits.h>
25
25
 
26
+ #ifndef MAX_INTERFACE_NAME_LEN
27
+ #define MAX_INTERFACE_NAME_LEN 256
28
+ #endif
29
+
26
30
  #ifdef __cplusplus
27
31
  extern "C" {
28
32
  #endif
@@ -529,7 +533,7 @@ typedef struct {
529
533
 
530
534
  typedef struct {
531
535
  char default_gateway[SIGAR_INET6_ADDRSTRLEN];
532
- char default_gateway_interface[16];
536
+ char default_gateway_interface[MAX_INTERFACE_NAME_LEN];
533
537
  char host_name[SIGAR_MAXHOSTNAMELEN];
534
538
  char domain_name[SIGAR_MAXDOMAINNAMELEN];
535
539
  char primary_dns[SIGAR_INET6_ADDRSTRLEN];
@@ -556,7 +560,7 @@ typedef struct {
556
560
  mtu,
557
561
  window,
558
562
  irtt;
559
- char ifname[16];
563
+ char ifname[MAX_INTERFACE_NAME_LEN];
560
564
  } sigar_net_route_t;
561
565
 
562
566
  typedef struct {
@@ -602,7 +606,7 @@ SIGAR_DECLARE(int) sigar_net_route_list_destroy(sigar_t *sigar,
602
606
  #define SIGAR_IPV6_ADDR_COMPATv4 0x0080
603
607
 
604
608
  typedef struct {
605
- char name[16];
609
+ char name[MAX_INTERFACE_NAME_LEN];
606
610
  char type[64];
607
611
  char description[256];
608
612
  sigar_net_address_t hwaddr;
@@ -847,7 +851,7 @@ sigar_net_listen_address_get(sigar_t *sigar,
847
851
  sigar_net_address_t *address);
848
852
 
849
853
  typedef struct {
850
- char ifname[16];
854
+ char ifname[MAX_INTERFACE_NAME_LEN];
851
855
  char type[64];
852
856
  sigar_net_address_t hwaddr;
853
857
  sigar_net_address_t address;
@@ -403,7 +403,7 @@ int sigar_get_iftype(const char *name, int *type, int *inst);
403
403
  #include <netdb.h>
404
404
  #endif
405
405
 
406
- #define SIGAR_HOSTENT_LEN 512
406
+ #define SIGAR_HOSTENT_LEN 1024
407
407
  #if defined(_AIX)
408
408
  #define SIGAR_HAS_HOSTENT_DATA
409
409
  #endif
@@ -50,8 +50,7 @@
50
50
  #endif
51
51
  #include <mach-o/dyld.h>
52
52
  #define __OPENTRANSPORTPROVIDERS__
53
- #include <Gestalt.h>
54
- #include <CFString.h>
53
+ #include <CoreServices/CoreServices.h>
55
54
  #include <CoreFoundation/CoreFoundation.h>
56
55
  #include <IOKit/IOBSD.h>
57
56
  #include <IOKit/IOKitLib.h>
@@ -3661,6 +3660,9 @@ int sigar_os_sys_info_get(sigar_t *sigar,
3661
3660
  case 6:
3662
3661
  codename = "Snow Leopard";
3663
3662
  break;
3663
+ case 7:
3664
+ codename = "Lion";
3665
+ break;
3664
3666
  default:
3665
3667
  codename = "Unknown";
3666
3668
  break;
@@ -19,11 +19,24 @@
19
19
  #ifndef SIGAR_OS_H
20
20
  #define SIGAR_OS_H
21
21
 
22
+ #if !defined(MSVC) && defined(_MSC_VER)
23
+ #define MSVC
24
+ #endif
25
+
26
+ #ifdef MSVC
27
+ #define WIN32_LEAN_AND_MEAN
28
+ #define snprintf _snprintf
22
29
  #if _MSC_VER <= 1200
23
30
  #define SIGAR_USING_MSC6 /* Visual Studio version 6 */
31
+ #define HAVE_MIB_IPADDRROW_WTYPE 0
32
+ #else
33
+ #define HAVE_MIB_IPADDRROW_WTYPE 1
34
+ #endif
35
+ #else
36
+ /* Cross compiling */
37
+ #define _WIN32_WINNT 0x0501
24
38
  #endif
25
39
 
26
- #define WIN32_LEAN_AND_MEAN
27
40
  #include <windows.h>
28
41
  #include <winreg.h>
29
42
  #include <winperf.h>
@@ -38,12 +51,27 @@
38
51
 
39
52
  #include "sigar_util.h"
40
53
 
41
- #define INT64_C(val) val##i64
54
+ #ifdef MSVC
55
+ # define INT64_C(val) val##i64
56
+ # define SIGAR_DLLFUNC(api, name) \
57
+ struct { \
58
+ const char *name; \
59
+ ##api##_##name func; \
60
+ } ##name
61
+ #else
62
+ /* The GCC compiler doesn't require/accept the ## prefix */
63
+ # define INT64_C(val) val##L
64
+ # define SIGAR_DLLFUNC(api, name) \
65
+ struct { \
66
+ const char *name; \
67
+ api##_##name func; \
68
+ } name
69
+ #endif
42
70
 
43
71
  /* see apr/include/arch/win32/atime.h */
44
72
  #define EPOCH_DELTA INT64_C(11644473600000000)
45
73
 
46
- #define SIGAR_CMDLINE_MAX 4096
74
+ #define SIGAR_CMDLINE_MAX 4096<<2
47
75
 
48
76
  /* XXX: support CP_UTF8 ? */
49
77
 
@@ -457,12 +485,6 @@ typedef BOOL (CALLBACK *mpr_get_net_connection)(LPCTSTR,
457
485
  LPTSTR,
458
486
  LPDWORD);
459
487
 
460
- #define SIGAR_DLLFUNC(api, name) \
461
- struct { \
462
- const char *name; \
463
- ##api##_##name func; \
464
- } ##name
465
-
466
488
  typedef struct {
467
489
  sigar_dll_handle_t handle;
468
490
 
@@ -567,6 +589,7 @@ struct sigar_t {
567
589
  sigar_cache_t *netif_mib_rows;
568
590
  sigar_cache_t *netif_addr_rows;
569
591
  sigar_cache_t *netif_names; /* dwIndex -> net_interface_config.name */
592
+ int netif_name_short;
570
593
 
571
594
  WORD ws_version;
572
595
  int ws_error;
@@ -23,6 +23,9 @@
23
23
  #include "sigar_util.h"
24
24
  #include "sigar_format.h"
25
25
  #include <shellapi.h>
26
+ #ifndef MSVC
27
+ #include <iphlpapi.h>
28
+ #endif
26
29
 
27
30
  #define USING_WIDE_S(s) (s)->using_wide
28
31
  #define USING_WIDE() USING_WIDE_S(sigar)
@@ -124,6 +127,9 @@ typedef enum {
124
127
  #define MS_LOOPBACK_ADAPTER "Microsoft Loopback Adapter"
125
128
  #define NETIF_LA "la"
126
129
 
130
+ static int get_proc_info(sigar_t *sigar, sigar_pid_t pid);
131
+ static int netif_hash(char *s);
132
+
127
133
  sigar_uint64_t sigar_FileTimeToTime(FILETIME *ft)
128
134
  {
129
135
  sigar_uint64_t time;
@@ -375,13 +381,13 @@ static sigar_mpr_t sigar_mpr = {
375
381
  };
376
382
 
377
383
  #define DLLMOD_COPY(name) \
378
- memcpy(&(sigar->##name), &sigar_##name, sizeof(sigar_##name))
384
+ memcpy(&(sigar->name), &sigar_##name, sizeof(sigar_##name))
379
385
 
380
386
  #define DLLMOD_INIT(name, all) \
381
- sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->##name), all)
387
+ sigar_dllmod_init(sigar, (sigar_dll_module_t *)&(sigar->name), all)
382
388
 
383
389
  #define DLLMOD_FREE(name) \
384
- sigar_dllmod_free((sigar_dll_module_t *)&(sigar->##name))
390
+ sigar_dllmod_free((sigar_dll_module_t *)&(sigar->name))
385
391
 
386
392
  static void sigar_dllmod_free(sigar_dll_module_t *module)
387
393
  {
@@ -507,6 +513,19 @@ static int sigar_enable_privilege(char *name)
507
513
  return status;
508
514
  }
509
515
 
516
+ static int netif_name_short(void)
517
+ {
518
+ char value[32767]; /* max size from msdn docs */
519
+ DWORD retval =
520
+ GetEnvironmentVariable("SIGAR_NETIF_NAME_SHORT", value, sizeof(value));
521
+ if ((retval > 0) && (strEQ(value, "1") || (strEQ(value, "true")))) {
522
+ return 1;
523
+ }
524
+ else {
525
+ return 0;
526
+ }
527
+ }
528
+
510
529
  int sigar_os_open(sigar_t **sigar_ptr)
511
530
  {
512
531
  LONG result;
@@ -567,6 +586,8 @@ int sigar_os_open(sigar_t **sigar_ptr)
567
586
  sigar->netif_addr_rows = NULL;
568
587
  sigar->netif_adapters = NULL;
569
588
  sigar->netif_names = NULL;
589
+ sigar->netif_name_short = netif_name_short();
590
+
570
591
  sigar->pinfo.pid = -1;
571
592
  sigar->ws_version = 0;
572
593
  sigar->lcpu = -1;
@@ -1470,7 +1491,9 @@ static int sigar_remote_proc_args_get(sigar_t *sigar, sigar_pid_t pid,
1470
1491
  }
1471
1492
 
1472
1493
  /* likely we are 32-bit, pid process is 64-bit */
1494
+ #ifdef MSVC
1473
1495
  status = sigar_proc_args_wmi_get(sigar, pid, procargs);
1496
+ #endif
1474
1497
  if (status == ERROR_NOT_FOUND) {
1475
1498
  status = SIGAR_NO_SUCH_PROCESS;
1476
1499
  }
@@ -1507,7 +1530,7 @@ static int sigar_proc_env_parse(UCHAR *ptr, sigar_proc_env_t *procenv,
1507
1530
  break; /*XXX*/
1508
1531
  }
1509
1532
 
1510
- klen = val - ptr;
1533
+ klen = val - (char*)ptr;
1511
1534
  SIGAR_SSTRCPY(key, ptr);
1512
1535
  key[klen] = '\0';
1513
1536
  ++val;
@@ -1640,6 +1663,7 @@ SIGAR_DECLARE(int) sigar_proc_exe_get(sigar_t *sigar, sigar_pid_t pid,
1640
1663
  }
1641
1664
 
1642
1665
  status = sigar_proc_exe_peb_get(sigar, proc, procexe);
1666
+ #ifdef MSVC
1643
1667
  if (procexe->name[0] == '\0') {
1644
1668
  /* likely we are 32-bit, pid process is 64-bit */
1645
1669
  /* 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,
1648
1672
  status = SIGAR_NO_SUCH_PROCESS;
1649
1673
  }
1650
1674
  }
1651
-
1675
+ #endif
1652
1676
  if (procexe->cwd[0] != '\0') {
1653
1677
  /* strip trailing '\' */
1654
1678
  int len = strlen(procexe->cwd);
@@ -2279,9 +2303,9 @@ static int sigar_get_adapter_info(sigar_t *sigar,
2279
2303
 
2280
2304
  static int sigar_get_adapters_addresses(sigar_t *sigar,
2281
2305
  ULONG family, ULONG flags,
2282
- PIP_ADAPTER_ADDRESSES *addrs)
2306
+ PIP_ADAPTER_ADDRESSES *addrs,
2307
+ ULONG *size)
2283
2308
  {
2284
- ULONG size = sigar->ifconf_len;
2285
2309
  ULONG rc;
2286
2310
 
2287
2311
  DLLMOD_INIT(iphlpapi, FALSE);
@@ -2290,28 +2314,23 @@ static int sigar_get_adapters_addresses(sigar_t *sigar,
2290
2314
  return SIGAR_ENOTIMPL;
2291
2315
  }
2292
2316
 
2293
- *addrs = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf;
2294
2317
  rc = sigar_GetAdaptersAddresses(family,
2295
2318
  flags,
2296
2319
  NULL,
2297
2320
  *addrs,
2298
- &size);
2321
+ size);
2299
2322
 
2300
2323
  if (rc == ERROR_BUFFER_OVERFLOW) {
2301
2324
  sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
2302
- "GetAdaptersAddresses "
2303
- "realloc ifconf_buf old=%d, new=%d",
2304
- sigar->ifconf_len, size);
2305
- sigar->ifconf_len = size;
2306
- sigar->ifconf_buf = realloc(sigar->ifconf_buf,
2307
- sigar->ifconf_len);
2325
+ "GetAdaptersAddresses realloc to %d", size);
2326
+
2327
+ *addrs = realloc(*addrs, *size);
2308
2328
 
2309
- *addrs = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf;
2310
2329
  rc = sigar_GetAdaptersAddresses(family,
2311
2330
  flags,
2312
2331
  NULL,
2313
- *addrs,
2314
- &size);
2332
+ (PIP_ADAPTER_ADDRESSES)*addrs,
2333
+ size);
2315
2334
  }
2316
2335
 
2317
2336
  if (rc != ERROR_SUCCESS) {
@@ -2394,10 +2413,10 @@ static int sigar_get_netif_ipaddr(sigar_t *sigar,
2394
2413
  MIB_IPADDRROW *row = &mib->table[i];
2395
2414
  short type;
2396
2415
 
2397
- #ifdef SIGAR_USING_MSC6
2398
- type = row->unused2;
2399
- #else
2416
+ #if HAVE_MIB_IPADDRROW_WTYPE
2400
2417
  type = row->wType;
2418
+ #else
2419
+ type = row->unused2;
2401
2420
  #endif
2402
2421
  if (!(type & MIB_IPADDR_PRIMARY)) {
2403
2422
  continue;
@@ -2651,6 +2670,33 @@ static int netif_hash(char *s)
2651
2670
  #define IF_TYPE_IEEE80211 71
2652
2671
  #endif
2653
2672
 
2673
+ static int
2674
+ sigar_net_interface_name_get(sigar_t *sigar, MIB_IFROW *ifr, PIP_ADAPTER_ADDRESSES address_list, char *name)
2675
+ {
2676
+ PIP_ADAPTER_ADDRESSES iter;
2677
+ int lpc = 0;
2678
+
2679
+ if (address_list == NULL) {
2680
+ return SIGAR_ENOTIMPL;
2681
+ }
2682
+
2683
+ for (iter = address_list; iter != NULL; iter = iter->Next) {
2684
+ for (lpc = 0; lpc < iter->PhysicalAddressLength; lpc++) {
2685
+ if (iter->PhysicalAddress[lpc] != ifr->bPhysAddr[lpc]) {
2686
+ break;
2687
+ }
2688
+ }
2689
+
2690
+ if (lpc == iter->PhysicalAddressLength) {
2691
+ wcstombs(name, iter->FriendlyName, MAX_INTERFACE_NAME_LEN);
2692
+ name[MAX_INTERFACE_NAME_LEN-1] = '\0';
2693
+ return SIGAR_OK;
2694
+ }
2695
+ }
2696
+
2697
+ return SIGAR_ENOENT;
2698
+ }
2699
+
2654
2700
  SIGAR_DECLARE(int)
2655
2701
  sigar_net_interface_list_get(sigar_t *sigar,
2656
2702
  sigar_net_interface_list_t *iflist)
@@ -2658,6 +2704,14 @@ sigar_net_interface_list_get(sigar_t *sigar,
2658
2704
  MIB_IFTABLE *ift;
2659
2705
  int i, status;
2660
2706
  int lo=0, eth=0, la=0;
2707
+ PIP_ADAPTER_ADDRESSES address_list = NULL;
2708
+ ULONG size = 0;
2709
+
2710
+ status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, GAA_FLAG_INCLUDE_PREFIX, &address_list, &size);
2711
+
2712
+ if (status != SIGAR_OK) {
2713
+ address_list = NULL;
2714
+ }
2661
2715
 
2662
2716
  if (!sigar->netif_mib_rows) {
2663
2717
  sigar->netif_mib_rows =
@@ -2670,6 +2724,9 @@ sigar_net_interface_list_get(sigar_t *sigar,
2670
2724
  }
2671
2725
 
2672
2726
  if ((status = sigar_get_if_table(sigar, &ift)) != SIGAR_OK) {
2727
+ if (address_list) {
2728
+ free(address_list);
2729
+ }
2673
2730
  return status;
2674
2731
  }
2675
2732
 
@@ -2681,22 +2738,43 @@ sigar_net_interface_list_get(sigar_t *sigar,
2681
2738
  }
2682
2739
 
2683
2740
  for (i=0; i<ift->dwNumEntries; i++) {
2684
- char name[16];
2741
+ char name[MAX_INTERFACE_NAME_LEN];
2685
2742
  int key;
2686
2743
  MIB_IFROW *ifr = ift->table + i;
2687
2744
  sigar_cache_entry_t *entry;
2688
2745
 
2746
+ status = SIGAR_ENOENT;
2747
+
2689
2748
  if (strEQ(ifr->bDescr, MS_LOOPBACK_ADAPTER)) {
2690
2749
  /* special-case */
2691
2750
  sprintf(name, NETIF_LA "%d", la++);
2692
2751
  }
2693
2752
  else if (ifr->dwType == MIB_IF_TYPE_LOOPBACK) {
2694
- sprintf(name, "lo%d", lo++);
2753
+ if (!sigar->netif_name_short) {
2754
+ status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
2755
+ }
2756
+ if (status != SIGAR_OK) {
2757
+ sprintf(name, "lo%d", lo++);
2758
+ }
2695
2759
  }
2696
2760
  else if ((ifr->dwType == MIB_IF_TYPE_ETHERNET) ||
2697
2761
  (ifr->dwType == IF_TYPE_IEEE80211))
2698
2762
  {
2699
- sprintf(name, "eth%d", eth++);
2763
+ if (!sigar->netif_name_short &&
2764
+ (strstr(ifr->bDescr, "Scheduler") == NULL) &&
2765
+ (strstr(ifr->bDescr, "Filter") == NULL))
2766
+ {
2767
+ status = sigar_net_interface_name_get(sigar, ifr, address_list, name);
2768
+ }
2769
+
2770
+ if (status != SIGAR_OK) {
2771
+ if (sigar->netif_name_short) {
2772
+ sprintf(name, "eth%d", eth++);
2773
+ }
2774
+ else {
2775
+ snprintf(name, ifr->dwDescrLen, "%s", ifr->bDescr);
2776
+ }
2777
+ }
2700
2778
  }
2701
2779
  else {
2702
2780
  continue; /*XXX*/
@@ -2720,6 +2798,10 @@ sigar_net_interface_list_get(sigar_t *sigar,
2720
2798
  }
2721
2799
  }
2722
2800
 
2801
+ if (address_list != NULL) {
2802
+ free(address_list);
2803
+ }
2804
+
2723
2805
  return SIGAR_OK;
2724
2806
  }
2725
2807
 
@@ -2730,10 +2812,9 @@ static int sigar_net_interface_ipv6_config_find(sigar_t *sigar, int index,
2730
2812
  return SIGAR_ENOTIMPL;
2731
2813
  #else
2732
2814
  int status;
2733
- PIP_ADAPTER_ADDRESSES aa, addrs;
2815
+ PIP_ADAPTER_ADDRESSES aa = (PIP_ADAPTER_ADDRESSES)sigar->ifconf_buf, addrs;
2734
2816
  ULONG flags = GAA_FLAG_INCLUDE_PREFIX;
2735
-
2736
- status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, flags, &aa);
2817
+ status = sigar_get_adapters_addresses(sigar, AF_UNSPEC, flags, &aa, &sigar->ifconf_len);
2737
2818
 
2738
2819
  if (status != SIGAR_OK) {
2739
2820
  return status;