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

Dmitry Safonov 0x7f454c46 at gmail.com
Tue Apr 3 16:11:23 MSK 2018


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.

> +{
> +       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?

Thanks,
             Dmitry


More information about the CRIU mailing list