mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-09-28 10:45:34 +00:00
Run display discovery asynchronously and bound batched disk-image inventory queries. Filter auxiliary mounts by basename, filesystem and owner, and keep unresolved candidates separate from verified volumes. Allow targeted dismounts despite incomplete discovery while requiring complete results for slot allocation and empty-inventory decisions. Use nonthrowing GUI snapshots with monotonic freshness, completion events and safe window lifetimes. Suspend inactivity decisions while the snapshot is stale, without restarting idle timers: activity counters are cumulative per volume instance. Refresh logout targets and retry only failed ones. Show a progress dialog for interactive unmounts, but keep automatic ones synchronous, so a quit or logout request that arrives meanwhile is handled afterwards rather than refused. Guard core operations against reentry and route wait-dialog requests only from worker threads, so a main-thread message cannot wait for itself. Bind teardown to captured mount and service identities, including process start time. Report a service exit that cannot be confirmed after auxiliary mount removal as a distinct error that keeps the original details. Such volumes are not retried, and a multi-volume unmount reports all of them together with any other failure or a declined prompt. Warn about it after automatic unmounts and at quit, and keep the background application until the warning is acknowledged. Keep rollback responsive, and let services remove their auxiliary directories without probing mounted paths. Preserve released /control compatibility and perform best-effort cleanup for older services. Reap bounded subprocesses as soon as their output ends. A child that survives SIGKILL is reaped by a later call, which starts no new child until then. Keep subjects and subprocess command, status and error output when formatting exceptions for wrapping and logs. Clarify discovery and rollback diagnostics. Fix the localization-dependent busy-volume regression assertion and extend discovery, snapshot, process identity, cleanup, GUI lifecycle, inactivity and teardown coverage.
90 lines
3.3 KiB
C++
90 lines
3.3 KiB
C++
// Read-only subprocess tests. Every child is this test executable; no mounts,
|
|
// privilege changes, or installed VeraCrypt services are involved.
|
|
#include "Platform/Platform.h"
|
|
#include "Platform/Unix/Process.h"
|
|
#include <chrono>
|
|
#include <fcntl.h>
|
|
#include <iostream>
|
|
#include <signal.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
|
|
using namespace VeraCrypt;
|
|
|
|
static void Require (bool condition, const char *message)
|
|
{
|
|
if (!condition) throw std::runtime_error (message);
|
|
}
|
|
|
|
static int DescriptorCount ()
|
|
{
|
|
int count = 0;
|
|
for (int fd = 0; fd < 256; ++fd)
|
|
if (fcntl (fd, F_GETFD) != -1) ++count;
|
|
return count;
|
|
}
|
|
|
|
int main (int argc, char **argv)
|
|
{
|
|
if (argc > 1)
|
|
{
|
|
std::string mode = argv[1];
|
|
if (mode == "success")
|
|
{
|
|
char byte;
|
|
if (read (STDIN_FILENO, &byte, 1) != 0 || fcntl (80, F_GETFD) != -1) return 9;
|
|
write (STDOUT_FILENO, "complete", 8);
|
|
return 0;
|
|
}
|
|
if (mode == "failure") { write (STDERR_FILENO, "expected", 8); return 7; }
|
|
if (mode == "closed") { close (STDOUT_FILENO); close (STDERR_FILENO); sleep (5); return 0; }
|
|
if (mode == "stream")
|
|
{
|
|
for (;;) { write (STDOUT_FILENO, ".", 1); usleep (100); }
|
|
}
|
|
if (mode == "large")
|
|
{
|
|
char data[8192] = {};
|
|
for (;;) write (STDOUT_FILENO, data, sizeof (data));
|
|
}
|
|
sleep (5);
|
|
return 0;
|
|
}
|
|
try
|
|
{
|
|
uint64 startTime = Process::GetProcessStartTime (getpid());
|
|
Require (startTime != 0 && Process::IsProcessRunning (getpid(), startTime), "own process instance not recognized");
|
|
Require (!Process::IsProcessRunning (getpid(), startTime + 1), "different process instance accepted");
|
|
Require (Process::IsProcessRunning (getpid()), "unknown birth time discarded a live process");
|
|
int nullFd = open ("/dev/null", O_RDONLY);
|
|
Require (nullFd >= 0 && dup2 (nullFd, 80) == 80, "test descriptor setup");
|
|
close (nullFd);
|
|
int before = DescriptorCount();
|
|
std::cout << "process: success" << std::endl;
|
|
Require (Process::ExecuteBounded (argv[0], { "success" }, 1000) == "complete", "output/descriptor isolation");
|
|
std::cout << "process: failure" << std::endl;
|
|
try { Process::ExecuteBounded (argv[0], { "failure" }, 1000); throw std::runtime_error ("missing child error"); }
|
|
catch (ExecutedProcessFailed &e) { Require (e.GetExitCode() == 7 && e.GetErrorOutput() == "expected", "child error details"); }
|
|
for (const auto &mode : { "silent", "closed", "stream" })
|
|
{
|
|
std::cout << "process: " << mode << std::endl;
|
|
auto start = std::chrono::steady_clock::now();
|
|
try { Process::ExecuteBounded (argv[0], { mode }, 150); throw std::runtime_error ("missing timeout"); }
|
|
catch (TimeOut &) { }
|
|
Require (std::chrono::steady_clock::now() - start < std::chrono::seconds (2), "deadline overrun");
|
|
int status;
|
|
Require (waitpid (-1, &status, WNOHANG) == -1 && errno == ECHILD, "timed-out child not reaped");
|
|
}
|
|
std::cout << "process: output cap" << std::endl;
|
|
try { Process::ExecuteBounded (argv[0], { "large" }, 1000, 64); throw std::runtime_error ("missing output cap"); }
|
|
catch (ParameterTooLarge &) { }
|
|
int status;
|
|
Require (waitpid (-1, &status, WNOHANG) == -1 && errno == ECHILD, "output-limited child not reaped");
|
|
Require (DescriptorCount() == before, "descriptor leak");
|
|
close (80);
|
|
std::cout << "PASS: output, errors, descriptor isolation, silent/closed/stream deadlines, output cap, reaping\n";
|
|
}
|
|
catch (std::exception &e) { std::cerr << e.what() << '\n'; return 1; }
|
|
return 0;
|
|
}
|