Compare commits
12 Commits
ef8b785ac6
...
53faaeb396
| Author | SHA1 | Date | |
|---|---|---|---|
| 53faaeb396 | |||
| 2928a690b8 | |||
| 220ce225f8 | |||
| ac89c499ab | |||
| 8d1c97da04 | |||
| aa140fd4ec | |||
| 08161c9aad | |||
| 40cda7d988 | |||
| c05b8b4095 | |||
| 3d7ba1dee6 | |||
| a299ada873 | |||
| 91144ad338 |
@@ -5,7 +5,7 @@ if (POLICY CMP0177)
|
|||||||
endif()
|
endif()
|
||||||
project(PIP)
|
project(PIP)
|
||||||
set(PIP_MAJOR 5)
|
set(PIP_MAJOR 5)
|
||||||
set(PIP_MINOR 1)
|
set(PIP_MINOR 2)
|
||||||
set(PIP_REVISION 0)
|
set(PIP_REVISION 0)
|
||||||
set(PIP_SUFFIX )
|
set(PIP_SUFFIX )
|
||||||
set(PIP_COMPANY SHS)
|
set(PIP_COMPANY SHS)
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ bool PISystemMonitor::startOnProcess(int pID, PISystemTime interval) {
|
|||||||
}
|
}
|
||||||
# endif
|
# endif
|
||||||
# else
|
# else
|
||||||
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
|
PRIVATE->hProc = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pID_);
|
||||||
if (PRIVATE->hProc == 0) {
|
if (PRIVATE->hProc == 0) {
|
||||||
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
|
piCoutObj << "Can`t open process with ID = %1, %2!"_tr("PISystemMonitor").arg(pID_).arg(errorString());
|
||||||
return false;
|
return false;
|
||||||
@@ -130,7 +130,7 @@ bool PISystemMonitor::startOnSelf(PISystemTime interval) {
|
|||||||
bool ret = startOnProcess(PIProcess::currentPID(), interval);
|
bool ret = startOnProcess(PIProcess::currentPID(), interval);
|
||||||
cycle = -1;
|
cycle = -1;
|
||||||
#else
|
#else
|
||||||
bool ret = start(interval);
|
bool ret = start(interval);
|
||||||
#endif
|
#endif
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -212,7 +212,7 @@ void PISystemMonitor::run() {
|
|||||||
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
|
// piCout << (PRIVATE->cpu_u_cur - PRIVATE->cpu_u_prev).toMilliseconds() / delay_ms;
|
||||||
# else
|
# else
|
||||||
PRIVATE->file.seekToBegin();
|
PRIVATE->file.seekToBegin();
|
||||||
PIString str = PIString::fromAscii(PRIVATE->file.readAll(true));
|
PIString str = PIString::fromAscii(PRIVATE->file.readAll());
|
||||||
int si = str.find('(') + 1, fi = 0, cc = 1;
|
int si = str.find('(') + 1, fi = 0, cc = 1;
|
||||||
for (int i = si; i < str.size_s(); ++i) {
|
for (int i = si; i < str.size_s(); ++i) {
|
||||||
if (str[i] == '(') cc++;
|
if (str[i] == '(') cc++;
|
||||||
@@ -250,7 +250,7 @@ void PISystemMonitor::run() {
|
|||||||
// piCout << sl[0] << sl[12] << sl[13];
|
// piCout << sl[0] << sl[12] << sl[13];
|
||||||
|
|
||||||
PRIVATE->filem.seekToBegin();
|
PRIVATE->filem.seekToBegin();
|
||||||
str = PIString::fromAscii(PRIVATE->filem.readAll(true));
|
str = PIString::fromAscii(PRIVATE->filem.readAll());
|
||||||
sl = str.split(" ");
|
sl = str.split(" ");
|
||||||
if (sl.size_s() < 6) return;
|
if (sl.size_s() < 6) return;
|
||||||
tstat.virtual_memsize = sl[0].toLong() * page_size;
|
tstat.virtual_memsize = sl[0].toLong() * page_size;
|
||||||
@@ -352,12 +352,12 @@ void PISystemMonitor::gatherThread(llong id) {
|
|||||||
#ifdef MICRO_PIP
|
#ifdef MICRO_PIP
|
||||||
ts.name = tbid.value(id, "<PIThread>");
|
ts.name = tbid.value(id, "<PIThread>");
|
||||||
#else
|
#else
|
||||||
ts.name = tbid.value(id, "<non-PIThread>");
|
ts.name = tbid.value(id, "<non-PIThread>");
|
||||||
# ifndef WINDOWS
|
# ifndef WINDOWS
|
||||||
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
|
PIFile f(PRIVATE->proc_dir + "task/" + PIString::fromNumber(id) + "/stat");
|
||||||
// piCout << f.path();
|
// piCout << f.path();
|
||||||
if (!f.open(PIIODevice::ReadOnly)) return;
|
if (!f.open(PIIODevice::ReadOnly)) return;
|
||||||
PIString str = PIString::fromAscii(f.readAll(true));
|
PIString str = PIString::fromAscii(f.readAll());
|
||||||
int si = str.find('(') + 1, fi = 0, cc = 1;
|
int si = str.find('(') + 1, fi = 0, cc = 1;
|
||||||
for (int i = si; i < str.size_s(); ++i) {
|
for (int i = si; i < str.size_s(); ++i) {
|
||||||
if (str[i] == '(') cc++;
|
if (str[i] == '(') cc++;
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include "pidir.h"
|
#include "pidir.h"
|
||||||
#include "piincludes_p.h"
|
#include "piincludes_p.h"
|
||||||
#include "piiostream.h"
|
#include "piiostream.h"
|
||||||
|
#include "piliterals_bytes.h"
|
||||||
#include "pitime_win.h"
|
#include "pitime_win.h"
|
||||||
#include "pitranslator.h"
|
#include "pitranslator.h"
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
@@ -251,28 +252,18 @@ llong PIFile::readAll(void * data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIFile::readAll(bool forceRead) {
|
PIByteArray PIFile::readAll() {
|
||||||
PIByteArray a;
|
if (!isOpened()) return {};
|
||||||
llong cp = pos();
|
llong prev_pos = pos();
|
||||||
if (forceRead) {
|
PIByteArray ret, buffer(4_KiB);
|
||||||
seekToBegin();
|
|
||||||
for (;;) {
|
|
||||||
uchar byte = static_cast<uchar>(fgetc(PRIVATE->fd));
|
|
||||||
if (feof(PRIVATE->fd) || ferror(PRIVATE->fd)) break;
|
|
||||||
a.push_back(byte);
|
|
||||||
}
|
|
||||||
seek(cp);
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
llong s = size();
|
|
||||||
if (s < 0) return a;
|
|
||||||
a.resize(s);
|
|
||||||
seekToBegin();
|
seekToBegin();
|
||||||
auto _r = fread(a.data(), 1, s, PRIVATE->fd);
|
for (;;) {
|
||||||
NO_UNUSED(_r);
|
size_t readed = fread(buffer.data(), 1, buffer.size(), PRIVATE->fd);
|
||||||
seek(cp);
|
if (readed == 0) break;
|
||||||
if (s >= 0) a.resize(s);
|
ret.append(buffer.data(), readed);
|
||||||
return a;
|
}
|
||||||
|
seek(prev_pos);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -631,10 +622,10 @@ bool PIFile::applyFileInfo(const PIString & path, const PIFile::FileInfo & info)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
PIByteArray PIFile::readAll(const PIString & path, bool forceRead) {
|
PIByteArray PIFile::readAll(const PIString & path) {
|
||||||
PIFile f(path, PIIODevice::ReadOnly);
|
PIFile f(path, PIIODevice::ReadOnly);
|
||||||
if (!f.isOpened()) return PIByteArray();
|
if (!f.isOpened()) return PIByteArray();
|
||||||
return f.readAll(forceRead);
|
return f.readAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -225,8 +225,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Read all file content to byte array and return it. Position leaved unchanged
|
//! \~english Read all file content to byte array and return it. Position leaved unchanged
|
||||||
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
|
//! \~russian Читает всё содержимое файла и возвращает его как массив байтов. Позиция остаётся неизменной
|
||||||
PIByteArray readAll(bool forceRead = false);
|
PIByteArray readAll();
|
||||||
|
|
||||||
|
|
||||||
//! \~english Set file path to "path" and reopen file if need
|
//! \~english Set file path to "path" and reopen file if need
|
||||||
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
|
//! \~russian Устанавливает путь файла на "path" и переоткрывает его при необходимости
|
||||||
@@ -295,7 +294,7 @@ public:
|
|||||||
|
|
||||||
//! \~english Read all file content at path "path" to byte array and return it.
|
//! \~english Read all file content at path "path" to byte array and return it.
|
||||||
//! \~russian Читает всё содержимое файла по пути "path" и возвращает его как массив байтов.
|
//! \~russian Читает всё содержимое файла по пути "path" и возвращает его как массив байтов.
|
||||||
static PIByteArray readAll(const PIString & path, bool forceRead = false);
|
static PIByteArray readAll(const PIString & path);
|
||||||
|
|
||||||
//! \~english Clear file at path "path" and write "data", returns written bytes.
|
//! \~english Clear file at path "path" and write "data", returns written bytes.
|
||||||
//! \~russian Очищает файл по пути "path", пишет туда "data" и возвращает количество записанных байт.
|
//! \~russian Очищает файл по пути "path", пишет туда "data" и возвращает количество записанных байт.
|
||||||
|
|||||||
@@ -1208,7 +1208,7 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
|
|||||||
# endif
|
# endif
|
||||||
PIFile file_prefixes("/proc/tty/drivers", PIIODevice::ReadOnly);
|
PIFile file_prefixes("/proc/tty/drivers", PIIODevice::ReadOnly);
|
||||||
if (file_prefixes.open()) {
|
if (file_prefixes.open()) {
|
||||||
PIString fc = PIString::fromAscii(file_prefixes.readAll(true)), line, cpref;
|
PIString fc = PIString::fromAscii(file_prefixes.readAll()), line, cpref;
|
||||||
PIStringList words;
|
PIStringList words;
|
||||||
file_prefixes.close();
|
file_prefixes.close();
|
||||||
while (!fc.isEmpty()) {
|
while (!fc.isEmpty()) {
|
||||||
@@ -1235,8 +1235,8 @@ PIVector<PISerial::DeviceInfo> PISerial::availableDevicesInfo(bool test) {
|
|||||||
for (const auto & e: de) { // TODO changes in FileInfo
|
for (const auto & e: de) { // TODO changes in FileInfo
|
||||||
for (const auto & p: prefixes) {
|
for (const auto & p: prefixes) {
|
||||||
if (e.name().startsWith(p)) {
|
if (e.name().startsWith(p)) {
|
||||||
di = DeviceInfo();
|
di = DeviceInfo();
|
||||||
di.path = e.path;
|
di.path = e.path;
|
||||||
# ifdef LINUX
|
# ifdef LINUX
|
||||||
ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024);
|
ssize_t lsz = readlink(("/sys/class/tty/" + e.name()).dataAscii(), linkbuf, 1024);
|
||||||
if (lsz > 0) {
|
if (lsz > 0) {
|
||||||
|
|||||||
@@ -211,14 +211,14 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
while (1) {
|
while (1) {
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
DWORD available = 0;
|
DWORD available = 0;
|
||||||
bytes_read = 0;
|
bytes_read = 0;
|
||||||
PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
PeekNamedPipe(pipes[pipe_type][PipeRead], nullptr, 0, nullptr, &available, nullptr);
|
||||||
if (available > 0) {
|
if (available > 0) {
|
||||||
BOOL ok = ReadFile(pipes[pipe_type][PipeRead],
|
BOOL ok = ReadFile(pipes[pipe_type][PipeRead],
|
||||||
read_buffer.data(offset),
|
read_buffer.data(offset),
|
||||||
piMini(available, read_buffer.size() - offset),
|
piMini(available, read_buffer.size() - offset),
|
||||||
&bytes_read,
|
&bytes_read,
|
||||||
nullptr);
|
nullptr);
|
||||||
if (!ok) bytes_read = 0;
|
if (!ok) bytes_read = 0;
|
||||||
}
|
}
|
||||||
# else
|
# else
|
||||||
@@ -244,7 +244,7 @@ PRIVATE_DEFINITION_START(PIProcess)
|
|||||||
# else
|
# else
|
||||||
sz = ::write(pipes[StdIn][PipeWrite], data.data(), data.size());
|
sz = ::write(pipes[StdIn][PipeWrite], data.data(), data.size());
|
||||||
# endif
|
# endif
|
||||||
return sz == data.size_s();
|
return sz == (SizeType)data.size_s();
|
||||||
}
|
}
|
||||||
|
|
||||||
PRIVATE_DEFINITION_END(PIProcess)
|
PRIVATE_DEFINITION_END(PIProcess)
|
||||||
@@ -354,7 +354,7 @@ void PIProcess::startProc(bool detached) {
|
|||||||
if (WIFEXITED(exit_code)) {
|
if (WIFEXITED(exit_code)) {
|
||||||
exec_finished = WEXITSTATUS(exit_code) != 127;
|
exec_finished = WEXITSTATUS(exit_code) != 127;
|
||||||
}
|
}
|
||||||
pid_ = 0;
|
pid_ = 0;
|
||||||
if (!detached) PRIVATE->pid = pid_;
|
if (!detached) PRIVATE->pid = pid_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ PIString PISystemInfo::machineKey() {
|
|||||||
PISystemInfo * si = instance();
|
PISystemInfo * si = instance();
|
||||||
PIByteArray salt;
|
PIByteArray salt;
|
||||||
PIString conf = confDir() + "/.pip_machine_salt";
|
PIString conf = confDir() + "/.pip_machine_salt";
|
||||||
if (PIFile::isExists(conf)) salt = PIFile::readAll(conf, false);
|
if (PIFile::isExists(conf)) salt = PIFile::readAll(conf);
|
||||||
if (salt.size_s() != SALT_SIZE) {
|
if (salt.size_s() != SALT_SIZE) {
|
||||||
salt = generateSalt();
|
salt = generateSalt();
|
||||||
PIFile::writeAll(conf, salt);
|
PIFile::writeAll(conf, salt);
|
||||||
|
|||||||
19
main.cpp
19
main.cpp
@@ -83,6 +83,15 @@ void piDeserializeJSON(S & v, const PIJSON & js) {
|
|||||||
PIKbdListener kbd;
|
PIKbdListener kbd;
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
|
if (argc < 2) return 0;
|
||||||
|
PIFile f(argv[1], PIIODevice::ReadOnly);
|
||||||
|
piCout << "read" << f.path();
|
||||||
|
auto fc = f.readAll();
|
||||||
|
piCout << fc.size();
|
||||||
|
if (!fc.isEmpty()) piCout << PIString::fromUTF8(fc.resized(32));
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
PIHTTPServer server;
|
PIHTTPServer server;
|
||||||
server.listen({"127.0.0.1:7777"});
|
server.listen({"127.0.0.1:7777"});
|
||||||
// server.setBasicAuthRealm("pip");
|
// server.setBasicAuthRealm("pip");
|
||||||
@@ -102,11 +111,13 @@ int main(int argc, char * argv[]) {
|
|||||||
};
|
};
|
||||||
// });
|
// });
|
||||||
|
|
||||||
reg("/*/3/get");
|
reg(" /*/a/get ");
|
||||||
reg("/*/{ID}/get");
|
reg(" /*/{ID}/get ");
|
||||||
|
reg(" /*/*/get ");
|
||||||
|
reg(" /*/*_b/get ");
|
||||||
|
|
||||||
reg("/api/{ID}/get");
|
reg("/api/{ID}/get");
|
||||||
reg("/api/1/get");
|
reg("/api/1/get");
|
||||||
server.unregisterPath("*/{ID}/get");
|
|
||||||
// reg("/api/1/bort{bortID}/get");
|
// reg("/api/1/bort{bortID}/get");
|
||||||
// reg("/api/**");
|
// reg("/api/**");
|
||||||
// reg("/api/1/bort2/get");
|
// reg("/api/1/bort2/get");
|
||||||
@@ -164,7 +175,7 @@ int main(int argc, char * argv[]) {
|
|||||||
// return 0;
|
// return 0;
|
||||||
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
|
PIRegularExpression pire("(?:\\/\\/\\s*)?.*\\n?(?:\\bfunction\\b)\\s*(?<name>\\b\\w+\\b)\\s*(?:\\((?<args>[^;()]*?)\\))",
|
||||||
PIRegularExpression::Multiline);
|
PIRegularExpression::Multiline);
|
||||||
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs", false));
|
PIString subj = PIString::fromUTF8(PIFile::readAll("telegram.qs"));
|
||||||
|
|
||||||
piCout << "Pattern:" << pire.pattern();
|
piCout << "Pattern:" << pire.pattern();
|
||||||
piCout << "Valid:" << pire.isValid();
|
piCout << "Valid:" << pire.isValid();
|
||||||
|
|||||||
@@ -462,12 +462,17 @@ bool procDpkg(const PIString & l) {
|
|||||||
PIFile::FileInfo fi;
|
PIFile::FileInfo fi;
|
||||||
fi.path = l;
|
fi.path = l;
|
||||||
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + ign_err_suffix;
|
PIString cmd = dpkg + dpkgdir + " -S " + fi.name() + ign_err_suffix;
|
||||||
// PICout(true) << cmd;
|
// PICout(true) << "** dpkg:" << cmd;
|
||||||
PIString vs = execute(cmd);
|
PIString vs = execute(cmd).trim();
|
||||||
if (!vs.isEmpty()) {
|
if (!vs.isEmpty()) {
|
||||||
vs = vs.left(vs.find(":"));
|
PIStringList lines = vs.split('\n').reverse();
|
||||||
if (!vs.isEmpty() && !vs.endsWith("-cross")) all_deps << vs;
|
for (auto l: lines) {
|
||||||
return true;
|
auto sl = l;
|
||||||
|
l = l.left(l.find(":"));
|
||||||
|
if (!l.isEmpty() && !l.endsWith("-cross") && !l.contains(' ')) all_deps << l;
|
||||||
|
// PICout(true) << "** found \"" << l << "\" in \"" << sl << "\"";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// piCout << "No dep on" << l;
|
// piCout << "No dep on" << l;
|
||||||
return false;
|
return false;
|
||||||
@@ -787,7 +792,16 @@ int main(int argc, char * argv[]) {
|
|||||||
out_dir.replaceAll("/", "\\");
|
out_dir.replaceAll("/", "\\");
|
||||||
#endif
|
#endif
|
||||||
PIVector<PIString> clibs = all_libs.toVector();
|
PIVector<PIString> clibs = all_libs.toVector();
|
||||||
|
static PIStringList ignore_libs({"libc.so"});
|
||||||
for (auto l: clibs) {
|
for (auto l: clibs) {
|
||||||
|
bool ignore_lib = false;
|
||||||
|
for (auto il: ignore_libs) {
|
||||||
|
if (l.startsWith(il)) {
|
||||||
|
ignore_lib = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ignore_lib) continue;
|
||||||
PIFile::FileInfo fi;
|
PIFile::FileInfo fi;
|
||||||
fi.path = l;
|
fi.path = l;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
|
|||||||
Reference in New Issue
Block a user