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

« back to all changes in this revision

Viewing changes to src/momctl/momctl.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:
127
127
 
128
128
      case 'd':
129
129
 
 
130
        /* diagnose */
130
131
        /* FORMAT:  momctl -d<X> */
131
132
 
132
133
        CmdIndex = momQuery;
133
134
 
134
135
        if ((Query[QueryI] = calloc(strlen(DiagPtr) + 3, sizeof(char))) == NULL)
135
 
          {
 
136
          {
136
137
          fprintf(stderr,"ERROR:    could not calloc %d bytes!\n",
137
138
            (int)strlen(DiagPtr) + 3);
138
139
 
139
140
          exit(EXIT_FAILURE);
140
 
          }
 
141
          }
141
142
 
142
143
        if (optarg == NULL)
143
144
          {
196
197
 
197
198
      case 'h':
198
199
 
199
 
        strncpy(HostList, optarg, sizeof(HostList));
 
200
        /* connect to specified host */
 
201
 
 
202
        strncpy(HostList,optarg,sizeof(HostList));
200
203
 
201
204
        break;
202
205
 
311
314
 
312
315
      case 'v':
313
316
 
 
317
        /* report verbose logging */
 
318
 
314
319
        IsVerbose = TRUE;
315
320
 
316
321
        break;
339
344
    if ((*HPtr == ':') && (*(HPtr + 1) != '\0'))
340
345
      {
341
346
      /* finds nodes with this property */
 
347
 
342
348
      int con;
343
349
      char *def_server, *pserver, *servername;
344
350
 
348
354
 
349
355
      def_server = pbs_default();
350
356
 
351
 
      if ((pserver = strchr(HPtr, '@')) != NULL)
 
357
      if ((pserver = strchr(HPtr,'@')) != NULL)
352
358
        {
353
359
        *pserver = '\0';
354
360
        servername = pserver + 1;
362
368
 
363
369
      if (con < 0)
364
370
        {
365
 
        fprintf(stderr, "failed to connect to pbs_server:%s\n", servername);
 
371
        fprintf(stderr,"failed to connect to pbs_server:%s\n",
 
372
          servername);
366
373
 
367
374
        exit(EXIT_FAILURE);
368
375
        }
369
376
 
370
377
      /* get a batch_status entry for each node in ":property" */
371
 
      bstatus = pbs_statnode(con, HPtr, NULL, NULL);
 
378
 
 
379
      bstatus = pbs_statnode(con,HPtr,NULL,NULL);
372
380
 
373
381
      if (bstatus != NULL)
374
382
        {
375
383
        for (pbstat = bstatus;pbstat != NULL;pbstat = pbstat->next)
376
384
          {
377
385
          /* check state first, only do_mom() if not down */
 
386
 
378
387
          for (nodeattrs = pbstat->attribs;nodeattrs != NULL; nodeattrs = nodeattrs->next)
379
388
            {
380
389
            if (!strcmp(nodeattrs->name, ATTR_NODE_state))
385
394
                }
386
395
              else
387
396
                {
388
 
                fprintf(stderr, "%12s:   skipping down node\n", pbstat->name);
 
397
                fprintf(stderr,"%12s:   skipping down node\n",
 
398
                  pbstat->name);
389
399
                }
390
400
 
391
401
              break;
392
 
              } /* END if (attrib name eq state) */
393
 
            } /* END foreach nodeattrib */
394
 
          } /* END foreach node */
 
402
              }  /* END if (attrib name eq state) */
 
403
            }    /* END for (nodeattrs) */
 
404
          }      /* END for (pbstat) */
395
405
 
396
406
        pbs_statfree(bstatus);
397
 
        }
 
407
        }  /* END if (bstatus != NULL) */
398
408
      else
399
409
        {
400
 
        fprintf(stderr, "no nodes found in %s on %s\n", HPtr, servername);
 
410
        fprintf(stderr,"no nodes found in %s on %s\n",
 
411
          HPtr,
 
412
          servername);
401
413
        }
402
414
 
403
415
      pbs_disconnect(con);
404
416
 
405
417
      if (pserver != NULL)
406
418
        *pserver = '@';
407
 
 
408
419
      }
409
420
    else
410
421
      {
412
423
      } /* END if (*HPtr == ':') */
413
424
 
414
425
    HPtr = strtok(NULL, ", \t\n");
415
 
 
416
426
    }  /* END while (HPtr != NULL) */
417
427
 
 
428
 
418
429
  if (IsVerbose == TRUE)
