mirror of
https://github.com/clearlinux/telemetrics-client.git
synced 2026-09-01 11:15:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df94f719ab | ||
|
|
0c34fab4fa | ||
|
|
bd51b7c692 | ||
|
|
77874c9c40 | ||
|
|
6a91a71475 | ||
|
|
0b10f69f2b | ||
|
|
b7f5eb0a7c | ||
|
|
4d32436b6c | ||
|
|
3a73ca4e75 | ||
|
|
b506773879 | ||
|
|
3b3f882c3a | ||
|
|
4f97b51f10 | ||
|
|
f3e29b5e5a | ||
|
|
5820a1b959 | ||
|
|
44d423a7c4 | ||
|
|
1bcaf35a6c | ||
|
|
00556dde05 | ||
|
|
d162311e31 | ||
|
|
f23bc1ae12 | ||
|
|
d0ee68ba43 | ||
|
|
9bb9288153 | ||
|
|
b9ec06fe9a | ||
|
|
32b306daa9 | ||
|
|
c3b8d81b6d | ||
|
|
f4f012af7b | ||
|
|
9db4e1d8c9 |
@@ -8,15 +8,13 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.event.pull_request.head.sha }}
|
||||
- name: install dependencies
|
||||
run: sudo apt-get install libcurl4-gnutls-dev valgrind libelf-dev libdw-dev
|
||||
- name: install check
|
||||
run: wget https://github.com/libcheck/check/releases/download/0.12.0/check-0.12.0.tar.gz &&
|
||||
tar xf check-0.12.0.tar.gz &&
|
||||
pushd check-0.12.0 &&
|
||||
./configure --prefix=/usr --libdir=/usr/lib/x86_64-linux-gnu &&
|
||||
make -j8 && sudo make install && popd
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get --fix-missing install libcurl4-gnutls-dev valgrind libelf-dev libdw-dev libjson-c-dev check
|
||||
- name: autogen
|
||||
run: sh autogen.sh
|
||||
- name: configure
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I build-aux/m4
|
||||
|
||||
EXTRA_DIST = \
|
||||
AUTHORS \
|
||||
LICENSE.LGPL-2.1
|
||||
LICENSE
|
||||
|
||||
DISTCHECK_CONFIGURE_FLAGS = \
|
||||
--with-systemdsystemunitdir=$$dc_install_base/$(systemdunitdir) \
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
## DISCONTINUATION OF PROJECT.
|
||||
|
||||
This project will no longer be maintained by Intel.
|
||||
|
||||
Intel will not provide or guarantee development of or support for this project, including but not limited to, maintenance, bug fixes, new releases or updates. Patches to this project are no longer accepted by Intel. If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the community, please create your own fork of the project.
|
||||
|
||||
Contact: webadmin@linux.intel.com
|
||||

