gcontini
2020-11-08 ee082d3120f29af98bd8f1e933a9a3706e1f6386
centos fix
4个文件已修改
35 ■■■■ 已修改文件
.gitignore 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
CMakeLists.txt 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/execution_environment_common.cpp 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/library/os/linux/execution_environment.cpp 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
.gitignore
@@ -37,3 +37,4 @@
**/CMakeFiles
/CMakeSettings.json
/.venv/
/Pipfile
CMakeLists.txt
@@ -6,8 +6,8 @@
SET(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
IF(NOT LCC_PROJECT_NAME)
    message(WARNING "You should define a variable LCC_PROJECT_NAME containing the name of the software you want to add a license to."
        "A mock product named DEFAULT has been added for you.")
    message(STATUS "You should define a variable LCC_PROJECT_NAME containing the name of the software you want to add a license to."
        "A mock project named DEFAULT has been added for you.")
    set(LCC_PROJECT_NAME "DEFAULT" CACHE STRING "Project name (name of the software for which you want to issue a license)") 
ENDIF(NOT LCC_PROJECT_NAME)
src/library/os/execution_environment_common.cpp
@@ -24,7 +24,7 @@
    {"VBOX", VIRTUALBOX}};
const unordered_map<string, LCC_API_VIRTUALIZATION_DETAIL> vm_vendors{{"VMWARE", VMWARE},
                                                                      {"MICROSOFT", HV},
                                                                      {"MICROSOFT", HV},
                                                                      {"PARALLELS", PARALLELS},
                                                                      {"VITRUAL MACHINE", V_OTHER},
                                                                      {"INNOTEK GMBH", VIRTUALBOX},
@@ -98,8 +98,8 @@
        } else if (bios_vendor.find("AWS") != string::npos || bios_description.find("AMAZON") != string::npos ||
                   sys_vendor.find("AWS") != string::npos) {
            result = AWS;
        } else if (bios_description.find("HP-COMPAQ") != string::npos || bios_description.find("ASUS") ||
                   bios_description.find("DELL")) {
        } else if (bios_description.find("HP-COMPAQ") != string::npos ||
                   bios_description.find("ASUS") != string::npos || bios_description.find("DELL") != string::npos) {
            result = ON_PREMISE;
        }
    }
src/library/os/linux/execution_environment.cpp
@@ -4,14 +4,14 @@
 *  Created on: Dec 15, 2019
 *      Author: GC
 */
#define __STDC_WANT_LIB_EXT1__1
#include <paths.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cstring>
#include <dirent.h>
#include <sys/utsname.h>
@@ -29,26 +29,20 @@
static CONTAINER_TYPE 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();
    snprintf(pidStr, sizeof(pidStr), "%d", pid);
    strncpy(proc_path, "/proc/", sizeof(proc_path));
    strncat(proc_path, pidStr, sizeof(proc_path));
    strncpy(proc_path, "/cgroup", sizeof(proc_path));
    FILE *fp;
    char *line = NULL;
    char *line = nullptr;
    size_t len = 0;
    ssize_t read;
    CONTAINER_TYPE result = CONTAINER_TYPE::NONE;
    fp = fopen(proc_path, "r");
    if (fp == NULL) {
    fp = fopen("/proc/self/cgroup", "r");
    if (fp == nullptr) {
        return CONTAINER_TYPE::NONE;
    }
    while ((read = getline(&line, &len, fp)) != -1 && result == 0) {
    while ((read = getline(&line, &len, fp)) != -1
            && result == CONTAINER_TYPE::NONE) {
        if (strstr(line, "docker") != NULL) {
            result = CONTAINER_TYPE::DOCKER;
        }
@@ -57,8 +51,10 @@
        }
    }
    if (line) {
        free(line);
    }
    fclose(fp);
    if (line) free(line);
    return result;
}