master-service.h revision 275385a2ecc58e41dc7df3ce3cd943caaa58c4d1
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* stdin/stdout already contains a client which we want to serve */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen /* this process is currently running standalone without a master */
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen /* Log to configured log file instead of stderr. By default when
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen _FLAG_STANDALONE is set, logging is done to stderr. */
c6335901c67a4c9365319190a111a2168f3b06f5Timo Sirainen MASTER_SERVICE_FLAG_DONT_LOG_TO_STDERR = 0x04,
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainen /* Service is going to do multiple configuration lookups,
01230de017cd273de41143d88e9c18df1243ae8aTimo Sirainen keep the connection to config service open. */
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen /* Don't read settings by executing config binary */
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen MASTER_SERVICE_FLAG_NO_CONFIG_SETTINGS = 0x10,
047c00cd3f7f403672f81569413669238df8c15aTimo Sirainen /* Don't read settings from environment */
cf0ad1a0bddb0787f3d7b408a96d721a8b2a98a3Timo Sirainen /* Use MASTER_LOGIN_NOTIFY_FD to track login overflow state */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenmaster_service_connection_callback_t(const struct master_service_connection *conn);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenconst char *master_service_getopt_string(void);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Start service initialization. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenmaster_service_init(const char *name, enum master_service_flags flags,
a3fe8c0c54d87822f4b4f8f0d10caac611861b2bTimo Sirainen int *argc, char **argv[], const char *getopt_str);
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen/* Call getopt() and handle internal parameters. Return values are the same as
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainen getopt()'s. */
578ef2538ccf42e2a48234c24a8b709397101d88Timo Sirainenint master_getopt(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Parser command line option. Returns TRUE if processed. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenbool master_service_parse_option(struct master_service *service,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Finish service initialization. The caller should drop privileges
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen before calling this. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid master_service_init_finish(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Clean environment from everything except TZ, USER and optionally HOME. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid master_service_env_clean(bool preserve_home);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Initialize logging. */
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainenvoid master_service_init_log(struct master_service *service,
e0740628f6ca05f4bc79a9d8a90b650f4d38d4d0Timo Sirainen const char *prefix);
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen/* If set, die immediately when connection to master is lost.
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainen Normally all existing clients are handled first. */
3f603ef00e35fca21605afa0ad8d76e94fee2b96Timo Sirainenvoid master_service_set_die_with_master(struct master_service *service,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen/* Call the given when master connection dies and die_with_master is TRUE.
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen The callback is expected to shut down the service somewhat soon or it's
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen done forcibly. If NULL, the service is stopped immediately. */
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainenvoid master_service_set_die_callback(struct master_service *service,
86791365b10f45982c88e70f2eb94fd6c3fea151Timo Sirainen void (*callback)(void));
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen/* Call the given callback when there are no available connections and master
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen has indicated that it can't create any more processes to handle requests.
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen The callback could decide to kill one of the existing connections. */
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainenvoid master_service_set_avail_overflow_callback(struct master_service *service,
6fdfa4d4cf14d1d7764d7faa8258f112e39c8dbeTimo Sirainen void (*callback)(void));
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Set maximum number of clients we can handle. Default is given by master. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid master_service_set_client_limit(struct master_service *service,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Returns the maximum number of clients we can handle. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenunsigned int master_service_get_client_limit(struct master_service *service);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Set maximum number of client connections we will handle before shutting
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid master_service_set_service_count(struct master_service *service,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen unsigned int count);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Returns the number of client connections we will handle before shutting
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen down. The value is decreased only after connection has been closed. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenunsigned int master_service_get_service_count(struct master_service *service);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Return the number of listener sockets. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenunsigned int master_service_get_socket_count(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns configuration file path. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenconst char *master_service_get_config_path(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Returns PACKAGE_VERSION or NULL if version_ignore=yes. This function is
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen useful mostly as parameter to module_dir_load(). */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenconst char *master_service_get_version_string(struct master_service *service);
b2d562f9c7fd13f9a16e9b3bcee904630b80b1feTimo Sirainen/* Returns name of the service, as given in name parameter to _init(). */
b2d562f9c7fd13f9a16e9b3bcee904630b80b1feTimo Sirainenconst char *master_service_get_name(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Start the service. Blocks until finished */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid master_service_run(struct master_service *service,
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen master_service_connection_callback_t *callback);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Stop a running service. */
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainenvoid master_service_stop(struct master_service *service);
275385a2ecc58e41dc7df3ce3cd943caaa58c4d1Timo Sirainen/* Stop once we're done serving existing new connections, but don't accept
275385a2ecc58e41dc7df3ce3cd943caaa58c4d1Timo Sirainen any new ones. */
275385a2ecc58e41dc7df3ce3cd943caaa58c4d1Timo Sirainenvoid master_service_stop_new_connections(struct master_service *service);
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainen/* Send command to anvil process, if we have fd to it. */
6c2ce1d5bf17b21e804a079eb0f973b7ab83e0d8Timo Sirainenvoid master_service_anvil_send(struct master_service *service, const char *cmd);
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainen/* Call whenever a client connection is destroyed. */
d176f84ce5ca2073f4dfbafb457b9c74f6bf0d76Timo Sirainenvoid master_service_client_connection_destroyed(struct master_service *service);
8d3278a82b964217d95c340ec6f82037cdc59d19Timo Sirainen/* Deinitialize the service. */