mirror of
https://github.com/clearlinux/telemetrics-client.git
synced 2026-09-01 11:15:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
913cbb1c1e | ||
|
|
d3ce2f435c | ||
|
|
d0a3e6bafa |
+1
-1
@@ -2,7 +2,7 @@
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([telemetrics-client], [1.13.0], [https://clearlinux.org/])
|
||||
AC_INIT([telemetrics-client], [1.14.0], [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])
|
||||
|
||||
+4
-1
@@ -33,7 +33,10 @@ static const char *header_names[] = {
|
||||
TM_SYSTEM_BUILD_STR,
|
||||
TM_KERNEL_VERSION_STR,
|
||||
TM_PAYLOAD_VERSION_STR,
|
||||
TM_SYSTEM_NAME_STR
|
||||
TM_SYSTEM_NAME_STR,
|
||||
TM_BOARD_NAME_STR,
|
||||
TM_CPU_MODEL_STR,
|
||||
TM_BIOS_VERSION_STR
|
||||
};
|
||||
|
||||
const char *get_header_name(int ind)
|
||||
|
||||
+7
-1
@@ -35,6 +35,9 @@
|
||||
#define TM_KERNEL_VERSION 8
|
||||
#define TM_PAYLOAD_VERSION 9
|
||||
#define TM_SYSTEM_NAME 10
|
||||
#define TM_BOARD_NAME 11
|
||||
#define TM_CPU_MODEL 12
|
||||
#define TM_BIOS_VERSION 13
|
||||
|
||||
#define TM_RECORD_VERSION_STR "record_format_version"
|
||||
#define TM_CLASSIFICATION_STR "classification"
|
||||
@@ -47,8 +50,11 @@
|
||||
#define TM_KERNEL_VERSION_STR "kernel_version"
|
||||
#define TM_PAYLOAD_VERSION_STR "payload_format_version"
|
||||
#define TM_SYSTEM_NAME_STR "system_name"
|
||||
#define TM_BOARD_NAME_STR "board_name"
|
||||
#define TM_CPU_MODEL_STR "cpu_model"
|
||||
#define TM_BIOS_VERSION_STR "bios_version"
|
||||
|
||||
#define NUM_HEADERS 11
|
||||
#define NUM_HEADERS 14
|
||||
|
||||
/* For internal library usage. Bump the version whenever we change the record
|
||||
* structure (e.g. adding or removing a header field). Note that the value
|
||||
|
||||
@@ -71,7 +71,6 @@ static char unknown_class[30] = "org.clearlinux/crash/unknown";
|
||||
static char temp_core[] = "/tmp/corefile-XXXXXX";
|
||||
static bool keep_core = false;
|
||||
|
||||
|
||||
static const Dwfl_Callbacks cb =
|
||||
{
|
||||
.find_elf = dwfl_build_id_find_elf,
|
||||
|
||||
+158
@@ -400,6 +400,62 @@ static int set_timestamp_header(struct telem_ref *t_ref)
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets cpu model for telemetry record. The information from cpu is extracted
|
||||
* from /proc/cpuinfo, specifically "model name" attribute.
|
||||
*
|
||||
* @param t_ref Telemetry Record reference obtained from tm_create_record.
|
||||
*
|
||||
* @return 0 if successful, or a negative errno-style value if not.
|
||||
*
|
||||
*/
|
||||
static int set_cpu_model_header(struct telem_ref *t_ref)
|
||||
{
|
||||
FILE *fs = NULL;
|
||||
char buf[SMALL_LINE_BUF] = { 0 };
|
||||
char *model_name = NULL;
|
||||
const char *attr_name = "model name";
|
||||
int status = 0;
|
||||
size_t attr_len = strlen(attr_name);
|
||||
size_t model_str_len = 0;
|
||||
|
||||
fs = fopen("/proc/cpuinfo", "r");
|
||||
if (fs != NULL) {
|
||||
while (fgets(buf, SMALL_LINE_BUF, fs)) {
|
||||
if (strncmp(attr_name, buf, attr_len) == 0) {
|
||||
model_name = strchr(buf, ':');
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose(fs);
|
||||
if (model_name != NULL) {
|
||||
model_str_len = strlen(model_name);
|
||||
if (model_str_len > 2) {
|
||||
model_name = (char *)model_name + 2 * sizeof(char);
|
||||
model_name[model_str_len - 2] = '\0';
|
||||
} else {
|
||||
model_name = "blank";
|
||||
}
|
||||
} else {
|
||||
model_name = "blank";
|
||||
fprintf(stderr, "NOTICE: Unable to find attribute:%s\n", attr_name);
|
||||
}
|
||||
|
||||
status = set_header(
|
||||
&(t_ref->record->headers[TM_CPU_MODEL]),
|
||||
TM_CPU_MODEL_STR, model_name,
|
||||
&(t_ref->record->header_size));
|
||||
|
||||
} else {
|
||||
#ifdef DEBUG
|
||||
fprint(stderr, "NOTICE: Unable to open /proc/cpuinfo\n");
|
||||
#endif
|
||||
status = -1;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* A healper function for set_host_type_header that reads the first line out of
|
||||
* a file and chomps the newline if necessary. If the file does not exist the
|
||||
@@ -497,6 +553,90 @@ static int get_dmi_value(const char *source, const char *key, char **buf)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the board name for telemetry record, this record is a combination of
|
||||
* board name and board vendor. This information is read from dmi filesystem
|
||||
* Board Name (board_name) and Board Vendor (board_vendor).
|
||||
*
|
||||
* @param t_ref Telemetry Record reference obtained from tm_create_record.
|
||||
*
|
||||
* @return 0 if successful, or a negative errno-style value if not.
|
||||
*
|
||||
*/
|
||||
static int set_board_name_header(struct telem_ref *t_ref)
|
||||
{
|
||||
int status = 0;
|
||||
int rc;
|
||||
char *buf = NULL;
|
||||
char *bn = NULL;
|
||||
char *bv = NULL;
|
||||
|
||||
rc = get_dmi_value("/sys/class/dmi/id/board_name", "bn", &bn);
|
||||
if (rc < 0) {
|
||||
status = rc;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = get_dmi_value("/sys/class/dmi/id/board_vendor", "bv", &bv);
|
||||
if (rc < 0) {
|
||||
status = rc;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
rc = asprintf(&buf, "%s|%s", bn, bv);
|
||||
|
||||
if (rc < 0) {
|
||||
status = -ENOMEM;
|
||||
goto cleanup;
|
||||
} else {
|
||||
status = set_header(
|
||||
&(t_ref->record->headers[TM_BOARD_NAME]),
|
||||
TM_BOARD_NAME_STR, buf,
|
||||
&(t_ref->record->header_size));
|
||||
free(buf);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (bn != NULL) {
|
||||
free(bn);
|
||||
}
|
||||
|
||||
if (bv != NULL) {
|
||||
free(bv);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets BIOS version header for telemetry record, this information is
|
||||
* read from dmi filesystem BIOS Version (bios_version).
|
||||
*
|
||||
* @param t_ref Telemetry Record reference obtained from tm_create_record.
|
||||
*
|
||||
* @return 0 if successful, or a negative errno-style value if not.
|
||||
*
|
||||
*/
|
||||
static int set_bios_version_header(struct telem_ref *t_ref)
|
||||
{
|
||||
int status = 0;
|
||||
int rc = 0;
|
||||
char *bios_version = NULL;
|
||||
|
||||
rc = get_dmi_value("/sys/class/dmi/id/bios_version", "bv", &bios_version);
|
||||
if (rc < 0) {
|
||||
status = rc;
|
||||
} else {
|
||||
status = set_header(
|
||||
&(t_ref->record->headers[TM_BIOS_VERSION]),
|
||||
TM_BIOS_VERSION_STR, bios_version,
|
||||
&(t_ref->record->header_size));
|
||||
free(bios_version);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the hosttype header, which is a tuple of three values looked for
|
||||
* in the dmi filesystem. System Vendor (sys_vendor), Product Name
|
||||
@@ -730,6 +870,24 @@ int allocate_header(struct telem_ref *t_ref, uint32_t severity,
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if ((ret = set_board_name_header(t_ref)) < 0) {
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if ((ret = set_cpu_model_header(t_ref)) < 0) {
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
i++;
|
||||
|
||||
if ((ret = set_bios_version_header(t_ref)) < 0) {
|
||||
goto free_and_fail;
|
||||
}
|
||||
|
||||
i++; /* Not necessary, but including for future expansion */
|
||||
|
||||
return ret;
|
||||
|
||||
@@ -295,7 +295,10 @@ START_TEST(check_process_record_with_correct_size_and_data)
|
||||
"machine_id: 1234\ncreation_timestamp: 1418672344\narch:x86_64\n"
|
||||
"host_type: macbookpro\nbuild: 200\nkernel_version: 3.15\n"
|
||||
"payload_format_version: 1\n"
|
||||
"system_name: clear-linux-os\n";
|
||||
"system_name: clear-linux-os\n"
|
||||
"board_name: Qemu|Intel\n"
|
||||
"cpu_model: Intel(R) Core(TM) i7-5650U CPU @ 2.20GHz\n"
|
||||
"bios_version: Qemu\n";
|
||||
char *post_body = "test message";
|
||||
|
||||
set_up_socket_pair(&client_fd, &server_fd);
|
||||
|
||||
Reference in New Issue
Block a user