419
430
    {
420
431
    fprintf(stdout, "Node Summary:  %d Successful  %d Failed\n",
430
441
 
431
442
 
432
443
 
433
 
int do_mom(char *HPtr, int MOMPort, int CmdIndex)
 
444
 
 
445
int do_mom(
 
446
 
 
447
  char *HPtr,
 
448
  int   MOMPort,
 
449
  int   CmdIndex)
 
450
 
434
451
  {
435
452
  int sd;
436
453
 
437
454
  if ((sd = openrm(HPtr, MOMPort)) < 0)
438
455
    {
 
456
    /* FAILURE */
 
457
 
439
458
    extern char TRMEMsg[];
440
459
 
441
460
    fprintf(stderr, "cannot connect to MOM on node '%s', errno=%d (%s)\n",
449
468
              TRMEMsg);
450
469
      }
451
470
 
452
 
    return sd;
 
471
    return(sd);
453
472
    }
454
473
 
455
474
  if (IsVerbose == TRUE)
473
492
 
474
493
      if (addreq(sd, tmpLine) != 0)
475
494
        {
476
 
        fprintf(stderr, "ERROR:    cannot request job clear on %s (errno=%d-%s: %d-%s)\n",
477
 
                HPtr,
478
 
                errno,
479
 
                pbs_strerror(errno),
480
 
                pbs_errno,
481
 
                pbs_strerror(pbs_errno));
 
495
        /* FAILURE */
 
496
 
 
497
        fprintf(stderr,"ERROR:    cannot request job clear on %s (errno=%d-%s: %d-%s)\n",
 
498
          HPtr,
 
499
          errno,
 
500
          pbs_strerror(errno),
 
501
          pbs_errno,
 
502
          pbs_strerror(pbs_errno));
482
503
 
483
504
        closerm(sd);
484
505
 
485
 
        return -1;
 
506
        return(-1);
486
507
        }
487
508
 
488
509
      if ((Value = (char *)getreq(sd)) == NULL)
489
510
        {
490
 
        fprintf(stderr, "ERROR:    job clear failed on %s (errno=%d-%s: %d-%s)\n",
491
 
                HPtr,
492
 
                errno,
493
 
                pbs_strerror(errno),
494
 
                pbs_errno,
495
 
                pbs_strerror(pbs_errno));
 
511
        /* FAILURE */
 
512
 
 
513
        fprintf(stderr,"ERROR:    job clear failed on %s (errno=%d-%s: %d-%s)\n",
 
514
          HPtr,
 
515
          errno,
 
516
          pbs_strerror(errno),
 
517
          pbs_errno,
 
518
          pbs_strerror(pbs_errno));
496
519
 
497
520
        closerm(sd);
498
521
 
499
 
        return -1;
 
522
        return(-1);
500
523
        }
501
524
 
502
525
      /* job cleared */
503
526
 
504
 
      fprintf(stdout, "job clear request successful on %s\n",
505
 
              HPtr);
 
527
      fprintf(stdout,"job clear request successful on %s\n",
 
528
        HPtr);
506
529
      }  /* END BLOCK (case momClear) */
507
530
 
508
531
    break;
516
539
 
517
540
      if (rc != 0)
518
541
        {
519
 
        fprintf(stderr, "ERROR:    cannot shutdown mom daemon on %s (errno=%d-%s: %d-%s)\n",
520
 
                HPtr,
521
 
                errno,
522
 
                pbs_strerror(errno),
523
 
                pbs_errno,
524
 
                pbs_strerror(pbs_errno));
 
542
        /* FAILURE */
 
543
 
 
544
        fprintf(stderr,"ERROR:    cannot shutdown mom daemon on %s (errno=%d-%s: %d-%s)\n",
 
545
          HPtr,
 
546
          errno,
 
547
          pbs_strerror(errno),
 
548
          pbs_errno,
 
549
          pbs_strerror(pbs_errno));
525
550
 
526
551
        closerm(sd);
527
552
 
528
 
        return -1;
 
553
        exit(EXIT_FAILURE);
529
554
        }
530
555
 
531
556
      fprintf(stdout, "shutdown request successful on %s\n",
532
 
 
533
 
              HPtr);
 
557
        HPtr);
534
558
      }    /* END BLOCK */
535
559
 
536
560
    break;
544
568
 
545
569
      if (rc != 0)
