char post_mortem_magic[32]; // "POST-MORTEM STARTS HERE+7654321\0"
struct {
struct utsname utsname; // OS name+ver+arch+hostname
+ char distro[64]; // Distro name and version from os-release file if exists
char hw_vendor[64]; // hardware/hypervisor vendor when known
char hw_family[64]; // hardware/hypervisor product family when known
char hw_model[64]; // hardware/hypervisor product/model when known
chunk_appendf(&trash, " OS architecture: %s\n", post_mortem.platform.utsname.machine);
if (*post_mortem.platform.utsname.nodename)
chunk_appendf(&trash, " node name: %s\n", HA_ANON_CLI(post_mortem.platform.utsname.nodename));
+ if (*post_mortem.platform.distro)
+ chunk_appendf(&trash, " distro pretty name: %s\n", HA_ANON_CLI(post_mortem.platform.distro));
chunk_appendf(&trash, "Process info\n");
chunk_appendf(&trash, " pid: %d\n", post_mortem.process.pid);
static int feed_post_mortem()
{
+ FILE *file;
+ struct stat statbuf;
+ char line[64];
+ char file_path[32];
+ int line_cnt = 0;
+
/* write an easily identifiable magic at the beginning of the struct */
strncpy(post_mortem.post_mortem_magic,
"POST-MORTEM STARTS HERE+7654321\0",
/* kernel type, version and arch */
uname(&post_mortem.platform.utsname);
+ /* try to find os-release file, this may give the current minor version of
+ * distro if it was recently updated.
+ */
+ snprintf(file_path, sizeof(file_path), "%s", "/etc/os-release");
+ if (stat(file_path, &statbuf) != 0) {
+ /* fallback to "/usr/lib/os-release" */
+ snprintf(file_path, sizeof(file_path), "%s", "/usr/lib/os-release");
+ if (stat(file_path, &statbuf) != 0 ) {
+ goto process_info;
+ }
+ }
+
+ /* try open and find the line with distro PRETTY_NAME (name + full version) */
+ if ((file = fopen(file_path, "r")) == NULL) {
+ goto process_info;
+ }
+
+ while ((fgets(line, sizeof(post_mortem.platform.distro), file)) && (line_cnt < MAX_LINES_TO_READ)) {
+ line_cnt++;
+ if (strncmp(line, "PRETTY_NAME=", 12) == 0) {
+ /* cut \n and trim possible quotes */
+ char *start = line + 12;
+ char *newline = strchr(start, '\n');
+
+ if (newline) {
+ *newline = '\0';
+ } else {
+ newline = start + strlen(start);
+ }
+
+ /* trim possible quotes */
+ if (*start == '"')
+ start++;
+ if (newline > start && *(newline - 1) == '"')
+ *(--newline) = '\0';
+
+ strlcpy2(post_mortem.platform.distro, start, sizeof(post_mortem.platform.distro));
+ break;
+ }
+ }
+ fclose(file);
+
+process_info:
/* some boot-time info related to the process */
post_mortem.process.pid = getpid();
post_mortem.process.boot_uid = geteuid();