[torquedev] new node attribute: "note"

Marcus R. Epperson mrepper at sandia.gov
Tue Mar 20 17:34:31 MDT 2007


Garrick Staples wrote:
> On Mon, Mar 19, 2007 at 09:59:17PM -0600, Marcus R. Epperson alleged:
>> Garrick Staples wrote:
>>> On Mon, Mar 19, 2007 at 02:02:21PM -0600, Marcus R. Epperson alleged:
>>>> Do you have any suggestions for how to do this argument parsing correctly?
>>> Indeed, we definitely need to stay away from GNU extensions.
>>>
>>> How about we use lowercase n for listing, and capital N for setting?
>> Ok, I think this is a lot cleaner.  Let me know what you think.
> 
> I think this makes me all gushy inside.
> 
> Since this doesn't apply to trunk, can you whip up another patch or
> should I just copy 2.1-fixes' pbsnodes.c into trunk?

Here's one for 2.2.0-snap.200703191105.  Though I think the trunk's pbsnodes -l is a little broken.  It seems to be doing strcmp() comparisons on the state attribute instead of strstr().  So if a node is both down and offline, it isn't shown.

-Marcus
-------------- next part --------------
--- torque-2.2.0-snap.200703191105-orig/src/cmds/pbsnodes.c	2007-03-16 12:17:34.000000000 -0600
+++ torque-2.2.0-snap.200703191105/src/cmds/pbsnodes.c	2007-03-19 22:20:40.000000000 -0600
@@ -124,6 +124,8 @@
 #define DIAG    7
 #define NOTE    8
 
+enum note_flags {unused, set, list};
+
 int quiet = 0;
 
 
@@ -377,6 +379,26 @@ static int is_unknown(
 
 
 
+/* returns a pointer to the note if there is one, otherwise NULL */
+static char *get_note(
+
+  struct batch_status *pbs)  /* I */
+
+  {
+  struct attrl *pat;
+
+  for (pat = pbs->attribs;pat != NULL;pat = pat->next) 
+    {
+    if (strcmp(pat->name,ATTR_NODE_note) == 0)
+      {
+      return(pat->value);
+      }
+    }
+
+  return(NULL);
+  }
+
+
 
 static int marknode(
 
@@ -482,8 +504,7 @@ int main(
   struct batch_status *pbstat;
   int	flag = ALLI;
   char	*note = NULL;
-  int	note_flag = 0;
-  int	len;
+  enum  note_flags note_flag = unused;
   char  NodeArg[256000];
 
   enum NStateEnum ListType = tnsNONE;
@@ -495,7 +516,7 @@ int main(
   if (def_server == NULL)
     def_server = "";
 
-  while ((i = getopt(argc,argv,"acdlopqrs:x-:n:")) != EOF)
+  while ((i = getopt(argc,argv,"acdlopqrs:x-:N:n")) != EOF)
     {
     switch(i) 
       {
@@ -561,12 +582,10 @@ int main(
 
         break;
 
-      case 'n':
-
-        note_flag = 1;
+      case 'N':
 
         /* preserve any previous option other than the default,
-         * to allow -n to be combined with -o, -c, etc
+         * to allow -N to be combined with -o, -c, etc
          */
 
         if (flag == ALLI)
@@ -574,18 +593,21 @@ int main(
 
         note = strdup(optarg);
 
-        if (note != NULL)
+        if (note == NULL)
           {
-          /* -n n is the same as -n ""  -- it clears the note */
+          perror("Error: strdup() returned NULL");
+          exit(1);
+          }
+        else
+          {
+          note_flag = set;
+
+          /* -N n is the same as -N ""  -- it clears the note */
 
           if (!strcmp(note,"n"))
-            {
             *note = '\0';
-            }
-
-          len = strlen(note);
 
-          if (len > MAX_NOTE)
+          if (strlen(note) > MAX_NOTE)
             fprintf(stderr,"Warning: note exceeds length limit (%d) - server may reject it...\n",
               MAX_NOTE);
 
@@ -595,6 +617,12 @@ int main(
 
         break;
 
+      case 'n':
+
+        note_flag = list;
+
+        break;
+
       case '-':
 
         if ((optarg != NULL) && !strcmp(optarg,"version"))
@@ -622,16 +650,22 @@ int main(
 
         break;
       }  /* END switch (i) */
-    }    /* END while (i == getopt()) */
+    }    /* END while (i = getopt()) */
+
+  if ((note_flag == list) && (flag != LIST))
+    {
+    fprintf(stderr,"Error: -n requires -l\n");
+    errflg = 1;
+    }
 
   if (errflg != 0) 
     {
     if (!quiet)
       {
-      fprintf(stderr,"usage:\t%s [-{c|d|l|o|p|r}][-s server] [-n \"note\"] [-q] node node ...\n",
+      fprintf(stderr,"usage:\t%s [-{c|d|l|o|p|r}] [-s server] [-n] [-N \"note\"] [-q] node ...\n",
         argv[0]);
 
-      fprintf(stderr,"\t%s -{a|x} [-s server] [-q] [node]\n",
+      fprintf(stderr,"\t%s [-{a|x}] [-s server] [-q] [node]\n",
         argv[0]);
       }
 
@@ -724,7 +758,7 @@ int main(
       }
     }    /* END if ((flag == ALLI) || (flag == DOWN) || (flag == LIST) || (flag == DIAG)) */
 
-  if (note_flag && (note != NULL))
+  if ((note_flag == set) && (note != NULL))
     {
     /* set the note attrib string on specified nodes */
     for (pa = argv + optind;*pa;pa++) 
@@ -995,9 +1029,21 @@ int main(
 
         if (Display == 1)
           {
-          printf("%-20.20s %s\n",
-            pbstat->name,
-            S);
+          char *n;
+
+          if ((note_flag == list) && (n = get_note(pbstat)))
+            {
+            printf("%-20.20s %-26.26s %s\n",
+              pbstat->name,
+              S,
+              n);
+            }
+          else
+            {
+            printf("%-20.20s %s\n",
+              pbstat->name,
+              S);
+            }
           }
         }
       }    /* END BLOCK (case LIST) */


More information about the torquedev mailing list