546
570
        {
547
 
        fprintf(stderr, "ERROR:    cannot reconfigure mom on %s (errno=%d-%s: %d-%s)\n",
548
 
                HPtr,
549
 
                errno,
550
 
                pbs_strerror(errno),
551
 
                pbs_errno,
552
 
                pbs_strerror(pbs_errno));
 
571
        /* FAILURE */
 
572
 
 
573
        fprintf(stderr,"ERROR:    cannot reconfigure mom on %s (errno=%d-%s: %d-%s)\n",
 
574
          HPtr,
 
575
          errno,
 
576
          pbs_strerror(errno),
 
577
          pbs_errno,
 
578
          pbs_strerror(pbs_errno));
553
579
 
554
580
        closerm(sd);
555
581
 
556
 
        return -1;
 
582
        return(-1);
557
583
        }
558
584
 
559
585
      fprintf(stdout, "reconfig successful on %s\n",
560
 
 
561
 
              HPtr);
 
586
        HPtr);
562
587
      }  /* END BLOCK (case momReconfig) */
563
588
 
564
589
    break;
578
603
        {
579
604
        if (addreq(sd, Query[rindex]) != 0)
580
605
          {
581
 
          fprintf(stderr, "ERROR:    cannot add query for '%s' on %s (errno=%d-%s: %d-%s)\n",
582
 
                  Query[rindex],
583
 
                  HPtr,
584
 
                  errno,
585
 
                  pbs_strerror(errno),
586
 
                  pbs_errno,
587
 
                  pbs_strerror(pbs_errno));
 
606
          fprintf(stderr,"ERROR:    cannot add query for '%s' on %s (errno=%d-%s: %d-%s)\n",
 
607
            Query[rindex],
 
608
            HPtr,
 
609
            errno,
 
610
 
 
611
          pbs_strerror(errno),
 
612
          pbs_errno,
 
613
          pbs_strerror(pbs_errno));
588
614
          }
589
615
        }
590
616
 
591
617
      for (rindex = 0;rindex < QueryI;rindex++)
592
618
        {
593
 
        if ((ptr = strchr(Query[rindex], '=')) != NULL)
 
619
        if ((ptr = strchr(Query[rindex],'=')) != NULL)
594
620
          {
595
621
          *ptr = '\0';
596
622
          }
598
624
        if ((Value = (char *)getreq(sd)) == NULL)
599
625
          {
600
626
          fprintf(stderr, "ERROR:    query[%d] '%s' failed on %s (errno=%d-%s: %d-%s)\n",
601
 
                  rindex,
602
 
                  Query[rindex],
603
 
                  HPtr,
604
 
                  errno,
605
 
                  pbs_strerror(errno),
606
 
                  pbs_errno,
607
 
                  pbs_strerror(pbs_errno));
 
627
            rindex,
 
628
            Query[rindex],
 
629
            HPtr,
 
630
            errno,
 
631
            pbs_strerror(errno),
 
632
            pbs_errno,
 
633
            pbs_strerror(pbs_errno));
608
634
          }
609
635
        else
610
636
          {
611
637
          if (!strncmp(Query[rindex], "diag", strlen("diag")))
612
638
            {
613
639
            fprintf(stdout, "%s\n",
614
 
                    Value);
 
640
              Value);
615
641
            }
616
642
          else if (!strncmp(Query[rindex], "cycle", strlen("cycle")))
617
643
            {
618
644
            fprintf(stdout, "mom %s successfully cycled %s\n",
619
 
                    HPtr,
620
 
                    Value);
 
645
              HPtr,
 
646
              Value);
621
647
            }
622
648
          else
623
649
            {
624
650
            fprintf(stdout, "%12s: %12s = '%s'\n",
625
 
                    HPtr,
626
 
                    Query[rindex],
627
 
                    Value);
 
651
              HPtr,
 
652
              Query[rindex],
 
653
              Value);
628
654
            }
629
655
          }
630
656
 
640
666
 
641
667
  closerm(sd);
642
668
 
643
 
  return 0;
 
669
  return(0);
644
670
  } /* END do_mom() */
645
671
 
646
672
 
656
682
  {
657
683
  if (Msg != NULL)
658
684
    fprintf(stderr, "  %s\n",
659
 
            Msg);
 
685
      Msg);
660
686
 
661
687
  fprintf(stderr, "USAGE:  momctl <ARGS>\n");
662
688
 
687
713
  exit(EXIT_FAILURE);
688
714
  }  /* END MCShowUsage() */
689
715
 
 
716
 
 
717
 
 
718
/* END momctl.c */
 
719