cd includes; ln -sf ../../includes/*.h .
cd includes; ln -sf ../test-includes/*.h .
-tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o
- $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS)
+tests: prepare-incdir $(parent_objs) tests.o test-dinit.o test-bpsys.o test-run-child-proc.o
+ $(CXX) $(SANITIZEOPTS) -o tests $(parent_objs) tests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(EXTRA_LIBS)
-proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o
- $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o $(EXTRA_LIBS)
+proctests: prepare-incdir $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o
+ $(CXX) $(SANITIZEOPTS) -o proctests $(parent_objs) proctests.o test-dinit.o test-bpsys.o test-run-child-proc.o $(EXTRA_LIBS)
$(objects): %.o: %.cc
$(CXX) $(CXXOPTS) $(SANITIZEOPTS) -MMD -MP -Iincludes -I../dasynq -c $< -o $@
static void handle_exit(base_process_service *bsp, int exit_status)
{
+ bsp->pid = -1;
bsp->handle_exit_status(exit_status);
}
};
namespace bp_sys {
// last signal sent:
extern int last_sig_sent;
+ extern pid_t last_forked_pid;
}
// Regular service start
base_process_service_test::exec_succeeded(&p);
sset.process_queues();
+ pid_t first_instance = bp_sys::last_forked_pid;
+
assert(p.get_state() == service_state_t::STARTED);
base_process_service_test::handle_exit(&p, 0);
sset.process_queues();
+ // since time hasn't been changed, we expect that the process has not yet been re-launched:
+ assert(first_instance == bp_sys::last_forked_pid);
+ assert(p.get_state() == service_state_t::STARTED);
+
+ p.timer_expired();
+ sset.process_queues();
+
+ // Now a new process should've been launched:
+ assert(first_instance + 1 == bp_sys::last_forked_pid);
assert(p.get_state() == service_state_t::STARTED);
}
namespace bp_sys {
int last_sig_sent = -1; // last signal number sent, accessible for tests.
+pid_t last_forked_pid = 1; // last forked process id (incremented each 'fork')
int pipe2(int fds[2], int flags)
{
using rearm = dasynq::rearm;
using time_val = dasynq::time_val;
+namespace bp_sys {
+ extern pid_t last_forked_pid;
+}
+
class eventloop_t
{
public:
public:
pid_t fork(eventloop_t &loop, bool reserved_child_watcher, int priority = dasynq::DEFAULT_PRIORITY)
{
- return 2; // doesn't matter much what we return here, but it should be a potentially valid pid
+ bp_sys::last_forked_pid++;
+ return bp_sys::last_forked_pid;
}
void add_reserved(eventloop_t &eloop, pid_t child, int prio = dasynq::DEFAULT_PRIORITY) noexcept