@@ -408,45 +408,56 @@ static int do_cond_dump(char *arg)
408408
409409typedef enum { COND_CLR , COND_SET , COND_GET } condop_t ;
410410
411- static int do_cond_act (char * arg , condop_t op )
411+ /*
412+ * cond get allows only one argument
413+ * cond set|clr iterate over multiple args
414+ */
415+ static int do_cond_act (char * args , condop_t op )
412416{
413417 char path [256 ];
414- size_t off ;
418+ char * arg ;
415419
416- if (arg && strncmp (arg , COND_USR , strlen (COND_USR )) == 0 )
417- arg += strlen (COND_USR );
418-
419- if (!arg || !arg [0 ])
420+ if (!args || !args [0 ])
420421 ERRX (2 , "Invalid condition (empty)" );
421422
422- /* allowed to read any condition, but not set/clr */
423- if (op != COND_GET ) {
423+ arg = strtok (args , " \t" );
424+ while (arg ) {
425+ size_t off ;
426+
427+ if (strncmp (arg , COND_USR , strlen (COND_USR )) == 0 )
428+ arg += strlen (COND_USR );
429+
430+ /* allowed to read any condition, but not set/clr */
431+ if (op != COND_GET ) {
432+ if (strchr (arg , '/' ))
433+ ERRX (2 , "Invalid condition (slashes)" );
434+ if (strchr (arg , '.' ))
435+ ERRX (2 , "Invalid condition (periods)" );
436+ }
437+
424438 if (strchr (arg , '/' ))
425- ERRX (2 , "Invalid condition (slashes)" );
426- if (strchr (arg , '.' ))
427- ERRX (2 , "Invalid condition (periods)" );
428- }
439+ snprintf (path , sizeof (path ), _PATH_COND "%s" , arg );
440+ else
441+ snprintf (path , sizeof (path ), _PATH_CONDUSR "%s" , arg );
442+ off = strlen (_PATH_COND );
443+
444+ switch (op ) {
445+ case COND_GET :
446+ off = !fexist (path );
447+ if (verbose )
448+ puts (off ? "off" : "on" );
449+ return off ;
450+ case COND_SET :
451+ if (symlink (_PATH_RECONF , path ) && errno != EEXIST )
452+ ERR (73 , "Failed asserting condition <%s>" , & path [off ]);
453+ break ;
454+ case COND_CLR :
455+ if (erase (path ) && errno != ENOENT )
456+ ERR (73 , "Failed deasserting condition <%s>" , & path [off ]);
457+ break ;
458+ }
429459
430- if (strchr (arg , '/' ))
431- snprintf (path , sizeof (path ), _PATH_COND "%s" , arg );
432- else
433- snprintf (path , sizeof (path ), _PATH_CONDUSR "%s" , arg );
434- off = strlen (_PATH_COND );
435-
436- switch (op ) {
437- case COND_GET :
438- off = !fexist (path );
439- if (verbose )
440- puts (off ? "off" : "on" );
441- return off ;
442- case COND_SET :
443- if (symlink (_PATH_RECONF , path ) && errno != EEXIST )
444- ERR (73 , "Failed asserting condition <%s>" , & path [off ]);
445- break ;
446- case COND_CLR :
447- if (erase (path ) && errno != ENOENT )
448- ERR (73 , "Failed deasserting condition <%s>" , & path [off ]);
449- break ;
460+ arg = strtok (NULL , " \t" );
450461 }
451462
452463 return 0 ;
@@ -1263,9 +1274,9 @@ static int usage(int rc)
12631274
12641275 fprintf (stderr ,
12651276 "\n"
1266- " cond set <COND> Set (assert) user-defined condition +usr/COND\n"
1277+ " cond set <COND> Set (assert) user-defined conditions +usr/COND\n"
12671278 " cond get <COND> Get status of user-defined condition, see $? and -v\n"
1268- " cond clear <COND> Clear (deassert) user-defined condition -usr/COND\n"
1279+ " cond clear <COND> Clear (deassert) user-defined conditions -usr/COND\n"
12691280 " cond status Show condition status, default cond command\n"
12701281 " cond dump [TYPE] Dump all, or a type of, conditions and their status\n"
12711282 "\n"
0 commit comments