8 #include <unordered_set>
15 #include "service-listener.h"
16 #include "service-constants.h"
18 #include "dinit-log.h"
21 * This header defines service_record, a data record maintaining information about a service,
22 * and service_set, a set of interdependent service records. It also defines some associated
23 * types and exceptions.
27 * Services have both a current state and a desired state. The desired state can be
28 * either STARTED or STOPPED. The current state can also be STARTING or STOPPING.
29 * A service can be "pinned" in either the STARTED or STOPPED states to prevent it
30 * from leaving that state until it is unpinned.
32 * The total state is a combination of the two, current and desired:
33 * STOPPED/STOPPED : stopped and will remain stopped
34 * STOPPED/STARTED : stopped (pinned), must be unpinned to start
35 * STARTING/STARTED : starting, but not yet started. Dependencies may also be starting.
36 * STARTING/STOPPED : as above, but the service will be stopped again as soon as it has
38 * STARTED/STARTED : running and will continue running.
39 * STARTED/STOPPED : started (pinned), must be unpinned to stop
40 * STOPPING/STOPPED : stopping and will stop. Dependents may be stopping.
41 * STOPPING/STARTED : as above, but the service will be re-started again once it stops.
43 * A scripted service is in the STARTING/STOPPING states during the script execution.
44 * A process service is in the STOPPING state when it has been signalled to stop, and is
45 * in the STARTING state when waiting for dependencies to start or for the exec() call in
46 * the forked child to complete and return a status.
48 * Acquisition/release:
50 * Each service has a dependent-count ("required_by"). This starts at 0, adds 1 if the
51 * service has explicitly been started (i.e. "start_explicit" is true), and adds 1 for
52 * each dependent service which is not STOPPED (including dependents with a soft dependency).
53 * When required_by transitions to 0, the service is stopped (unless it is pinned). When
54 * require_by transitions from 0, the service is started (unless pinned).
56 * So, in general, the dependent-count determines the desired state (STARTED if the count
57 * is greater than 0, otherwise STOPPED). However, a service can be issued a stop-and-take
58 * down order (via `stop(true)'); this will first stop dependent services, which may restart
59 * and cancel the stop of the former service. Finally, a service can be force-stopped, which
60 * means that its stop process cannot be cancelled (though it may still be put in a desired
61 * state of STARTED, meaning it will start immediately upon stopping).
65 * A service may be "pinned" in either STARTED or STOPPED states (or even both). Once it
66 * reaches a pinned state, a service will not leave that state, though its desired state
67 * may still be set. (Note that pinning prevents, but never causes, state transition).
69 * The priority of the different state deciders is:
72 * - desired state (which is manipulated by require/release operations)
74 * So a forced stop cannot occur until the service is not pinned started, for instance.
76 * Two-phase transition
77 * --------------------
78 * Transition between states occurs in two phases: propagation and execution. In both phases
79 * a linked-list queue is used to keep track of which services need processing; this avoids
80 * recursion (which would be of unknown depth and therefore liable to stack overflow).
82 * In the propagation phase, acquisition/release messages are processed, and desired state may be
83 * altered accordingly. Start and stop requests are also propagated in this phase. The state may
84 * be set to STARTING or STOPPING to reflect the desired state, but will never be set to STARTED
85 * or STOPPED (that happens in the execution phase).
87 * The two-phase transition is needed to avoid problem where a service that becomes STOPPED has
88 * an incorrect acquisition count, which may cause it to restart when it should not. The
89 * propagation phase allows the acquisition count to settle before the transition to the STOPPED
90 * state occurs, and the decision whether to restart can then be made based on the (correct)
93 * Propagation variables:
94 * prop_acquire: the service has transitioned to an acquired state and must issue an acquire
96 * prop_release: the service has transitioned to a released state and must issue a release on
99 * prop_start: the service should start
100 * prop_stop: the service should stop
102 * Note that "prop_acquire"/"prop_release" form a pair which cannot both be set at the same time
103 * which is enforced via explicit checks. For "prop_start"/"prop_stop" this occurs implicitly.
105 * In the execution phase, actions are taken to achieve the desired state. Actual state may
106 * transition according to the current and desired states. Processes can be sent signals, etc
107 * in order to stop them. A process can restart if it stops, but it does so by raising prop_start
108 * which needs to be processed in a second transition phase. Seeing as starting never causes
109 * another process to stop, the transition-execute-transition cycle always ends at the 2nd
110 * transition stage, at the latest.
113 struct service_flags_t {
115 bool rw_ready : 1; // file system should be writable once this service starts
116 bool log_ready : 1; // syslog should be available once this service starts
118 // Other service options flags:
119 bool no_sigterm : 1; // do not send SIGTERM
120 bool runs_on_console : 1; // run "in the foreground"
121 bool starts_on_console : 1; // starts in the foreground
122 bool pass_cs_fd : 1; // pass this service a control socket connection via fd
123 bool start_interruptible : 1; // the startup of this service process is ok to interrupt with SIGINT
124 bool skippable : 1; // if interrupted the service is skipped (scripted services)
126 service_flags_t() noexcept : rw_ready(false), log_ready(false),
127 no_sigterm(false), runs_on_console(false), starts_on_console(false),
128 pass_cs_fd(false), start_interruptible(false), skippable(false)
133 // Exception while loading a service
134 class service_load_exc
137 std::string serviceName;
138 std::string excDescription;
141 service_load_exc(std::string serviceName, std::string &&desc) noexcept
142 : serviceName(serviceName), excDescription(std::move(desc))
147 class service_not_found : public service_load_exc
150 service_not_found(std::string serviceName) noexcept
151 : service_load_exc(serviceName, "Service description not found.")
156 class service_cyclic_dependency : public service_load_exc
159 service_cyclic_dependency(std::string serviceName) noexcept
160 : service_load_exc(serviceName, "Has cyclic dependency.")
165 class service_description_exc : public service_load_exc
168 service_description_exc(std::string serviceName, std::string &&extraInfo) noexcept
169 : service_load_exc(serviceName, std::move(extraInfo))
174 class service_record;
176 class base_process_service;
178 enum class dependency_type
181 SOFT, // dependency starts in parallel, failure/stop does not affect dependent
182 WAITS_FOR, // as for SOFT, but dependent waits until dependency starts/fails before starting
183 MILESTONE // dependency must start successfully, but once started the dependency becomes soft
186 enum class stopped_reason_t
191 DEPFAILED, // A dependency failed to start
192 FAILED, // failed to start (process terminated)
193 EXECFAILED, // failed to start (couldn't launch process)
194 TIMEDOUT, // timed out when starting
196 // Failure after starting:
197 TERMINATED // process terminated
200 /* Service dependency record */
203 service_record * from;
207 /* Whether the 'from' service is waiting for the 'to' service to start */
209 /* Whether the 'from' service is holding an acquire on the 'to' service */
212 const dependency_type dep_type;
214 service_dep(service_record * from, service_record * to, dependency_type dep_type_p) noexcept
215 : from(from), to(to), waiting_on(false), holding_acq(false), dep_type(dep_type_p)
218 service_record * get_from() noexcept
223 service_record * get_to() noexcept
229 /* preliminary service dependency information */
233 service_record * const to;
234 dependency_type const dep_type;
236 prelim_dep(service_record *to_p, dependency_type dep_type_p) : to(to_p), dep_type(dep_type_p)
242 class service_child_watcher : public eventloop_t::child_proc_watcher_impl<service_child_watcher>
245 base_process_service * service;
246 dasynq::rearm status_change(eventloop_t &eloop, pid_t child, int status) noexcept;
248 service_child_watcher(base_process_service * sr) noexcept : service(sr) { }
251 // Watcher for the pipe used to receive exec() failure status errno
252 class exec_status_pipe_watcher : public eventloop_t::fd_watcher_impl<exec_status_pipe_watcher>
255 base_process_service * service;
256 dasynq::rearm fd_event(eventloop_t &eloop, int fd, int flags) noexcept;
258 exec_status_pipe_watcher(base_process_service * sr) noexcept : service(sr) { }
261 // service_record: base class for service record containing static information
262 // and current state of each service.
264 // This abstract base class defines the dependency behaviour of services. The actions to actually bring a
265 // service up or down are specified by subclasses in the virtual methods (see especially bring_up() and
271 using string = std::string;
272 using time_val = dasynq::time_val;
276 service_type_t record_type; /* ServiceType::DUMMY, PROCESS, SCRIPTED, INTERNAL */
277 service_state_t service_state = service_state_t::STOPPED; /* service_state_t::STOPPED, STARTING, STARTED, STOPPING */
278 service_state_t desired_state = service_state_t::STOPPED; /* service_state_t::STOPPED / STARTED */
283 service_flags_t onstart_flags;
285 string logfile; // log file name, empty string specifies /dev/null
287 bool auto_restart : 1; // whether to restart this (process) if it dies unexpectedly
288 bool smooth_recovery : 1; // whether the service process can restart without bringing down service
290 bool pinned_stopped : 1;
291 bool pinned_started : 1;
292 bool waiting_for_deps : 1; // if STARTING, whether we are waiting for dependencies (inc console) to start
293 // if STOPPING, whether we are waiting for dependents to stop
294 bool waiting_for_console : 1; // waiting for exclusive console access (while STARTING)
295 bool have_console : 1; // whether we have exclusive console access (STARTING/STARTED)
296 bool waiting_for_execstat : 1; // if we are waiting for exec status after fork()
297 bool start_explicit : 1; // whether we are are explicitly required to be started
299 bool prop_require : 1; // require must be propagated
300 bool prop_release : 1; // release must be propagated
301 bool prop_failure : 1; // failure to start must be propagated
305 bool restarting : 1; // re-starting after unexpected termination
306 bool start_failed : 1; // failed to start (reset when begins starting)
307 bool start_skipped : 1; // start was skipped by interrupt
309 int required_by = 0; // number of dependents wanting this service to be started
311 // list of dependencies
312 typedef std::list<service_dep> dep_list;
314 // list of dependents
315 typedef std::list<service_dep *> dpt_list;
317 dep_list depends_on; // services this one depends on
318 dpt_list dependents; // services depending on this one
320 service_set *services; // the set this service belongs to
322 std::unordered_set<service_listener *> listeners;
325 bool force_stop; // true if the service must actually stop. This is the
326 // case if for example the process dies; the service,
327 // and all its dependencies, MUST be stopped.
329 int term_signal = -1; // signal to use for process termination
331 string socket_path; // path to the socket for socket-activation service
332 int socket_perms; // socket permissions ("mode")
333 uid_t socket_uid = -1; // socket user id or -1
334 gid_t socket_gid = -1; // socket group id or -1
336 stopped_reason_t stop_reason = stopped_reason_t::NORMAL; // reason why stopped
338 // Data for use by service_set
342 lld_node<service_record> console_queue_node;
344 // Propagation and start/stop queues
345 lls_node<service_record> prop_queue_node;
346 lls_node<service_record> stop_queue_node;
350 // Service has actually stopped (includes having all dependents
351 // reaching STOPPED state).
352 void stopped() noexcept;
354 // Service has successfully started
355 void started() noexcept;
357 // Service failed to start (only called when in STARTING state).
358 // dep_failed: whether failure is recorded due to a dependency failing
359 // immediate_stop: whether to set state as STOPPED and handle complete stop.
360 void failed_to_start(bool dep_failed = false, bool immediate_stop = true) noexcept;
362 // Run a child process (call after forking).
363 // - args specifies the program arguments including the executable (argv[0])
364 // - working_dir specifies the working directory; may be null
365 // - logfile specifies the logfile
366 // - on_console: if true, process is run with access to console
367 // - wpipefd: if the exec is unsuccessful, or another error occurs beforehand, the
368 // error number (errno) is written to this file descriptor
369 // - csfd: the control socket fd; may be -1 to inhibit passing of control socket
370 // - socket_fd: the pre-opened socket file descriptor (may be -1)
371 // - uid/gid: the identity to run the process as (may be both -1, otherwise both must be valid)
372 void run_child_proc(const char * const *args, const char *working_dir, const char *logfile,
373 bool on_console, int wpipefd, int csfd, int socket_fd, uid_t uid, gid_t gid) noexcept;
375 // A dependency has reached STARTED state
376 void dependency_started() noexcept;
378 void all_deps_started() noexcept;
380 // Start all dependencies, return true if all have started
381 bool start_check_dependencies() noexcept;
383 // Check whether all dependencies have started (i.e. whether we can start now)
384 bool check_deps_started() noexcept;
386 // Whether a STOPPING service can immediately transition to STARTED.
387 bool can_interrupt_stop() noexcept
389 return waiting_for_deps && ! force_stop;
392 // A dependent has reached STOPPED state
393 void dependent_stopped() noexcept;
395 // check if all dependents have stopped
396 bool stop_check_dependents() noexcept;
398 // issue a stop to all dependents, return true if they are all already stopped
399 bool stop_dependents() noexcept;
401 void require() noexcept;
402 void release(bool issue_stop = true) noexcept;
403 void release_dependencies() noexcept;
405 // Check if service is, fundamentally, stopped.
406 bool is_stopped() noexcept
408 return service_state == service_state_t::STOPPED
409 || (service_state == service_state_t::STARTING && waiting_for_deps);
412 void notify_listeners(service_event_t event) noexcept
414 for (auto l : listeners) {
415 l->service_event(this, event);
419 // Queue to run on the console. 'acquired_console()' will be called when the console is available.
420 // Has no effect if the service has already queued for console.
421 void queue_for_console() noexcept;
423 // Release console (console must be currently held by this service)
424 void release_console() noexcept;
426 bool do_auto_restart() noexcept;
428 // Started state reached
429 bool process_started() noexcept;
431 // Called on transition of desired state from stopped to started (or unpinned stop)
432 void do_start() noexcept;
434 // Begin stopping, release activation.
435 void do_stop() noexcept;
437 // Set the service state
438 void set_state(service_state_t new_state) noexcept
440 service_state = new_state;
443 // Virtual functions, to be implemented by service implementations:
445 // Do any post-dependency startup; return false on failure
446 virtual bool bring_up() noexcept;
448 // All dependents have stopped, and this service should proceed to stop.
449 virtual void bring_down() noexcept;
451 // Whether a STARTING service can immediately transition to STOPPED (as opposed to
452 // having to wait for it reach STARTED and then go through STOPPING).
453 virtual bool can_interrupt_start() noexcept
455 return waiting_for_deps;
458 // Whether a STARTING service can transition to its STARTED state, once all
459 // dependencies have started.
460 virtual bool can_proceed_to_start() noexcept
465 // Interrupt startup. Returns true if service start is fully cancelled; returns false if cancel order
466 // issued but service has not yet responded (state will be set to STOPPING).
467 virtual bool interrupt_start() noexcept;
469 // The service is becoming inactive - i.e. it has stopped and will not be immediately restarted. Perform
470 // any appropriate cleanup.
471 virtual void becoming_inactive() noexcept { }
475 service_record(service_set *set, string name)
476 : service_state(service_state_t::STOPPED), desired_state(service_state_t::STOPPED),
477 auto_restart(false), smooth_recovery(false),
478 pinned_stopped(false), pinned_started(false), waiting_for_deps(false),
479 waiting_for_console(false), have_console(false), waiting_for_execstat(false),
480 start_explicit(false), prop_require(false), prop_release(false), prop_failure(false),
481 prop_start(false), prop_stop(false), restarting(false), start_failed(false),
482 start_skipped(false), force_stop(false)
486 record_type = service_type_t::DUMMY;
490 service_record(service_set *set, string name, service_type_t record_type_p,
491 const std::list<prelim_dep> &deplist_p)
492 : service_record(set, name)
496 this->record_type = record_type_p;
498 for (auto & pdep : deplist_p) {
499 auto b = depends_on.emplace(depends_on.end(), this, pdep.to, pdep.dep_type);
500 pdep.to->dependents.push_back(&(*b));
504 virtual ~service_record() noexcept
508 // Get the type of this service record
509 service_type_t get_type() noexcept
514 // begin transition from stopped to started state or vice versa depending on current and desired state
515 void execute_transition() noexcept;
517 void do_propagation() noexcept;
519 // Console is available.
520 void acquired_console() noexcept;
522 // Get the target (aka desired) state.
523 service_state_t get_target_state() noexcept
525 return desired_state;
528 // Set logfile, should be done before service is started
529 void set_log_file(string logfile)
531 this->logfile = logfile;
534 // Set whether this service should automatically restart when it dies
535 void set_auto_restart(bool auto_restart) noexcept
537 this->auto_restart = auto_restart;
540 void set_smooth_recovery(bool smooth_recovery) noexcept
542 this->smooth_recovery = smooth_recovery;
545 // Set "on start" flags (commands)
546 void set_flags(service_flags_t flags) noexcept
548 this->onstart_flags = flags;
551 void set_pid_file(string &&pid_file) noexcept
553 this->pid_file = std::move(pid_file);
556 void set_socket_details(string &&socket_path, int socket_perms, uid_t socket_uid, uid_t socket_gid) noexcept
558 this->socket_path = std::move(socket_path);
559 this->socket_perms = socket_perms;
560 this->socket_uid = socket_uid;
561 this->socket_gid = socket_gid;
564 const std::string &get_name() const noexcept { return service_name; }
565 service_state_t get_state() const noexcept { return service_state; }
567 void start(bool activate = true) noexcept; // start the service
568 void stop(bool bring_down = true) noexcept; // stop the service
570 void forced_stop() noexcept; // force-stop this service and all dependents
572 // Pin the service in "started" state (when it reaches the state)
573 void pin_start() noexcept
575 pinned_started = true;
578 // Pin the service in "stopped" state (when it reaches the state)
579 void pin_stop() noexcept
581 pinned_stopped = true;
584 // Remove both "started" and "stopped" pins. If the service is currently pinned
585 // in either state but would naturally be in the opposite state, it will immediately
586 // commence starting/stopping.
587 void unpin() noexcept;
589 // Is this a dummy service (used only when loading a new service)?
590 bool is_dummy() noexcept
592 return record_type == service_type_t::DUMMY;
595 bool did_start_fail() noexcept
600 bool was_start_skipped() noexcept
602 return start_skipped;
605 // Add a listener. A listener must only be added once. May throw std::bad_alloc.
606 void add_listener(service_listener * listener)
608 listeners.insert(listener);
611 // Remove a listener.
612 void remove_listener(service_listener * listener) noexcept
614 listeners.erase(listener);
617 // Assuming there is one reference (from a control link), return true if this is the only reference,
618 // or false if there are others (including dependents).
619 bool has_lone_ref() noexcept
621 if (! dependents.empty()) return false;
622 auto i = listeners.begin();
623 return (++i == listeners.end());
626 // Prepare this service to be unloaded.
627 void prepare_for_unload() noexcept
629 // Remove all dependencies:
630 for (auto &dep : depends_on) {
631 auto &dep_dpts = dep.get_to()->dependents;
632 dep_dpts.erase(std::find(dep_dpts.begin(), dep_dpts.end(), &dep));
637 // Why did the service stop?
638 stopped_reason_t get_stop_reason()
644 inline auto extract_prop_queue(service_record *sr) -> decltype(sr->prop_queue_node) &
646 return sr->prop_queue_node;
649 inline auto extract_stop_queue(service_record *sr) -> decltype(sr->stop_queue_node) &
651 return sr->stop_queue_node;
654 inline auto extract_console_queue(service_record *sr) -> decltype(sr->console_queue_node) &
656 return sr->console_queue_node;
660 * A service_set, as the name suggests, manages a set of services.
662 * Other than the ability to find services by name, the service set manages various queues.
663 * One is the queue for processes wishing to acquire the console. There is also a set of
664 * processes that want to start, and another set of those that want to stop. These latter
665 * two "queues" (not really queues since their order is not important) are used to prevent too
666 * much recursion and to prevent service states from "bouncing" too rapidly.
668 * A service that wishes to start or stop puts itself on the start/stop queue; a service that
669 * needs to propagate changes to dependent services or dependencies puts itself on the
670 * propagation queue. Any operation that potentially manipulates the queues must be followed
671 * by a "process queues" order (processQueues() method).
673 * Note that processQueues always repeatedly processes both queues until they are empty. The
674 * process is finite because starting a service can never cause services to stop, unless they
675 * fail to start, which should cause them to stop semi-permanently.
681 std::list<service_record *> records;
682 bool restart_enabled; // whether automatic restart is enabled (allowed)
684 shutdown_type_t shutdown_type = shutdown_type_t::CONTINUE; // Shutdown type, if stopping
686 // Services waiting for exclusive access to the console
687 dlist<service_record, extract_console_queue> console_queue;
689 // Propagation and start/stop "queues" - list of services waiting for processing
690 slist<service_record, extract_prop_queue> prop_queue;
691 slist<service_record, extract_stop_queue> stop_queue;
697 restart_enabled = true;
700 virtual ~service_set()
702 for (auto * s : records) {
707 // Start the specified service. The service will be marked active.
708 void start_service(service_record *svc)
714 // Stop the specified service. Its active mark will be cleared.
715 void stop_service(service_record *svc)
721 // Locate an existing service record.
722 service_record *find_service(const std::string &name) noexcept;
724 // Load a service description, and dependencies, if there is no existing
725 // record for the given name.
727 // ServiceLoadException (or subclass) on problem with service description
728 // std::bad_alloc on out-of-memory condition
729 virtual service_record *load_service(const char *name)
731 auto r = find_service(name);
733 throw service_not_found(name);
738 // Start the service with the given name. The named service will begin
739 // transition to the 'started' state.
741 // Throws a ServiceLoadException (or subclass) if the service description
742 // cannot be loaded or is invalid;
743 // Throws std::bad_alloc if out of memory.
744 void start_service(const char *name)
747 service_record *record = load_service(name);
748 service_set::start_service(record);
751 void add_service(service_record *svc)
753 records.push_back(svc);
756 void remove_service(service_record *svc)
758 records.erase(std::find(records.begin(), records.end(), svc));
761 // Get the list of all loaded services.
762 const std::list<service_record *> &list_services() noexcept
767 // Stop the service with the given name. The named service will begin
768 // transition to the 'stopped' state.
769 void stop_service(const std::string &name) noexcept;
771 // Add a service record to the state propagation queue. The service record will have its
772 // do_propagation() method called when the queue is processed.
773 void add_prop_queue(service_record *service) noexcept
775 if (! prop_queue.is_queued(service)) {
776 prop_queue.insert(service);
780 // Add a service record to the stop queue. The service record will have its
781 // execute_transition() method called when the queue is processed.
782 void add_transition_queue(service_record *service) noexcept
784 if (! stop_queue.is_queued(service)) {
785 stop_queue.insert(service);
789 // Process state propagation and start/stop queues, until they are empty.
790 void process_queues() noexcept
792 while (! stop_queue.is_empty() || ! prop_queue.is_empty()) {
793 while (! prop_queue.is_empty()) {
794 auto next = prop_queue.pop_front();
795 next->do_propagation();
797 while (! stop_queue.is_empty()) {
798 auto next = stop_queue.pop_front();
799 next->execute_transition();
804 // Set the console queue tail (returns previous tail)
805 void append_console_queue(service_record * newTail) noexcept
807 bool was_empty = console_queue.is_empty();
808 console_queue.append(newTail);
810 enable_console_log(false);
814 // Pull and dispatch a waiter from the console queue
815 void pull_console_queue() noexcept
817 if (console_queue.is_empty()) {
818 enable_console_log(true);
821 service_record * front = console_queue.pop_front();
822 front->acquired_console();
826 void unqueue_console(service_record * service) noexcept
828 if (console_queue.is_queued(service)) {
829 console_queue.unlink(service);
833 // Check if console queue is empty (possibly due to console already having
834 // been assigned to the only queueing service)
835 bool is_console_queue_empty() noexcept
837 return console_queue.is_empty();
840 // Check whether a service is queued for the console
841 bool is_queued_for_console(service_record * service) noexcept
843 return console_queue.is_queued(service);
846 // Notification from service that it is active (state != STOPPED)
847 // Only to be called on the transition from inactive to active.
848 void service_active(service_record *) noexcept;
850 // Notification from service that it is inactive (STOPPED)
851 // Only to be called on the transition from active to inactive.
852 void service_inactive(service_record *) noexcept;
854 // Find out how many services are active (starting, running or stopping,
856 int count_active_services() noexcept
858 return active_services;
861 void stop_all_services(shutdown_type_t type = shutdown_type_t::HALT) noexcept
863 restart_enabled = false;
864 shutdown_type = type;
865 for (std::list<service_record *>::iterator i = records.begin(); i != records.end(); ++i) {
872 void set_auto_restart(bool restart) noexcept
874 restart_enabled = restart;
877 bool get_auto_restart() noexcept
879 return restart_enabled;
882 shutdown_type_t get_shutdown_type() noexcept
884 return shutdown_type;
888 // A service directory entry, tracking the directory as a nul-terminated string, which may either
889 // be static or dynamically allocated (via new char[...]).
890 class service_dir_entry
893 bool dir_dyn_allocd; // dynamically allocated?
896 service_dir_entry(const char *dir_p, bool dir_dyn_allocd_p) :
897 dir(dir_p), dir_dyn_allocd(dir_dyn_allocd_p)
902 if (dir_dyn_allocd) {
907 const char *get_dir() const
913 // A service set which loads services from one of several service directories.
914 class dirload_service_set : public service_set
916 std::vector<service_dir_entry> service_dirs; // directories containing service descriptions
919 dirload_service_set() : service_set()
924 dirload_service_set(const dirload_service_set &) = delete;
926 // Construct a dirload_service_set which loads services from the specified directory. The
927 // directory specified can be dynamically allocated via "new char[...]" (dyn_allocd == true)
928 // or statically allocated.
929 dirload_service_set(const char *service_dir_p, bool dyn_allocd = false) : service_set()
931 service_dirs.emplace_back(service_dir_p, false);
934 // Append a directory to the list of service directories, so that it is searched last for
935 // service description files.
936 void add_service_dir(const char *service_dir_p, bool dyn_allocd = true)
938 service_dirs.emplace_back(service_dir_p, dyn_allocd);
941 service_record *load_service(const char *name) override;