コード例 #1
0
ファイル: pbsD_connect.c プロジェクト: ansonl/torque
int pbs_connect(
    
  char *server_name_ptr)    /* I (optional) */

  {
  int connect = -1;
  int i, list_len;
  char server_name_list[PBS_MAXSERVERNAME*3+1];
  char current_name[PBS_MAXSERVERNAME+1];
  char *tp;

  memset(server_name_list, 0, sizeof(server_name_list));

  /* Use the list from the server_name file.
   * If a server name is passed in, append it at the beginning. */

  if (server_name_ptr && server_name_ptr[0])
    snprintf(server_name_list, sizeof(server_name_list), "%s", server_name_ptr);
  else
    snprintf(server_name_list, sizeof(server_name_list), "%s", pbs_get_server_list());

  if (getenv("PBSDEBUG"))
    fprintf(stderr, "pbs_connect using following server list \"%s\"\n",
        server_name_list);

  list_len = csv_length(server_name_list);

  for (i = 0; i < list_len; i++)  /* Try all server names in the list. */
    {
    tp = csv_nth(server_name_list, i);

    if (tp && tp[0])
      {
      /* Trim any leading space */
      while(isspace(*tp)) tp++;

      memset(current_name, 0, sizeof(current_name));
      snprintf(current_name, sizeof(current_name), "%s", tp);

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "pbs_connect attempting connection to server \"%s\"\n",
                current_name);
        }

      if ((connect = pbs_original_connect(current_name)) >= 0)
        {
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "pbs_connect: Successful connection to server \"%s\", fd = %d\n", current_name, connect);
          }

        return(connect);  /* Success, we have a connection, return it. */
        }
      else
        print_server_port_to_stderr(current_name);
      }
    }

  return(connect);
  } /* END pbs_connect() */
コード例 #2
0
ファイル: pbsD_connect.c プロジェクト: CESNET/torque
int pbs_connect(char *server_name_ptr)    /* I (optional) */
  {
  int connect = -1;
  int i, list_len;
  char server_name_list[PBS_MAXSERVERNAME*3+1];
  char current_name[PBS_MAXSERVERNAME+1];
  char *tp;

  memset(server_name_list, 0, sizeof(server_name_list));

  /* If a server name is passed in, use it, otherwise use the list from server_name file. */

  if (server_name_ptr && server_name_ptr[0])
    {
    strncpy(server_name_list, server_name_ptr, sizeof(server_name_list) - 1);

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "pbs_connect called with explicit server name \"%s\"\n",
        server_name_list);
      }
    }
  else
    {
    strncpy(server_name_list, pbs_get_server_list(), sizeof(server_name_list) - 1);

    if (getenv("PBSDEBUG"))
      {
      fprintf(stderr, "pbs_connect using default server name list \"%s\"\n",
        server_name_list);
      }
    }

  list_len = csv_length(server_name_list);

  for (i = 0; i < list_len; i++)  /* Try all server names in the list. */
    {
    tp = csv_nth(server_name_list, i);

    if (tp && tp[0])
      {
      memset(current_name, 0, sizeof(current_name));
      strncpy(current_name, tp, sizeof(current_name) - 1);

      if (getenv("PBSDEBUG"))
        {
        fprintf(stderr, "pbs_connect attempting connection to server \"%s\"\n",
                current_name);
        }

      if ((connect = pbs_original_connect(current_name)) >= 0)
        {
        if (getenv("PBSDEBUG"))
          {
          fprintf(stderr, "pbs_connect: Successful connection to server \"%s\", fd = %d\n",
                  current_name, connect);
          }

        return(connect);  /* Success, we have a connection, return it. */
        }
      }
    }

  return(connect);
  }