コード例 #1
0
int
main(int argc,
     char *argv[],
     const char *envp[])
{
   int i;
   int ret = EXIT_FAILURE;
   char **argvCopy;
   GSource *src;

   Unicode_Init(argc, &argv, NULL);

   /*
    * ToolsCore_ParseCommandLine() uses g_option_context_parse(), which modifies
    * argv. We don't want that to happen, so we make a copy of the array and
    * use that as the argument instead.
    */
   argvCopy = g_malloc(argc * sizeof *argvCopy);
   for (i = 0; i < argc; i++) {
      argvCopy[i] = argv[i];
   }

   setlocale(LC_ALL, "");
   VMTools_ConfigLogging(G_LOG_DOMAIN, NULL, FALSE, FALSE);
   VMTools_BindTextDomain(VMW_TEXT_DOMAIN, NULL, NULL);

   if (!ToolsCore_ParseCommandLine(&gState, argc, argvCopy)) {
      g_free(argvCopy);
      goto exit;
   }
   g_free(argvCopy);
   argvCopy = NULL;

   if (gState.pidFile != NULL) {
      /*
       * If argv[0] is not an absolute path, make it so; all other path
       * arguments should have been given as absolute paths if '--background'
       * was used, or things may not work as expected.
       */
      if (!g_path_is_absolute(argv[0])) {
         gchar *abs = g_find_program_in_path(argv[0]);
         if (abs == NULL || strcmp(abs, argv[0]) == 0) {
            char *cwd = File_Cwd(NULL);
            g_free(abs);
            abs = g_strdup_printf("%s%c%s", cwd, DIRSEPC, argv[0]);
            vm_free(cwd);
         }
         argv[0] = abs;
      }

      /*
       * Need to remove --background from the command line or we'll get
       * into an infinite loop. ToolsCore_ParseCommandLine() already
       * validated that "-b" has an argument, so it's safe to assume the
       * data is there.
       */
      for (i = 1; i < argc; i++) {
         size_t count = 0;
         if (strcmp(argv[i], "--background") == 0 ||
             strcmp(argv[i], "-b") == 0) {
            count = 2;
         } else if (g_str_has_prefix(argv[i], "--background=")) {
            count = 1;
         }
         if (count) {
            memmove(argv + i, argv + i + count, (argc - i - count) * sizeof *argv);
            argv[argc - count] = NULL;
            break;
         }
      }

      if (!Hostinfo_Daemonize(argv[0],
                              argv,
                              HOSTINFO_DAEMONIZE_LOCKPID,
                              gState.pidFile, NULL, 0)) {
         goto exit;
      }
      return 0;
   }

   ToolsCore_Setup(&gState);

   src = VMTools_NewSignalSource(SIGHUP);
   VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src,
                            ToolsCoreSigHUPCb, &gState, NULL);
   g_source_unref(src);

   src = VMTools_NewSignalSource(SIGINT);
   VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src,
                            ToolsCoreSigHandler, gState.ctx.mainLoop, NULL);
   g_source_unref(src);

   src = VMTools_NewSignalSource(SIGQUIT);
   VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src,
                            ToolsCoreSigHandler, gState.ctx.mainLoop, NULL);
   g_source_unref(src);

   src = VMTools_NewSignalSource(SIGTERM);
   VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src,
                            ToolsCoreSigHandler, gState.ctx.mainLoop, NULL);
   g_source_unref(src);

   src = VMTools_NewSignalSource(SIGUSR1);
   VMTOOLSAPP_ATTACH_SOURCE(&gState.ctx, src, ToolsCoreSigUsrHandler, NULL, NULL);
   g_source_unref(src);

   /* Ignore SIGUSR2 by default. */
   signal(SIGUSR2, SIG_IGN);

   /*
    * Save the original environment so that we can safely spawn other
    * applications (since we may have to modify the original environment
    * to launch vmtoolsd successfully).
    */
   gState.ctx.envp = System_GetNativeEnviron(envp);

   ret = ToolsCore_Run(&gState);

   if (gState.pidFile != NULL) {
      g_unlink(gState.pidFile);
   }
exit:
   return ret;
}
コード例 #2
0
main(int argc,    // IN: length of command line arguments
     char **argv) // IN: Command line arguments
