[新增] 增加kdk_system_get_hostVirtType接口,获取当前宿主机是物理机还是虚拟机
This commit is contained in:
parent
db7e843cb3
commit
c0eb54f26a
|
@ -100,7 +100,7 @@ char* kdk_system_get_version(bool verbose)
|
|||
|
||||
int kdk_system_get_activationStatus(int *status_error_num,int *date_error_num)
|
||||
{
|
||||
if (NULL == status_error_num | NULL == date_error_num)
|
||||
if (NULL == status_error_num || NULL == date_error_num)
|
||||
{
|
||||
klog_err("激活状态接口调用失败:参数错误\n");
|
||||
return -1;
|
||||
|
@ -200,7 +200,7 @@ int kdk_system_get_activationStatus(int *status_error_num,int *date_error_num)
|
|||
}
|
||||
else
|
||||
dbus_message_iter_get_basic(&args, status_error_num);
|
||||
klog_debug("激活状态:%d,错误码:%d\n",stat,*status_error_num);
|
||||
// klog_debug("激活状态:%d,错误码:%d\n",stat,*status_error_num);
|
||||
|
||||
//释放status_pending_msg
|
||||
dbus_message_unref(status_pending_msg);
|
||||
|
@ -230,7 +230,7 @@ int kdk_system_get_activationStatus(int *status_error_num,int *date_error_num)
|
|||
date_pending_msg = dbus_pending_call_steal_reply(date_pending);
|
||||
|
||||
if (NULL == date_pending_msg) {
|
||||
klog_err(stderr, "date_pending_msg:Reply Null\n");
|
||||
klog_err("date_pending_msg:Reply Null\n");
|
||||
return -1;
|
||||
}
|
||||
if (!dbus_message_iter_init(date_pending_msg, &args)){
|
||||
|
@ -306,7 +306,7 @@ data_free:
|
|||
{
|
||||
dbus_pending_call_unref(date_pending);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char* kdk_system_get_serialNumber()
|
||||
|
@ -320,6 +320,8 @@ char* kdk_system_get_serialNumber()
|
|||
|
||||
serial = get_val_from_file(fp, "key");
|
||||
fclose(fp);
|
||||
if (serial)
|
||||
strskipspace(serial);
|
||||
#else
|
||||
int err;
|
||||
serial = kylin_activation_get_serial_number(&err);
|
||||
|
@ -327,7 +329,10 @@ char* kdk_system_get_serialNumber()
|
|||
{
|
||||
klog_err("序列号获取失败:%d\n", err);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
strskipspace(serial);
|
||||
}
|
||||
return serial;
|
||||
#endif // _KYLIN_ACTIVATION_H_
|
||||
#endif // __linux__
|
||||
|
@ -389,10 +394,35 @@ char* kdk_system_get_projectName()
|
|||
project_codename = get_val_from_file(fp, "PROJECT_CODENAME");
|
||||
fclose(fp);
|
||||
}
|
||||
if (project_codename)
|
||||
strstripspace(project_codename);
|
||||
#endif
|
||||
return project_codename;
|
||||
}
|
||||
|
||||
char* kdk_system_get_hostVirtType()
|
||||
{
|
||||
char *virtType = (char*)malloc(sizeof(char) * 65);
|
||||
ASSERT_NOT_NULL(virtType, NULL);
|
||||
#ifdef __linux__
|
||||
char *cmdStr = "systemd-detect-virt"; // 准备运行的命令
|
||||
FILE *pipeLine = popen(cmdStr, "r"); // 建立流管道
|
||||
ASSERT_NOT_NULL(pipeLine, NULL);
|
||||
if (fgets(virtType, 64 * sizeof(char), pipeLine) == NULL)
|
||||
{
|
||||
SAFE_FREE(virtType);
|
||||
}
|
||||
if (virtType)
|
||||
strstripspace(virtType);
|
||||
if (strcmp(virtType, "microsoft") == 0)
|
||||
strcpy(virtType, "hyper-v");
|
||||
else if (strcmp(virtType, "oracle") == 0)
|
||||
strcpy(virtType, "orcale virtualbox");
|
||||
pclose(pipeLine);
|
||||
#endif
|
||||
return virtType;
|
||||
}
|
||||
|
||||
bool kdk_system_is_zyj(void)
|
||||
{
|
||||
bool bool_value = false;
|
||||
|
|
|
@ -82,6 +82,20 @@ extern char* kdk_system_get_eUser();
|
|||
*/
|
||||
extern char* kdk_system_get_projectName();
|
||||
|
||||
/**
|
||||
* @brief 获取操作系统宿主机的虚拟机类型
|
||||
*
|
||||
* @return char* 获取失败返回NULL,获取成功返回一个字符串,字符串内容如下:
|
||||
* [none, qemu, kvm, zvm, vmware, hyper-v, orcale virtualbox, xen, bochs, \
|
||||
* uml, parallels, bhyve, qnx, arcn, openvz, lxc, lxc-libvirt, systemd-nspawn,\
|
||||
* docker, podman, rkt, wsl]
|
||||
* 其中 none 表示运行在物理机环境中;其他字符串代表具体的虚拟环境类型。
|
||||
*/
|
||||
extern char* kdk_system_get_hostVirtType();
|
||||
|
||||
|
||||
extern char* kdk_system_get_hostCloudPlatform();
|
||||
|
||||
/**
|
||||
* @brief 判断当前镜像系统是否为 专用机 系统
|
||||
*
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include <stdbool.h>
|
||||
|
||||
/**
|
||||
* @file systeminfo.hpp
|
||||
* @file systeminfo.hpp(停止维护,请使用C语言接口)
|
||||
* @author liuyunhe (liuyunhe@kylinos.cn)
|
||||
* @brief 操作系统基础信息
|
||||
* @version 0.1
|
||||
|
|
|
@ -38,5 +38,9 @@ int main()
|
|||
free(res);
|
||||
int zyj = kdk_system_is_zyj();
|
||||
printf("专用机:%s\n", zyj == 0 ? "非专用机":"专用机");
|
||||
|
||||
res = kdk_system_get_virtType();
|
||||
printf("虚拟机类型:%s\n", res);
|
||||
free(res);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue