paraslash Paraslash Audio Streaming
About   News   Download   Documentation   Development

Macros | Functions | Variables
server.c File Reference

Paraslash's main server. More...

#include <netinet/in.h>
#include <sys/socket.h>
#include <signal.h>
#include <regex.h>
#include <osl.h>
#include <sys/types.h>
#include <arpa/inet.h>
#include <sys/un.h>
#include <netdb.h>
#include <lopsub.h>
#include "server.lsg.h"
#include "para.h"
#include "error.h"
#include "lsu.h"
#include "crypt.h"
#include "afh.h"
#include "string.h"
#include "afs.h"
#include "net.h"
#include "server.h"
#include "list.h"
#include "sched.h"
#include "send.h"
#include "vss.h"
#include "config.h"
#include "close_on_fork.h"
#include "daemon.h"
#include "ipc.h"
#include "fd.h"
#include "user_list.h"
#include "color.h"
#include "version.h"

Macros

#define ALARM_TIMEOUT   10
 Shut down non-authorized connections after that many seconds. More...
 
#define CMD_PTR   (lls_cmd(0, server_suite))
 Get a reference to the supercommand of para_server. More...
 

Functions

bool process_is_command_handler (void)
 Tell whether the executing process is a command handler. More...
 
char * server_get_tasks (void)
 Return the list of tasks for the server process. More...
 
void parse_config_or_die (bool reload)
 (Re-)read the server configuration files. More...
 
void free_lpr (void)
 Deallocate all lopsub parse results. More...
 
int main (int argc, char *argv[])
 The main function of para_server. More...
 

Variables

 DEFINE_PARA_ERRLIST
 Array of error strings. More...
 
__printf_2_3 void(* para_log )(int, const char *,...) = daemon_log
 The log function of para_gui, always set to curses_log(). More...
 
struct misc_meta_datammd
 Pointer to shared memory area for communication between para_server and its children. More...
 
struct lls_parse_result * server_lpr = NULL
 The active value for all config options of para_server. More...
 
uint32_t afs_socket_cookie
 A random number used to "authenticate" the afs connection. More...
 
int mmd_mutex
 The mutex protecting the shared memory area containing the mmd struct. More...
 
pid_t afs_pid = 0
 The process id of the audio file selector process. More...
 

Detailed Description

Paraslash's main server.

Macro Definition Documentation

◆ ALARM_TIMEOUT

#define ALARM_TIMEOUT   10

Shut down non-authorized connections after that many seconds.

◆ CMD_PTR

#define CMD_PTR   (lls_cmd(0, server_suite))

Get a reference to the supercommand of para_server.

Function Documentation

◆ process_is_command_handler()

bool process_is_command_handler ( void  )

Tell whether the executing process is a command handler.

Cleanup on exit must be performed differently for command handlers.

Returns
True if the pid of the executing process is neither the server pid nor the afs pid.

References afs_pid.

Referenced by shutdown_client(), and vss_shutdown().

◆ server_get_tasks()

char* server_get_tasks ( void  )

Return the list of tasks for the server process.

This is called from com_tasks(). The helper is necessary since command handlers can not access the scheduler structure directly.

Returns
A dynamically allocated string that must be freed by the caller.

References get_task_list().

◆ parse_config_or_die()

void parse_config_or_die ( bool  reload)

(Re-)read the server configuration files.

Parameters
reloadWhether config file overrides command line.

This function also re-opens the logfile and the user list. On SIGHUP it is called from both server and afs context.

References MCF_DONT_FREE, and server_lpr.

◆ free_lpr()

void free_lpr ( void  )

Deallocate all lopsub parse results.

The server allocates a parse result for command line options and optionally a second parse result for the effective configuration, defined by merging the command line options with the options stored in the configuration file. This function frees both structures.

References CMD_PTR, and server_lpr.

◆ main()

int main ( int  argc,
char *  argv[] 
)

The main function of para_server.

Parameters
argcUsual argument count.
argvUsual argument vector.
Returns
EXIT_SUCCESS or EXIT_FAILURE.

References sched::default_timeout, and sched::poll_function.

Variable Documentation

◆ DEFINE_PARA_ERRLIST

DEFINE_PARA_ERRLIST

Array of error strings.

◆ para_log

__printf_2_3 void(* para_log) (int, const char *,...) = daemon_log

The log function of para_gui, always set to curses_log().

◆ mmd

struct misc_meta_data* mmd

Pointer to shared memory area for communication between para_server and its children.

Exported to vss.c, command.c and to afs.

Referenced by vss_chunk_time(), vss_next(), vss_paused(), vss_playing(), vss_repos(), and vss_stopped().

◆ server_lpr

struct lls_parse_result* server_lpr = NULL

The active value for all config options of para_server.

It is computed by merging the parse result of the command line options with the parse result of the config file.

Referenced by free_lpr(), and parse_config_or_die().

◆ afs_socket_cookie

uint32_t afs_socket_cookie

A random number used to "authenticate" the afs connection.

para_server picks this number by random before it forks the afs process. The command handlers know this number as well and write it to the afs socket, together with the id of the shared memory area which contains the payload of the afs command. A local process has to know this number to abuse the afs service provided by the local socket.

Referenced by send_callback_request().

◆ mmd_mutex

int mmd_mutex

The mutex protecting the shared memory area containing the mmd struct.

◆ afs_pid

pid_t afs_pid = 0

The process id of the audio file selector process.

Referenced by process_is_command_handler().