summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukasz Stanislawski <l.stanislaws@samsung.com>2018-06-15 09:24:22 +0000
committerGerrit Code Review <gerrit@review.ap-northeast-2.compute.internal>2018-06-15 09:24:22 +0000
commite7112bd7d40b979a9af64dea22a4a8a5979783c9 (patch)
treedd0a7cde5092f4935d7cc68c6d619fb391fb38cb
parentaaac6a3c6b463fcc63d858236e48f7cbe4e2bcfe (diff)
parent11e2e6f742e2a3ce1928156004782f6c3da083a3 (diff)
downloadttsd-worker-task-e7112bd7d40b979a9af64dea22a4a8a5979783c9.tar.gz
ttsd-worker-task-e7112bd7d40b979a9af64dea22a4a8a5979783c9.tar.bz2
ttsd-worker-task-e7112bd7d40b979a9af64dea22a4a8a5979783c9.zip
Merge "procfs: implement reading uptime"
-rw-r--r--src/procfs.c24
-rw-r--r--src/procfs.h2
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