Ejemplo n.º 1
0
Archivo: try.C Proyecto: xalt/xalt
int main(int argc, char* argv[])
{

  const char* p;
  const char* s;
  
  s = "./hello\\uD8FF\\uDFFDabc";
  int len = strlen(s);
  
  p = xalt_unquotestring(s, len);
  strcpy(buf,p);
  printf("buf: %s\n",buf);

  p = xalt_quotestring(buf);
  
  printf("p: %s\n",p);

  s = "./helloñ";
  p = xalt_quotestring(s);
  strcpy(buf, p);

  if (strcmp(buf, ans1) != 0)
    {
      printf("failed part 1\n");
      return 1;
    }

  len = strlen(buf);
  
  p = xalt_unquotestring(buf, len);

  if (strcmp(p, ans2) != 0)
    {
      printf("failed part 2\n");
      return 1;
    }

  return 0;
}
Ejemplo n.º 2
0
void myinit(int argc, char **argv)
{
  int    status, i;
  char * p;
  char * p_dbg;
  char * cmdline;
  char * v;
  const char *  rankA[] = {"PMI_RANK", "OMPI_COMM_WORLD_RANK", "MV2_COMM_WORLD_RANK", NULL}; 
  const char *  sizeA[] = {"PMI_SIZE", "OMPI_COMM_WORLD_SIZE", "MV2_COMM_WORLD_SIZE", NULL}; 
  
  struct timeval tv;
  struct utsname u;

  uuid_t uuid;

  
  unsetenv("LD_PRELOAD");

  /* Stop tracking if XALT is turned off */
  p_dbg = getenv("XALT_TRACING");
  if (p_dbg && strcmp(p_dbg,"yes") == 0)
    {
      xalt_tracing = 1;
      errfd = dup(STDERR_FILENO);
    }
  
  v = getenv("XALT_EXECUTABLE_TRACKING");
  if (xalt_tracing)
    {
      abspath(path,sizeof(path));
      FULL_DEBUG3(stderr,"myinit(%s,%s):\n  Test for XALT_EXECUTABLE_TRACKING: \"%s\"\n", STR(STATE),path,(v != NULL) ? v : "(NULL)");
    }

  if (!v || strcmp(v,"yes") != 0)
    {
      FULL_DEBUG0(stderr,"  XALT_EXECUTABLE_TRACKING is off -> exiting\n\n");
      return;
    }

  v = getenv("__XALT_INITIAL_STATE__");
  FULL_DEBUG2(stderr,"  Test for __XALT_INITIAL_STATE__: \"%s\", STATE: \"%s\"\n", (v != NULL) ? v : "(NULL)", STR(STATE));
  /* Stop tracking if any myinit routine has been called */
  if (v && (strcmp(v,STR(STATE)) != 0))
    {
      FULL_DEBUG2(stderr," __XALT_INITIAL_STATE__ has a value: \"%s\" -> and it is different from STATE: \"%s\" exiting\n\n",v,STR(STATE));
      return;
    }

  /* Stop tracking if my mpi rank is not zero */
  my_rank = compute_value(rankA);
  FULL_DEBUG1(stderr,"  Test for rank == 0, rank: %ld\n",my_rank);
  if (my_rank > 0L)
    {
      FULL_DEBUG0(stderr," MPI Rank is not zero -> exiting\n\n");
      return;
    }

  my_size = compute_value(sizeA);
  if (my_size < 1L)
    my_size = 1L;

  errno = 0;
  if (uname(&u) != 0)
    {
      perror("uname");
      exit(EXIT_FAILURE);
    }

  /* Get full absolute path to executable */
  abspath(path,sizeof(path));
  reject_flag = reject(path, u.nodename);
  FULL_DEBUG3(stderr,"  Test for path and hostname, hostname: %s, path: %s, reject: %d\n", u.nodename, path, reject_flag);
  if (reject_flag)
    {
      FULL_DEBUG0(stderr,"  reject_flag is true -> exiting\n\n");
      return;
    }

  setenv("__XALT_INITIAL_STATE__",STR(STATE),1);
  errfd = dup(STDERR_FILENO);

  syshost = xalt_syshost();

  /* Build a json version of the user's command line. */

  /* Calculate size of buffer*/
  int sz = 0;
  for (i = 0; i < argc; ++i)
    sz += strlen(argv[i]);

  /* this size formula uses 3 facts:
   *   1) if every character was a utf-16 character that is four bytes converts to 12 (sz*3)
   *   2) Each entry has two quotes and a comma (argc*3)
   *   3) There are two square brackets and a null byte (+3)
   */

  sz = sz*3 + argc*3 + 3;

  usr_cmdline = (char *) malloc(sz);
  p	      = &usr_cmdline[0];
  *p++        = '[';
  for (i = 0; i < argc; ++i)
    {
      *p++ = '"';
      const char* qs  = xalt_quotestring(argv[i]);
      int         len = strlen(qs);
      memcpy(p,qs,len);
      p += len;
      *p++= '"';
      *p++= ',';
    }
  *--p = ']';
  *++p = '\0';
  if (p > &usr_cmdline[sz])
    {
      fprintf(stderr,"XALT: Failure in building user command line json string!\n");
      reject_flag = 1;
      return;
    }

  uuid_generate(uuid);
  uuid_unparse_lower(uuid,uuid_str);
  gettimeofday(&tv,NULL);
  start_time = tv.tv_sec + 1.e-6*tv.tv_usec;

  asprintf(&cmdline, "LD_LIBRARY_PATH=%s PATH=/usr/bin:/bin %s --syshost \"%s\" --start \"%.3f\" --end 0 --exec \"%s\" --ntasks %ld --uuid \"%s\" '%s'",
	   SYS_LD_LIB_PATH, PREFIX "/libexec/xalt_run_submission", syshost, start_time, path, my_size, uuid_str, usr_cmdline);
  
  DEBUG1(stderr, "  Start Tracking: %s\nEnd myinit()\n",cmdline);
  system(cmdline);
  free(cmdline);
}