summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d75a4d)
raw | patch | inline | side by side (parent: 1d75a4d)
author | Rinigus <rinigus.git@gmail.com> | |
Sat, 17 Sep 2016 10:07:26 +0000 (13:07 +0300) | ||
committer | Rinigus <rinigus.git@gmail.com> | |
Sat, 17 Sep 2016 10:13:48 +0000 (13:13 +0300) |
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 e2c872cc1ce819d562e5063f40e261c98cd43b19..d2fae5710bd39c62e78118612d0f2452a6df08d5 100644 (file)
--- a/src/daemon/common.c
+++ b/src/daemon/common.c
} /* }}} int parse_identifier_vl */
int parse_value (const char *value_orig, value_t *ret_value, int ds_type)
+{
+ return parse_value_ext(value_orig, ret_value, ds_type, "");
+}
+
+int parse_value_ext (const char *value_orig, value_t *ret_value, int ds_type, const char *error_identifier)
{
char *value;
char *endptr = NULL;
default:
sfree (value);
- ERROR ("parse_value: Invalid data source type: %i.", ds_type);
+ ERROR ("parse_value %s: Invalid data source type: %i.", error_identifier, ds_type);
return -1;
}
if (value == endptr) {
- ERROR ("parse_value: Failed to parse string as %s: %s.",
+ ERROR ("parse_value %s: Failed to parse string as %s: %s.", error_identifier,
DS_TYPE_TO_STRING (ds_type), value);
sfree (value);
return -1;
}
else if ((NULL != endptr) && ('\0' != *endptr))
- INFO ("parse_value: Ignoring trailing garbage \"%s\" after %s value. "
- "Input string was \"%s\".",
+ INFO ("parse_value %s: Ignoring trailing garbage \"%s\" after %s value. "
+ "Input string was \"%s\".", error_identifier,
endptr, DS_TYPE_TO_STRING (ds_type), value_orig);
sfree (value);
int parse_value_file (char const *path, value_t *ret_value, int ds_type)
{
+ FILE *fh;
char buffer[256];
- if (read_file_contents (path, buffer, sizeof (buffer)) < 0)
- return errno;
+ fh = fopen (path, "r");
+ if (fh == NULL)
+ return (-1);
+
+ if (fgets (buffer, sizeof (buffer), fh) == NULL)
+ {
+ fclose (fh);
+ return (-1);
+ }
- strstripnewline (buffer);
+ fclose (fh);
- return parse_value (buffer, ret_value, ds_type);
+ return parse_value_ext (buffer, ret_value, ds_type, path);
} /* int parse_value_file */
#if !HAVE_GETPWNAM_R
diff --git a/src/daemon/common.h b/src/daemon/common.h
index 6d01ca4bdeef5e3b1a74bea55c1686bcddb9a5cb..87dd4a047c448b42239bf63604df1da85ca723f6 100644 (file)
--- a/src/daemon/common.h
+++ b/src/daemon/common.h
char **ret_type, char **ret_type_instance);
int parse_identifier_vl (const char *str, value_list_t *vl);
int parse_value (const char *value, value_t *ret_value, int ds_type);
+int parse_value_ext (const char *value, value_t *ret_value, int ds_type, const char *error_identifier);
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