From 596ad63d1c27cbc390b39510a537e2020c43ce8c Mon Sep 17 00:00:00 2001 From: jadilet Date: Sat, 27 Oct 2018 13:30:16 +0600 Subject: [PATCH 1/4] added get list hostname --- hub/src/P2PController.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/hub/src/P2PController.cpp b/hub/src/P2PController.cpp index 7a121bb6..69047b4b 100644 --- a/hub/src/P2PController.cpp +++ b/hub/src/P2PController.cpp @@ -138,17 +138,29 @@ void P2PConnector::update_status() { static QString lxc_path("/var/lib/lxc"); QDir directory(lxc_path); - QString tmp; + QString tmp, hostfile_path; // check container directory if (directory.exists()) { for (QFileInfo info : directory.entryInfoList()) { tmp = info.fileName().trimmed(); - qDebug() << "local container foreach: " << tmp; - if (tmp.contains("Container")) { - qDebug() << "found local container: " - << tmp; - local_containers << tmp; + hostfile_path = lxc_path + QDir::separator() + tmp + QDir::separator() + "rootsf/etc/hostname"; + QFileInfo hostname(hostfile_path); + + if (hostname.exists()) { + QFile file(hostfile_path); + + if(!file.open(QIODevice::ReadOnly)) { + qDebug() << "error opening file: " << file.error() << hostfile_path; + break; + } + + QTextStream instream(&file); + QString line = instream.readLine(); + + qDebug() << "local container hotname found: " << line; + local_containers << line; + file.close(); } } From b159c3dde7b7a85ac6f0920717f47066b44ef880 Mon Sep 17 00:00:00 2001 From: jadilet Date: Sat, 27 Oct 2018 14:04:34 +0600 Subject: [PATCH 2/4] fix check exist --- hub/src/P2PController.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hub/src/P2PController.cpp b/hub/src/P2PController.cpp index 69047b4b..a9fb25e9 100644 --- a/hub/src/P2PController.cpp +++ b/hub/src/P2PController.cpp @@ -143,11 +143,13 @@ void P2PConnector::update_status() { // check container directory if (directory.exists()) { for (QFileInfo info : directory.entryInfoList()) { + if (info.fileName() == "." || info.fileName() == "..") + continue; + tmp = info.fileName().trimmed(); hostfile_path = lxc_path + QDir::separator() + tmp + QDir::separator() + "rootsf/etc/hostname"; - QFileInfo hostname(hostfile_path); - if (hostname.exists()) { + if (QFileInfo::exists(hostfile_path)) { QFile file(hostfile_path); if(!file.open(QIODevice::ReadOnly)) { @@ -161,6 +163,9 @@ void P2PConnector::update_status() { qDebug() << "local container hotname found: " << line; local_containers << line; file.close(); + } else { + qInfo() << "not exist container hostname file: " + << hostname.absoluteFilePath(); } } From f4edcfcf5bbdada48c30ba262d98509c970762a3 Mon Sep 17 00:00:00 2001 From: jadilet Date: Sat, 27 Oct 2018 14:08:24 +0600 Subject: [PATCH 3/4] variable remove --- hub/src/P2PController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hub/src/P2PController.cpp b/hub/src/P2PController.cpp index a9fb25e9..1bd06e12 100644 --- a/hub/src/P2PController.cpp +++ b/hub/src/P2PController.cpp @@ -165,7 +165,7 @@ void P2PConnector::update_status() { file.close(); } else { qInfo() << "not exist container hostname file: " - << hostname.absoluteFilePath(); + << hostfile_path; } } From 8dc9ef03fa304f80847a7ad9e8536198a091d79f Mon Sep 17 00:00:00 2001 From: jadilet Date: Sat, 27 Oct 2018 14:19:10 +0600 Subject: [PATCH 4/4] fixed hostname path --- hub/src/P2PController.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hub/src/P2PController.cpp b/hub/src/P2PController.cpp index 1bd06e12..8708ca11 100644 --- a/hub/src/P2PController.cpp +++ b/hub/src/P2PController.cpp @@ -147,7 +147,7 @@ void P2PConnector::update_status() { continue; tmp = info.fileName().trimmed(); - hostfile_path = lxc_path + QDir::separator() + tmp + QDir::separator() + "rootsf/etc/hostname"; + hostfile_path = lxc_path + QDir::separator() + tmp + QDir::separator() + "rootfs/etc/hostname"; if (QFileInfo::exists(hostfile_path)) { QFile file(hostfile_path);