mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-03 07:45:17 +00:00
parse: add a helper to obtain an uptime
will be used in the next patch https://jira.sw.ru/browse/PSBM-67502 note: man for /proc/uptime says that uptime is in seconds and for now the format is "seconds.centiseconds", where ecentiseconds is 2 digits v8: add length specifier to parse only centiseconds Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This commit is contained in:
committed by
Andrei Vagin
parent
3930040274
commit
cf2f035d9f
@@ -108,5 +108,6 @@ int parse_children(pid_t pid, pid_t **_c, int *_n);
|
|||||||
|
|
||||||
extern bool is_vma_range_fmt(char *line);
|
extern bool is_vma_range_fmt(char *line);
|
||||||
extern void parse_vmflags(char *buf, u32 *flags, u64 *madv, int *io_pf);
|
extern void parse_vmflags(char *buf, u32 *flags, u64 *madv, int *io_pf);
|
||||||
|
extern int parse_uptime(struct timeval *_tv);
|
||||||
|
|
||||||
#endif /* __CR_PROC_PARSE_H__ */
|
#endif /* __CR_PROC_PARSE_H__ */
|
||||||
|
@@ -2712,3 +2712,27 @@ err:
|
|||||||
xfree(ch);
|
xfree(ch);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__maybe_unused int parse_uptime(struct timeval *_tv)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
_tv->tv_sec = sec;
|
||||||
|
_tv->tv_usec = csec * (USEC_PER_SEC / 100);
|
||||||
|
|
||||||
|
fclose(f);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user