|
||||
|
||||
Telemetrics-client
|
||||
@@ -333,7 +340,12 @@ $ org.clearlinux/hello/world Mon 2018-04-02 17:48:01 UTC a19a0d41ba16788881e
|
||||
$ hello
|
||||
```
|
||||
|
||||
## Using tarball
|
||||
|
||||
When building the telemetrics-client using the tarball, a signature is provided for
|
||||
validation. Please follow the steps outlined in the release's README.txt for guidance.
|
||||
|
||||
## Security Disclosures
|
||||
|
||||
To report a security issue or receive security advisories please follow procedures
|
||||
in this [link](https://01.org/security).
|
||||
in [link](security.md).
|
||||
|
||||
+5
-3
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([telemetrics-client], [2.3.4], [https://clearlinux.org/])
|
||||
AC_INIT([telemetrics-client], [2.4.3], [https://clearlinux.org/])
|
||||
AC_CONFIG_AUX_DIR([build-aux])
|
||||
AM_INIT_AUTOMAKE([1.14 -Wall -Werror -Wno-extra-portability foreign subdir-objects])
|
||||
AM_SILENT_RULES([yes])
|
||||
@@ -33,6 +33,7 @@ AX_VALGRIND_CHECK
|
||||
# check >= 0.9.12 is required for TAP output
|
||||
PKG_CHECK_MODULES([CHECK], [check >= 0.12])
|
||||
PKG_CHECK_MODULES([CURL], [libcurl])
|
||||
PKG_CHECK_MODULES([JSON_C], [json-c])
|
||||
AC_CHECK_LIB([elf], [elf_begin], [have_elflib=yes], [AC_MSG_ERROR([Unable to find libelf from elfutils])])
|
||||
AC_CHECK_LIB([dw], [dwfl_begin], [have_dwlib=yes], [AC_MSG_ERROR([Unable to find libdw from elfutils])])
|
||||
AS_IF([test "x$have_elflib" = "xyes" -a "x$have_dwlib" = "xyes"],
|
||||
@@ -49,6 +50,7 @@ AC_CHECK_HEADERS([elfutils/libdwfl.h])
|
||||
AC_CHECK_HEADERS([fcntl.h])
|
||||
AC_CHECK_HEADERS([getopt.h])
|
||||
AC_CHECK_HEADERS([inttypes.h])
|
||||
AC_CHECK_HEADERS([json-c/json.h])
|
||||
AC_CHECK_HEADERS([libelf.h])
|
||||
AC_CHECK_HEADERS([limits.h])
|
||||
AC_CHECK_HEADERS([stdarg.h])
|
||||
@@ -128,8 +130,8 @@ AC_ARG_WITH([loglevel], AS_HELP_STRING([--with-loglevel=NUM],
|
||||
AC_DEFINE_UNQUOTED([MAX_LOG_LEVEL], [${loglevel}], [Maximum log level for binaries])
|
||||
|
||||
AC_ARG_WITH([backendserveraddr], AS_HELP_STRING([--with-backendserveraddr=URI],
|
||||
[uri to telemetrics backend server @<:@default=https://clr.telemetry.intel.com/v2/collector@:>@]), [backendaddr=${withval}])
|
||||
test -z "${backendaddr}" && backendaddr=https://clr.telemetry.intel.com/v2/collector
|
||||
[uri to telemetrics backend server @<:@default=https://clr.telemetry.intel.com/v3/collector@:>@]), [backendaddr=${withval}])
|
||||
test -z "${backendaddr}" && backendaddr=https://clr.telemetry.intel.com/v3/collector
|
||||
AC_SUBST(BACKEND_ADDR, [${backendaddr}])
|
||||
|
||||
AC_ARG_ENABLE([logtype], AS_HELP_STRING([--enable-logtype],
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
# Security Policy
|
||||
Intel is committed to rapidly addressing security vulnerabilities affecting our
|
||||
customers and providing clear guidance on the solution, impact, severity and
|
||||
mitigation.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
Please report any security vulnerabilities in this project [utilizing the
|
||||
guidelines here](https://www.intel.com/content/www/us/en/security-center/vulnerability-handling-guidelines.html).
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
[Unit]
|
||||
Description=Telemetrics Kernel Log Scanner
|
||||
ConditionVirtualization=!container
|
||||
Requires=telemprobd.socket
|
||||
After=telemprobd.socket
|
||||
|
||||
|
||||
+2
-2
@@ -124,8 +124,8 @@ bool read_record(char *fullpath, char *headers[], char **body, char **cfg_file)
|
||||
}
|
||||
memset(*body, 0, (size_t)size);
|
||||
|
||||
//read rest of file
|
||||
size_t newlen = fread(*body, sizeof(char), (size_t)size, fp);
|
||||
//read rest of file. '-1' ensures it's null terminated
|
||||
size_t newlen = fread(*body, sizeof(char), (size_t)size - 1, fp);
|
||||
if (newlen == 0) {
|
||||
telem_perror("Error reading staged file");
|
||||
result = false;
|
||||
|
||||
@@ -421,6 +421,7 @@ static void print_record(char *record_id)
|
||||
recordfp = fopen(filepath, "r");
|
||||
if (!recordfp) {
|
||||
telem_log(LOG_INFO, "Could not open record %s: %s\n", record_id, strerror(errno));
|
||||
free(filepath);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -661,7 +662,8 @@ int prune_journal(struct TelemJournal *telem_journal, char *tmp_dir)
|
||||
telem_journal->fptr = fopen(telem_journal->journal_file, "a+");
|
||||
if (!telem_journal->fptr) {
|
||||
telem_log(LOG_ERR, "Error re-opening journal file\n");
|
||||
return rc;
|
||||
rc = 1;
|
||||
goto quit;
|
||||
}
|
||||
// update record count
|
||||
telem_journal->record_count = telem_journal->record_count - count;
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ endif
|
||||
%D%/iorecord.c \
|
||||
%D%/iorecord.h
|
||||
|
||||
%C%_telempostd_LDADD = $(CURL_LIBS) \
|
||||
%C%_telempostd_LDADD = $(CURL_LIBS) $(JSON_C_LIBS) \
|
||||
%D%/libtelem-shared.la \
|
||||
%D%/libtelemetry.la
|
||||
|
||||
|
||||
@@ -587,7 +587,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (core_file) {
|
||||
core_fd = open(core_file, O_RDONLY);
|
||||
core_fd = open(core_file, O_RDONLY|O_NOFOLLOW);
|
||||
if (core_fd == -1) {
|
||||
telem_perror("Failed to open input core file");
|
||||
goto fail;
|
||||
|
||||
+1
-1
@@ -159,7 +159,7 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
case 'H':
|
||||
str = "org.clearlinux/heartbeat/ping";
|
||||
memcpy(classification, str, strlen(str));
|
||||
memcpy(classification, str, strlen(str) + 1);
|
||||
break;
|
||||
case 'l':
|
||||
payload_options |= PAYLOAD_LOCALE;
|
||||
|
||||
@@ -44,14 +44,14 @@ int copy_file(char *src_file, char *dest_file)
|
||||
ssize_t bytes_read, bytes_written;
|
||||
int ret = -1;
|
||||
|
||||
src_fd = open(src_file, O_RDONLY);
|
||||
src_fd = open(src_file, O_RDONLY|O_NOFOLLOW);
|
||||
if (src_fd == -1) {
|
||||
telem_log(LOG_ERR, "Failed to open file %s:%s\n", src_file,
|
||||
strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
|
||||
dest_fd = open(dest_file, O_WRONLY | O_CREAT, 0644);
|
||||
dest_fd = open(dest_file, O_WRONLY|O_CREAT|O_NOFOLLOW, 0644);
|
||||
if (dest_fd == -1) {
|
||||
telem_log(LOG_ERR, "Failed to create file %s:%s\n", dest_file,
|
||||
strerror(errno));
|
||||
|
||||
+20
-8
@@ -25,6 +25,7 @@
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "spool.h"
|
||||
#include "telempostdaemon.h"
|
||||
@@ -149,25 +150,32 @@ void process_spooled_record(const char *spool_dir, char *name,
|
||||
}
|
||||
|
||||
(*records_processed)++;
|
||||
ret = stat(record_name, &buf);
|
||||
if (ret == -1) {
|
||||
telem_perror("Unable to stat record in spool");
|
||||
free(record_name);
|
||||
return;
|
||||
// Use file descriptor to mitigate TOCTOU
|
||||
int fd = open(record_name, O_RDONLY|O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
telem_perror("Unable to open record in spool");
|
||||
goto clean;
|
||||
}
|
||||
|
||||
if (fstat(fd, &buf) == -1) {
|
||||
telem_perror("Unable to fstat record in spool");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/*
|
||||
* If file is a regular file , if uid is diff than process uid
|
||||
* or if mtime is greater than record expiry delete the file
|
||||
* If file is a regular file, if uid is different than process uid,
|
||||
* or if mtime is greater than record expiry, delete the file.
|
||||
*/
|
||||
|
||||
if (record_expiry_config() == -1) {
|
||||
telem_log(LOG_ERR, "Invalid record expiry value\n");
|
||||
close(fd);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!S_ISREG(buf.st_mode) ||
|
||||
(current_time - buf.st_mtime > (record_expiry_config() * 60)) ||
|
||||
(buf.st_uid != getuid())) {
|
||||
(buf.st_uid != getuid())) {
|
||||
unlink(record_name);
|
||||
} else if (post_succeeded && *records_sent <= TM_SPOOL_MAX_SEND_RECORDS) {
|
||||
transmit_spooled_record(record_name, &post_succeeded, buf.st_size);
|
||||
@@ -194,6 +202,9 @@ void process_spooled_record(const char *spool_dir, char *name,
|
||||
}
|
||||
}
|
||||
}
|
||||
exit:
|
||||
close(fd);
|
||||
clean:
|
||||
free(record_name);
|
||||
}
|
||||
|
||||
@@ -344,6 +355,7 @@ int spool_record_compare(const void *entrya, const void *entryb, void *path)
|
||||
ret = stat(pathb, &statentryb);
|
||||
if (ret == -1) {
|
||||
telem_log(LOG_ERR, "Unable to stat %s: %s\n", patha, strerror(errno));
|
||||
free(patha);
|
||||
free(pathb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -428,7 +428,7 @@ static int telemctl_opt_in(void)
|
||||
|
||||
/* Create a brand new file TM_OPT_IN, we may fail because the file exists already.
|
||||
* In that case we are already opted in and we are done here. */
|
||||
int fd = open(TM_OPT_IN, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
|
||||
int fd = open(TM_OPT_IN, O_CREAT|O_EXCL|O_WRONLY, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH|O_NOFOLLOW);
|
||||
if (fd == -1) {
|
||||
if (errno == EEXIST) {
|
||||
fprintf(stderr, "Already opted in. Nothing to do.\n");
|
||||
|
||||
+8
-7
@@ -49,9 +49,9 @@ static int version_file(void)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = open(TM_SITE_VERSION_FILE, O_RDONLY);
|
||||
fd = open(TM_SITE_VERSION_FILE, O_RDONLY|O_NOFOLLOW);
|
||||
if (fd < 0) {
|
||||
fd = open(TM_DIST_VERSION_FILE, O_RDONLY);
|
||||
fd = open(TM_DIST_VERSION_FILE, O_RDONLY|O_NOFOLLOW);
|
||||
}
|
||||
|
||||
return fd;
|
||||
@@ -977,17 +977,18 @@ int tm_set_payload(struct telem_ref *t_ref, char *payload)
|
||||
size_t payload_len;
|
||||
int ret = 0;
|
||||
|
||||
payload_len = strlen((char *)payload);
|
||||
|
||||
if (payload_len > MAX_PAYLOAD_LENGTH) {
|
||||
if (payload == NULL) {
|
||||
telem_log(LOG_WARNING, "payload pointer is NULL\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
payload_len = strnlen(payload, MAX_PAYLOAD_LENGTH);
|
||||
|
||||
if (payload_is_ascii(payload, payload_len) != 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
t_ref->record->payload = strdup(payload);
|
||||
t_ref->record->payload = strndup(payload, payload_len);
|
||||
|
||||
if (!t_ref->record->payload) {
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
@@ -1273,7 +1274,7 @@ int tm_send_record(struct telem_ref *t_ref)
|
||||
*/
|
||||
record_size = (2 * sizeof(uint32_t)) + total_size + 1;
|
||||
|
||||
data = calloc(sizeof(char), record_size);
|
||||
data = (char *)calloc(sizeof(char), record_size);
|
||||
if (!data) {
|
||||
telem_log(LOG_CRIT, "CRIT: Out of memory\n");
|
||||
close(sfd);
|
||||
|
||||
+85
-39
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* This program is part of the Clear Linux Project
|
||||
*
|
||||
* Copyright 2018 Intel Corporation
|
||||
* Copyright 2018-2023 Intel Corporation
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms and conditions of the GNU Lesser General Public License, as
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <curl/curl.h>
|
||||
#include <json-c/json.h>
|
||||
#include <sys/signalfd.h>
|
||||
|
||||
#include "log.h"
|
||||
@@ -210,13 +211,47 @@ size_t write_callback(char *ptr, size_t size, size_t nmemb, void *userdata)
|
||||
return size * nmemb;
|
||||
}
|
||||
|
||||
char *create_json_message(char *tm_headers[], char *tm_payload)
|
||||
{
|
||||
/*
|
||||
* Embed the telemetry record headers and the telemetry payload into a
|
||||
* JSON object string.
|
||||
*/
|
||||
char *json_string = NULL;
|
||||
json_object *root = json_object_new_object();
|
||||
|
||||
/* Add the telemetry record headers */
|
||||
|
||||
for (int i = 0; i < NUM_HEADERS; i++) {
|
||||
/* ex: arch: x86_64 */
|
||||
|
||||
/* Split the header field into name/value */
|
||||
strtok(tm_headers[i], ":");
|
||||
json_object *value = json_object_new_string(strtok(NULL, " "));
|
||||
json_object_object_add(root, tm_headers[i], value);
|
||||
}
|
||||
json_object *payload = json_object_new_string(tm_payload);
|
||||
json_object_object_add(root, "payload", payload);
|
||||
|
||||
/* Keep our own copy of the json string */
|
||||
json_string = strdup(json_object_to_json_string_ext(root,
|
||||
JSON_C_TO_STRING_PLAIN |
|
||||
JSON_C_TO_STRING_NOSLASHESCAPE));
|
||||
|
||||
/* Free the memory associated with the JSON objects */
|
||||
json_object_put(root);
|
||||
|
||||
return json_string;
|
||||
}
|
||||
|
||||
bool post_record_http(char *headers[], char *body, char *cfg)
|
||||
{
|
||||
CURL *curl;
|
||||
int res = 0;
|
||||
char *content = "Content-Type: application/text";
|
||||
char *content = "Content-Type: application/json";
|
||||
struct curl_slist *custom_headers = NULL;
|
||||
char errorbuf[CURL_ERROR_SIZE];
|
||||
char *json_body = NULL;
|
||||
long http_response = 0;
|
||||
const char *cert_file = get_cainfo_config();
|
||||
const char *tid_header = get_tidheader_config();
|
||||
@@ -231,12 +266,15 @@ bool post_record_http(char *headers[], char *body, char *cfg)
|
||||
// settings than explicitly requested.
|
||||
// However, report success so the record gets deleted.
|
||||
res = 0;
|
||||
goto Done;
|
||||
goto done;
|
||||
}
|
||||
reload_config();
|
||||
telem_debug("DEBUG: override server_addr:%s\n", server_addr_config());
|
||||
}
|
||||
|
||||
// Generate the JSON message body
|
||||
json_body = create_json_message(headers, body);
|
||||
|
||||
// Initialize the libcurl global environment once per POST. This lets us
|
||||
// clean up the environment after each POST so that when the daemon is
|
||||
// sitting idle, it will be consuming as little memory as possible.
|
||||
@@ -250,35 +288,35 @@ bool post_record_http(char *headers[], char *body, char *cfg)
|
||||
/* TODO: check if memory needs to be released */
|
||||
}
|
||||
|
||||
// Errors for any curl_easy_* functions will store nice error messages
|
||||
// in errorbuf, so send log messages with errorbuf contents
|
||||
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuf);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, server_addr_config());
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L);
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L);
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
||||
#ifdef DEBUG
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);
|
||||
#endif
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
|
||||
for (int i = 0; i < NUM_HEADERS; i++) {
|
||||
custom_headers = curl_slist_append(custom_headers, headers[i]);
|
||||
}
|
||||
custom_headers = curl_slist_append(custom_headers, tid_header);
|
||||
// This should be set by probes/libtelemetry in the future
|
||||
custom_headers = curl_slist_append(custom_headers, content);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, custom_headers);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body);
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(body));
|
||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);
|
||||
// Errors for any curl_easy_* functions will store nice error messages
|
||||
// in errorbuf, so send log messages with errorbuf contents
|
||||
if (curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorbuf) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_URL, server_addr_config()) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 5L) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10L) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_POST, 1) != CURLE_OK ||
|
||||
#ifdef DEBUG
|
||||
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) != CURLE_OK ||
|
||||
#endif
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, custom_headers) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, json_body) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(json_body)) != CURLE_OK ||
|
||||
curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY) != CURLE_OK) {
|
||||
telem_log(LOG_ERR, "curl_easy_setopt(): Failed to set one or more options\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if (strlen(cert_file) > 0) {
|
||||
if (access(cert_file, F_OK) != -1) {
|
||||
curl_easy_setopt(curl, CURLOPT_CAINFO, cert_file);
|
||||
if (curl_easy_setopt(curl, CURLOPT_CAINFO, cert_file) != CURLE_OK) {
|
||||
telem_log(LOG_ERR, "curl_easy_setopt(): Failed to set CAINFO\n");
|
||||
goto exit;
|
||||
}
|
||||
telem_log(LOG_INFO, "cafile was set to %s\n", cert_file);
|
||||
}
|
||||
}
|
||||
@@ -309,12 +347,17 @@ bool post_record_http(char *headers[], char *body, char *cfg)
|
||||
telem_log(LOG_INFO, "Record sent successfully\n");
|
||||
}
|
||||
|
||||
exit:
|
||||
curl_slist_free_all(custom_headers);
|
||||
curl_easy_cleanup(curl);
|
||||
|
||||
curl_global_cleanup();
|
||||
|
||||
Done:
|
||||
done:
|
||||
if (json_body) {
|
||||
free(json_body);
|
||||
json_body = NULL;
|
||||
}
|
||||
|
||||
if (saved_config_file != NULL) {
|
||||
if (set_config_file(saved_config_file) != 0) {
|
||||
telem_log(LOG_ERR, "set-config_file(): Failed to set %s",
|
||||
@@ -490,7 +533,7 @@ static bool deliver_record(TelemPostDaemon *daemon, char *headers[], char *body,
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemon)
|
||||
bool process_staged_record(char *filename, TelemPostDaemon *daemon)
|
||||
{
|
||||
int k;
|
||||
bool ret = false;
|
||||
@@ -530,20 +573,12 @@ bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemo
|
||||
goto end_processing_file;
|
||||
}
|
||||
|
||||
/* Retries should not be recorded */
|
||||
if (is_retry == false) {
|
||||
/** Journal entry **/
|
||||
save_entry_to_journal(daemon, current_time, headers);
|
||||
/** Record retention **/
|
||||
apply_retention_policies(daemon, body);
|
||||
}
|
||||
|
||||
/** Record delivery **/
|
||||
if (!daemon->record_server_delivery_enabled) {
|
||||
telem_log(LOG_INFO, "record server delivery disabled\n");
|
||||
// Not an error condition
|
||||
ret = true;
|
||||
goto end_processing_file;
|
||||
goto end_record_delivery;
|
||||
}
|
||||
|
||||
/** Spool policies **/
|
||||
@@ -571,6 +606,17 @@ bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemo
|
||||
/** Deliver or spool **/
|
||||
ret = deliver_record(daemon, headers, body, cfg_file);
|
||||
|
||||
end_record_delivery:
|
||||
/** Save record once it is properly delivered, if record
|
||||
* is spooled the record is not saved to journal until
|
||||
* delievered on a re-try **/
|
||||
if (ret) {
|
||||
/** Save to journal **/
|
||||
save_entry_to_journal(daemon, current_time, headers);
|
||||
/** Record retention **/
|
||||
apply_retention_policies(daemon, body);
|
||||
}
|
||||
|
||||
end_processing_file:
|
||||
/** Update spool size if record will be removed **/
|
||||
if (ret) {
|
||||
@@ -625,7 +671,7 @@ int staging_records_loop(TelemPostDaemon *daemon)
|
||||
telem_log(LOG_ERR, "Failed to allocate memory for staging record full path\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (process_staged_record(record_path, true, daemon)) {
|
||||
if (process_staged_record(record_path, daemon)) {
|
||||
unlink(record_path);
|
||||
processed++;
|
||||
}
|
||||
@@ -721,7 +767,7 @@ void run_daemon(TelemPostDaemon *daemon)
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
/* Process inotify event */
|
||||
if (process_staged_record(record_name, false, daemon)) {
|
||||
if (process_staged_record(record_name, daemon)) {
|
||||
unlink(record_name);
|
||||
}
|
||||
free(record_name);
|
||||
|
||||
@@ -85,11 +85,9 @@ void close_daemon(TelemPostDaemon *daemon);
|
||||
* Processed record written on disk
|
||||
*
|
||||
* @param filename a pointor to record on disk
|
||||
* @param is_retry a boolean value that indicates if
|
||||
* the record has been previously processed.
|
||||
* @param daemon post to telemetry post daemon
|
||||
*/
|
||||
bool process_staged_record(char *filename, bool is_retry, TelemPostDaemon *daemon);
|
||||
bool process_staged_record(char *filename, TelemPostDaemon *daemon);
|
||||
|
||||
/**
|
||||
* Scans staging directory to process files that were
|
||||
@@ -107,6 +105,7 @@ int staging_records_loop(TelemPostDaemon *daemon);
|
||||
* @param body a pointer to the payload
|
||||
* @param cfg_file a pointer to a non-default configuration
|
||||
* file to be used.
|
||||
* @return true if successful, false otherwise
|
||||
*/
|
||||
bool post_record_http(char *headers[], char *body, char *cfg_file);
|
||||
|
||||
|
||||
+1
-1
@@ -143,7 +143,7 @@ int get_random_id(char **buff)
|
||||
int frandom = -1;
|
||||
uint64_t random_id[2] = { '\0' };
|
||||
|
||||
frandom = open("/dev/urandom", O_RDONLY);
|
||||
frandom = open("/dev/urandom", O_RDONLY|O_NOFOLLOW);
|
||||
if (frandom < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
+4
-4
@@ -62,7 +62,7 @@ START_TEST(check_handle_client_with_no_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/empty_message";
|
||||
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
@@ -75,7 +75,7 @@ START_TEST(check_handle_client_with_incorrect_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/incorrect_message";
|
||||
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ START_TEST(check_process_record_with_correct_size_and_data)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/correct_message";
|
||||
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
ck_assert(success == true);
|
||||
}
|
||||
END_TEST
|
||||
@@ -100,7 +100,7 @@ START_TEST(check_process_record_with_incorrect_headers)
|
||||
bool success;
|
||||
char *filename = ABSTOPSRCDIR "/tests/telempostd/incorrect_headers";
|
||||
|
||||
success = process_staged_record(filename, false, &tdaemon);
|
||||
success = process_staged_record(filename, &tdaemon);
|
||||
// Return true to remove corrupted record
|
||||
ck_assert(success == true);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,7 @@ EXTRA_DIST += \
|
||||
%C%_check_postd_LDADD = \
|
||||
@CHECK_LIBS@ \
|
||||
@CURL_LIBS@ \
|
||||
@JSON_C_LIBS@ \
|
||||
$(top_builddir)/src/libtelem-shared.la
|
||||
|
||||
if LOG_SYSTEMD
|
||||
|
||||
Reference in New Issue
Block a user