Skip to content

Commit a489147

Browse files
committed
libpromises/attributes: Add some comments to code
For better readability on what's currently checked, add comments and rearrange code
1 parent 63db2bc commit a489147

File tree

1 file changed

+43
-24
lines changed

1 file changed

+43
-24
lines changed

libpromises/attributes.c

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,7 @@ 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)
@@ -550,25 +546,20 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
550546
}
551547
}
552548

549+
// get constraint bsdflags
553550
s.bsdflags = PromiseGetConstraintAsList(ctx, "search_bsdflags", pp);
554551

555552
fplus = 0;
556553
fminus = 0;
557554

555+
// cannot fail, ParseFlagString always returns true
558556
if (!ParseFlagString(s.bsdflags, &fplus, &fminus))
559557
{
560558
Log(LOG_LEVEL_ERR, "Problem validating a BSD flag string");
561559
PromiseRef(LOG_LEVEL_ERR, pp);
562560
}
563561

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-
562+
// get constraint search_size
572563
value = PromiseGetConstraintAsRval(pp, "search_size", RVAL_TYPE_SCALAR);
573564
if (value)
574565
{
@@ -581,6 +572,7 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
581572
FatalError(ctx, "Could not make sense of integer range [%s]", value);
582573
}
583574

575+
// get constraint creation time
584576
value = PromiseGetConstraintAsRval(pp, "ctime", RVAL_TYPE_SCALAR);
585577
if (value)
586578
{
@@ -593,6 +585,7 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
593585
FatalError(ctx, "Could not make sense of integer range [%s]", value);
594586
}
595587

588+
// get constraint access time
596589
value = PromiseGetConstraintAsRval(pp, "atime", RVAL_TYPE_SCALAR);
597590
if (value)
598591
{
@@ -604,6 +597,8 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
604597
PromiseRef(LOG_LEVEL_ERR, pp);
605598
FatalError(ctx, "Could not make sense of integer range [%s]", value);
606599
}
600+
601+
// get constraint modification time
607602
value = PromiseGetConstraintAsRval(pp, "mtime", RVAL_TYPE_SCALAR);
608603
if (value)
609604
{
@@ -616,14 +611,24 @@ FileSelect GetSelectConstraints(const EvalContext *ctx, const Promise *pp)
616611
FatalError(ctx, "Could not make sense of integer range [%s]", value);
617612
}
618613

614+
// get constraints owners, groups, exec_regex, exec_program, file types, name, path
615+
s.owners = (Rlist *) PromiseGetConstraintAsRval(pp, "search_owners", RVAL_TYPE_LIST);
616+
s.groups = (Rlist *) PromiseGetConstraintAsRval(pp, "search_groups", RVAL_TYPE_LIST);
619617
s.exec_regex = PromiseGetConstraintAsRval(pp, "exec_regex", RVAL_TYPE_SCALAR);
620618
s.exec_program = PromiseGetConstraintAsRval(pp, "exec_program", RVAL_TYPE_SCALAR);
619+
s.filetypes = (Rlist *) PromiseGetConstraintAsRval(pp, "file_types", RVAL_TYPE_LIST);
620+
s.name = (Rlist *) PromiseGetConstraintAsRval(pp, "leaf_name", RVAL_TYPE_LIST);
621+
s.path = (Rlist *) PromiseGetConstraintAsRval(pp, "path_name", RVAL_TYPE_LIST);
622+
s.issymlinkto = (Rlist *) PromiseGetConstraintAsRval(pp, "issymlinkto", RVAL_TYPE_LIST);
621623

622-
if ((s.owners) || (s.min_size) || (s.exec_regex) || (s.exec_program))
624+
// check if file_result is needed
625+
if ((s.owners) || (s.min_size) || (s.exec_regex) || (s.exec_program) || (s.filetypes)
626+
|| (s.name) || (s.path) || (s.issymlinkto) || (s.perms) || (s.bsdflags))
623627
{
624628
entries = true;
625629
}
626630

