nefelim4ag / Ananicy

Ananicy - is Another auto nice daemon, with community rules support (Use pull request please)
GNU General Public License v3.0
567 stars 79 forks source link

Bug: rules setting a value to zero will never get applied! #466

Open tehybel opened 1 year ago

tehybel commented 1 year ago

There's a bug in ananicy which causes a rule on the form {..., "ionice": 0} to not have its "ionice" set.

Consider the following excerpt from ananicy.py:

    def get_rule_info(self, line):
        ...
        _type = line.get("type")
        if _type:
            if not self.types.get(_type):
                raise Failure('"type": "{}" not defined'.format(_type))
            _type = self.types[_type]
            for attr in ("nice", "ioclass", "ionice", "sched", "rtprio",
                         "oom_score_adj", "cgroup"):
                tmp = _type.get(attr)
                if not tmp:
                    continue

The check if not tmp: should actually be if tmp is None:.

I'm unsure of the if statements inside apply_rules also require changing, to check for is not None, but I believe so. You then get something on the form:

if rules.get("ioclass") is not None or rules.get("ionice") is not None: