Skip to content

Commit 7b73e78

Browse files
authored
Merge pull request #5730 from btriller/select-attributes
libpromises/attributes: Fix minor issues
2 parents 18ee00a + afdc3f9 commit 7b73e78

File tree

1 file changed

+46
-32
lines changed

1 file changed

+46
-32
lines changed

libpromises/attributes.c

Lines changed: 46 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -530,17 +530,11 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
530530
u_long fplus, fminus;
531531
int entries = false;
532532

533-
s.name = (Rlist *) PromiseGetConstraintAsRval(pp, "leaf_name", RVAL_TYPE_LIST);
534-
s.path = (Rlist *) PromiseGetConstraintAsRval(pp, "path_name", RVAL_TYPE_LIST);
535-
s.filetypes = (Rlist *) PromiseGetConstraintAsRval(pp, "file_types", RVAL_TYPE_LIST);
536-
s.issymlinkto = (Rlist *) PromiseGetConstraintAsRval(pp, "issymlinkto", RVAL_TYPE_LIST);
537-
533+
// get constraint permissions
538534
s.perms = PromiseGetConstraintAsList(ctx, "search_mode", pp);
539535

540536
for (rp = s.perms; rp != NULL; rp = rp->next)
541537
{
542-
plus = 0;
543-
minus = 0;
544538
value = RlistScalarValue(rp);
545539

546540
if (!ParseModeString(value, &plus, &minus))
@@ -550,25 +544,17 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
550544
}
551545
}
552546

547+
// get constraint bsdflags
553548
s.bsdflags = PromiseGetConstraintAsList(ctx, "search_bsdflags", pp);
554549

555-
fplus = 0;
556-
fminus = 0;
557-
550+
// cannot fail, ParseFlagString always returns true
558551
if (!ParseFlagString(s.bsdflags, &fplus, &fminus))
559552
{
560553
Log(LOG_LEVEL_ERR, "Problem validating a BSD flag string");
561554
PromiseRef(LOG_LEVEL_ERR, pp);
562555
}
563556

564-
if ((s.name) || (s.path) || (s.filetypes) || (s.issymlinkto) || (s.perms) || (s.bsdflags))
565-
{
566-
entries = true;
567-
}
568-
569-
s.owners = (Rlist *) PromiseGetConstraintAsRval(pp, "search_owners", RVAL_TYPE_LIST);
570-
s.groups = (Rlist *) PromiseGetConstraintAsRval(pp, "search_groups", RVAL_TYPE_LIST);
571-
557+
// get constraint search_size
572558
value = PromiseGetConstraintAsRval(pp, "search_size", RVAL_TYPE_SCALAR);
573559
if (value)
574560
{
@@ -581,6 +567,7 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
581567
FatalError(ctx, "Could not make sense of integer range [%s]", value);
582568
}
583569

570+
// get constraint creation time
584571
value = PromiseGetConstraintAsRval(pp, "ctime", RVAL_TYPE_SCALAR);
585572
if (value)
586573
{
@@ -593,6 +580,7 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
593580
FatalError(ctx, "Could not make sense of integer range [%s]", value);
594581
}
595582

583+
// get constraint access time
596584
value = PromiseGetConstraintAsRval(pp, "atime", RVAL_TYPE_SCALAR);
597585
if (value)
598586
{
@@ -604,6 +592,8 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
604592
PromiseRef(LOG_LEVEL_ERR, pp);
605593
FatalError(ctx, "Could not make sense of integer range [%s]", value);
606594
}
595+
596+
// get constraint modification time
607597
value = PromiseGetConstraintAsRval(pp, "mtime", RVAL_TYPE_SCALAR);
608598
if (value)
609599
{
@@ -616,19 +606,29 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
616606
FatalError(ctx, "Could not make sense of integer range [%s]", value);
617607
}
618608

609+
// get constraints owners, groups, exec_regex, exec_program, file types, name, path
610+
s.owners = (Rlist *) PromiseGetConstraintAsRval(pp, "search_owners", RVAL_TYPE_LIST);
611+
s.groups = (Rlist *) PromiseGetConstraintAsRval(pp, "search_groups", RVAL_TYPE_LIST);
619612
s.exec_regex = PromiseGetConstraintAsRval(pp, "exec_regex", RVAL_TYPE_SCALAR);
620613
s.exec_program = PromiseGetConstraintAsRval(pp, "exec_program", RVAL_TYPE_SCALAR);
614+
s.filetypes = (Rlist *) PromiseGetConstraintAsRval(pp, "file_types", RVAL_TYPE_LIST);
615+
s.name = (Rlist *) PromiseGetConstraintAsRval(pp, "leaf_name", RVAL_TYPE_LIST);
616+
s.path = (Rlist *) PromiseGetConstraintAsRval(pp, "path_name", RVAL_TYPE_LIST);
617+
s.issymlinkto = (Rlist *) PromiseGetConstraintAsRval(pp, "issymlinkto", RVAL_TYPE_LIST);
621618

622-
if ((s.owners) || (s.min_size) || (s.exec_regex) || (s.exec_program))
619+
// check if file_result is needed
620+
if ((s.owners) || (s.groups) || (s.exec_regex) || (s.exec_program) || (s.filetypes)
621+
|| (s.name) || (s.path) || (s.issymlinkto) || (s.perms) || (s.bsdflags))
623622
{
624623
entries = true;
625624
}
626625

