From ef7df8048d1067d3148287f27af9047743f1e2ae Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周日, 15 3月 2020 16:26:21 +0800
Subject: [PATCH] Merge branch 'feature/pc_identifiers' into develop issues #2 #3 #14 #49

---
 src/library/os/linux/os_linux.cpp |  100 +++-----------------------------------------------
 1 files changed, 6 insertions(+), 94 deletions(-)

diff --git a/src/library/os/os-linux.c b/src/library/os/linux/os_linux.cpp
similarity index 72%
rename from src/library/os/os-linux.c
rename to src/library/os/linux/os_linux.cpp
index 00409cc..57fb028 100644
--- a/src/library/os/os-linux.c
+++ b/src/library/os/linux/os_linux.cpp
@@ -1,9 +1,8 @@
 #include <paths.h>
 #include <sys/stat.h>
-#include "os.h"
-#include "../base/logger.h"
-#include <openssl/pem.h>
-#include <openssl/err.h>
+#include <stdio.h>
+#include "../os.h"
+#include "../../base/logger.h"
 
 #include <mntent.h>
 #include <dirent.h>
@@ -112,7 +111,9 @@
 				if (strcmp(ent->mnt_dir, "/") == 0) {
 					strcpy(tmpDrives[drive_found].label, "root");
 					LOG_DEBUG("drive %s set to preferred\n", ent->mnt_fsname);
-					tmpDrives[drive_found].preferred = true;
+					tmpDrives[drive_found].preferred = 1;
+				} else {
+					tmpDrives[drive_found].preferred = 0;
 				}
 			}
 		}
@@ -170,27 +171,9 @@
 	} else {
 		result = FUNC_RET_BUFFER_TOO_SMALL;
 	}
-	/*
-	 FILE *mounts = fopen(_PATH_MOUNTED, "r");
-	 if (mounts == NULL) {
-	 return ERROR;
-	 }
-
-	 while (fscanf(mounts, "%64s %64s %64s %1024[^\n]", device, name, type,
-	 discard) != EOF) {
-	 if (stat(device, &mount_stat) != 0)
-	 continue;
-	 if (filename_stat.st_dev == mount_stat.st_rdev) {
-	 fprintf(stderr, "device: %s; name: %s; type: %s\n", device, name,
-	 type);
-	 }
-	 }
-	 */
 	free(statDrives);
 	return result;
 }
-
-void os_initialize() {}
 
 static void _getCpuid(unsigned int *p, unsigned int ax) {
 	__asm __volatile(
@@ -212,78 +195,7 @@
 	return FUNC_RET_OK;
 }
 
-// 0=NO 1=Docker/Lxc
-static int checkContainerProc() {
-	// in docer /proc/self/cgroups contains the "docker" or "lxc" string
-	// https://stackoverflow.com/questions/23513045/how-to-check-if-a-process-is-running-inside-docker-container
-	char path[MAX_PATH] = {0};
-	char proc_path[MAX_PATH], pidStr[64];
-	pid_t pid = getpid();
-	sprintf(pidStr, "%d", pid);
-	strcpy(proc_path, "/proc/");
-	strcat(proc_path, pidStr);
-	strcat(proc_path, "/cgroup");
 
-	FILE *fp;
-	char *line = NULL;
-	size_t len = 0;
-	ssize_t read;
-	int result = 0;
-
-	fp = fopen(proc_path, "r");
-	if (fp == NULL) {
-		return 0;
-	}
-
-	while ((read = getline(&line, &len, fp)) != -1 && result == 0) {
-		// line[len]=0;
-		// printf("Retrieved line of length %zu:\n", read);
-		// printf("%s", line);
-		if (strstr(line, "docker") != NULL || strstr(line, "lxc") != NULL) {
-			result = 1;
-		}
-	}
-
-	fclose(fp);
-	if (line) free(line);
-	return result;
-}
-
-// 0=NO 1=Docker/Lxc
-static int checkLXC() { return (access("/var/run/systemd/container", F_OK) == 0) ? 1 : 0; }
-
-VIRTUALIZATION getVirtualization() {
-	VIRTUALIZATION result = NONE;
-	int isContainer = checkContainerProc();
-	if (isContainer == 1) {
-		result = CONTAINER;
-	} else if (checkLXC()) {
-		result = CONTAINER;
-	}
-	return result;
-
-	// http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html
-	//
-	// bool rc = true;
-	/*__asm__ (
-	 "push   %edx\n"
-	 "push   %ecx\n"
-	 "push   %ebx\n"
-	 "mov    %eax, 'VMXh'\n"
-	 "mov    %ebx, 0\n" // any value but not the MAGIC VALUE
-	 "mov    %ecx, 10\n"// get VMWare version
-	 "mov    %edx, 'VX'\n"// port number
-	 "in     %eax, dx\n"// read port on return EAX returns the VERSION
-	 "cmp    %ebx, 'VMXh'\n"// is it a reply from VMWare?
-	 "setz   [rc] \n"// set return value
-	 "pop    %ebx \n"
-	 "pop    %ecx \n"
-	 "pop    %edx \n"
-	 );*/
-
-	// systemd-detect-virt
-	return NONE;
-}
 
 FUNCTION_RETURN getMachineName(unsigned char identifier[6]) {
 	static struct utsname u;

--
Gitblit v1.9.1