# HG changeset patch # User Paper # Date 1704193506 18000 # Node ID 71832ffe425ae700f56c9f268742663141dd0e92 # Parent 8f6f8dd2eb23bd944cca21390281981f4ecde21d# Parent da91af31ae73ab0137909b47314df96686ddde6c animia: re-add kvm fd source this is all being merged from my wildly out-of-date laptop. SORRY! in other news, I edited the CI file to install the wayland client as well, so the linux CI build might finally get wayland stuff. diff -r da91af31ae73 -r 71832ffe425a CMakeLists.txt --- a/CMakeLists.txt Tue Jan 02 02:37:03 2024 -0500 +++ b/CMakeLists.txt Tue Jan 02 06:05:06 2024 -0500 @@ -190,8 +190,7 @@ set_property(TARGET minori PROPERTY AUTOMOC ON) set_property(TARGET minori PROPERTY AUTORCC ON) -target_include_directories(minori PUBLIC ${CURL_INCLUDE_DIRS} PRIVATE ${INCLUDE}) -target_include_directories(minori PUBLIC ${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS}) +target_include_directories(minori PUBLIC ${Qt${QT_VERSION_MAJOR}Widgets_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} PRIVATE ${INCLUDE}) target_compile_options(minori PRIVATE -Wall -Wpedantic -Wextra -Wsuggest-override -Wold-style-cast) if(APPLE) target_compile_definitions(minori PUBLIC MACOSX) diff -r da91af31ae73 -r 71832ffe425a dep/animia/CMakeLists.txt --- a/dep/animia/CMakeLists.txt Tue Jan 02 02:37:03 2024 -0500 +++ b/dep/animia/CMakeLists.txt Tue Jan 02 06:05:06 2024 -0500 @@ -72,17 +72,19 @@ list(APPEND DEFINES LIBUTIL) list(APPEND SRC_FILES src/fd/libutil.cc) endif() # LIBUTIL_GOOD - elseif(LIBKVM_LIBRARY) # BSD libkvm + elseif(LIBKVM_LIBRARY) # OpenBSD kvm + list(APPEND LIBRARIES ${LIBKVM_LIBRARY}) + list(APPEND DEFINES LIBKVM) + list(APPEND SRC_FILES src/fd/kvm.cc) + get_filename_component(LIBKVM_DIR ${LIBKVM_LIBRARY} DIRECTORY) include(CheckLibraryExists) - check_library_exists(kvm kvm_getprocs ${LIBKVM_DIR} LIBKVM_GOOD) + check_library_exists(kvm kvm_getfiles ${LIBKVM_DIR} LIBKVM_HAS_GETFILES) - if(LIBKVM_GOOD) - list(APPEND LIBRARIES ${LIBKVM_LIBRARY}) - list(APPEND DEFINES LIBKVM) - list(APPEND SRC_FILES src/fd/libkvm.cc) - endif() # LIBUTIL_GOOD + if(LIBKVM_HAS_GETFILES) + list(APPEND DEFINES HAVE_KVM_GETFILES) + endif() # LIBKVM_HAS_GETFILES endif() # LINUX # X11 @@ -108,8 +110,8 @@ pkg_check_modules(X11 x11) if(X11_FOUND) # Check for XRes the hard way - find_path(X11_XRes_HEADER "extensions/XRes.h" PATHS ${X11_INCLUDE_DIRS}) - find_library(X11_XRes_LIB XRes ${X11_LIBRARY_DIRS}) + find_path(X11_XRes_HEADER "X11/extensions/XRes.h" PATHS ${X11_INCLUDE_DIRS}) + find_library(X11_XRes_LIB XRes PATHS ${X11_LIBRARY_DIRS}) if(X11_XRes_HEADER AND X11_XRes_LIB) # TODO: We should REALLY check for XResQueryClientIds here... @@ -150,5 +152,5 @@ ) target_compile_definitions(animia PRIVATE ${DEFINES}) -target_include_directories(animia PRIVATE include PUBLIC ${INCLUDE_DIRS}) +target_include_directories(animia PUBLIC include PRIVATE ${INCLUDE_DIRS}) target_link_libraries(animia PUBLIC ${LIBRARIES}) diff -r da91af31ae73 -r 71832ffe425a dep/animia/include/animia/fd/kvm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dep/animia/include/animia/fd/kvm.h Tue Jan 02 06:05:06 2024 -0500 @@ -0,0 +1,17 @@ +#ifndef __animia__animia__fd__kvm_h +#define __animia__animia__fd__kvm_h + +#include +#include + +#include "animia/fd.h" +#include "animia/types.h" + +namespace animia::internal::kvm { + +bool EnumerateOpenProcesses(process_proc_t process_proc); +bool EnumerateOpenFiles(const std::set& pids, open_file_proc_t open_file_proc); + +} // namespace animia::internal::kvm + +#endif // __animia__animia__fd__kvm_h diff -r da91af31ae73 -r 71832ffe425a dep/animia/src/fd.cc --- a/dep/animia/src/fd.cc Tue Jan 02 02:37:03 2024 -0500 +++ b/dep/animia/src/fd.cc Tue Jan 02 06:05:06 2024 -0500 @@ -16,6 +16,10 @@ # include "animia/fd/libutil.h" #endif +#ifdef LIBKVM +# include "animia/fd/kvm.h" +#endif + namespace animia::internal { bool EnumerateOpenFiles(const std::set& pids, open_file_proc_t open_file_proc) { @@ -37,6 +41,10 @@ success ^= libutil::EnumerateOpenFiles(pids, open_file_proc); #endif +#ifdef LIBKVM + success ^= kvm::EnumerateOpenFiles(pids, open_file_proc); +#endif + return success; } @@ -59,6 +67,10 @@ success ^= libutil::EnumerateOpenProcesses(process_proc); #endif +#ifdef LIBKVM + success ^= kvm::EnumerateOpenProcesses(process_proc); +#endif + return success; } diff -r da91af31ae73 -r 71832ffe425a dep/animia/src/fd/kvm.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dep/animia/src/fd/kvm.cc Tue Jan 02 06:05:06 2024 -0500 @@ -0,0 +1,103 @@ +/* kvm.cc: provides support for OpenBSD's libkvm +** +** Theoretically, this code *should* work, but I haven't +** even tested it. +** +** This also contains some code to support NetBSD, although +** it calls the kernel instead of kvm. +*/ + +#include "animia/fd/kvm.h" +#include "animia/fd.h" +#include "animia.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +namespace animia::internal::kvm { + +bool EnumerateOpenProcesses(process_proc_t process_proc) { + char errbuf[_POSIX2_LINE_MAX]; + kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (!kernel) + return false; + + int entries = 0; + struct kinfo_proc* kinfo = kvm_getprocs(kernel, KERN_PROC_ALL, 0, &entries); + if (!kinfo) + return false; + + for (int i = 0; i < entries; i++) + if (!process_proc({kinfo[i].ki_paddr->p_pid, kinfo[i].ki_paddr->p_comm})) + return false; + + kvm_close(kernel); + + return true; +} + +bool EnumerateOpenFiles(std::set& pids, open_file_proc_t open_file_proc) { +#ifdef HAVE_KVM_GETFILES + char errbuf[_POSIX2_LINE_MAX]; + kvm_t* kernel = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (!kernel) + return false; + + for (const auto& pid : pids) { + int cnt; + struct kinfo_file* kfile = kvm_getfiles(kernel, KERN_FILE_BYPID, pid, &cnt); + if (!kfile) + return false; + + for (int i = 0; i < cnt; i++) + if (!open_file_proc({pid, kfile[i].kf_path})) + return false; + } + + kvm_close(kernel); + + return true; +#else /* For NetBSD... I think */ + for (const auto& pid : pids) { + int mib[6] = { + CTL_KERN, + KERN_FILE2, + KERN_FILE_BYPID, + pid, + sizeof(struct kinfo_file), + 0 + }; + + size_t len = 0; + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), NULL, &len, NULL, 0) == -1) + return false; + + mib[5] = len / sizeof(struct kinfo_file); + + std::unique_ptr buf(new struct kinfo_file[mib[5]]); + if (!buf) + return false; + + if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), buf.get(), &len, NULL, 0) == -1) + return false; + + for (size_t i = 0; i < cnt; i++) + if (!open_file_proc({pid, kfile[i].kf_path})) + return false; + } + + return true; +#endif +} + +} diff -r da91af31ae73 -r 71832ffe425a src/gui/translate/anime.cc --- a/src/gui/translate/anime.cc Tue Jan 02 02:37:03 2024 -0500 +++ b/src/gui/translate/anime.cc Tue Jan 02 06:05:06 2024 -0500 @@ -1,8 +1,11 @@ #include "core/anime.h" #include "core/strings.h" #include "gui/translate/anime.h" + #include +#include + namespace Translate { std::string ToString(const Anime::ListStatus status) { diff -r da91af31ae73 -r 71832ffe425a src/gui/translate/config.cc --- a/src/gui/translate/config.cc Tue Jan 02 02:37:03 2024 -0500 +++ b/src/gui/translate/config.cc Tue Jan 02 06:05:06 2024 -0500 @@ -1,6 +1,8 @@ #include "core/config.h" #include "gui/translate/config.h" +#include + namespace Translate { Themes ToTheme(const std::string& theme) {