Loading CMakeLists.txt +5 −0 Changes for CMakeLists.txt: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(SYSLITE_UNIT_DIR "/etc/syslite/services" CACHE STRING "Service unit file directory") set(SYSLITE_DEFAULT_TARGET "multi-user.target" CACHE STRING "Default boot target") set(SYSLITE_TTY_COUNT 3 CACHE STRING "Number of TTYs to spawn") set(SYSLITE_JOURNAL "/var/log/syslite/journal.log" CACHE STRING "Journal: syslite's and the services' output") configure_file(config.h.in ${CMAKE_BINARY_DIR}/config.h) Loading @@ -27,6 +28,8 @@ set_target_properties(sysbus PROPERTIES POSITION_INDEPENDENT_CODE ON) add_executable(syslite src/main.cpp src/unitfile.cpp src/mount.cpp src/journal.cpp src/service.cpp src/tty.cpp src/network.cpp Loading Loading @@ -59,6 +62,8 @@ install(TARGETS netdev DESTINATION sbin) install(TARGETS syslitectl DESTINATION sbin) install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink syslitectl \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/sbin/systemctl)") install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink syslitectl \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/sbin/journalctl)") install(TARGETS sysbus EXPORT sysbusTargets ARCHIVE DESTINATION lib) install(DIRECTORY include/sysbus DESTINATION include) Loading config.h.in +1 −0 Changes for config.h.in: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,3 +5,4 @@ #define SYSLITE_DEFAULT_TARGET "@SYSLITE_DEFAULT_TARGET@" #define SYSLITE_TTY_COUNT @SYSLITE_TTY_COUNT@ #define SYSLITE_HOSTNAME_FILE "/etc/hostname" #define SYSLITE_JOURNAL "@SYSLITE_JOURNAL@" include/sysbus/client.h +28 −1 Changes for include/sysbus/client.h: 28 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -36,6 +36,13 @@ constexpr const char *Subscribe = "Subscribe"; constexpr const char *Reboot = "Reboot"; constexpr const char *PowerOff = "PowerOff"; // Mounts: .mount units in syslite's unit directory (see MountSettings). // CreateMount writes and loads the unit (what, where, type, options, // description) and replies with its name in "unit"; start it with // StartUnit. DeleteMount unmounts it and removes its file. Root only. constexpr const char *CreateMount = "CreateMount"; constexpr const char *DeleteMount = "DeleteMount"; // unit // Services: other daemons register a name (root only, see sysbus/service.h); // a call with the field "sysbus.destination" set to that name is forwarded // to the daemon and its reply passed back (Client::callService()). Loading Loading @@ -78,7 +85,8 @@ constexpr const char *Timeout = "sysbus.Error.Timeout"; // it did } // namespace error struct UnitInfo { std::string name; // without ".service" std::string name; // without ".service"; mounts: "srv-data.mount" std::string kind; // "service" or "mount" std::string description; std::string state; // stopped, starting, running, stopping, failed std::string enabled; // enabled, disabled, static (no [Install] WantedBy=) Loading @@ -87,6 +95,20 @@ struct UnitInfo { long pid = -1; int exitCode = 0; int restarts = 0; // mounts ("running": mounted, "starting": waiting for What) std::string what, where, fsType, options; std::string mountSource; // the device it is mounted from std::string lastError; }; // A .mount unit: What= is a device path or UUID=/LABEL=; Type= may be // empty (the file system found there); Options= mount(8) style. struct MountSettings { std::string what; std::string where; std::string type; std::string options; std::string description; }; struct InterfaceInfo { Loading Loading @@ -166,6 +188,11 @@ public: bool getUnit(const std::string &name, UnitInfo &out); std::vector<UnitInfo> listUnits(); // Mount units: true on success, otherwise see lastError(). createMount // only writes and loads the unit; *unit gets its name. bool createMount(const MountSettings &settings, std::string *unit = nullptr); bool deleteMount(const std::string &unit); // Network interfaces: true on success, otherwise see lastError(). std::vector<InterfaceInfo> listInterfaces(); bool getInterface(const std::string &name, InterfaceInfo &out); Loading src/busserver.cpp +15 −8 Changes for src/busserver.cpp: 15 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -85,21 +85,28 @@ void BusServer::close() { _listenFd = -1; } void BusServer::poll(int timeoutMs) { if (_listenFd < 0) { if (timeoutMs > 0) ::usleep(static_cast<useconds_t>(timeoutMs) * 1000); return; } void BusServer::poll(int timeoutMs, const std::vector<int> &extra, const std::function<void(int)> &onReadable) { std::vector<pollfd> fds; for (int fd : extra) fds.push_back({fd, POLLIN, 0}); size_t first = fds.size(); if (_listenFd >= 0) { fds.push_back({_listenFd, POLLIN, 0}); for (auto &c : _clients) fds.push_back({c.first, POLLIN, 0}); } if (fds.empty()) { if (timeoutMs > 0) ::usleep(static_cast<useconds_t>(timeoutMs) * 1000); return; } int r = ::poll(fds.data(), fds.size(), timeoutMs); expirePending(); if (_listenFd >= 0) expirePending(); if (r <= 0) return; // timeout, or EINTR from SIGCHLD & co. if (fds[0].revents & POLLIN) accept(); for (size_t i = 1; i < fds.size(); ++i) for (size_t i = 0; i < first; ++i) if (onReadable && (fds[i].revents & (POLLIN | POLLHUP | POLLERR))) onReadable(fds[i].fd); if (_listenFd < 0) return; if (fds[first].revents & POLLIN) accept(); for (size_t i = first + 1; i < fds.size(); ++i) if (fds[i].revents & (POLLIN | POLLHUP | POLLERR)) serve(fds[i].fd); } Loading src/busserver.h +3 −1 Changes for src/busserver.h: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ public: void close(); // Waits up to timeoutMs for activity, then serves what arrived. void poll(int timeoutMs); // also waits for the extra fds; onReadable(fd) for each with data/EOF void poll(int timeoutMs, const std::vector<int> &extra = {}, const std::function<void(int)> &onReadable = nullptr); // Sends a signal to every subscribed client. void broadcast(sysbus::Message signal); Loading Loading
CMakeLists.txt +5 −0 Changes for CMakeLists.txt: 5 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(SYSLITE_UNIT_DIR "/etc/syslite/services" CACHE STRING "Service unit file directory") set(SYSLITE_DEFAULT_TARGET "multi-user.target" CACHE STRING "Default boot target") set(SYSLITE_TTY_COUNT 3 CACHE STRING "Number of TTYs to spawn") set(SYSLITE_JOURNAL "/var/log/syslite/journal.log" CACHE STRING "Journal: syslite's and the services' output") configure_file(config.h.in ${CMAKE_BINARY_DIR}/config.h) Loading @@ -27,6 +28,8 @@ set_target_properties(sysbus PROPERTIES POSITION_INDEPENDENT_CODE ON) add_executable(syslite src/main.cpp src/unitfile.cpp src/mount.cpp src/journal.cpp src/service.cpp src/tty.cpp src/network.cpp Loading Loading @@ -59,6 +62,8 @@ install(TARGETS netdev DESTINATION sbin) install(TARGETS syslitectl DESTINATION sbin) install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink syslitectl \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/sbin/systemctl)") install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink syslitectl \$ENV{DESTDIR}${CMAKE_INSTALL_PREFIX}/sbin/journalctl)") install(TARGETS sysbus EXPORT sysbusTargets ARCHIVE DESTINATION lib) install(DIRECTORY include/sysbus DESTINATION include) Loading
config.h.in +1 −0 Changes for config.h.in: 1 added line, 0 removed lines. Original line number Diff line number Diff line Loading @@ -5,3 +5,4 @@ #define SYSLITE_DEFAULT_TARGET "@SYSLITE_DEFAULT_TARGET@" #define SYSLITE_TTY_COUNT @SYSLITE_TTY_COUNT@ #define SYSLITE_HOSTNAME_FILE "/etc/hostname" #define SYSLITE_JOURNAL "@SYSLITE_JOURNAL@"
include/sysbus/client.h +28 −1 Changes for include/sysbus/client.h: 28 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -36,6 +36,13 @@ constexpr const char *Subscribe = "Subscribe"; constexpr const char *Reboot = "Reboot"; constexpr const char *PowerOff = "PowerOff"; // Mounts: .mount units in syslite's unit directory (see MountSettings). // CreateMount writes and loads the unit (what, where, type, options, // description) and replies with its name in "unit"; start it with // StartUnit. DeleteMount unmounts it and removes its file. Root only. constexpr const char *CreateMount = "CreateMount"; constexpr const char *DeleteMount = "DeleteMount"; // unit // Services: other daemons register a name (root only, see sysbus/service.h); // a call with the field "sysbus.destination" set to that name is forwarded // to the daemon and its reply passed back (Client::callService()). Loading Loading @@ -78,7 +85,8 @@ constexpr const char *Timeout = "sysbus.Error.Timeout"; // it did } // namespace error struct UnitInfo { std::string name; // without ".service" std::string name; // without ".service"; mounts: "srv-data.mount" std::string kind; // "service" or "mount" std::string description; std::string state; // stopped, starting, running, stopping, failed std::string enabled; // enabled, disabled, static (no [Install] WantedBy=) Loading @@ -87,6 +95,20 @@ struct UnitInfo { long pid = -1; int exitCode = 0; int restarts = 0; // mounts ("running": mounted, "starting": waiting for What) std::string what, where, fsType, options; std::string mountSource; // the device it is mounted from std::string lastError; }; // A .mount unit: What= is a device path or UUID=/LABEL=; Type= may be // empty (the file system found there); Options= mount(8) style. struct MountSettings { std::string what; std::string where; std::string type; std::string options; std::string description; }; struct InterfaceInfo { Loading Loading @@ -166,6 +188,11 @@ public: bool getUnit(const std::string &name, UnitInfo &out); std::vector<UnitInfo> listUnits(); // Mount units: true on success, otherwise see lastError(). createMount // only writes and loads the unit; *unit gets its name. bool createMount(const MountSettings &settings, std::string *unit = nullptr); bool deleteMount(const std::string &unit); // Network interfaces: true on success, otherwise see lastError(). std::vector<InterfaceInfo> listInterfaces(); bool getInterface(const std::string &name, InterfaceInfo &out); Loading
src/busserver.cpp +15 −8 Changes for src/busserver.cpp: 15 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -85,21 +85,28 @@ void BusServer::close() { _listenFd = -1; } void BusServer::poll(int timeoutMs) { if (_listenFd < 0) { if (timeoutMs > 0) ::usleep(static_cast<useconds_t>(timeoutMs) * 1000); return; } void BusServer::poll(int timeoutMs, const std::vector<int> &extra, const std::function<void(int)> &onReadable) { std::vector<pollfd> fds; for (int fd : extra) fds.push_back({fd, POLLIN, 0}); size_t first = fds.size(); if (_listenFd >= 0) { fds.push_back({_listenFd, POLLIN, 0}); for (auto &c : _clients) fds.push_back({c.first, POLLIN, 0}); } if (fds.empty()) { if (timeoutMs > 0) ::usleep(static_cast<useconds_t>(timeoutMs) * 1000); return; } int r = ::poll(fds.data(), fds.size(), timeoutMs); expirePending(); if (_listenFd >= 0) expirePending(); if (r <= 0) return; // timeout, or EINTR from SIGCHLD & co. if (fds[0].revents & POLLIN) accept(); for (size_t i = 1; i < fds.size(); ++i) for (size_t i = 0; i < first; ++i) if (onReadable && (fds[i].revents & (POLLIN | POLLHUP | POLLERR))) onReadable(fds[i].fd); if (_listenFd < 0) return; if (fds[first].revents & POLLIN) accept(); for (size_t i = first + 1; i < fds.size(); ++i) if (fds[i].revents & (POLLIN | POLLHUP | POLLERR)) serve(fds[i].fd); } Loading
src/busserver.h +3 −1 Changes for src/busserver.h: 3 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -40,7 +40,9 @@ public: void close(); // Waits up to timeoutMs for activity, then serves what arrived. void poll(int timeoutMs); // also waits for the extra fds; onReadable(fd) for each with data/EOF void poll(int timeoutMs, const std::vector<int> &extra = {}, const std::function<void(int)> &onReadable = nullptr); // Sends a signal to every subscribed client. void broadcast(sysbus::Message signal); Loading