From: Davin McCall Date: Tue, 13 Feb 2018 18:32:01 +0000 (+0000) Subject: Mock tcsetpgrp() and getpgrp() for tests. X-Git-Tag: v0.1.0~23 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=99faa8ca388f7c40a741f43499c9db7cb00bed40;p=oweals%2Fdinit.git Mock tcsetpgrp() and getpgrp() for tests. --- diff --git a/src/includes/baseproc-sys.h b/src/includes/baseproc-sys.h index 217c8ca..44da762 100644 --- a/src/includes/baseproc-sys.h +++ b/src/includes/baseproc-sys.h @@ -13,5 +13,7 @@ using ::fcntl; using ::close; using ::kill; using ::getpgid; +using ::tcsetpgrp; +using ::getpgrp; } diff --git a/src/service.cc b/src/service.cc index 4047c6e..fb27d81 100644 --- a/src/service.cc +++ b/src/service.cc @@ -13,6 +13,7 @@ #include "dinit-log.h" #include "dinit-socket.h" #include "dinit-util.h" +#include "baseproc-sys.h" /* * service.cc - Service management. @@ -52,7 +53,7 @@ void service_set::stop_service(const std::string & name) noexcept void service_record::stopped() noexcept { if (onstart_flags.runs_on_console) { - tcsetpgrp(0, getpgrp()); + bp_sys::tcsetpgrp(0, bp_sys::getpgrp()); discard_console_log_buffer(); release_console(); } @@ -332,7 +333,7 @@ void service_record::started() noexcept { // If we start on console but don't keep it, release it now: if (have_console && ! onstart_flags.runs_on_console) { - tcsetpgrp(0, getpgrp()); + bp_sys::tcsetpgrp(0, bp_sys::getpgrp()); release_console(); } @@ -363,7 +364,7 @@ void service_record::started() noexcept void service_record::failed_to_start(bool depfailed) noexcept { if (have_console) { - tcsetpgrp(0, getpgrp()); + bp_sys::tcsetpgrp(0, bp_sys::getpgrp()); release_console(); } if (waiting_for_console) { diff --git a/src/tests/test-includes/baseproc-sys.h b/src/tests/test-includes/baseproc-sys.h index 638b7c2..3ca25e0 100644 --- a/src/tests/test-includes/baseproc-sys.h +++ b/src/tests/test-includes/baseproc-sys.h @@ -1,5 +1,5 @@ #include -#include +#include // Mock system functions for testing. @@ -20,4 +20,14 @@ inline pid_t getpgid(pid_t pid) return pid; } +inline int tcsetpgrp(int fd, pid_t pgid) +{ + return 0; +} + +inline pid_t getpgrp() +{ + return getpid(); +} + }