public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: LTP List <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH v3 1/3] lib: add functions to adjust oom score
Date: Tue, 21 Dec 2021 10:59:11 +0100	[thread overview]
Message-ID: <YcGlb4NoDGSP4ZkU@yuki> (raw)
In-Reply-To: <CAEemH2dDEM30-fM89LDZq1E7YN8rf44doGgnkPXuce0ttP67OA@mail.gmail.com>

Hi!
> Not exactly, if someone gives a wrong PID, that also cannot find
> the score_path. So we shouldn't skip OOM adjustment only
> with printing the TFINO.

Right, we would have to check if the /proc/$PID/ directory exists
first.

> > if (access(score_path, F_OK)) {
> >         tst_res(TINFO,
> >                 "'%s' does not exist, skipping OOM score adjustement",
> >                 score_path);
> >         return;
> > }
> >
> > if (access(score_path, W_OK)) {
> >         tst_res(TWARN, "'%s' not writeable, are you root?", score_path);
> >         return;
> > }
> >
> 
> As Petr points out, only root user can set a negative value to
> oom_score_adj,
> this W_OK is not enough for ordinary users.

Ah, right this makes it even more complex.

> Consider about situation, I'd suggest go with non-safe macros and add
> additional check in the last.
> 
> e.g.
> 
> --- a/lib/tst_memutils.c
> +++ b/lib/tst_memutils.c
> @@ -108,17 +108,21 @@ static void set_oom_score_adj(pid_t pid, int value)
>         else
>                 sprintf(score_path, "/proc/%d/oom_score_adj", pid);
> 
> -       if (access(score_path, R_OK | W_OK) == -1) {
> -               tst_res(TINFO, "Warning: %s cannot be accessed for
> reading/writing,
> -                       please check if test run with root user.",
> -                       score_path);
> -               return
> -       }
> -
> -       SAFE_FILE_PRINTF(score_path, "%d", value);
> -       SAFE_FILE_SCANF(score_path, "%d", &val);
> -       if (val != value)
> +       if (access(score_path, F_OK) == -1)
> +               tst_brk(TBROK, "%s does not exist, please check if PID is
> valid");

Maybe we should print the pid in the message here as well.

> +
> +       FILE_PRINTF(score_path, "%d", value);
> +       FILE_SCANF(score_path, "%d", &val);
> +
> +       if (val != value) {
> +               if (value < 0) {
> +                       tst_res(TINFO, "Warning: %s cannot be set to
> negative value,
> +                               please check if test run with root user.",

I would say that we TBROK here, otherwise it could be silently ignored.
Also I would shorten the message to something as:

	"'%s' cannot be set to %i, are you root?", score_path, value);

> +                               score_path);
> +                       return
> +               }
>                 tst_brk(TBROK, "oom_score_adj = %d, but expect %d.", val,
> value);
> +       }
>  }
> 
> 
> -- 
> Regards,
> Li Wang

-- 
Cyril Hrubis
chrubis@suse.cz

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2021-12-21  9:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20  9:54 [LTP] [PATCH v3 1/3] lib: add functions to adjust oom score Li Wang
2021-12-20  9:54 ` [LTP] [PATCH v3 2/3] lib: enable OOM protection for ltp lib process Li Wang
2021-12-20 13:26   ` Cyril Hrubis
2021-12-20  9:54 ` [LTP] [PATCH v3 3/3] oom: enable OOM protection for mem " Li Wang
2021-12-20 13:27   ` Cyril Hrubis
2021-12-20 13:26 ` [LTP] [PATCH v3 1/3] lib: add functions to adjust oom score Cyril Hrubis
2021-12-20 18:13 ` Petr Vorel
2021-12-20 18:34 ` Petr Vorel
2021-12-21  2:50   ` Li Wang
2021-12-21  8:33     ` Petr Vorel
2021-12-21  9:18     ` Cyril Hrubis
2021-12-21  9:23       ` Li Wang
2021-12-21  9:40         ` Li Wang
2021-12-21  9:59         ` Cyril Hrubis [this message]
2021-12-21 10:12           ` Li Wang
2021-12-21 10:36             ` Cyril Hrubis
2021-12-21 10:44               ` Petr Vorel
2021-12-21 11:32                 ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YcGlb4NoDGSP4ZkU@yuki \
    --to=chrubis@suse.cz \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox