(file) Return to check.cpp CVS log (file) (dir) Up to [OMI] / omi / check

Diff for /omi/check/check.cpp between version 1.2 and 1.3

version 1.2, 2015/04/20 18:10:10 version 1.3, 2015/04/20 18:19:50
Line 27 
Line 27 
 #include <cstdlib> #include <cstdlib>
 #include <cstdio> #include <cstdio>
 #include <omiclient/client.h> #include <omiclient/client.h>
 #include <base/args.h>  #include <pal/dir.h>
 #include <base/dir.h>  
 #include <base/result.h> #include <base/result.h>
 #include <base/strings.h>  #include <pal/strings.h>
 #include <base/paths.h> #include <base/paths.h>
 #include <base/conf.h> #include <base/conf.h>
 #include <base/env.h> #include <base/env.h>
 #include <base/getopt.h>  #include <base/omigetopt.h>
 #include <base/io.h>  #include <pal/format.h>
 #include <base/time.h>  #include <pal/sleep.h>
   
 #define T MI_T  
   
 #if (MI_CHAR_TYPE == 1)  
 #define STRF "%s"  
 #else  
 #define STRF "%S"  
 #endif  
  
 using namespace mi; using namespace mi;
  
Line 58 
Line 49 
 static Options opts; static Options opts;
  
 PRINTF_FORMAT(1, 2) PRINTF_FORMAT(1, 2)
 static void err(const char* fmt, ...)  static void err(const ZChar* fmt, ...)
 { {
     fprintf(stderr, "%s: ", arg0);      Ftprintf(stderr, ZT("%s: "), scs(arg0));
  
     va_list ap;     va_list ap;
     va_start(ap, fmt);     va_start(ap, fmt);
     vfprintf(stderr, fmt, ap);      Vftprintf(stderr, fmt, ap);
     va_end(ap);     va_end(ap);
  
     fputc('\n', stderr);      Ftprintf(stderr, ZT("\n"));
     exit(1);     exit(1);
 } }
  
Line 91 
Line 82 
             break;             break;
  
         if (r == -1)         if (r == -1)
             err("%s", state.err);              err(ZT("%s"), scs(state.err));
  
         if (strcmp(state.opt, "-h") == 0)         if (strcmp(state.opt, "-h") == 0)
         {         {
Line 109 
Line 100 
     }     }
  
  
     virtual void HandleNoOp(Uint64 msgID)      virtual void HandleNoOp(Uint64 operationId)
     {     {
     }     }
  
Line 121 
Line 112 
     {     {
     }     }
  
     virtual void HandleInstance(Uint64 msgID, const DInstance& instance)      virtual void HandleInstance(Uint64 operationId, const DInstance& instance)
     {     {
     }     }
  
     virtual void HandleResult(Uint64 msgID, MI_Result result)      virtual void HandleResult(Uint64 operationId, MI_Result result)
     {     {
     }     }
   
       /* need to define both HandleResult functions to prevent error about hiding base class virtual functions */
       virtual void HandleResult(Uint64 operationId, MI_Result result, const MI_Char *errorMessage, const DInstance* cimError)
       {
           return Handler::HandleResult(operationId, result, errorMessage, cimError);
       }
 }; };
  
 static void _CheckIdentifyProvider(Client& cli, const MI_Char* nameSpace)  static void _CheckIdentifyProvider(Client& cli, const ZChar* nameSpace)
 { {
     const Uint64 TIMEOUT = 10 * 1000 * 1000;     const Uint64 TIMEOUT = 10 * 1000 * 1000;
  
Line 139 
Line 136 
     Array<DInstance> instances;     Array<DInstance> instances;
     Result result;     Result result;
  
     printf("Enumerating identify instances... ");      Tprintf(ZT("Enumerating identify instances... "));
     fflush(stdout);     fflush(stdout);
  
     if (!cli.EnumerateInstances(nameSpace, "OMI_Identify", true,      if (!cli.EnumerateInstances(nameSpace, ZT("OMI_Identify"), true,
         TIMEOUT, instances, String(), String(), result))         TIMEOUT, instances, String(), String(), result))
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("communication failed (cannot connect/initiate command)");          err(ZT("communication failed (cannot connect/initiate command)"));
         exit(1);         exit(1);
     }     }
  
     printf("ok\n");      Tprintf(ZT("ok\n"));
  
     // Check identify instance.     // Check identify instance.
  
     if (instances.GetSize() != 1)     if (instances.GetSize() != 1)
     {     {
         err("expected one instance of OMI_Identify but found %u",          err(ZT("expected one instance of OMI_Identify but found %u"),
             instances.GetSize());             instances.GetSize());
     }     }
  
     printf("Checking for standard namespaces... ");      Tprintf(ZT("Checking for standard namespaces... "));
     fflush(stdout);     fflush(stdout);
  
     StringA nameSpaces;     StringA nameSpaces;
     bool isNull;     bool isNull;
     bool isKey;     bool isKey;
  
     if (!instances[0].GetStringA("ConfigNameSpaces", nameSpaces, isNull, isKey))      if (!instances[0].GetStringA(
           ZT("ConfigNameSpaces"),
           nameSpaces,
           isNull,
           isKey))
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("missing ConfigNameSpaces property\n");          err(ZT("missing ConfigNameSpaces property\n"));
     }     }
  
     bool foundRootNw = false;     bool foundRootNw = false;
Line 181 
Line 182 
     // Sort the array     // Sort the array
     for (size_t i = 0; i < nameSpaces.GetSize(); i++)     for (size_t i = 0; i < nameSpaces.GetSize(); i++)
     {     {
         if (nameSpaces[i] == "root#omi")          if (nameSpaces[i] == ZT("root-omi"))
         {         {
             foundRootNw = true;             foundRootNw = true;
         }         }
         else if (nameSpaces[i] == "root#check")          else if (nameSpaces[i] == ZT("root-check"))
         {         {
             foundRootCheck = true;             foundRootCheck = true;
         }         }
         else if (nameSpaces[i] == "root#cimv2")          else if (nameSpaces[i] == ZT("root-cimv2"))
         {         {
             foundRootCimv2 = true;             foundRootCimv2 = true;
         }         }
         else if (nameSpaces[i] == "interop")          else if (nameSpaces[i] == ZT("interop"))
         {         {
             foundInterop = true;             foundInterop = true;
         }         }
Line 201 
Line 202 
  
     if (!foundRootNw)     if (!foundRootNw)
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("missing namespace directory: root#omi");          err(ZT("missing namespace directory: root-omi"));
     }     }
  
     if (!foundRootCheck)     if (!foundRootCheck)
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("missing namespace directory: root#check");          err(ZT("missing namespace directory: root-check"));
     }     }
  
     if (!foundRootCimv2)     if (!foundRootCimv2)
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("missing namespace directory: root#cimv2");          err(ZT("missing namespace directory: root-cimv2"));
     }     }
  
     if (!foundInterop)     if (!foundInterop)
     {     {
         printf("failed\n");          Tprintf(ZT("failed\n"));
         err("missing namespace directory: interop");          err(ZT("missing namespace directory: interop"));
     }     }
  
     printf("ok\n");      Tprintf(ZT("ok\n"));
 } }
  
 static void _CheckDirLayout() static void _CheckDirLayout()
 { {
     printf("Checking directory layout... ");      Tprintf(ZT("Checking directory layout... "));
     fflush(stdout);     fflush(stdout);
  
     if (Chdir(GetPath(ID_PREFIX)) != 0)      if (Chdir(OMI_GetPath(ID_PREFIX)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_PREFIX));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_PREFIX)));
  
     if (Chdir(GetPath(ID_LIBDIR)) != 0)      if (Chdir(OMI_GetPath(ID_LIBDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_LIBDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_LIBDIR)));
  
     if (Chdir(GetPath(ID_BINDIR)) != 0)      if (Chdir(OMI_GetPath(ID_BINDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_BINDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_BINDIR)));
  
     if (Chdir(GetPath(ID_LOCALSTATEDIR)) != 0)      if (Chdir(OMI_GetPath(ID_LOCALSTATEDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_LOCALSTATEDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_LOCALSTATEDIR)));
  
     if (Chdir(GetPath(ID_SYSCONFDIR)) != 0)      if (Chdir(OMI_GetPath(ID_SYSCONFDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_SYSCONFDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_SYSCONFDIR)));
  
     if (Chdir(GetPath(ID_CERTSDIR)) != 0)      if (Chdir(OMI_GetPath(ID_CERTSDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_CERTSDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_CERTSDIR)));
  
     if (Chdir(GetPath(ID_CERTSDIR)) != 0)      if (Chdir(OMI_GetPath(ID_CERTSDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_CERTSDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_CERTSDIR)));
  
     if (Chdir(GetPath(ID_DATADIR)) != 0)      if (Chdir(OMI_GetPath(ID_DATADIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_DATADIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_DATADIR)));
  
     if (Chdir(GetPath(ID_RUNDIR)) != 0)      if (Chdir(OMI_GetPath(ID_RUNDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_RUNDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_RUNDIR)));
  
     if (Chdir(GetPath(ID_LOGDIR)) != 0)      if (Chdir(OMI_GetPath(ID_LOGDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_LOGDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_LOGDIR)));
  
     if (Chdir(GetPath(ID_REGISTERDIR)) != 0)      if (Chdir(OMI_GetPath(ID_REGISTERDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_REGISTERDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_REGISTERDIR)));
  
     if (Chdir(GetPath(ID_INCLUDEDIR)) != 0)      if (Chdir(OMI_GetPath(ID_INCLUDEDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_INCLUDEDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_INCLUDEDIR)));
  
     if (Chdir(GetPath(ID_DESTDIR)) != 0)      if (Chdir(OMI_GetPath(ID_DESTDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_DESTDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_DESTDIR)));
  
     if (Chdir(GetPath(ID_AUTHDIR)) != 0)      if (Chdir(OMI_GetPath(ID_AUTHDIR)) != 0)
         err("chdir(%s) failed\n", GetPath(ID_AUTHDIR));          err(ZT("chdir(%s) failed\n"), scs(OMI_GetPath(ID_AUTHDIR)));
  
     printf("ok\n");      Tprintf(ZT("ok\n"));
 } }
  
 static void _Check(Client& cli) static void _Check(Client& cli)
