win-pvdrivers

changeset 506:49699f57543e

Better error checking
author James Harper <james.harper@bendigoit.com.au>
date Mon Dec 22 22:35:55 2008 +1100 (2008-12-22)
parents f1be6c082c71
children 69b067a93d0e
files shutdownmon/shutdownmon.c
line diff
     1.1 --- a/shutdownmon/shutdownmon.c	Mon Dec 22 22:35:17 2008 +1100
     1.2 +++ b/shutdownmon/shutdownmon.c	Mon Dec 22 22:35:55 2008 +1100
     1.3 @@ -183,21 +183,32 @@ do_shutdown(BOOL bRebootAfterShutdown)
     1.4  static char *
     1.5  get_xen_interface_path()
     1.6  {
     1.7 -  HDEVINFO handle = SetupDiGetClassDevs(&GUID_XEN_IFACE, 0, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
     1.8 +  HDEVINFO handle;
     1.9    SP_DEVICE_INTERFACE_DATA sdid;
    1.10    SP_DEVICE_INTERFACE_DETAIL_DATA *sdidd;
    1.11    DWORD buf_len;
    1.12    char *path;
    1.13  
    1.14 +  handle = SetupDiGetClassDevs(&GUID_XEN_IFACE, 0, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
    1.15 +  if (handle == INVALID_HANDLE_VALUE)
    1.16 +  {
    1.17 +    write_log("SetupDiGetClassDevs failed\n"); 
    1.18 +    return NULL;
    1.19 +  }
    1.20    sdid.cbSize = sizeof(sdid);
    1.21    if (!SetupDiEnumDeviceInterfaces(handle, NULL, &GUID_XEN_IFACE, 0, &sdid))
    1.22 +  {
    1.23 +    write_log("SetupDiEnumDeviceInterfaces failed\n");
    1.24      return NULL;
    1.25 +  }
    1.26    SetupDiGetDeviceInterfaceDetail(handle, &sdid, NULL, 0, &buf_len, NULL);
    1.27 -  printf("buf_len = %d\n", buf_len);
    1.28    sdidd = malloc(buf_len);
    1.29    sdidd->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
    1.30    if (!SetupDiGetDeviceInterfaceDetail(handle, &sdid, sdidd, buf_len, NULL, NULL))
    1.31 +  {
    1.32 +    write_log("SetupDiGetDeviceInterfaceDetail failed\n"); 
    1.33      return NULL;
    1.34 +  }
    1.35    
    1.36    path = malloc(strlen(sdidd->DevicePath) + 1);
    1.37    strcpy(path, sdidd->DevicePath);
    1.38 @@ -254,7 +265,6 @@ do_monitoring()
    1.39      case 1:
    1.40        if (inchar == '\n')
    1.41        {
    1.42 -        printf("%s\n", buf);
    1.43          if (strcmp("poweroff", buf) == 0 || strcmp("halt", buf) == 0)
    1.44          {
    1.45            do_shutdown(FALSE);
    1.46 @@ -326,7 +336,7 @@ void service_main(int argc, char *argv[]
    1.47  
    1.48    do_monitoring();
    1.49  
    1.50 -write_log("All done\n"); 
    1.51 +  write_log("All done\n"); 
    1.52  
    1.53    return; 
    1.54  }