mirror of
https://github.com/clearlinux/telemetrics-client.git
synced 2026-09-01 19:21:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
071ad2c883 | ||
|
|
72ea0d9360 | ||
|
|
49823eae83 | ||
|
|
a12c1d8761 | ||
|
|
eb1e670b5f |
+1
-1
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([telemetrics-client], [2.2.3], [https://clearlinux.org/])
|
||||
AC_INIT([telemetrics-client], [2.3.1], [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])
|
||||
|
||||
@@ -7,7 +7,7 @@ ConditionPathExists=/sys/firmware/acpi/tables/data/BERT
|
||||
|
||||
[Service]
|
||||
ExecStart=@bindir@/bertprobe
|
||||
User=telemetry
|
||||
User=root
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
|
||||
+83
-7
@@ -40,6 +40,77 @@ void print_usage(char *prog)
|
||||
printf(" -V, --version Print the program version\n");
|
||||
}
|
||||
|
||||
struct acpi_generic_error_data_entry {
|
||||
uint8_t section_type[16];
|
||||
uint32_t error_severity;
|
||||
uint16_t revision;
|
||||
uint8_t validation_bits;
|
||||
uint8_t flags;
|
||||
uint32_t error_data_length;
|
||||
uint8_t fru_ld[16];
|
||||
uint8_t fru_text[16];
|
||||
uint64_t timestamp;
|
||||
uint8_t data[1]; // error_data_length
|
||||
} __attribute__((packed));
|
||||
|
||||
struct acpi_generic_error_status_block {
|
||||
// Bit [0] - Uncorrectable Error Valid
|
||||
// Bit [1] - Correctable Error Valid
|
||||
// Bit [2] - Multiple Uncorrectable Errors
|
||||
// Bit [3] - Multiple Correctable Errors
|
||||
// Bit [13:4] - Error Data Entry Count: Number of Error Data Entries found in the Data section.
|
||||
// Bit [31:14] - Reserved
|
||||
uint32_t block_status;
|
||||
uint32_t raw_data_offset;
|
||||
// Length in bytes of the generic error data
|
||||
uint32_t data_length;
|
||||
uint32_t error_severity;
|
||||
// The information contained in this field is a collection of zero
|
||||
// or more Generic Error Data Entrie
|
||||
struct acpi_generic_error_data_entry data[];
|
||||
} __attribute__((packed));
|
||||
|
||||
static int check_bert_file(const char *filename, char *buff, size_t buff_size) {
|
||||
|
||||
int ret = EXIT_FAILURE;
|
||||
size_t len;
|
||||
uint32_t block_status;
|
||||
FILE *fh = fopen(filename, "rb");
|
||||
|
||||
if (fh == NULL) {
|
||||
telem_log(LOG_ERR, "Failed to open: %s\n", filename);
|
||||
goto done;
|
||||
}
|
||||
|
||||
len = fread(&block_status, 1, sizeof(block_status), fh);
|
||||
if (ferror(fh) || (len != sizeof(block_status))){
|
||||
telem_log(LOG_ERR, "Error reading block_status: %s\n", filename);
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Check the "Error Data Entry Count", if 0 then nothing
|
||||
* to report */
|
||||
|
||||
if ((block_status & 0x3FFF) != 0) {
|
||||
rewind(fh);
|
||||
|
||||
/* nc_b64enc_file returns 1 in success and 0 in failure */
|
||||
if (nc_b64enc_file(fh, buff, buff_size) == 0) {
|
||||
telem_log(LOG_ERR, "Failed to read payload from: %s\n", filename);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
ret = EXIT_SUCCESS;
|
||||
done:
|
||||
if (fh) {
|
||||
fclose(fh);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct telem_ref *tm_handle = NULL;
|
||||
@@ -79,29 +150,34 @@ int main(int argc, char **argv)
|
||||
|
||||
payload = calloc(sizeof(char), MAX_PAYLOAD_LENGTH);
|
||||
if (!payload) {
|
||||
printf("Unable to allocate more memory.\n");
|
||||
telem_log(LOG_ERR, "Unable to allocate more memory.\n");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
if (!(ret = nc_b64enc_filename(bert_record_file, payload, MAX_PAYLOAD_LENGTH))) {
|
||||
printf("Failed to read payload from: %s\n", bert_record_file);
|
||||
ret = EXIT_FAILURE;
|
||||
ret = check_bert_file(bert_record_file, payload, MAX_PAYLOAD_LENGTH);
|
||||
if (ret == EXIT_FAILURE) {
|
||||
goto done;
|
||||
} else {
|
||||
if (payload[0] == 0) {
|
||||
/* Nothing to report */
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
/* Valid payload, send the record */
|
||||
if ((ret = tm_create_record(&tm_handle, severity, classification,
|
||||
payload_version)) < 0) {
|
||||
printf("Failed to create record: %s\n", strerror(-ret));
|
||||
telem_log(LOG_ERR, "Failed to create record: %s\n", strerror(-ret));
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = tm_set_payload(tm_handle, payload)) < 0) {
|
||||
printf("Failed to set record payload: %s\n", strerror(-ret));
|
||||
telem_log(LOG_ERR, "Failed to set record payload: %s\n", strerror(-ret));
|
||||
goto done;
|
||||
}
|
||||
|
||||
if ((ret = tm_send_record(tm_handle)) < 0) {
|
||||
printf("Failed to send record to daemon: %s\n", strerror(-ret));
|
||||
telem_log(LOG_ERR, "Failed to send record to daemon: %s\n", strerror(-ret));
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
||||
+12
-11
@@ -69,6 +69,7 @@ static int telemctl_opt_in(void);
|
||||
static int telemctl_journal(char *);
|
||||
|
||||
struct telemcmd {
|
||||
bool root;
|
||||
char *cmd;
|
||||
union {
|
||||
int (*f1)(void);
|
||||
@@ -78,13 +79,13 @@ struct telemcmd {
|
||||
};
|
||||
|
||||
static struct telemcmd commands[] = {
|
||||
{"stop", {.f1=telemctl_stop}, "Stops all running telemetry services" },
|
||||
{"start", {.f1=telemctl_start}, "Starts all telemetry services" },
|
||||
{"restart", {.f1=telemctl_restart}, "Restarts all telemetry services" },
|
||||
{"is-active", {.f1=telemctl_is_active},"Checks if telemprobd and telempostd are active" },
|
||||
{"opt-in", {.f1=telemctl_opt_in}, "Opts in to telemetry, and starts telemetry services" },
|
||||
{"opt-out", {.f1=telemctl_opt_out}, "Opts out of telemetry, and stops telemetry services" },
|
||||
{"journal", {.f2=telemctl_journal}, "Prints telemetry journal contents. Use -h argument with\n command for more options"}
|
||||
{true, "stop", {.f1=telemctl_stop}, "Stops all running telemetry services" },
|
||||
{true, "start", {.f1=telemctl_start}, "Starts all telemetry services" },
|
||||
{true, "restart", {.f1=telemctl_restart}, "Restarts all telemetry services" },
|
||||
{false, "is-active", {.f1=telemctl_is_active},"Checks if telemprobd and telempostd are active" },
|
||||
{true, "opt-in", {.f1=telemctl_opt_in}, "Opts in to telemetry, and starts telemetry services" },
|
||||
{true, "opt-out", {.f1=telemctl_opt_out}, "Opts out of telemetry, and stops telemetry services" },
|
||||
{true, "journal", {.f2=telemctl_journal}, "Prints telemetry journal contents. Use -h argument with\n command for more options"}
|
||||
};
|
||||
|
||||
static int syscmd(char *cmd, char *buff, int bufflen)
|
||||
@@ -396,9 +397,9 @@ static int telemctl_opt_out(void)
|
||||
fprintf(stderr, "Already opted out. Nothing to do.\n");
|
||||
return 0;
|
||||
}
|
||||
fprintf(stderr, "Failed to remove %s.\n", TM_OPT_IN);
|
||||
fprintf(stderr, "Failed to remove %s.\n", TM_OPT_IN);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = telemctl_stop();
|
||||
ret |= telemctl_remove_work_dirs();
|
||||
@@ -425,7 +426,7 @@ static int telemctl_opt_in(void)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Create a brand new file TM_OPT_IN, we maight fail because the file exists already.
|
||||
/* 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);
|
||||
if (fd == -1) {
|
||||
@@ -521,7 +522,7 @@ int main(int argc, char **argv)
|
||||
|
||||
for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) {
|
||||
if (strcmp(commands[i].cmd, argv[1]) == 0) {
|
||||
if (!is_root) {
|
||||
if (commands[i].root == true && is_root == false) {
|
||||
fprintf(stderr, "Must be root to run this command. Exiting...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user