626+
// get constraint file_result
627627
if ((s.result = PromiseGetConstraintAsRval(pp, "file_result", RVAL_TYPE_SCALAR)) == NULL)
628628
{
629-
if (!entries)
629+
if (entries)
630630
{
631-
Log(LOG_LEVEL_ERR, "file_select body missing its a file_result return value");
631+
Log(LOG_LEVEL_ERR, "file_select body missing its file_result return value");
632632
}
633633
}
634634

@@ -1319,10 +1319,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13191319
char *value;
13201320
int entries = 0;
13211321

1322-
p.owner = PromiseGetConstraintAsList(ctx, "process_owner", pp);
1323-
1322+
// get constraint process ID
13241323
value = PromiseGetConstraintAsRval(pp, "pid", RVAL_TYPE_SCALAR);
1325-
13261324
if (value)
13271325
{
13281326
entries++;
@@ -1333,8 +1331,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13331331
PromiseRef(LOG_LEVEL_ERR, pp);
13341332
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13351333
}
1336-
value = PromiseGetConstraintAsRval(pp, "ppid", RVAL_TYPE_SCALAR);
13371334

1335+
// get constraint parent process ID
1336+
value = PromiseGetConstraintAsRval(pp, "ppid", RVAL_TYPE_SCALAR);
13381337
if (value)
13391338
{
13401339
entries++;
@@ -1345,8 +1344,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13451344
PromiseRef(LOG_LEVEL_ERR, pp);
13461345
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13471346
}
1348-
value = PromiseGetConstraintAsRval(pp, "pgid", RVAL_TYPE_SCALAR);
13491347

1348+
// get constraint process group ID
1349+
value = PromiseGetConstraintAsRval(pp, "pgid", RVAL_TYPE_SCALAR);
13501350
if (value)
13511351
{
13521352
entries++;
@@ -1357,8 +1357,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13571357
PromiseRef(LOG_LEVEL_ERR, pp);
13581358
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13591359
}
1360-
value = PromiseGetConstraintAsRval(pp, "rsize", RVAL_TYPE_SCALAR);
13611360

1361+
// get constraint resident set size
1362+
value = PromiseGetConstraintAsRval(pp, "rsize", RVAL_TYPE_SCALAR);
13621363
if (value)
13631364
{
13641365
entries++;
@@ -1369,6 +1370,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13691370
PromiseRef(LOG_LEVEL_ERR, pp);
13701371
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13711372
}
1373+
1374+
// get constraint VM size
13721375
value = PromiseGetConstraintAsRval(pp, "vsize", RVAL_TYPE_SCALAR);
13731376
if (value)
13741377
{
@@ -1380,6 +1383,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13801383
PromiseRef(LOG_LEVEL_ERR, pp);
13811384
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13821385
}
1386+
1387+
// get constraint cumulated CPU time
13831388
value = PromiseGetConstraintAsRval(pp, "ttime_range", RVAL_TYPE_SCALAR);
13841389
if (value)
13851390
{
@@ -1391,6 +1396,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13911396
PromiseRef(LOG_LEVEL_ERR, pp);
13921397
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13931398
}
1399+
1400+
// get constraint start time
13941401
value = PromiseGetConstraintAsRval(pp, "stime_range", RVAL_TYPE_SCALAR);
13951402
if (value)
13961403
{
@@ -1403,10 +1410,7 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14031410
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14041411
}
14051412

1406-
p.status = PromiseGetConstraintAsRval(pp, "status", RVAL_TYPE_SCALAR);
1407-
p.command = PromiseGetConstraintAsRval(pp, "command", RVAL_TYPE_SCALAR);
1408-
p.tty = PromiseGetConstraintAsRval(pp, "tty", RVAL_TYPE_SCALAR);
1409-
1413+
// get constraint priority
14101414
value = PromiseGetConstraintAsRval(pp, "priority", RVAL_TYPE_SCALAR);
14111415
if (value)
14121416
{
@@ -1418,6 +1422,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14181422
PromiseRef(LOG_LEVEL_ERR, pp);
14191423
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14201424
}
1425+
1426+
// get constraint threads
14211427
value = PromiseGetConstraintAsRval(pp, "threads", RVAL_TYPE_SCALAR);
14221428
if (value)
14231429
{
@@ -1430,16 +1436,24 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14301436
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14311437
}
14321438

1439+
// get constraints owner, status, command and tty
1440+
p.owner = PromiseGetConstraintAsList(ctx, "process_owner", pp);
1441+
p.status = PromiseGetConstraintAsRval(pp, "status", RVAL_TYPE_SCALAR);
1442+
p.command = PromiseGetConstraintAsRval(pp, "command", RVAL_TYPE_SCALAR);
1443+
p.tty = PromiseGetConstraintAsRval(pp, "tty", RVAL_TYPE_SCALAR);
1444+
1445+
// check if file_result is needed
14331446
if ((p.owner) || (p.status) || (p.command) || (p.tty))
14341447
{
14351448
entries = true;
14361449
}
14371450

1451+
// get constraint process_result
14381452
if ((p.process_result = PromiseGetConstraintAsRval(pp, "process_result", RVAL_TYPE_SCALAR)) == NULL)
14391453
{
14401454
if (entries)
14411455
{
1442-
Log(LOG_LEVEL_ERR, "process_select body missing its a process_result return value");
1456+
Log(LOG_LEVEL_ERR, "process_select body missing its process_result return value");
14431457
}
14441458
}
14451459

0 commit comments

Comments
 (0)