params->msg = create_glued_string(argv + optind, argc - optind);
}
-void send_log(struct parsed_params *params)
+int send_log(struct parsed_params *params)
{
unsigned i;
+ int r = EXIT_SUCCESS;
struct timespec start, end;
assert(params);
for (i = 0; i < params->count; ++i) {
dlog_error_e ret = __dlog_print(params->buffer, params->priority, params->tag, "%s", params->msg);
- if (ret != DLOG_ERROR_NONE) {
- // Ignore for now because the API does not actually return DLOG_ERROR_NONE on success.
- // printf("Log #%d: error %d\n", i, ret);
+ if (ret < 0) {
+ r = EXIT_FAILURE;
+ fprintf(stderr, "Log #%d: error %d\n", i, ret);
}
}
clock_gettime(CLOCK_MONOTONIC, &end);
printf("Sending log took %ld us\n", (end.tv_sec - start.tv_sec)*1000000 + (end.tv_nsec - start.tv_nsec) / 1000);
}
+ return r;
}
int send_from_stdin(struct parsed_params *params)
{
+ int r = EXIT_SUCCESS;
params->msg = malloc(LOG_MAX_PAYLOAD_SIZE);
if (!params->msg)
return EXIT_FAILURE;
- while (fgets(params->msg, LOG_MAX_PAYLOAD_SIZE, stdin) != NULL)
- send_log(params);
+ while (fgets(params->msg, LOG_MAX_PAYLOAD_SIZE, stdin) != NULL) {
+ if (send_log(params) == EXIT_FAILURE)
+ r = EXIT_FAILURE;
+ }
free(params->msg);
- return EXIT_SUCCESS;
+ return r;
}
void print_help(const char *progname)
return send_from_stdin(¶ms);
}
- send_log(¶ms);
+ int ret = send_log(¶ms);
free(params.msg);
-
- return EXIT_SUCCESS;
+ return ret;
}