summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2a9bdee)
raw | patch | inline | side by side (parent: 2a9bdee)
author | Florian Forster <octo@collectd.org> | |
Fri, 9 Sep 2016 14:50:06 +0000 (16:50 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Mon, 12 Sep 2016 07:28:37 +0000 (09:28 +0200) |
Fixes: #1914
src/daemon/common.c | patch | blob | history | |
src/daemon/common.h | patch | blob | history |
diff --git a/src/daemon/common.c b/src/daemon/common.c
index 05b119901ce2bf9a606a4e07c1ed45b7c2d78ce7..7806c716f5efc2eaa5a3031b9bf63cb06e937923 100644 (file)
--- a/src/daemon/common.c
+++ b/src/daemon/common.c
return (0);
} /* int parse_values */
+int parse_value_file (char const *path, value_t *ret_value, int ds_type)
+{
+ char buffer[256];
+
+ if (read_file_contents (path, buffer, sizeof (buffer)) < 0)
+ return errno;
+
+ strstripnewline (buffer);
+
+ return parse_value (buffer, ret_value, ds_type);
+} /* int parse_value_file */
+
#if !HAVE_GETPWNAM_R
int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
size_t buflen, struct passwd **pwbufp)
diff --git a/src/daemon/common.h b/src/daemon/common.h
index 720e5f1bc0a408f097fe1d586b5bbb26dda9bcce..9e2529326dbb871a72510fcf30b91a9b7cb7cb60 100644 (file)
--- a/src/daemon/common.h
+++ b/src/daemon/common.h
int parse_value (const char *value, value_t *ret_value, int ds_type);
int parse_values (char *buffer, value_list_t *vl, const data_set_t *ds);
+/* parse_value_file reads "path" and parses its content as an integer or
+ * floating point, depending on "ds_type". On success, the value is stored in
+ * "ret_value" and zero is returned. On failure, a non-zero value is returned. */
+int parse_value_file (char const *path, value_t *ret_value, int ds_type);
+
#if !HAVE_GETPWNAM_R
int getpwnam_r (const char *name, struct passwd *pwbuf, char *buf,
size_t buflen, struct passwd **pwbufp);