[CRIU] [PATCH v9 05/10] parse: add a helper to obtain an uptime

Dmitry Safonov 0x7f454c46 at gmail.com
Tue Apr 3 16:29:37 MSK 2018


вт, 3 апр 2018 г., 14:24 Pavel Tikhomirov <ptikhomirov at virtuozzo.com>:

>
>
> On 04/03/2018 04:11 PM, Dmitry Safonov wrote:
> > 2018-04-03 10:34 GMT+01:00 Pavel Tikhomirov <ptikhomirov at virtuozzo.com>:
> > [..]
> >> +
> >> +#define CSEC_PER_SEC 100
> >> +
> >> +__maybe_unused int parse_uptime(u_int64_t *upt)
> >
> > Nit: can we use uint64_t?
> > I see u_int64_t the first time and git says we've it only in one other
> place.
>
> Oops, I brought it from encode_time - will use uint64_t instead, thanks!
>
> >
> >> +{
> >> +       unsigned long sec, csec;
> >> +       FILE *f;
> >> +
> >> +       f = fopen("/proc/uptime", "r");
> >> +       if (!f) {
> >> +               pr_perror("Failed to fopen /proc/uptime");
> >> +               return -1;
> >> +       }
> >> +
> >> +       if (fscanf(f, "%lu.%2lu", &sec, &csec) != 2) {
> >> +               pr_perror("Failed to parse /proc/uptime");
> >> +               fclose(f);
> >> +               return -1;
> >> +       }
> >> +
> >> +       *upt = sec * USEC_PER_SEC + csec * (USEC_PER_SEC /
> CSEC_PER_SEC);
> >
> > It's not clear from the commit message, why do you save time in usec,
> > rather than in csec?
>
> I thought it would be better to have usec in image, so when/if we have
> more precise uptime we can just reuse same variable in image and won't
> need adding another one.
>

I don't mind. As you'll resend anyway - could you mention
that in commit message, please? ;)

 Thanks,
              Dmitry
(answering from phone, sorry for html)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openvz.org/pipermail/criu/attachments/20180403/5b3e04ba/attachment.html>


More information about the CRIU mailing list