diff options
author | Lukasz Stanislawski <l.stanislaws@samsung.com> | 2018-05-14 14:52:41 +0200 |
---|---|---|
committer | Lukasz Stanislawski <l.stanislaws@samsung.com> | 2018-06-12 10:07:17 +0000 |
commit | 11e2e6f742e2a3ce1928156004782f6c3da083a3 (patch) | |
tree | 2136b7888f9f40803925308c2bf2a08c45229334 | |
parent | efa20431292aaa7bfcb0b0cce7a444cd4a130481 (diff) | |
download | ttsd-worker-task-11e2e6f742e2a3ce1928156004782f6c3da083a3.tar.gz ttsd-worker-task-11e2e6f742e2a3ce1928156004782f6c3da083a3.tar.bz2 ttsd-worker-task-11e2e6f742e2a3ce1928156004782f6c3da083a3.zip |
procfs: implement reading uptime
Change-Id: Ibed295319c087196cc551f1cbb1d2384465d2c61
-rw-r--r-- | src/procfs.c | 24 | ||||
-rw-r--r-- | src/procfs.h | 2 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/procfs.c b/src/procfs.c index 346a151..95478a2 100644 --- a/src/procfs.c +++ b/src/procfs.c @@ -21,6 +21,7 @@ #include "err-check.h" #define LOADAVG_FILEPATH "/proc/loadavg" +#define UPTIME_FILEPATH "/proc/uptime" int procfs_read_system_load_average(struct procfs_load_average_info *info) { @@ -74,9 +75,28 @@ int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info return -1; } -int procfs_read_uptime(int *uptime) +int procfs_read_uptime(unsigned long *uptime) { - return -1; + ON_NULL_RETURN_VAL(uptime, -1); + + double duptime; + + FILE *uptime_fp = fopen(UPTIME_FILEPATH, "r"); + if (!uptime_fp) { + ERR("failed to open " UPTIME_FILEPATH); + return -1; + } + + if (fscanf(uptime_fp, "%lf ", &duptime) != 1) { + ERR("failed to read " UPTIME_FILEPATH); + fclose(uptime_fp); + return -1; + } + + fclose(uptime_fp); + *uptime = (unsigned long)duptime; + + return 0; } int procfs_read_cpu_count(int *cpu_count) diff --git a/src/procfs.h b/src/procfs.h index 734bd23..acedc9f 100644 --- a/src/procfs.h +++ b/src/procfs.h @@ -137,7 +137,7 @@ int procfs_read_process_cpu_usage(int pid, struct procfs_process_cpu_usage_info * @param[out] uptime Number of seconds after boot * @return: 0 on success, other value on error */ -int procfs_read_uptime(int *uptime); +int procfs_read_uptime(unsigned long *uptime); /** * @brief Parses information from /sys/devices/system/cpu/possible |