Skip to content

Commit

Permalink
Remove the "catch-all" option for now
Browse files Browse the repository at this point in the history
There is still no rules specified for the "catch-all" one,
consider detecting a "all" label in the YAML config that
indicates a specific rule is for "catch-all"
  • Loading branch information
yunchih committed Oct 3, 2017
1 parent f71bb35 commit a1df421
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions bin/resrctl
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,6 @@ if __name__ == '__main__':
help="(Optional) A list of users to be constrained")
parser.add_argument("--groups", "-g", nargs="+", action="store", default=[],
help="(Optional) A list of groups to be constrained")
parser.add_argument("--apply-all", "-a", dest="apply_all", action="store_true",
help="(Optional) Apply the constraints to all users")
parser.add_argument("--rules", "-r", action="store", default="",
help="(Required) A comma-seperated list of rules to be applied")
parser.add_argument("--apply-existing", "-e", dest="apply_existing", action="store_true",
Expand All @@ -79,7 +77,7 @@ if __name__ == '__main__':
rules = _parse_config(args.config)
rules = rules + parse_cmd(args.users, args.groups, args.rules)

manager = UsersResourceManager(rules, args.dry, args.apply_all, args.apply_existing)
manager = UsersResourceManager(rules, args.dry, args.apply_existing)
manager.monitor_new_user()
manager.run()

9 changes: 4 additions & 5 deletions resrc/systemd.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,9 @@ def dict_to_dbus_properties(ct):

class UsersResourceManager:

def __init__(self, ruleset=[], dry_run=False, all_user=False, apply_existing=False):
def __init__(self, ruleset=[], dry_run=False, apply_existing=False):
self.ruleset = ruleset
self.dry_run = dry_run
self.all_user = all_user

if len(ruleset) == 0:
quit("No rules installed!")
Expand Down Expand Up @@ -100,11 +99,11 @@ def apply_rule(self, uid, gid):

for entry in self.ruleset:
# Only apply the first matched rule
if self.all_user or entry.match(uid, gid):
if entry.match(uid, gid):
logging.info("UID {0} matches rule \"{1}\"".format(uid, entry.get_rules().name))
r = entry.get_rules().rules
if (not self.dry_run) and r:
self.sd_set_unit_properties(uid, r)
logging.info("UID {0} matches rule \"{1}\"".format(uid, entry.get_rules().name))
break

def sd_set_unit_properties(self, uid, properties):
Expand All @@ -113,7 +112,7 @@ def sd_set_unit_properties(self, uid, properties):

try:
self.sd_manager.run("SetUnitProperties", sd_unit, sd_runtime, properties)
logging.info("Resource limitation imposed on user: %d" % uid)
logging.info("Resource limitation imposed on user: UID %d" % uid)
except Exception as e:
logging.error("Failed imposing resource limit on %d: %s" % (uid, e))

Expand Down

0 comments on commit a1df421

Please sign in to comment.