~n-muench/ubuntu/precise/open-vm-tools/open-vm-tools.raring-precise.backport

« back to all changes in this revision

Viewing changes to lib/misc/hostinfoPosix.c

  • Committer: Package Import Robot
  • Author(s): Nate Muench
  • Date: 2012-01-23 16:09:45 UTC
  • mfrom: (1.4.6) (2.4.26 sid)
  • Revision ID: package-import@ubuntu.com-20120123160945-b6s0r1vkcovucpf3
Tags: 2011.12.20-562307-0ubuntu1
* Merge latest upstream git tag. Fixes building on Precise
  (LP: #898289, LP: #905612)

* Items merged from Debian unstable:
  - debian/control:
    + open-vm-tools recommends open-vm-dkms. (LP: #598933)
    + open-vm-tools now suggests open-vm-toolbox. (LP: #604998)
  (From 2011.08.21-471295-1 release)
  - Updating maintainer and uploaders fields.
  - Removing vcs fields.
  - Removing references to Daniel's old email address.
  - Updating years in copyright file.
  - Updating to standards version 3.9.2.
  - Updating to debhelper version 8.
  - Switching to source format 3.0 (quilt).
  - Removing manual chrpath setting.
  - Removing exclusion from plugins from debhelper shlibs.
  - Rediffing kvers.patch.
  (From 2011.09.23-491607-1 release)
  - Marking binary architecture-dependend packages as linux and kfreebsd
  only.
  - Removing liburiparser-dev from build-depends as upstream dropped
  unity support.
  - Building with libproc-dev on amd64 again.
  - Dropping disabling of dnet support.
  (From 2011.09.23-491607-2 release)
  - Adding doxygen to build-depends for api documentation.
  - Adding libcunit1-dev to build-depends for test suites.
  - Minimizing rules file.
  - Adding open-vm-tools-dev package, containing only the api
    documentation for now.
  (From 2011.09.23-491607-3 release)
  - Sorting overrides in rules alphabetically.
  - Compacting copyright file.
  - Adding udev rule to set timeout for vmware scsi devices
  (From 2011.12.20-562307-1 release)
  - Adding patch to correct typo in upstreams dkms configuration

* Remaining Changes:
  - Remove Stable part of version numbering.
  - debian folder:
    + Re-added open-vm-dkms.postinst & open-vm-dkms.prerm.
      * Allows dkms modules to compile upon installation.
  - debian/control:
    + Re-add open-vm-source and make into a transitional package
      for open-vm-toolbox.
    + Return dependancies that were moved to open-vm-tools back to
      open-vm-toolbox.
  - debian/rules and debian/open-vm-toolbox.lintian-overrides:
    + Make vmware-user-suid-wrapper suid-root
  - debian/rules:
    + Added CFLAGS field with -Wno-deprecated-declarations
      * Will suppress issues with glib 2.31 or later.
    + Add line to copy vmware-xdg-detect-de into place.
    + Install vmware-user.desktop through toolbox package.
  - debian/open-vm-tools.init:
    + Re-add 'modprobe [-r] vmblock'.
    + Add 'modprobe [-r] vmxnet'.
      * Incase it's not loaded during boot.
    + Remove and re-add pcnet32 module
      * Will be done before (remove) and after (readd) vmxnet module
        is added.
      * If vmxnet doesn't exist (aka modules fail to build), pcnet32 can be
        still used for network connectivity.
      * Workaround until a better fix can be done.
  - Re-add gnome-session to debian/local/xautostart.conf
  - Manpages removed (from debian/manpages):
    + vmmemctl.9
    + vmxnet3.9
    + Remove references to manpages that have been removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1417
1417
                       float *avg1,  // IN/OUT:
1418
1418
                       float *avg2)  // IN/OUT:
1419
1419
{
1420
 
#if defined(__linux__) || defined(__APPLE__)
 
1420
#if (defined(__linux__) && !defined(__UCLIBC__)) || defined(__APPLE__)
1421
1421
   double avg[3];
1422
1422
   int res;
1423
1423
 
2405
2405
   uint32 hz;
2406
2406
   size_t hzSize = sizeof hz;
2407
2407
 
2408
 
   /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */
 
2408
   /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */
2409
2409
 
2410
2410
   if (sysctlbyname(CPUMHZ_SYSCTL_NAME, &hz, &hzSize, NULL, 0) == -1) {
2411
2411
      return FALSE;
2418
2418
   return FALSE;
2419
2419
#  endif
2420
2420
#else
2421
 
   float fMhz = 0;
2422
 
   char *readVal = HostinfoGetCpuInfo(cpuNumber, "cpu MHz");
2423
 
 
2424
 
   if (readVal == NULL) {
2425
 
      return FALSE;
2426
 
   }
2427
 
 
2428
 
   if (sscanf(readVal, "%f", &fMhz) == 1) {
2429
 
      *mHz = (unsigned int)(fMhz + 0.5);
2430
 
   }
2431
 
   free(readVal);
 
2421
#if defined(VMX86_SERVER)
 
2422
   if (HostType_OSIsVMK()) {
 
2423
      uint32 tscKhzEstimate;
 
2424
      VMK_ReturnStatus status = VMKernel_GetTSCkhzEstimate(&tscKhzEstimate);
 
2425
 
 
2426
      /*
 
2427
       * The TSC frequency matches the CPU frequency in all modern CPUs.
 
2428
       * Regardless, the TSC frequency is a much better estimate of
 
2429
       * reality than failing or returning zero.
 
2430
       */
 
2431
 
 
2432
      *mHz = tscKhzEstimate / 1000;
 
2433
 
 
2434
      return (status == VMK_OK);
 
2435
   }
 
2436
#endif
 
2437
 
 
2438
   {
 
2439
      float fMhz = 0;
 
2440
      char *readVal = HostinfoGetCpuInfo(cpuNumber, "cpu MHz");
 
2441
 
 
2442
      if (readVal == NULL) {
 
2443
         return FALSE;
 
2444
      }
 
2445
 
 
2446
      if (sscanf(readVal, "%f", &fMhz) == 1) {
 
2447
         *mHz = (unsigned int)(fMhz + 0.5);
 
2448
      }
 
2449
 
 
2450
      free(readVal);
 
2451
   }
2432
2452
 
2433
2453
   return TRUE;
2434
2454
#endif
2435
2455
}
2436
2456
 
2437
2457
 
 
2458
#if defined(__APPLE__) || defined(__FreeBSD__)
2438
2459
/*
2439
2460
 *-----------------------------------------------------------------------------
2440
2461
 *
2441
 
 * Hostinfo_GetCpuDescription --
 
2462
 * HostinfoGetSysctlStringAlloc --
2442
2463
 *
2443
 
 *      Get the descriptive name associated with a given CPU.
 
2464
 *      Obtains the value of a string-type host sysctl.
2444
2465
 *
2445
2466
 * Results:
2446
2467
 *      On success: Allocated, NUL-terminated string.
2452
2473
 *-----------------------------------------------------------------------------
2453
2474
 */
2454
2475
 
2455
 
char *
2456
 
Hostinfo_GetCpuDescription(uint32 cpuNumber)  // IN:
 
2476
static char *
 
2477
HostinfoGetSysctlStringAlloc(char const *sysctlName) // IN
2457
2478
{
2458
 
#if defined(__APPLE__) || defined(__FreeBSD__)
2459
 
#  if defined(__APPLE__)
2460
 
#     define CPUDESC_SYSCTL_NAME "machdep.cpu.brand_string"
2461
 
#  else
2462
 
#     define CPUDESC_SYSCTL_NAME "hw.model"
2463
 
#  endif
2464
 
 
2465
2479
   char *desc;
2466
2480
   size_t descSize;
2467
2481
 
2468
 
   /* 'cpuNumber' is ignored: Intel Macs are always perfectly symetric. */
2469
 
 
2470
 
   if (sysctlbyname(CPUDESC_SYSCTL_NAME, NULL, &descSize, NULL, 0) == -1) {
 
2482
   if (sysctlbyname(sysctlName, NULL, &descSize, NULL, 0) == -1) {
2471
2483
      return NULL;
2472
2484
   }
2473
2485
 
2476
2488
      return NULL;
2477
2489
   }
2478
2490
 
2479
 
   if (sysctlbyname(CPUDESC_SYSCTL_NAME, desc, &descSize, NULL, 0) == -1) {
 
2491
   if (sysctlbyname(sysctlName, desc, &descSize, NULL, 0) == -1) {
2480
2492
      free(desc);
2481
2493
 
2482
2494
      return NULL;
2483
2495
   }
2484
2496
 
2485
2497
   return desc;
 
2498
}
 
2499
#endif
 
2500
 
 
2501
 
 
2502
/*
 
2503
 *-----------------------------------------------------------------------------
 
2504
 *
 
2505
 * Hostinfo_GetCpuDescription --
 
2506
 *
 
2507
 *      Get the descriptive name associated with a given CPU.
 
2508
 *
 
2509
 * Results:
 
2510
 *      On success: Allocated, NUL-terminated string.
 
2511
 *      On failure: NULL.
 
2512
 *
 
2513
 * Side effects:
 
2514
 *      None.
 
2515
 *
 
2516
 *-----------------------------------------------------------------------------
 
2517
 */
 
2518
 
 
2519
char *
 
2520
Hostinfo_GetCpuDescription(uint32 cpuNumber)  // IN:
 
2521
{
 
2522
#if defined(__APPLE__)
 
2523
   /* 'cpuNumber' is ignored: Intel Macs are always perfectly symmetric. */
 
2524
   return HostinfoGetSysctlStringAlloc("machdep.cpu.brand_string");
 
2525
#elif defined(__FreeBSD__)
 
2526
   return HostinfoGetSysctlStringAlloc("hw.model");
2486
2527
#else
2487
2528
#ifdef VMX86_SERVER
2488
2529
   if (HostType_OSIsVMK()) {
2492
2533
      mName[0] = '\0';
2493
2534
      if (VMKernel_GetCPUModelName(cpuNumber, mName,
2494
2535
                                   sizeof(mName)) == VMK_OK) {
2495
 
         mName[sizeof(mName) - 1] = '\0';
 
2536
         mName[sizeof(mName) - 1] = '\0';
2496
2537
 
2497
2538
         return strdup(mName);
2498
2539
      }
2723
2764
 
2724
2765
   return retval;
2725
2766
}
 
2767
 
 
2768
 
 
2769
/*
 
2770
 *-----------------------------------------------------------------------------
 
2771
 *
 
2772
 * Hostinfo_GetHardwareModel --
 
2773
 *
 
2774
 *      Obtains the hardware model identifier (i.e. "MacPro5,1") from the host.
 
2775
 *
 
2776
 * Results:
 
2777
 *      On success: Allocated, NUL-terminated string.
 
2778
 *      On failure: NULL.
 
2779
 *
 
2780
 * Side effects:
 
2781
 *      None.
 
2782
 *
 
2783
 *-----------------------------------------------------------------------------
 
2784
 */
 
2785
 
 
2786
char *
 
2787
Hostinfo_GetHardwareModel(void)
 
2788
{
 
2789
   return HostinfoGetSysctlStringAlloc("hw.model");
 
2790
}
2726
2791
#endif /* __APPLE__ */
2727
2792
 
2728
2793
 
3343
3408
   return NULL;
3344
3409
#endif
3345
3410
}
 
3411
 
 
3412
 
 
3413
/*
 
3414
 *----------------------------------------------------------------------
 
3415
 *
 
3416
 * Hostinfo_QueryProcessExistence --
 
3417
 *
 
3418
 *      Determine if a PID is "alive" or "dead". Failing to be able to
 
3419
 *      do this perfectly, do not make any assumption - say the answer
 
3420
 *      is unknown.
 
3421
 *
 
3422
 * Results:
 
3423
 *      HOSTINFO_PROCESS_QUERY_ALIVE    Process is alive
 
3424
 *      HOSTINFO_PROCESS_QUERY_DEAD     Process is dead
 
3425
 *      HOSTINFO_PROCESS_QUERY_UNKNOWN  Don't know
 
3426
 *
 
3427
 * Side effects:
 
3428
 *      None
 
3429
 *
 
3430
 *----------------------------------------------------------------------
 
3431
 */
 
3432
 
 
3433
HostinfoProcessQuery
 
3434
Hostinfo_QueryProcessExistence(int pid)  // IN:
 
3435
{
 
3436
   HostinfoProcessQuery ret;
 
3437
   int err = (kill(pid, 0) == -1) ? errno : 0;
 
3438
 
 
3439
   switch (err) {
 
3440
   case 0:
 
3441
   case EPERM:
 
3442
      ret = HOSTINFO_PROCESS_QUERY_ALIVE;
 
3443
      break;
 
3444
   case ESRCH:
 
3445
      ret = HOSTINFO_PROCESS_QUERY_DEAD;
 
3446
      break;
 
3447
   default:
 
3448
      ret = HOSTINFO_PROCESS_QUERY_UNKNOWN;
 
3449
      break;
 
3450
   }
 
3451
 
 
3452
   return ret;
 
3453
}