service.h revision a34ceba66fc0e856d8f76f340389a4768b57a365
2N/A/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2N/A
2N/A#pragma once
2N/A
2N/A/***
2N/A This file is part of systemd.
2N/A
2N/A Copyright 2010 Lennart Poettering
2N/A
2N/A systemd is free software; you can redistribute it and/or modify it
2N/A under the terms of the GNU Lesser General Public License as published by
2N/A the Free Software Foundation; either version 2.1 of the License, or
2N/A (at your option) any later version.
2N/A
2N/A systemd is distributed in the hope that it will be useful, but
2N/A WITHOUT ANY WARRANTY; without even the implied warranty of
2N/A MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2N/A Lesser General Public License for more details.
2N/A
2N/A You should have received a copy of the GNU Lesser General Public License
2N/A along with systemd; If not, see <http://www.gnu.org/licenses/>.
2N/A***/
2N/A
2N/Atypedef struct Service Service;
2N/Atypedef struct ServiceFDStore ServiceFDStore;
2N/A
2N/A#include "path.h"
2N/A#include "ratelimit.h"
2N/A#include "kill.h"
2N/A#include "exit-status.h"
2N/A
2N/Atypedef enum ServiceRestart {
2N/A SERVICE_RESTART_NO,
2N/A SERVICE_RESTART_ON_SUCCESS,
2N/A SERVICE_RESTART_ON_FAILURE,
2N/A SERVICE_RESTART_ON_ABNORMAL,
2N/A SERVICE_RESTART_ON_WATCHDOG,
2N/A SERVICE_RESTART_ON_ABORT,
2N/A SERVICE_RESTART_ALWAYS,
2N/A _SERVICE_RESTART_MAX,
2N/A _SERVICE_RESTART_INVALID = -1
2N/A} ServiceRestart;
2N/A
2N/Atypedef enum ServiceType {
2N/A SERVICE_SIMPLE, /* we fork and go on right-away (i.e. modern socket activated daemons) */
2N/A SERVICE_FORKING, /* forks by itself (i.e. traditional daemons) */
2N/A SERVICE_ONESHOT, /* we fork and wait until the program finishes (i.e. programs like fsck which run and need to finish before we continue) */
2N/A SERVICE_DBUS, /* we fork and wait until a specific D-Bus name appears on the bus */
2N/A SERVICE_NOTIFY, /* we fork and wait until a daemon sends us a ready message with sd_notify() */
2N/A SERVICE_IDLE, /* much like simple, but delay exec() until all jobs are dispatched. */
2N/A _SERVICE_TYPE_MAX,
2N/A _SERVICE_TYPE_INVALID = -1
2N/A} ServiceType;
2N/A
2N/Atypedef enum ServiceExecCommand {
2N/A SERVICE_EXEC_START_PRE,
2N/A SERVICE_EXEC_START,
2N/A SERVICE_EXEC_START_POST,
2N/A SERVICE_EXEC_RELOAD,
2N/A SERVICE_EXEC_STOP,
2N/A SERVICE_EXEC_STOP_POST,
2N/A _SERVICE_EXEC_COMMAND_MAX,
2N/A _SERVICE_EXEC_COMMAND_INVALID = -1
2N/A} ServiceExecCommand;
2N/A
2N/Atypedef enum NotifyAccess {
2N/A NOTIFY_NONE,
2N/A NOTIFY_ALL,
2N/A NOTIFY_MAIN,
2N/A _NOTIFY_ACCESS_MAX,
2N/A _NOTIFY_ACCESS_INVALID = -1
2N/A} NotifyAccess;
2N/A
2N/Atypedef enum NotifyState {
2N/A NOTIFY_UNKNOWN,
2N/A NOTIFY_READY,
2N/A NOTIFY_RELOADING,
2N/A NOTIFY_STOPPING,
2N/A _NOTIFY_STATE_MAX,
2N/A _NOTIFY_STATE_INVALID = -1
2N/A} NotifyState;
2N/A
2N/Atypedef enum ServiceResult {
2N/A SERVICE_SUCCESS,
2N/A SERVICE_FAILURE_RESOURCES,
2N/A SERVICE_FAILURE_TIMEOUT,
2N/A SERVICE_FAILURE_EXIT_CODE,
2N/A SERVICE_FAILURE_SIGNAL,
2N/A SERVICE_FAILURE_CORE_DUMP,
2N/A SERVICE_FAILURE_WATCHDOG,
2N/A SERVICE_FAILURE_START_LIMIT,
2N/A _SERVICE_RESULT_MAX,
2N/A _SERVICE_RESULT_INVALID = -1
2N/A} ServiceResult;
2N/A
2N/Astruct ServiceFDStore {
2N/A Service *service;
2N/A
2N/A int fd;
2N/A char *fdname;
2N/A sd_event_source *event_source;
2N/A
2N/A LIST_FIELDS(ServiceFDStore, fd_store);
2N/A};
2N/A
2N/Astruct Service {
2N/A Unit meta;
2N/A
2N/A ServiceType type;
2N/A ServiceRestart restart;
2N/A ExitStatusSet restart_prevent_status;
2N/A ExitStatusSet restart_force_status;
2N/A ExitStatusSet success_status;
2N/A
2N/A /* If set we'll read the main daemon PID from this file */
2N/A char *pid_file;
2N/A
2N/A usec_t restart_usec;
2N/A usec_t timeout_start_usec;
2N/A usec_t timeout_stop_usec;
2N/A
2N/A dual_timestamp watchdog_timestamp;
2N/A usec_t watchdog_usec;
2N/A sd_event_source *watchdog_event_source;
2N/A
2N/A ExecCommand* exec_command[_SERVICE_EXEC_COMMAND_MAX];
2N/A
2N/A ExecContext exec_context;
2N/A KillContext kill_context;
2N/A CGroupContext cgroup_context;
2N/A
2N/A ServiceState state, deserialized_state;
2N/A
2N/A /* The exit status of the real main process */
2N/A ExecStatus main_exec_status;
2N/A
2N/A /* The currently executed control process */
2N/A ExecCommand *control_command;
2N/A
2N/A /* The currently executed main process, which may be NULL if
2N/A * the main process got started via forking mode and not by
2N/A * us */
2N/A ExecCommand *main_command;
2N/A
2N/A /* The ID of the control command currently being executed */
2N/A ServiceExecCommand control_command_id;
2N/A
2N/A /* Runtime data of the execution context */
2N/A ExecRuntime *exec_runtime;
2N/A
2N/A pid_t main_pid, control_pid;
2N/A int socket_fd;
2N/A bool socket_fd_selinux_context_net;
2N/A
2N/A int bus_endpoint_fd;
2N/A
2N/A bool permissions_start_only;
2N/A bool root_directory_start_only;
2N/A bool remain_after_exit;
2N/A bool guess_main_pid;
2N/A
2N/A /* If we shut down, remember why */
2N/A ServiceResult result;
2N/A ServiceResult reload_result;
2N/A
2N/A bool main_pid_known:1;
2N/A bool main_pid_alien:1;
2N/A bool bus_name_good:1;
2N/A bool forbid_restart:1;
2N/A bool start_timeout_defined:1;
2N/A
2N/A bool reset_cpu_usage:1;
2N/A
2N/A char *bus_name;
2N/A
2N/A char *status_text;
2N/A int status_errno;
2N/A
2N/A RateLimit start_limit;
2N/A FailureAction start_limit_action;
2N/A FailureAction failure_action;
2N/A char *reboot_arg;
2N/A
2N/A UnitRef accept_socket;
2N/A
2N/A sd_event_source *timer_event_source;
2N/A PathSpec *pid_file_pathspec;
2N/A
2N/A NotifyAccess notify_access;
2N/A NotifyState notify_state;
2N/A
2N/A ServiceFDStore *fd_store;
2N/A unsigned n_fd_store;
2N/A unsigned n_fd_store_max;
2N/A
2N/A char *usb_function_descriptors;
2N/A char *usb_function_strings;
2N/A
2N/A int stdin_fd;
2N/A int stdout_fd;
2N/A int stderr_fd;
2N/A};
2N/A
2N/Aextern const UnitVTable service_vtable;
2N/A
2N/Aint service_set_socket_fd(Service *s, int fd, struct Socket *socket, bool selinux_context_net);
2N/A
2N/Aconst char* service_restart_to_string(ServiceRestart i) _const_;
2N/AServiceRestart service_restart_from_string(const char *s) _pure_;
2N/A
2N/Aconst char* service_type_to_string(ServiceType i) _const_;
2N/AServiceType service_type_from_string(const char *s) _pure_;
2N/A
2N/Aconst char* service_exec_command_to_string(ServiceExecCommand i) _const_;
2N/AServiceExecCommand service_exec_command_from_string(const char *s) _pure_;
2N/A
2N/Aconst char* notify_access_to_string(NotifyAccess i) _const_;
2N/ANotifyAccess notify_access_from_string(const char *s) _pure_;
2N/A
2N/Aconst char* notify_state_to_string(NotifyState i) _const_;
2N/ANotifyState notify_state_from_string(const char *s) _pure_;
2N/A
2N/Aconst char* service_result_to_string(ServiceResult i) _const_;
2N/AServiceResult service_result_from_string(const char *s) _pure_;
2N/A