/** * Attempts to convert a string log facility * to an actual syslog log facility, * @arg val The string value * @arg result The destination for the result * @return 1 on success, 0 on error. */ static int name_to_facility(const char *val, int *result) { int log_facility = LOG_LOCAL0; if (VAL_MATCH("local0")) { log_facility = LOG_LOCAL0; } else if (VAL_MATCH("local1")) { log_facility = LOG_LOCAL1; } else if (VAL_MATCH("local2")) { log_facility = LOG_LOCAL2; } else if (VAL_MATCH("local3")) { log_facility = LOG_LOCAL3; } else if (VAL_MATCH("local4")) { log_facility = LOG_LOCAL4; } else if (VAL_MATCH("local5")) { log_facility = LOG_LOCAL5; } else if (VAL_MATCH("local6")) { log_facility = LOG_LOCAL6; } else if (VAL_MATCH("local7")) { log_facility = LOG_LOCAL7; } else if (VAL_MATCH("user")) { log_facility = LOG_LOCAL7; } else if (VAL_MATCH("daemon")) { log_facility = LOG_LOCAL7; } else { log_facility = LOG_LOCAL0; } if (errno == EINVAL) { return 0; } *result = log_facility; return 1; }
/** * Attempts to convert a string to a boolean, * and write the value out. * @arg val The string value * @arg result The destination for the result * @return 1 on success, 0 on error. */ static bool value_to_bool(const char *val, bool *result) { #define VAL_MATCH(param) (strcasecmp(param, val) == 0) if (VAL_MATCH("true") || VAL_MATCH("yes") || VAL_MATCH("1")) { *result = true; return 1; } else if (VAL_MATCH("false") || VAL_MATCH("no") || VAL_MATCH("0")) { *result = false; return 1; } return 0; }
/** * Attempts to convert a string to a boolean, * and write the value out. * @arg val The string value * @arg result The destination for the result * @return 1 on success, 0 on error. */ static bool value_to_bool(const char *val, bool *result) { #define VAL_MATCH(param) (strcasecmp(param, val) == 0) if (VAL_MATCH("true") || VAL_MATCH("yes") || VAL_MATCH("1")) { *result = true; return 0; } else if (VAL_MATCH("false") || VAL_MATCH("no") || VAL_MATCH("0")) { *result = false; return 0; } puts("Couldn't determine value of daemonize"); return 1; }