clsync
Loading...
Searching...
No Matches
ctx.h
Go to the documentation of this file.
1/*
2 clsync - file tree sync utility based on inotify
3
4 Copyright (C) 2013 Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#ifndef __CLSYNC_CTX_H
22#define __CLSYNC_CTX_H
23
24#include <regex.h>
25#ifdef CAPABILITIES_SUPPORT
26# include <sys/capability.h> // __u32
27#endif
28
29#define MAX_BLOCKTHREADS (1<<4)
30
31#define register_blockthread(thread) {\
32 critical_on (ctx_p->blockthread_count >= MAX_BLOCKTHREADS);\
33 ctx_p->blockthread[ctx_p->blockthread_count++] = pthread_self();\
34 debug(3, "register_blockthread(): ctx_p->blockthread_count -> %i", ctx_p->blockthread_count);\
35 }
36
37#define OPTION_FLAGS (1<<10)
38#define OPTION_LONGOPTONLY (1<<9)
39#define OPTION_CONFIGONLY (1<<8)
40#define NOTOPTION (3<<8)
42 WATCHDIR = 'W',
44 RULESFILE = 'R',
45 DESTDIR = 'D',
47
48 HELP = 'h',
52 UID = 'u',
53 GID = 'g',
55 THREADING = 'p',
56 RETRIES = 'r',
59 PIDFILE = 'z',
67 DELAY = 't',
69 SYNCDELAY = 'w',
71 DEBUG = 'd',
72 QUIET = 'q',
73 VERBOSE = 'v',
76 MODE = 'M',
79 INITFULL = 'F',
81 LABEL = 'l',
83
134};
135typedef enum flags_enum flags_t;
136
143
151
159
170typedef enum mode_id mode_id_t;
171
181typedef enum queue_id queue_id_t;
182
188
190 RA_NONE = 0x00,
192 RA_SYNC = 0x02,
193 RA_WALK = 0x04,
194 RA_ALL = 0x0f,
195};
197
198// signals (man 7 signal)
205
213typedef struct rule rule_t;
214
215struct queueinfo {
216 unsigned int collectdelay;
217 time_t stime;
218};
219typedef struct queueinfo queueinfo_t;
220
228
230 int ( *wait ) ( struct ctx *ctx_p, struct indexes *indexes_p, struct timeval *tv_p );
231 int ( *handle ) ( struct ctx *ctx_p, struct indexes *indexes_p );
232 int ( *add_watch_dir ) ( struct ctx *ctx_p, struct indexes *indexes_p, const char *const accpath );
233};
234
242typedef enum shflags shflags_t;
243
249
256
257#define STATE_STARTING(state_p) (state_p == NULL)
272typedef enum state_enum state_t;
273
274static char *const status_descr[] = {
275 [STATE_EXIT] = "exiting",
276 [STATE_STARTING] = "starting",
277 [STATE_RUNNING] = "running",
278 [STATE_SYNCHANDLER_ERR] = "synchandler error",
279 [STATE_REHASH] = "rehashing",
280 [STATE_PREEXIT] = "preexit",
281 [STATE_LASTSYNC] = "lastsync",
282 [STATE_TERM] = "terminating",
283 [STATE_THREAD_GC] = "thread gc",
284 [STATE_INITSYNC] = "initsync",
285 [STATE_HOLDON] = "hold on",
286 NULL
287};
288
307
309 CSC_RESET = 0x00,
311};
312
313#define CAP_PRESERVE_TRY (1<<16)
314
315struct ctx {
316#ifndef LIBCLSYNC
317 volatile state_t state;
318 pid_t pid;
319 char pid_str[65];
321 uid_t uid;
322 gid_t gid;
327#ifdef CAPABILITIES_SUPPORT
328 __u32 caps;
329#endif
330 pid_t child_pid[MAXCHILDREN]; // Used only for non-pthread mode
331 int children; // Used only for non-pthread mode
335 dev_t st_dev;
336#endif
340#ifndef LIBCLSYNC
342 const char *config_block;
344 char *label;
345 char *watchdir;
346 char *pidfile;
350 char *destdir;
357#ifdef CGROUP_SUPPORT
358 char *cg_groupname;
359#endif
361 mode_t socketmod;
364#ifdef CLUSTER_SUPPORT
365 char *cluster_iface;
366 char *cluster_mcastipaddr;
367 char *cluster_nodename;
368 uint32_t cluster_nodename_len;
369 uint16_t cluster_mcastipport;
370 uint16_t cluster_hash_dl_min;
371 uint16_t cluster_hash_dl_max;
372 uint16_t cluster_scan_dl_max;
373 unsigned int cluster_timeout;
374#endif
385 char *rulfpath;
391 unsigned int syncdelay;
392 queueinfo_t _queues[QUEUE_MAX]; // TODO: remove this from here
393 unsigned int rsyncinclimit;
394 time_t synctime;
395 unsigned int synctimeout;
396 sigset_t *sigset;
397 char isignoredexitcode[ ( 1 << 8 )];
400
402
403#ifdef CAPABILITIES_SUPPORT
404 char *permitted_hookfile[MAXPERMITTEDHOOKFILES + 1];
405 int permitted_hookfiles;
406#endif
407
408#ifdef UNSHARE_SUPPORT
409# ifdef GETMNTENT_SUPPORT
410 char *mountpoint[MAXMOUNTPOINTS + 1];
411 int mountpoints;
412# endif
413#endif
414
417#endif // ifndef LIBCLSYNC
418 void *indexes_p;
420};
421typedef struct ctx ctx_t;
422
423#endif
424
int(* api_funct_init)(struct ctx *, struct indexes *)
Definition clsync.h:51
int(* api_funct_sync)(int n, api_eventinfo_t *)
Definition clsync.h:52
int(* api_funct_rsync)(const char *inclist, const char *exclist)
Definition clsync.h:53
int(* api_funct_deinit)()
Definition clsync.h:54
#define MAXARGUMENTS
#define MAXSIGNALNUM
#define MAXMOUNTPOINTS
#define MAXRULES
#define MAXCHILDREN
#define MAXPERMITTEDHOOKFILES
enum ruleactionsign_enum ruleactionsign_t
Definition ctx.h:187
queue_id
Definition ctx.h:172
@ QUEUE_NORMAL
Definition ctx.h:173
@ QUEUE_LOCKWAIT
Definition ctx.h:176
@ QUEUE_AUTO
Definition ctx.h:179
@ QUEUE_INSTANT
Definition ctx.h:175
@ QUEUE_BIGFILE
Definition ctx.h:174
@ QUEUE_MAX
Definition ctx.h:178
flags_enum
Definition ctx.h:41
@ SOCKETAUTH
Definition ctx.h:97
@ CLUSTERIFACE
Definition ctx.h:60
@ SYNCHANDLERARGS1
Definition ctx.h:106
@ SECURESPLITTING
Definition ctx.h:121
@ DEBUG
Definition ctx.h:71
@ SYNCDELAY
Definition ctx.h:69
@ CLUSTERMCASTIPADDR
Definition ctx.h:61
@ SYNCHANDLERUID
Definition ctx.h:111
@ LABEL
Definition ctx.h:81
@ CLUSTERMCASTIPPORT
Definition ctx.h:62
@ MOUNTPOINTS
Definition ctx.h:109
@ SOCKETOWN
Definition ctx.h:99
@ INITFULL
Definition ctx.h:79
@ STANDBYFILE
Definition ctx.h:93
@ RSYNCPREFERINCLUDE
Definition ctx.h:86
@ CLUSTERTIMEOUT
Definition ctx.h:63
@ AUTORULESW
Definition ctx.h:75
@ DELAY
Definition ctx.h:67
@ HAVERECURSIVESYNC
Definition ctx.h:84
@ SYNCLISTSIMPLIFY
Definition ctx.h:87
@ DONTUNLINK
Definition ctx.h:78
@ ONEFILESYSTEM
Definition ctx.h:88
@ BFILEDELAY
Definition ctx.h:68
@ SYNCHANDLER
Definition ctx.h:43
@ GID
Definition ctx.h:53
@ CLUSTERHDLMIN
Definition ctx.h:65
@ SOCKETPATH
Definition ctx.h:46
@ CANCEL_SYSCALLS
Definition ctx.h:128
@ SYNCHANDLERARGS0
Definition ctx.h:105
@ SYNCTIMEOUT
Definition ctx.h:80
@ FORGET_PRIVTHREAD_INFO
Definition ctx.h:120
@ PERMIT_MPROTECT
Definition ctx.h:125
@ UID
Definition ctx.h:52
@ PRIVILEGEDUID
Definition ctx.h:131
@ SOCKETMOD
Definition ctx.h:98
@ OUTPUT_METHOD
Definition ctx.h:57
@ QUIET
Definition ctx.h:72
@ MAXITERATIONS
Definition ctx.h:100
@ CUSTOMSIGNALS
Definition ctx.h:107
@ CLUSTERNODENAME
Definition ctx.h:64
@ EXITONSYNCSKIP
Definition ctx.h:129
@ SKIPINITSYNC
Definition ctx.h:90
@ SECCOMP_FILTER
Definition ctx.h:119
@ SHM_MPROTECT
Definition ctx.h:126
@ FORBIDDEVICES
Definition ctx.h:123
@ PRIVILEGEDGID
Definition ctx.h:132
@ CONFIGBLOCK
Definition ctx.h:50
@ BFILETHRESHOLD
Definition ctx.h:70
@ DETACH_NETWORK
Definition ctx.h:116
@ RETRIES
Definition ctx.h:56
@ CHECK_EXECVP_ARGS
Definition ctx.h:114
@ CG_GROUPNAME
Definition ctx.h:124
@ MODE
Definition ctx.h:76
@ CLUSTERSDLMAX
Definition ctx.h:95
@ DETACH_MISCELLANEA
Definition ctx.h:117
@ RULESFILE
Definition ctx.h:44
@ MONITOR
Definition ctx.h:104
@ RSYNCINCLIMIT
Definition ctx.h:85
@ PIVOT_ROOT
Definition ctx.h:115
@ MODSIGN
Definition ctx.h:127
@ SHOW_VERSION
Definition ctx.h:82
@ CLUSTERHDLMAX
Definition ctx.h:66
@ EXITHOOK
Definition ctx.h:94
@ HELP
Definition ctx.h:48
@ THREADING
Definition ctx.h:55
@ BACKGROUND
Definition ctx.h:51
@ CAP_PRESERVE
Definition ctx.h:54
@ CAPS_INHERIT
Definition ctx.h:113
@ PIDFILE
Definition ctx.h:59
@ DESTDIR
Definition ctx.h:45
@ WATCHDIR
Definition ctx.h:42
@ CHROOT
Definition ctx.h:108
@ DETACH_IPC
Definition ctx.h:130
@ FTS_EXPERIMENTAL_OPTIMIZATION
Definition ctx.h:122
@ VERBOSE
Definition ctx.h:73
@ IGNOREFAILURES
Definition ctx.h:101
@ ONLYINITSYNC
Definition ctx.h:91
@ CONFIGBLOCKINHERITS
Definition ctx.h:103
@ EXCLUDEMOUNTPOINTS
Definition ctx.h:58
@ DUMPDIR
Definition ctx.h:102
@ SYNCHANDLERGID
Definition ctx.h:112
@ OUTLISTSDIR
Definition ctx.h:74
@ EXITONNOEVENTS
Definition ctx.h:92
@ STATUSFILE
Definition ctx.h:89
@ CONFIGFILE
Definition ctx.h:49
@ SPLITTING
Definition ctx.h:110
@ ADDPERMITTEDHOOKFILES
Definition ctx.h:118
@ PREEXITHOOK
Definition ctx.h:96
@ IGNOREEXITCODE
Definition ctx.h:77
@ SOFTEXITSYNC
Definition ctx.h:133
enum state_enum state_t
Definition ctx.h:272
enum mode_id mode_id_t
Definition ctx.h:170
mode_id
Definition ctx.h:160
@ 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
enum pivotroot_way pivotroot_way_t
Definition ctx.h:150
enum detachnetwork_way detachnetwork_way_t
Definition ctx.h:142
enum flags_enum flags_t
Definition ctx.h:135
#define STATE_STARTING(state_p)
Definition ctx.h:257
shargsid
Definition ctx.h:244
@ SHARGS_PRIMARY
Definition ctx.h:245
@ SHARGS_INITIAL
Definition ctx.h:246
@ SHARGS_MAX
Definition ctx.h:247
enum ruleaction_enum ruleaction_t
Definition ctx.h:196
static char *const status_descr[]
Definition ctx.h:274
syscall_bitmask
Definition ctx.h:308
@ CSC_MON_STAT
Definition ctx.h:310
@ CSC_RESET
Definition ctx.h:309
shflags
Definition ctx.h:235
@ SHFL_EXCLUDE_LIST_PATH
Definition ctx.h:240
@ SHFL_RSYNC_ARGS
Definition ctx.h:237
@ SHFL_INCLUDE_LIST_PATH
Definition ctx.h:239
@ SHFL_INCLUDE_LIST
Definition ctx.h:238
@ SHFL_NONE
Definition ctx.h:236
enum capsinherit capsinherit_t
Definition ctx.h:158
capsinherit
Definition ctx.h:152
@ CI_CLSYNC
Definition ctx.h:155
@ CI_DONTTOUCH
Definition ctx.h:153
@ CI_EMPTY
Definition ctx.h:156
@ CI_PERMITTED
Definition ctx.h:154
stat_fields
Definition ctx.h:289
@ STAT_FIELD_RDEV
Definition ctx.h:297
@ STAT_FIELD_ATIME
Definition ctx.h:301
@ STAT_FIELD_INO
Definition ctx.h:292
@ STAT_FIELD_CTIME
Definition ctx.h:303
@ STAT_FIELD_BLOCKS
Definition ctx.h:300
@ STAT_FIELD_NLINK
Definition ctx.h:294
@ STAT_FIELD_RESET
Definition ctx.h:290
@ STAT_FIELD_SIZE
Definition ctx.h:298
@ STAT_FIELD_MTIME
Definition ctx.h:302
@ STAT_FIELD_GID
Definition ctx.h:296
@ STAT_FIELD_UID
Definition ctx.h:295
@ STAT_FIELD_MODE
Definition ctx.h:293
@ STAT_FIELD_DEV
Definition ctx.h:291
@ STAT_FIELD_BLKSIZE
Definition ctx.h:299
@ STAT_FIELD_ALL
Definition ctx.h:305
ruleaction_enum
Definition ctx.h:189
@ RA_MONITOR
Definition ctx.h:191
@ RA_SYNC
Definition ctx.h:192
@ RA_NONE
Definition ctx.h:190
@ RA_ALL
Definition ctx.h:194
@ RA_WALK
Definition ctx.h:193
#define MAX_BLOCKTHREADS
Definition ctx.h:29
pivotroot_way
Definition ctx.h:144
@ PW_AUTO
Definition ctx.h:147
@ PW_OFF
Definition ctx.h:145
@ PW_AUTORO
Definition ctx.h:148
@ PW_DIRECT
Definition ctx.h:146
enum queue_id queue_id_t
Definition ctx.h:181
detachnetwork_way
Definition ctx.h:137
@ DN_NONPRIVILEGED
Definition ctx.h:139
@ DN_EVERYWHERE
Definition ctx.h:140
@ DN_OFF
Definition ctx.h:138
enum shflags shflags_t
Definition ctx.h:242
#define OPTION_FLAGS
Definition ctx.h:37
#define OPTION_LONGOPTONLY
Definition ctx.h:38
sigusr_enum
Definition ctx.h:199
@ SIGUSR_BLOPINT
Definition ctx.h:202
@ SIGUSR_INITSYNC
Definition ctx.h:201
@ SIGUSR_THREAD_GC
Definition ctx.h:200
@ SIGUSR_DUMP
Definition ctx.h:203
state_enum
Definition ctx.h:258
@ STATE_EXIT
Definition ctx.h:259
@ STATE_TERM
Definition ctx.h:266
@ STATE_UNKNOWN
Definition ctx.h:270
@ STATE_SYNCHANDLER_ERR
Definition ctx.h:262
@ STATE_HOLDON
Definition ctx.h:269
@ STATE_REHASH
Definition ctx.h:263
@ STATE_THREAD_GC
Definition ctx.h:267
@ STATE_INITSYNC
Definition ctx.h:268
@ STATE_PREEXIT
Definition ctx.h:264
@ STATE_RUNNING
Definition ctx.h:261
@ STATE_LASTSYNC
Definition ctx.h:265
ruleactionsign_enum
Definition ctx.h:183
@ RS_PERMIT
Definition ctx.h:185
@ RS_REJECT
Definition ctx.h:184
ctx_t * ctx_p
Definition mon_kqueue.c:85
api_funct_sync sync
Definition ctx.h:223
api_funct_init init
Definition ctx.h:222
api_funct_rsync rsync
Definition ctx.h:224
api_funct_deinit deinit
Definition ctx.h:225
Definition ctx.h:315
char * listoutdir
Definition ctx.h:387
size_t destdirwslashsize
Definition ctx.h:380
size_t pid_str_len
Definition ctx.h:320
int flags_set[(1<< 10)]
Definition ctx.h:339
char * statusfile
Definition ctx.h:354
unsigned int syncdelay
Definition ctx.h:391
char * handlerfpath
Definition ctx.h:382
size_t destdirsize
Definition ctx.h:378
char * flags_values_raw[(1<< 10)]
Definition ctx.h:337
size_t watchdirsize
Definition ctx.h:377
size_t rulfpathsize
Definition ctx.h:386
pid_t child_pid[MAXCHILDREN]
Definition ctx.h:330
int socket
Definition ctx.h:360
int retries
Definition ctx.h:389
char * preexithookfile
Definition ctx.h:349
void * fsmondata
Definition ctx.h:419
int children
Definition ctx.h:331
char * watchdirwslash
Definition ctx.h:352
char * destdir
Definition ctx.h:350
pthread_t blockthread[(1<< 4)]
Definition ctx.h:398
void * handler_handle
Definition ctx.h:383
char * pidfile
Definition ctx.h:346
shflags_t synchandler_argf
Definition ctx.h:416
short int watchdir_dirlevel
Definition ctx.h:381
size_t bfilethreshold
Definition ctx.h:390
char * exithookfile
Definition ctx.h:348
mode_t socketmod
Definition ctx.h:361
char * destdirwslash
Definition ctx.h:353
uid_t socketuid
Definition ctx.h:362
gid_t synchandler_gid
Definition ctx.h:326
char * chroot_dir
Definition ctx.h:401
pid_t pid
Definition ctx.h:318
const char * config_block
Definition ctx.h:342
char * socketpath
Definition ctx.h:355
char * label
Definition ctx.h:344
char * watchdir
Definition ctx.h:345
api_functs_t handler_funct
Definition ctx.h:384
uid_t uid
Definition ctx.h:321
char * config_path
Definition ctx.h:341
dev_t st_dev
Definition ctx.h:335
unsigned int synctimeout
Definition ctx.h:395
gid_t socketgid
Definition ctx.h:363
queueinfo_t _queues[QUEUE_MAX]
Definition ctx.h:392
volatile state_t state
Definition ctx.h:317
sigset_t * sigset
Definition ctx.h:396
size_t blockthread_count
Definition ctx.h:399
char pid_str[65]
Definition ctx.h:319
size_t watchdirwslashsize
Definition ctx.h:379
uid_t synchandler_uid
Definition ctx.h:325
char * dump_path
Definition ctx.h:356
char * standbyfile
Definition ctx.h:347
struct notifyenginefuncts notifyenginefunct
Definition ctx.h:388
int flags[(1<< 10)]
Definition ctx.h:338
time_t synctime
Definition ctx.h:394
size_t rules_count
Definition ctx.h:334
unsigned int rsyncinclimit
Definition ctx.h:393
size_t watchdirlen
Definition ctx.h:375
gid_t privileged_gid
Definition ctx.h:324
uint32_t iteration_num
Definition ctx.h:332
char * rulfpath
Definition ctx.h:385
char * customsignal[MAXSIGNALNUM+1]
Definition ctx.h:343
size_t destdirlen
Definition ctx.h:376
rule_t rules[MAXRULES]
Definition ctx.h:333
char * destproto
Definition ctx.h:351
uid_t privileged_uid
Definition ctx.h:323
gid_t gid
Definition ctx.h:322
char isignoredexitcode[(1<< 8)]
Definition ctx.h:397
int(* add_watch_dir)(struct ctx *ctx_p, struct indexes *indexes_p, const char *const accpath)
Definition ctx.h:232
int(* handle)(struct ctx *ctx_p, struct indexes *indexes_p)
Definition ctx.h:231
int(* wait)(struct ctx *ctx_p, struct indexes *indexes_p, struct timeval *tv_p)
Definition ctx.h:230
unsigned int collectdelay
Definition ctx.h:216
time_t stime
Definition ctx.h:217
Definition ctx.h:206
ruleaction_t perm
Definition ctx.h:210
mode_t objtype
Definition ctx.h:209
ruleaction_t mask
Definition ctx.h:211
regex_t expr
Definition ctx.h:208
int num
Definition ctx.h:207
char isexpanded[MAXARGUMENTS]
Definition ctx.h:253
char * v[MAXARGUMENTS]
Definition ctx.h:251