clsync
Loading...
Searching...
No Matches
main.c File Reference
#include "common.h"
#include <pwd.h>
#include <grp.h>
#include <glib.h>
#include "error.h"
#include "stringex.h"
#include "sync.h"
#include "malloc.h"
#include "cluster.h"
#include "fileutils.h"
#include "socket.h"
#include "syscalls.h"
#include "rules.h"
#include "posix-hacks.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define PEF_NONE   0
 
#define PEF_UNEXPECTED_END   1
 
#define PEF_UNSET_VARIABLE   2
 
#define PEF_LAZY_SUBSTITUTION   4
 
#define UGID_PRESERVE   (1<<16)
 

Enumerations

enum  xstatfield {
  X_STAT_FIELD_RESET = 0 , X_STAT_FIELD_DEV , X_STAT_FIELD_INO , X_STAT_FIELD_MODE ,
  X_STAT_FIELD_NLINK , X_STAT_FIELD_UID , X_STAT_FIELD_GID , X_STAT_FIELD_RDEV ,
  X_STAT_FIELD_SIZE , X_STAT_FIELD_BLKSIZE , X_STAT_FIELD_BLOCKS , X_STAT_FIELD_ATIME ,
  X_STAT_FIELD_MTIME , X_STAT_FIELD_CTIME , X_STAT_FIELD_ALL
}
 
enum  x_csc_bm { X_CSC_RESET = 0 , X_CSC_MON_STAT }
 

Functions

int syntax ()
 
pid_t waitpid_timed (pid_t child_pid, int *status_p, long sec, long nsec)
 
int parent_isalive ()
 
void child_sigchld ()
 
int sethandler_sigchld (void(*handler)())
 
void * watchforparent (void *parent_pid_p)
 
pid_t fork_helper ()
 
int version ()
 
int clsyncapi_getapiversion ()
 Returns currect API version.
 
const char * parameter_get (const char *variable_name, void *_ctx_p)
 Gets raw (string) an option value by an option name.
 
const char * parameter_get_name_by_id (const uint16_t param_id)
 Gets the name of the parameter by it's id.
 
const char * parameter_get_wmacro (const char *variable_name, void *_ctx_p)
 Gets raw (string) an option value by an option name and updates ctx_p->synchandler_argf.
 
char * parameter_expand (ctx_t *ctx_p, char *arg, int exceptionflags, int *macro_count_p, int *expand_count_p, const char *(*parameter_get)(const char *variable_name, void *arg), void *parameter_get_arg)
 Expands option values, e. g. "/var/log/clsync-%label%.pid" -> "/var/log/clsync-clone.pid".
 
const char * parametersource_get_name (paramsource_t paramsource)
 Gets the name of the parameter source by it's id.
 
static int synchandler_arg (char *arg, size_t arg_len, void *_ctx_p, enum shargsid shargsid)
 
static int synchandler_arg0 (char *arg, size_t arg_len, void *_ctx_p)
 
static int synchandler_arg1 (char *arg, size_t arg_len, void *_ctx_p)
 
static long xstrtol (const char *str, int *err)
 
static long xstrtol_trim (char *str, int *err)
 
static __extension__ int parse_customsignals (ctx_t *ctx_p, char *arg)
 
static __extension__ int parse_parameter (ctx_t *ctx_p, uint16_t param_id, char *arg, paramsource_t paramsource)
 
int arguments_parse (int argc, char *argv[], struct ctx *ctx_p)
 
void gkf_parse (ctx_t *ctx_p, GKeyFile *gkf, paramsource_t paramsource)
 
int configs_parse (ctx_t *ctx_p, paramsource_t paramsource)
 
int ctx_check (ctx_t *ctx_p)
 
int config_block_parse (ctx_t *ctx_p, const char *const config_block_name)
 
int ctx_set (ctx_t *ctx_p, const char *const parameter_name, const char *const parameter_value)
 
void ctx_cleanup (ctx_t *ctx_p)
 
int becomedaemon ()
 
int main_cleanup (ctx_t *ctx_p)
 
int main_rehash (ctx_t *ctx_p)
 
int main_status_update (ctx_t *ctx_p)
 
int main (int _argc, char *_argv[])
 

Variables

static const struct option long_options []
 
uint32_t xstatfield_to_statfield []
 
static char *const stat_fields []
 
uint32_t xcsc_to_csc []
 
static char *const syscalls_bitmask []
 
static char *const socketauth []
 
static char *const notify_engines []
 
static char *const output_methods []
 
static char *const modes []
 
int ncpus
 
pid_t parent_pid = 0
 
pthread_t pthread_watchforparent
 
FILE * main_statusfile_f
 
int argc
 
char ** argv
 

