~ubuntu-branches/ubuntu/precise/torque/precise-updates

« back to all changes in this revision

Viewing changes to src/lib/Libifl/pbsD_connect.c

  • Committer: Bazaar Package Importer
  • Author(s): Dominique Belhachemi
  • Date: 2010-05-17 20:56:46 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20100517205646-yjsoqs5r1s9xpnu9
Tags: upstream-2.4.8+dfsg
ImportĀ upstreamĀ versionĀ 2.4.8+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
#endif
109
109
 
110
110
#include "libpbs.h"
 
111
#include "csv.h"
111
112
#include "dis.h"
112
113
#include "net_connect.h"
113
114
 
138
139
 
139
140
 
140
141
/**
141
 
 * Gets the number of items in a string list.
142
 
 * @param str  The string list.
143
 
 * @return The number of items in the list.
144
 
 */
145
 
int csv_length(char *str)
146
 
  {
147
 
  int  length = 0;
148
 
  char *cp;
149
 
 
150
 
  if (!str || *str == 0)
151
 
    return(0);
152
 
 
153
 
  length++;
154
 
 
155
 
  cp = str;
156
 
 
157
 
  while ((cp = strchr(cp, ',')))
158
 
    {
159
 
    cp++;
160
 
    length++;
161
 
    }
162
 
 
163
 
  return(length);
164
 
  }
165
 
 
166
 
/**
167
 
 * Gets the nth item from a comma seperated list of names.
168
 
 * @param str  The string list.
169
 
 * @param n The item number requested (0 is the first item).
170
 
 * @return Null if str is null or empty,
171
 
 *     otherwise, a pointer to a local buffer containing the nth item.
172
 
 */
173
 
char *csv_nth(char *str, int n)
174
 
  {
175
 
  int  i;
176
 
  char *cp;
177
 
  char *tp;
178
 
  static char buffer[128];
179
 
 
180
 
  if (!str || *str == 0)
181
 
    return(0);
182
 
 
183
 
  cp = str;
184
 
 
185
 
  for (i = 0; i < n; i++)
186
 
    {
187
 
    if (!(cp = strchr(cp, ',')))
188
 
      {
189
 
      return(0);
190
 
      }
191
 
 
192
 
    cp++;
193
 
    }
194
 
 
195
 
  memset(buffer, 0, sizeof(buffer));
196
 
 
197
 
  if ((tp = strchr(cp, ',')))
198
 
    {
199
 
    strncpy(buffer, cp, tp - cp);
200
 
    }
201
 
  else
202
 
    {
203
 
    strcpy(buffer, cp);
204
 
    }
205
 
 
206
 
  return(buffer);
207
 
  }
208
 
 
209
 
 
210
 
 
211
 
 
212
 
/**
213
142
 * Attempts to get a list of server names.  Trys first
214
143
 * to obtain the list from an envrionment variable PBS_DEFAULT.
215
144
 * If this is not set, it then trys to read the first line
226
155
 * @see pbs_default()
227
156
 * @see pbs_fbserver()
228
157
 */
229
 
char *
230
 
pbs_get_server_list(void)
 
158
 
 
159
char *pbs_get_server_list(void)
231
160
  {
232
161
  FILE *fd;
233
162
  char *pn;
234
163
  char *server;
 
164
  char tmp[1024];
 
165
  int len;
235
166
 
236
167
  if (got_dflt != TRUE)
237
168
    {
240
171
 
241
172
    if ((server == NULL) || (*server == '\0'))
242
173
      {
 
174
      server = getenv("PBS_SERVER");
 
175
      }
 
176
 
 
177
    if ((server == NULL) || (*server == '\0'))
 
178
      {
243
179
      fd = fopen(pbs_destn_file, "r");
244
180
 
245
181
      if (fd == NULL)
247
183
        return(server_list);
248
184
        }
249
185
 
250
 
      if (fgets(server_list, PBS_MAXSERVERNAME, fd) == NULL)
 
186
      if (fgets(tmp, sizeof(tmp), fd) == NULL)
251
187
        {
252
188
        fclose(fd);
253
189
 
254
190
        return(server_list);
255
191
        }
256
192
 
 
193
      strcpy(server_list, tmp);
257
194
      if ((pn = strchr(server_list, (int)'\n')))
258
195
        * pn = '\0';
259
196
 
 
197
      while(fgets(tmp, sizeof(tmp), fd))
 
198
        {
 
199
        strcat(server_list, ",");
 
200
        strcat(server_list, tmp);
 
201
        len = strlen(server_list);
 
202
        if(server_list[len-1] == '\n')
 
203
          {
 
204
          server_list[len-1] = '\0';
 
205
          }
 
206
        }
 
207
 
260
208
      fclose(fd);
261
209
      }
262
210
    else
263
211
      {
264
 
      strncpy(server_list, server, PBS_MAXSERVERNAME);
 
212
      strncpy(server_list, server, sizeof(server_list));
265
213
      }
266
214
 
267
215
    got_dflt = TRUE;
270
218
  return(server_list);
271
219
  }
