Example #1
0
int sysExec(int type, char *path, char *argv[]) 
{
    int pid;
    int ret = 0;
    char **argvp;

    /* Win32 inexplicably breaks up arguments that contain white space,
     * so we quote them here.
     */
    for(argvp = argv; *argvp; argvp++) {
        *argvp = sysQuoteString(*argvp);
    }
    if (type == SYS_EXEC_REPLACE) {
        pid = spawnv(_P_NOWAIT, path, argv);
        /* The window API does not support replacing the existing process.
           However, we can simulate this by quitly existing this application */
        exit(0);
    }
    else if (type == SYS_EXEC_FORK) {
        pid = spawnv(_P_NOWAIT, path, argv);
    }
    else {
        ret = spawnv(_P_WAIT, path, argv);
        /* WAIT return value is exit status of process */
        pid = 0;
	if (ret != 0) {
	   return -1;
	}
    }
    return pid;
}
void UpdateJREInfo (JREDescription *jre) {
  char *argv[10];
  int buflen = 1024;
  char *buf = NULL, *start, *end;
  static char path[MAXPATHLEN];

  if (!ensureDeployDownloaded())
    exit(1);

  buf = (char *)malloc(buflen);
  argv[0] = jre->path;
  argv[1] = "-Dkernel.background.download=false";
  argv[2] = "-classpath";
  argv[3] = sysQuoteString(GetDeployJarPath());
  argv[4] = JRELOCATORCLASSNAME;
  argv[5] = NULL;

  sysExec2Buf(jre->path, 5, argv, buf, &buflen);

  /* find version info */
  if (buflen > 0) { 

    start = strstr(buf, PRODUCT_ID);
    if (start != NULL) {
      start += strlen(PRODUCT_ID);
      end = strchr(start, '\n');
      if (end > start) {
        char *p = jre->product_version = (char *)malloc(end - start + 1);
        while(!isWhitespace(*start)) {
            *p++ = *start++;
        }
        *p = 0;
      }
    }

    start = strstr(buf, PLATFORM_ID);
    if (start != NULL) {
      start += strlen(PLATFORM_ID);
      end = strchr(start, '\n');
      if (end > start) {
        char *p = jre->platform_version = (char *)malloc(end - start + 1);
        while(!isWhitespace(*start)) {
            *p++ = *start++;
        }
        *p = 0;
      }
    }

    /* 1.2* and before is no longer allowed */
    if  ((jre->product_version != NULL) && 
        (strncmp(jre->product_version, "1.2", 3) <= 0)) {
        jre->product_version = NULL;
    }

    if ((jre->platform_version != NULL) && 
        (strncmp(jre->platform_version, "1.2", 3) <= 0)) {
        jre->platform_version = NULL;
    }
  }

  jre->href = strdup(DEFHREF);
  jre->osname = PLATFORM;
  jre->osarch = sysGetOsArch();
}