Macro Definition Documentation

◆ PEF_LAZY_SUBSTITUTION

#define PEF_LAZY_SUBSTITUTION   4

Definition at line 673 of file main.c.

◆ PEF_NONE

#define PEF_NONE   0

Definition at line 670 of file main.c.

◆ PEF_UNEXPECTED_END

#define PEF_UNEXPECTED_END   1

Definition at line 671 of file main.c.

◆ PEF_UNSET_VARIABLE

#define PEF_UNSET_VARIABLE   2

Definition at line 672 of file main.c.

◆ UGID_PRESERVE

#define UGID_PRESERVE   (1<<16)

Definition at line 2726 of file main.c.

Enumeration Type Documentation

◆ x_csc_bm

enum x_csc_bm
Enumerator
X_CSC_RESET 
X_CSC_MON_STAT 

Definition at line 253 of file main.c.

◆ xstatfield

enum xstatfield
Enumerator
X_STAT_FIELD_RESET 
X_STAT_FIELD_DEV 
X_STAT_FIELD_INO 
X_STAT_FIELD_MODE 
X_STAT_FIELD_NLINK 
X_STAT_FIELD_UID 
X_STAT_FIELD_GID 
X_STAT_FIELD_RDEV 
X_STAT_FIELD_SIZE 
X_STAT_FIELD_BLKSIZE 
X_STAT_FIELD_BLOCKS 
X_STAT_FIELD_ATIME 
X_STAT_FIELD_MTIME 
X_STAT_FIELD_CTIME 
X_STAT_FIELD_ALL 

Definition at line 198 of file main.c.

Function Documentation

◆ arguments_parse()

int arguments_parse ( int argc,
char * argv[],
struct ctx * ctx_p )

Definition at line 1988 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ becomedaemon()

int becomedaemon ( )

Definition at line 2619 of file main.c.

Here is the caller graph for this function:

◆ child_sigchld()

void child_sigchld ( )

Definition at line 430 of file main.c.

Here is the caller graph for this function:

◆ clsyncapi_getapiversion()

int clsyncapi_getapiversion ( )

Returns currect API version.

Return values
api_versionVersion of clsync's API

Definition at line 550 of file main.c.

◆ config_block_parse()

int config_block_parse ( ctx_t * ctx_p,
const char *const config_block_name )

Definition at line 2547 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ configs_parse()

int configs_parse ( ctx_t * ctx_p,
paramsource_t paramsource )

Definition at line 2083 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ctx_check()

int ctx_check ( ctx_t * ctx_p)

Definition at line 2145 of file main.c.

Here is the caller graph for this function:

◆ ctx_cleanup()

void ctx_cleanup ( ctx_t * ctx_p)

Definition at line 2582 of file main.c.

Here is the caller graph for this function:

◆ ctx_set()

int ctx_set ( ctx_t * ctx_p,
const char *const parameter_name,
const char *const parameter_value )

Definition at line 2560 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fork_helper()

pid_t fork_helper ( )

Definition at line 463 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gkf_parse()

void gkf_parse ( ctx_t * ctx_p,
GKeyFile * gkf,
paramsource_t paramsource )

Definition at line 2046 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int _argc,
char * _argv[] )

Definition at line 2727 of file main.c.

Here is the call graph for this function:

◆ main_cleanup()

int main_cleanup ( ctx_t * ctx_p)

Definition at line 2642 of file main.c.

Here is the caller graph for this function:

◆ main_rehash()

int main_rehash ( ctx_t * ctx_p)

Definition at line 2653 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main_status_update()

int main_status_update ( ctx_t * ctx_p)

Definition at line 2673 of file main.c.

Here is the caller graph for this function:

◆ parameter_expand()

char * parameter_expand ( ctx_t * ctx_p,
char * arg,
int exceptionflags,
int * macro_count_p,
int * expand_count_p,
const char *(* parameter_get )(const char *variable_name, void *arg),
void * parameter_get_arg )

Expands option values, e. g. "/var/log/clsync-%label%.pid" -> "/var/log/clsync-clone.pid".

Parameters
[in]ctx_pContext
[in]argAn allocated string with unexpanded value. Will be free'd
[in]exceptionflagsA bit field of allowed exceptions during parameter expansion:
  • PEF_NONE No exceptions are allowed
  • PEF_UNEXPECTED_END Do not warn about unexpected end of macro-substitution
  • PEF_UNSET_VARIABLE Do not warn about unset variable
  • PEF_LAZY_SUBSTITUTION Perform lazy substitution preserving original value
[out]macro_count_pA pointer to count of found macro-s
[out]expand_count_pA pointer to count of expanded macro-s
[in]parameter_getA function to resolve macro-s
[in]parameter_get_argAn argument to the function
Return values
char* Pointer to newly allocated string, if successful
NULLOn error