Line 301 
Line 302 
         if (strcmp(argv[i], "--destdir") == 0)         if (strcmp(argv[i], "--destdir") == 0)
         {         {
             if (i + 1 == argc)             if (i + 1 == argc)
                 err("missing argument for --destdir option");                  err(ZT("missing argument for --destdir option"));
  
             destdir = argv[i+1];             destdir = argv[i+1];
             memmove((char*)&argv[i], (char*)&argv[i+2],             memmove((char*)&argv[i], (char*)&argv[i+2],
Line 323 
Line 324 
     if (destdir)     if (destdir)
     {     {
         if (SetPath(ID_DESTDIR, destdir) != 0)         if (SetPath(ID_DESTDIR, destdir) != 0)
             err("failed to set destdir");              err(ZT("failed to set destdir"));
     }     }
  
     *argc_ = argc;     *argc_ = argc;
Line 354 
Line 355 
     // There must be at least 1 argument left:     // There must be at least 1 argument left:
     if (argc != 1 || opts.help)     if (argc != 1 || opts.help)
     {     {
         fprintf(stdout, "%s", USAGE);          Ftprintf(stdout, ZT("%s"), scs(USAGE));
         exit(1);         exit(1);
     }     }
  
     // Connect to server:     // Connect to server:
     {     {
         printf("Connecting locally to server... ");          TChar path[PAL_MAX_PATH_SIZE];
           TcsStrlcpy(path, OMI_GetPath(ID_SOCKETFILE), PAL_MAX_PATH_SIZE);
   
           Tprintf(ZT("Connecting locally to server... "));
         fflush(stdout);         fflush(stdout);
  
         if (!client.Connect(GetPath(ID_SOCKETFILE), String(), String(),          if (!client.Connect(
               path,
               String(),
               String(),
             CONNECT_TIMEOUT_USEC))             CONNECT_TIMEOUT_USEC))
         {         {
             printf("failed\n");              Tprintf(ZT("failed\n"));
             err("failed to connect to %s", GetPath(ID_SOCKETFILE));              err(ZT("failed to connect to %s"), scs(OMI_GetPath(ID_SOCKETFILE)));
         }         }
  
         printf("ok\n");          Tprintf(ZT("ok\n"));
     }     }
  
     // Perform check!     // Perform check!
     _Check(client);     _Check(client);
     printf("\n");      Tprintf(ZT("\n"));
  
     return 0;     return 0;
 } }


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

ViewCVS 0.9.2