2010-08-17 05:33:07 +04:00
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2010-01-23 03:52:57 +03:00
2012-07-18 21:07:51 +04:00
# pragma once
2010-01-23 03:52:57 +03:00
2010-02-03 15:03:47 +03:00
/***
This file is part of systemd .
Copyright 2010 Lennart Poettering
systemd is free software ; you can redistribute it and / or modify it
2012-04-12 02:20:58 +04:00
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation ; either version 2.1 of the License , or
2010-02-03 15:03:47 +03:00
( at your option ) any later version .
systemd is distributed in the hope that it will be useful , but
WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
2012-04-12 02:20:58 +04:00
Lesser General Public License for more details .
2010-02-03 15:03:47 +03:00
2012-04-12 02:20:58 +04:00
You should have received a copy of the GNU Lesser General Public License
2010-02-03 15:03:47 +03:00
along with systemd ; If not , see < http : //www.gnu.org/licenses/>.
* * */
2010-01-23 03:52:57 +03:00
typedef struct Socket Socket ;
2010-01-27 06:31:52 +03:00
# include "manager.h"
2010-01-26 23:39:06 +03:00
# include "unit.h"
2010-01-23 05:35:54 +03:00
# include "socket-util.h"
2010-05-13 05:07:16 +04:00
# include "mount.h"
2012-01-07 02:08:54 +04:00
# include "service.h"
2010-01-23 03:52:57 +03:00
typedef enum SocketState {
SOCKET_DEAD ,
SOCKET_START_PRE ,
SOCKET_START_POST ,
SOCKET_LISTENING ,
SOCKET_RUNNING ,
SOCKET_STOP_PRE ,
2010-01-26 06:18:44 +03:00
SOCKET_STOP_PRE_SIGTERM ,
SOCKET_STOP_PRE_SIGKILL ,
2010-01-23 03:52:57 +03:00
SOCKET_STOP_POST ,
2010-04-13 04:06:27 +04:00
SOCKET_FINAL_SIGTERM ,
SOCKET_FINAL_SIGKILL ,
2010-08-31 02:23:34 +04:00
SOCKET_FAILED ,
2010-04-10 19:53:17 +04:00
_SOCKET_STATE_MAX ,
_SOCKET_STATE_INVALID = - 1
2010-01-23 03:52:57 +03:00
} SocketState ;
typedef enum SocketExecCommand {
SOCKET_EXEC_START_PRE ,
SOCKET_EXEC_START_POST ,
SOCKET_EXEC_STOP_PRE ,
SOCKET_EXEC_STOP_POST ,
2010-04-10 19:53:17 +04:00
_SOCKET_EXEC_COMMAND_MAX ,
_SOCKET_EXEC_COMMAND_INVALID = - 1
2010-01-23 03:52:57 +03:00
} SocketExecCommand ;
2010-01-23 05:35:54 +03:00
typedef enum SocketType {
SOCKET_SOCKET ,
2010-04-10 19:53:17 +04:00
SOCKET_FIFO ,
2011-04-20 07:02:23 +04:00
SOCKET_SPECIAL ,
2011-05-17 21:37:03 +04:00
SOCKET_MQUEUE ,
2010-04-10 19:53:17 +04:00
_SOCKET_FIFO_MAX ,
_SOCKET_FIFO_INVALID = - 1
2010-01-23 05:35:54 +03:00
} SocketType ;
2012-02-03 05:31:54 +04:00
typedef enum SocketResult {
SOCKET_SUCCESS ,
SOCKET_FAILURE_RESOURCES ,
SOCKET_FAILURE_TIMEOUT ,
SOCKET_FAILURE_EXIT_CODE ,
SOCKET_FAILURE_SIGNAL ,
SOCKET_FAILURE_CORE_DUMP ,
2012-03-06 04:29:29 +04:00
SOCKET_FAILURE_SERVICE_FAILED_PERMANENT ,
2012-02-03 05:31:54 +04:00
_SOCKET_RESULT_MAX ,
_SOCKET_RESULT_INVALID = - 1
} SocketResult ;
2010-05-24 07:25:33 +04:00
typedef struct SocketPort {
2010-01-23 05:35:54 +03:00
SocketType type ;
2010-04-21 06:01:24 +04:00
int fd ;
2010-01-23 05:35:54 +03:00
SocketAddress address ;
char * path ;
2010-01-27 06:31:52 +03:00
Watch fd_watch ;
2010-01-23 05:35:54 +03:00
2010-05-24 07:25:33 +04:00
LIST_FIELDS ( struct SocketPort , port ) ;
} SocketPort ;
2010-01-23 05:35:54 +03:00
2010-01-23 03:52:57 +03:00
struct Socket {
2012-01-15 15:04:08 +04:00
Unit meta ;
2010-01-23 03:52:57 +03:00
2010-01-23 05:35:54 +03:00
LIST_HEAD ( SocketPort , ports ) ;
2010-08-12 00:37:10 +04:00
unsigned n_accepted ;
unsigned n_connections ;
unsigned max_connections ;
2010-01-23 05:35:54 +03:00
unsigned backlog ;
2010-01-26 06:18:44 +03:00
usec_t timeout_usec ;
2010-04-10 19:53:17 +04:00
ExecCommand * exec_command [ _SOCKET_EXEC_COMMAND_MAX ] ;
2010-01-23 03:52:57 +03:00
ExecContext exec_context ;
2010-07-16 21:42:27 +04:00
/* For Accept=no sockets refers to the one service we'll
activate . For Accept = yes sockets is either NULL , or filled
when the next service we spawn . */
2012-01-07 02:08:54 +04:00
UnitRef service ;
2010-01-26 06:18:44 +03:00
2010-04-21 05:27:44 +04:00
SocketState state , deserialized_state ;
2010-01-26 06:18:44 +03:00
2010-08-12 00:37:10 +04:00
Watch timer_watch ;
2010-01-26 06:18:44 +03:00
ExecCommand * control_command ;
2010-04-21 05:27:44 +04:00
SocketExecCommand control_command_id ;
2010-01-23 03:52:57 +03:00
pid_t control_pid ;
2010-08-12 00:37:10 +04:00
mode_t directory_mode ;
mode_t socket_mode ;
2010-04-15 08:19:54 +04:00
2012-02-03 05:31:54 +04:00
SocketResult result ;
2010-08-12 00:37:10 +04:00
bool accept ;
2010-07-01 02:29:17 +04:00
/* Socket options */
bool keep_alive ;
2010-08-12 00:37:10 +04:00
bool free_bind ;
2011-05-19 15:22:31 +04:00
bool transparent ;
2011-05-19 20:10:19 +04:00
bool broadcast ;
2011-11-30 01:15:41 +04:00
bool pass_cred ;
2012-03-13 03:00:27 +04:00
bool pass_sec ;
2010-07-01 02:29:17 +04:00
int priority ;
2010-08-12 00:37:10 +04:00
int mark ;
2010-07-01 02:29:17 +04:00
size_t receive_buffer ;
size_t send_buffer ;
int ip_tos ;
int ip_ttl ;
size_t pipe_size ;
char * bind_to_device ;
2010-08-03 15:33:40 +04:00
char * tcp_congestion ;
2011-05-17 21:37:03 +04:00
long mq_maxmsg ;
long mq_msgsize ;
2012-01-07 02:08:54 +04:00
/* Only for INET6 sockets: issue IPV6_V6ONLY sockopt */
SocketAddressBindIPv6Only bind_ipv6_only ;
2010-01-23 03:52:57 +03:00
} ;
2010-01-26 09:02:51 +03:00
/* Called from the service code when collecting fds */
int socket_collect_fds ( Socket * s , int * * fds , unsigned * n_fds ) ;
2010-01-27 08:19:48 +03:00
/* Called from the service when it shut down */
2012-03-06 04:29:29 +04:00
void socket_notify_service_dead ( Socket * s , bool failed_permanent ) ;
2010-01-27 08:19:48 +03:00
2010-05-13 05:07:16 +04:00
/* Called from the mount code figure out if a mount is a dependency of
* any of the sockets of this socket */
int socket_add_one_mount_link ( Socket * s , Mount * m ) ;
2010-06-19 06:25:28 +04:00
/* Called from the service code when a per-connection service ended */
void socket_connection_unref ( Socket * s ) ;
2010-01-26 23:39:06 +03:00
extern const UnitVTable socket_vtable ;
2010-01-23 03:52:57 +03:00
2010-04-21 05:27:44 +04:00
const char * socket_state_to_string ( SocketState i ) ;
SocketState socket_state_from_string ( const char * s ) ;
const char * socket_exec_command_to_string ( SocketExecCommand i ) ;
SocketExecCommand socket_exec_command_from_string ( const char * s ) ;
2012-02-03 05:31:54 +04:00
const char * socket_result_to_string ( SocketResult i ) ;
SocketResult socket_result_from_string ( const char * s ) ;