631+
// get constraint file_result
627632
if ((s.result = PromiseGetConstraintAsRval(pp, "file_result", RVAL_TYPE_SCALAR)) == NULL)
628633
{
629634
if (!entries)
@@ -1319,10 +1324,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13191324
char *value;
13201325
int entries = 0;
13211326

1322-
p.owner = PromiseGetConstraintAsList(ctx, "process_owner", pp);
1323-
1327+
// get constraint process ID
13241328
value = PromiseGetConstraintAsRval(pp, "pid", RVAL_TYPE_SCALAR);
1325-
13261329
if (value)
13271330
{
13281331
entries++;
@@ -1333,8 +1336,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13331336
PromiseRef(LOG_LEVEL_ERR, pp);
13341337
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13351338
}
1336-
value = PromiseGetConstraintAsRval(pp, "ppid", RVAL_TYPE_SCALAR);
13371339

1340+
// get constraint parent process ID
1341+
value = PromiseGetConstraintAsRval(pp, "ppid", RVAL_TYPE_SCALAR);
13381342
if (value)
13391343
{
13401344
entries++;
@@ -1345,8 +1349,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13451349
PromiseRef(LOG_LEVEL_ERR, pp);
13461350
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13471351
}
1348-
value = PromiseGetConstraintAsRval(pp, "pgid", RVAL_TYPE_SCALAR);
13491352

1353+
// get constraint process group ID
1354+
value = PromiseGetConstraintAsRval(pp, "pgid", RVAL_TYPE_SCALAR);
13501355
if (value)
13511356
{
13521357
entries++;
@@ -1357,8 +1362,9 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13571362
PromiseRef(LOG_LEVEL_ERR, pp);
13581363
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13591364
}
1360-
value = PromiseGetConstraintAsRval(pp, "rsize", RVAL_TYPE_SCALAR);
13611365

1366+
// get constraint resident set size
1367+
value = PromiseGetConstraintAsRval(pp, "rsize", RVAL_TYPE_SCALAR);
13621368
if (value)
13631369
{
13641370
entries++;
@@ -1369,6 +1375,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13691375
PromiseRef(LOG_LEVEL_ERR, pp);
13701376
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13711377
}
1378+
1379+
// get constraint VM size
13721380
value = PromiseGetConstraintAsRval(pp, "vsize", RVAL_TYPE_SCALAR);
13731381
if (value)
13741382
{
@@ -1380,6 +1388,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13801388
PromiseRef(LOG_LEVEL_ERR, pp);
13811389
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13821390
}
1391+
1392+
// get constraint cumulated CPU time
13831393
value = PromiseGetConstraintAsRval(pp, "ttime_range", RVAL_TYPE_SCALAR);
13841394
if (value)
13851395
{
@@ -1391,6 +1401,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
13911401
PromiseRef(LOG_LEVEL_ERR, pp);
13921402
FatalError(ctx, "Could not make sense of integer range [%s]", value);
13931403
}
1404+
1405+
// get constraint start time
13941406
value = PromiseGetConstraintAsRval(pp, "stime_range", RVAL_TYPE_SCALAR);
13951407
if (value)
13961408
{
@@ -1403,10 +1415,7 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14031415
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14041416
}
14051417

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-
1418+
// get constraint priority
14101419
value = PromiseGetConstraintAsRval(pp, "priority", RVAL_TYPE_SCALAR);
14111420
if (value)
14121421
{
@@ -1418,6 +1427,8 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14181427
PromiseRef(LOG_LEVEL_ERR, pp);
14191428
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14201429
}
1430+
1431+
// get constraint threads
14211432
value = PromiseGetConstraintAsRval(pp, "threads", RVAL_TYPE_SCALAR);
14221433
if (value)
14231434
{
@@ -1430,11 +1441,19 @@ ProcessSelect GetProcessFilterConstraints(const EvalContext *ctx, const Promise
14301441
FatalError(ctx, "Could not make sense of integer range [%s]", value);
14311442
}
14321443

1444+
// get constraints owner, status, command and tty
1445+
p.owner = PromiseGetConstraintAsList(ctx, "process_owner", pp);
1446+
p.status = PromiseGetConstraintAsRval(pp, "status", RVAL_TYPE_SCALAR);
1447+
p.command = PromiseGetConstraintAsRval(pp, "command", RVAL_TYPE_SCALAR);
1448+
p.tty = PromiseGetConstraintAsRval(pp, "tty", RVAL_TYPE_SCALAR);
1449+
1450+
// check if file_result is needed
14331451
if ((p.owner) || (p.status) || (p.command) || (p.tty))
14341452
{
14351453
entries = true;
14361454
}
14371455

1456+
// get constraint process_result
14381457
if ((p.process_result = PromiseGetConstraintAsRval(pp, "process_result", RVAL_TYPE_SCALAR)) == NULL)
14391458
{
14401459
if (entries)

0 commit comments

Comments
 (0)