Definition at line 693 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parameter_get()

const char * parameter_get ( const char * variable_name,
void * _ctx_p )

Gets raw (string) an option value by an option name.

Parameters
[in]_ctx_pContext
[in]variable_nameThe name of the option
Return values
char* Pointer to constant string, if successful
NULLOn error

Definition at line 565 of file main.c.

Here is the caller graph for this function:

◆ parameter_get_name_by_id()

const char * parameter_get_name_by_id ( const uint16_t param_id)

Gets the name of the parameter by it's id.

Parameters
[in]param_idThe id of the parameter
Return values
char* Pointer to a constant string, if successful
NULLOn error

Definition at line 599 of file main.c.

Here is the caller graph for this function:

◆ parameter_get_wmacro()

const char * parameter_get_wmacro ( const char * variable_name,
void * _ctx_p )

Gets raw (string) an option value by an option name and updates ctx_p->synchandler_argf.

Parameters
[in]_ctx_pContext
[in]variable_nameThe name of the option
Return values
char* Pointer to newly allocated string, if successful
NULLOn error

Definition at line 634 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parametersource_get_name()

const char * parametersource_get_name ( paramsource_t paramsource)

Gets the name of the parameter source by it's id.

Parameters
[in]paramsourceThe id of the parameter source
Return values
char* Pointer to a constant string, if successful
NULLOn error

Definition at line 852 of file main.c.

Here is the caller graph for this function:

◆ parent_isalive()

int parent_isalive ( )

Definition at line 415 of file main.c.

◆ parse_customsignals()

static __extension__ int parse_customsignals ( ctx_t * ctx_p,
char * arg )
inlinestatic

Definition at line 968 of file main.c.

Here is the caller graph for this function:

◆ parse_parameter()

static __extension__ int parse_parameter ( ctx_t * ctx_p,
uint16_t param_id,
char * arg,
paramsource_t paramsource )
static

Definition at line 1060 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sethandler_sigchld()

int sethandler_sigchld ( void(* handler )())

Definition at line 440 of file main.c.

Here is the caller graph for this function:

◆ synchandler_arg()

static int synchandler_arg ( char * arg,
size_t arg_len,
void * _ctx_p,
enum shargsid shargsid )
inlinestatic

Definition at line 877 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ synchandler_arg0()

static int synchandler_arg0 ( char * arg,
size_t arg_len,
void * _ctx_p )
static

Definition at line 921 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ synchandler_arg1()

static int synchandler_arg1 ( char * arg,
size_t arg_len,
void * _ctx_p )
static

Definition at line 926 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ syntax()

int syntax ( )

Definition at line 361 of file main.c.

Here is the caller graph for this function:

◆ version()

int version ( )

Definition at line 484 of file main.c.

Here is the caller graph for this function:

◆ waitpid_timed()

pid_t waitpid_timed ( pid_t child_pid,
int * status_p,
long sec,
long nsec )

Definition at line 388 of file main.c.

Here is the caller graph for this function:

◆ watchforparent()

void * watchforparent ( void * parent_pid_p)

Definition at line 451 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ xstrtol()

static long xstrtol ( const char * str,
int * err )
inlinestatic

Definition at line 932 of file main.c.

Here is the caller graph for this function:

◆ xstrtol_trim()

static long xstrtol_trim ( char * str,
int * err )
inlinestatic

Definition at line 948 of file main.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ argc

int argc

Definition at line 2724 of file main.c.

◆ argv

char** argv

Definition at line 2725 of file main.c.

◆ long_options

const struct option long_options[]
static

Definition at line 59 of file main.c.

◆ main_statusfile_f

FILE* main_statusfile_f

Definition at line 2672 of file main.c.

◆ modes

char* const modes[]
static
Initial value:
= {
[MODE_UNSET] = "",
[MODE_SIMPLE] = "simple",
[MODE_DIRECT] = "direct",
[MODE_SHELL] = "shell",
[MODE_RSYNCSHELL] = "rsyncshell",
[MODE_RSYNCDIRECT] = "rsyncdirect",
[MODE_RSYNCSO] = "rsyncso",
[MODE_SO] = "so",
NULL
}
@ MODE_RSYNCSHELL
Definition ctx.h:165
@ MODE_DIRECT
Definition ctx.h:163
@ MODE_RSYNCSO
Definition ctx.h:167
@ MODE_SIMPLE
Definition ctx.h:162
@ MODE_UNSET
Definition ctx.h:161
@ MODE_RSYNCDIRECT
Definition ctx.h:166
@ MODE_SO
Definition ctx.h:168
@ MODE_SHELL
Definition ctx.h:164