#endif
{
   Bool show_help = FALSE;
   Bool show_version = FALSE;
   CmdTable *cmd = NULL;
   GKeyFile *conf = NULL;
   int c;
   int retval = EXIT_FAILURE;

#if defined(_WIN32)
   char **argv;
   Unicode_InitW(argc, wargv, NULL, &argv, NULL);
#else
   Unicode_Init(argc, &argv, NULL);
#endif

   setlocale(LC_ALL, "");
   VMTools_LoadConfig(NULL, G_KEY_FILE_NONE, &conf, NULL);
   VMTools_ConfigLogging("toolboxcmd", conf, FALSE, FALSE);
   VMTools_BindTextDomain(VMW_TEXT_DOMAIN, NULL, NULL);

   /*
    * Check if we are in a VM
    */
   if (!VmCheck_IsVirtualWorld()) {
      g_printerr(SU_(error.novirtual, "%s must be run inside a virtual machine.\n"),
                 argv[0]);
      goto exit;
   }

   /*
    * Parse the command line optional arguments
    */
   while (1) {
      int option_index = 0;

      c = getopt_long(argc, argv, options, long_options, &option_index);

      /* Detect the end of the options. */
      if (c == -1) {
         break;
      }

      switch (c) {
      case 'h':
         show_help = TRUE;
         break;

      case 'v':
         show_version = TRUE;
         break;

      case 'q':
         gQuiet = TRUE;
         break;

      case '?':
         /* getopt_long already printed an error message. */
         g_printerr(SU_(help.hint, "Try '%s %s%s%s' for more information.\n"),
                    argv[0], "-h", "", "");
         goto exit;

      default:
         goto exit;
      }
   }

   if (show_version) {
      g_print("%s (%s)\n", TOOLBOXCMD_VERSION_STRING, BUILD_NUMBER);
      retval = EXIT_SUCCESS;
   } else if (show_help) {
      ToolboxCmdHelp(argv[0], "help");
      retval = EXIT_SUCCESS;
   } else {
      /* Process any remaining command line arguments (not options), and
       * execute corresponding command
       */
      if (optind >= argc) {
         ToolsCmd_MissingEntityError(argv[0], SU_(arg.command, "command"));
         retval = EX_USAGE;
      } else if ((cmd = ParseCommand(argv, argc)) == NULL) {
         ToolsCmd_UnknownEntityError(argv[0], SU_(arg.command, "command"), argv[optind]);
         retval = EX_USAGE;
      } else if (cmd->requireRoot && !System_IsUserAdmin()) {
#if defined(_WIN32)
         g_printerr(SU_(error.noadmin.win,
                        "%s: Administrator permissions are needed to perform %s operations.\n"
                        "Use an administrator command prompt to complete these tasks.\n"),
                    argv[0], cmd->command);

#else
         g_printerr(SU_(error.noadmin.posix,
                        "%s: You must be root to perform %s operations.\n"),
                    argv[0], cmd->command);
#endif
         retval = EX_NOPERM;
      } else if (cmd->requireArguments && ++optind >= argc) {
         ToolsCmd_MissingEntityError(argv[0], SU_(arg.subcommand, "subcommand"));
         retval = EX_USAGE;
      } else {
         retval = cmd->func(argv, argc, gQuiet);
      }

      if (retval == EX_USAGE && (cmd == NULL || strcmp(cmd->command, "help"))) {
         g_printerr(SU_(help.hint, "Try '%s %s%s%s' for more information.\n"),
                    argv[0], "help", cmd ? " " : "", cmd ? cmd->command : "");
      }
   }

exit:
   if (conf != NULL) {
      g_key_file_free(conf);
   }

   return retval;
}
コード例 #3
0
	void Unicode_Render (void){
	
		int i, list_position;
	
		if (
			!Unicode_used_slots || // Mainly for saving cycles
			!FTGL_font ||
			cls.state == CA_CINEMATIC || // Not when a video is playing (it also distorts it)
			cls.state == CA_LOADING // It's plain ugly otherwise.
		) return; 
			
		// If font size or file changed, reload the font;
		if (clu.Unicode_Fontsize->modified || clu.Unicode_Font->modified) {

			Com_Printf("TTF Font file or font size changed; reinitializing FTGL.\n");
			clu.Unicode_Shutdown();
			Unicode_Init();

		}
				
		Unicode_Setup2D(); // Set up 2D Projection
			
		for (i = 0, list_position = 0; i < clu.Unicode_Lines->integer &&  i < MAX_UNICODE_LINES; i++) {
			GLfloat fade_value;
			int32_t fade_pos;
		
			if (!Unicode_Text[i].FadeTimeout) continue; // empty slot, do nothing

			fade_pos =Unicode_Text[i].FadeInitTime + Unicode_Text[i].FadeTimeout - Sys_Milliseconds();
			if (fade_pos < 0) {
				Unicode_Text[i].FadeTimeout = 0; // mark it as an empty slot
				Unicode_used_slots--;
				continue;
			}
						
			if (fade_pos > clu.Unicode_MessageFadeTime->integer) 
				fade_value = (GLfloat)1 * clu.Unicode_Alpha->value;
			else
				fade_value = (GLfloat) fade_pos * clu.Unicode_Alpha->value/clu.Unicode_MessageFadeTime->integer;

				
			// Shadow:
			glPushMatrix();	
							
				Cmd_TokenizeString(clu.Unicode_Shadow->string);
				glTranslatef(
					(GLfloat)glConfig.vidWidth * clu.Unicode_Fontsize->value * clu.Unicode_PositionX->value * atof(Cmd_Argv(0)), // shadow moves slightly
					(GLfloat)glConfig.vidHeight * clu.Unicode_Fontsize->value * atof(Cmd_Argv(1)) * (clu.Unicode_PositionY->value - list_position * clu.Unicode_LineSpace->value), 
					0 
				);

				glRotatef(180.0f, 1.0f, 0.0f, 0.0f); // rotated.. fixme?
					
				glColor4f(0.0, 0.0, 0.0, fade_value);

				qftglRenderFont(FTGL_font, Unicode_Text[i].Message, FTGL_RENDER_ALL);		
						
			glPopMatrix();	
	
			// Visible text:
			glPushMatrix();	

				glTranslatef(
					(GLfloat)glConfig.vidWidth * clu.Unicode_Fontsize->value * clu.Unicode_PositionX->value,

					(GLfloat)glConfig.vidHeight * clu.Unicode_Fontsize->value * (clu.Unicode_PositionY->value - list_position * clu.Unicode_LineSpace->value) , 
								
					0 
				);

				glRotatef(180.0f, 1.0f, 0.0f, 0.0f);

				Cmd_TokenizeString(clu.Unicode_Color->string);
				glColor4f(
					(GLfloat)atof(Cmd_Argv(0))/255.0, 
					(GLfloat)atof(Cmd_Argv(1))/225.9, 
					(GLfloat)atof(Cmd_Argv(2))/255.0,
					fade_value
				);
				qftglRenderFont(FTGL_font, Unicode_Text[i].Message, FTGL_RENDER_ALL);
			glPopMatrix();

			list_position++;
		}
	}