272
220
 
 
221
 
 
222
 
 
223
 
 
224
 
273
225
/**
274
226
 * The routine is called to get the name of the primary
275
227
 * server.  It can possibly trigger reading of the server name
280
232
 * @return A pointer to the default server name.
281
233
 * @see pbs_fbserver()
282
234
 */
283
 
char *
284
 
pbs_default(void)
 
235
 
 
236
char *pbs_default(void)
285
237
  {
286
238
  char *cp;
287
239
 
299
251
  }
300
252
 
301
253
 
 
254
 
 
255
 
 
256
 
302
257
/**
303
258
 * The routine is called to get the name of the fall-back
304
259
 * server.  It can possibly trigger reading of the server name
309
264
 * @return A pointer to the fall-back server name.
310
265
 * @see pbs_default()
311
266
 */
312
 
char *
313
 
pbs_fbserver(void)
 
267
 
 
268
char *pbs_fbserver(void)
314
269
  {
315
270
  char *cp;
316
271
 
433
388
 
434
389
      if ((ptr = getenv("PATH")) != NULL)
435
390
        {
436
 
        ptr = strtok(ptr, ";");
 
391
        ptr = strtok(ptr, ":");
437
392
 
438
393
        while (ptr != NULL)
439
394
          {
445
400
          if (rc != -1)
446
401
            break;
447
402
 
448
 
          ptr = strtok(NULL, ";");
 
403
          ptr = strtok(NULL, ":");
449
404
          }  /* END while (ptr != NULL) */
450
405
        }    /* END if ((ptr = getenv("PATH")) != NULL) */
451
406
 
598
553
  char *server)  /* I (FORMAT:  NULL | '\0' | HOSTNAME | HOSTNAME:PORT )*/
599
554
 
600
555
  {
601
 
 
602
556
  struct sockaddr_in server_addr;
603
557
 
604
558
  struct hostent *hp;
892
846
    }
893
847
 
894
848
  return(out);
895
 
  }  /* END pbs_connect() */
 
849
  }  /* END pbs_original_connect() */
896
850
 
897
851
 
898
852
 
961
915
 
962
916
 
963
917
 
 
918
 
 
919
 
964
920
/**
965
921
 * This is a new version of this function that allows
966
922
 * connecting to a list of servers.  It is backwards
970
926
 * @param server_name_ptr A pointer to a server name or server name list.
971
927
 * @returns A file descriptor number.
972
928
 */
 
929
 
973
930
int pbs_connect(char *server_name_ptr)    /* I (optional) */
974
931
  {
975
932
  int connect = -1;
989
946
    if (getenv("PBSDEBUG"))
990
947
      {
991
948
      fprintf(stderr, "pbs_connect called with explicit server name \"%s\"\n",
992
 
              server_name_list);
 
949
        server_name_list);
993
950
      }
994
951
    }
995
952
  else
999
956
    if (getenv("PBSDEBUG"))
1000
957
      {
1001
958
      fprintf(stderr, "pbs_connect using default server name list \"%s\"\n",
1002
 
              server_name_list);
 
959
        server_name_list);
1003
960
      }
1004
961
    }
1005
962