Definition at line 349 of file main.c.

◆ ncpus

int ncpus

Definition at line 385 of file main.c.

◆ notify_engines

char* const notify_engines[]
static
Initial value:
= {
[NE_UNDEFINED] = "",
[NE_INOTIFY] = "inotify",
[NE_KQUEUE] = "kqueue",
[NE_FANOTIFY] = "fanotify",
[NE_BSM] = "bsm",
[NE_BSM_PREFETCH] = "bsm_prefetch",
[NE_DTRACEPIPE] = "dtracepipe",
[NE_GIO] = "gio",
NULL
}
@ NE_UNDEFINED
Definition common.h:105
@ NE_INOTIFY
Definition common.h:107
@ NE_FANOTIFY
Definition common.h:106
@ NE_KQUEUE
Definition common.h:108
@ NE_GIO
Definition common.h:112
@ NE_BSM_PREFETCH
Definition common.h:110
@ NE_DTRACEPIPE
Definition common.h:111
@ NE_BSM
Definition common.h:109

Definition at line 330 of file main.c.

◆ output_methods

char* const output_methods[]
static
Initial value:
= {
[OM_STDERR] = "stderr",
[OM_STDOUT] = "stdout",
[OM_SYSLOG] = "syslog",
NULL
}
@ OM_STDOUT
Definition error.h:71
@ OM_STDERR
Definition error.h:70
@ OM_SYSLOG
Definition error.h:72

Definition at line 342 of file main.c.

◆ parent_pid

pid_t parent_pid = 0

Definition at line 386 of file main.c.

◆ pthread_watchforparent

pthread_t pthread_watchforparent

Definition at line 462 of file main.c.

◆ socketauth

char* const socketauth[]
static
Initial value:
= {
[SOCKAUTH_NULL] = "null",
NULL
}
@ SOCKAUTH_UNSET
Definition socket.h:200
@ SOCKAUTH_NULL
Definition socket.h:201

Definition at line 305 of file main.c.

◆ stat_fields

char* const stat_fields[]
static
Initial value:
= {
[X_STAT_FIELD_DEV] = "dev",
[X_STAT_FIELD_INO] = "ino",
[X_STAT_FIELD_MODE] = "mode",
[X_STAT_FIELD_NLINK] = "nlink",
[X_STAT_FIELD_UID] = "uid",
[X_STAT_FIELD_GID] = "gid",
[X_STAT_FIELD_RDEV] = "rdev",
[X_STAT_FIELD_SIZE] = "size",
[X_STAT_FIELD_BLKSIZE] = "blksize",
[X_STAT_FIELD_BLOCKS] = "blocks",
[X_STAT_FIELD_ATIME] = "atime",
[X_STAT_FIELD_MTIME] = "mtime",
[X_STAT_FIELD_CTIME] = "ctime",
NULL
}
@ X_STAT_FIELD_INO
Definition main.c:201
@ X_STAT_FIELD_MTIME
Definition main.c:211
@ X_STAT_FIELD_DEV
Definition main.c:200
@ X_STAT_FIELD_SIZE
Definition main.c:207
@ X_STAT_FIELD_CTIME
Definition main.c:212
@ X_STAT_FIELD_UID
Definition main.c:204
@ X_STAT_FIELD_ATIME
Definition main.c:210
@ X_STAT_FIELD_RESET
Definition main.c:199
@ X_STAT_FIELD_GID
Definition main.c:205
@ X_STAT_FIELD_BLKSIZE
Definition main.c:208
@ X_STAT_FIELD_RDEV
Definition main.c:206
@ X_STAT_FIELD_ALL
Definition main.c:213
@ X_STAT_FIELD_NLINK
Definition main.c:203
@ X_STAT_FIELD_MODE
Definition main.c:202
@ X_STAT_FIELD_BLOCKS
Definition main.c:209

Definition at line 234 of file main.c.

◆ syscalls_bitmask

char* const syscalls_bitmask[]
static
Initial value:
= {
[X_CSC_RESET] = "",
[X_CSC_MON_STAT] = "mon_stat",
NULL
}
@ X_CSC_MON_STAT
Definition main.c:255
@ X_CSC_RESET
Definition main.c:254

Definition at line 263 of file main.c.

◆ xcsc_to_csc

uint32_t xcsc_to_csc[]
Initial value:
= {
}
@ CSC_MON_STAT
Definition ctx.h:310
@ CSC_RESET
Definition ctx.h:309

Definition at line 258 of file main.c.

◆ xstatfield_to_statfield

uint32_t xstatfield_to_statfield[]
Initial value:

Definition at line 216 of file main.c.