Blame view

redmine authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
    clsync - file tree sync utility based on fanotify and inotify

    Copyright (C) 2013  Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

redmine authored
20

redmine authored
21 22
#ifndef __CLSYNC_CTX_H
#define __CLSYNC_CTX_H
redmine authored
23

redmine authored
24 25
#include <regex.h>

redmine authored
26 27 28
#define OPTION_FLAGS		(1<<10)
#define OPTION_LONGOPTONLY	(1<<9)
#define OPTION_CONFIGONLY	(1<<8)
redmine authored
29
#define NOTOPTION		(3<<8)
redmine authored
30
enum flags_enum {
redmine authored
31 32 33 34
	WATCHDIR	= 'W',
	SYNCHANDLER	= 'S',
	RULESFILE	= 'R',
	DESTDIR		= 'D',
redmine authored
35
	SOCKETPATH	= 's',
redmine authored
36

redmine authored
37
	HELP		= 'h',
redmine authored
38
	CONFIGFILE	= 'H',
redmine authored
39 40 41 42 43
	CONFIGBLOCK	= 'K',
	BACKGROUND	= 'b',
	UID		= 'u',
	GID		= 'g',
	CAP_PRESERVE_FILEACCESS = 'C',
redmine authored
44
	THREADING	= 'p',
redmine authored
45
	RETRIES		= 'r',
redmine authored
46
	OUTPUT_METHOD	= 'Y',
redmine authored
47
	EXCLUDEMOUNTPOINTS= 'X',
redmine authored
48 49 50
	PIDFILE		= 'z',
#ifdef CLUSTER_SUPPORT
	CLUSTERIFACE	= 'c',
redmine authored
51 52 53
	CLUSTERMCASTIPADDR='m',
	CLUSTERMCASTIPPORT='P',
	CLUSTERTIMEOUT	= 'G',
redmine authored
54 55 56
	CLUSTERNODENAME = 'n',
	CLUSTERHDLMIN	= 'o',
	CLUSTERHDLMAX	= 'O',
redmine authored
57
	CLUSTERSDLMAX	= 11|OPTION_LONGOPTONLY,
redmine authored
58 59 60 61 62
#endif
	DELAY		= 't',
	BFILEDELAY	= 'T',
	SYNCDELAY	= 'w',
	BFILETHRESHOLD	= 'B',
redmine authored
63
	DEBUG		= 'd',
redmine authored
64 65
	QUIET		= 'q',
	VERBOSE		= 'v',
redmine authored
66
	OUTLISTSDIR	= 'L',
redmine authored
67
	AUTORULESW	= 'A',
redmine authored
68
	MODE		= 'M',
redmine authored
69 70 71 72 73 74 75 76 77 78 79
	IGNOREEXITCODE	= 'x',
	DONTUNLINK	= 'U',
	INITFULL	= 'F',
	SYNCTIMEOUT	= 'k',
#ifdef FANOTIFY_SUPPORT
	FANOTIFY	= 'f',
#endif
	INOTIFY		= 'i',
	LABEL		= 'l',
	SHOW_VERSION	= 'V',

redmine authored
80 81 82 83 84 85 86 87 88 89 90
	HAVERECURSIVESYNC 	=  0|OPTION_LONGOPTONLY,
	RSYNCINCLIMIT		=  1|OPTION_LONGOPTONLY,
	RSYNCPREFERINCLUDE	=  2|OPTION_LONGOPTONLY,
	SYNCLISTSIMPLIFY	=  3|OPTION_LONGOPTONLY,
	ONEFILESYSTEM		=  4|OPTION_LONGOPTONLY,
	STATUSFILE		=  5|OPTION_LONGOPTONLY,
	SKIPINITSYNC		=  6|OPTION_LONGOPTONLY,
	ONLYINITSYNC		=  7|OPTION_LONGOPTONLY,
	EXITONNOEVENTS		=  8|OPTION_LONGOPTONLY,
	STANDBYFILE		=  9|OPTION_LONGOPTONLY,
	EXITHOOK		= 10|OPTION_LONGOPTONLY,
redmine authored
91 92 93 94

	SOCKETAUTH		= 12|OPTION_LONGOPTONLY,
	SOCKETMOD		= 13|OPTION_LONGOPTONLY,
	SOCKETOWN		= 14|OPTION_LONGOPTONLY,
Artyom A Anikeev authored
95 96

	MAXITERATIONS		= 15|OPTION_LONGOPTONLY,
redmine authored
97 98

	IGNOREFAILURES		= 16|OPTION_LONGOPTONLY,
redmine authored
99 100 101

// Not an options:
	THREADINGLOCKED		=  0|NOTOPTION,
redmine authored
102 103 104
};
typedef enum flags_enum flags_t;

redmine authored
105 106 107 108 109 110
enum mode_id {
	MODE_UNSET	= 0,
	MODE_SIMPLE,
	MODE_SHELL,
	MODE_RSYNCSHELL,
	MODE_RSYNCDIRECT,
redmine authored
111
	MODE_RSYNCSO,
redmine authored
112 113 114 115 116
	MODE_SO,
};
typedef enum mode_id mode_id_t;

enum queue_id {
redmine authored
117 118 119
	QUEUE_NORMAL,
	QUEUE_BIGFILE,
	QUEUE_INSTANT,
redmine authored
120 121
	QUEUE_LOCKWAIT,

redmine authored
122 123 124
	QUEUE_MAX,
	QUEUE_AUTO
};
redmine authored
125
typedef enum queue_id queue_id_t;
redmine authored
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

enum ruleactionsign_enum {
	RS_REJECT	= 0,
	RS_PERMIT	= 1
};
typedef enum ruleactionsign_enum ruleactionsign_t;

enum ruleaction_enum {
	RA_NONE		 = 0x00,
	RA_MONITOR	 = 0x01,
	RA_WALK		 = 0x02,
	RA_ALL		 = 0xff
};
typedef enum ruleaction_enum ruleaction_t;

// signals (man 7 signal)
enum sigusr_enum {
redmine authored
143
	SIGUSR_THREAD_GC	= 10,
redmine authored
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165
	SIGUSR_INITSYNC  	= 12,
	SIGUSR_BLOPINT		= 16
};

struct rule {
	int		num;
	regex_t		expr;
	mode_t		objtype;
	ruleaction_t	perm;
	ruleaction_t	mask;
};
typedef struct rule rule_t;

struct queueinfo {
	unsigned int 	collectdelay;
	time_t		stime;
};
typedef struct queueinfo queueinfo_t;

struct api_functs {
	api_funct_init   init;
	api_funct_sync   sync;
redmine authored
166
	api_funct_rsync  rsync;
redmine authored
167 168 169 170
	api_funct_deinit deinit;
};
typedef struct api_functs api_functs_t;

redmine authored
171
struct ctx {
redmine authored
172
#ifndef LIBCLSYNC
redmine authored
173 174
	uid_t uid;
	gid_t gid;
redmine authored
175 176
	pid_t child_pid[MAXCHILDREN];	// Used only for non-pthread mode
	int   children;			// Used only for non-pthread mode
Artyom A Anikeev authored
177
	uint32_t iteration_num;
redmine authored
178
	rule_t rules[MAXRULES];
redmine authored
179
	dev_t st_dev;
redmine authored
180
#endif
redmine authored
181
	char *flags_values_raw[OPTION_FLAGS];
redmine authored
182 183
	int flags[OPTION_FLAGS];
	int flags_set[OPTION_FLAGS];
redmine authored
184
#ifndef LIBCLSYNC
redmine authored
185 186 187 188 189
	char *config_path;
	char *config_block;
	char *label;
	char *watchdir;
	char *pidfile;
redmine authored
190
	char *standbyfile;
redmine authored
191
	char *exithookfile;
redmine authored
192 193 194
	char *destdir;
	char *watchdirwslash;
	char *destdirwslash;
redmine authored
195
	char *statusfile;
redmine authored
196 197
	char *socketpath;
	int socket;
redmine authored
198 199 200
	mode_t socketmod;
	uid_t  socketuid;
	gid_t  socketgid;
redmine authored
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
#ifdef CLUSTER_SUPPORT
	char *cluster_iface;
	char *cluster_mcastipaddr;
	char *cluster_nodename;
	uint32_t cluster_nodename_len;
	uint16_t cluster_mcastipport;
	uint16_t cluster_hash_dl_min;
	uint16_t cluster_hash_dl_max;
	uint16_t cluster_scan_dl_max;
	unsigned int cluster_timeout;
#endif
	size_t watchdirlen;
	size_t destdirlen;
	size_t watchdirsize;
	size_t destdirsize;
	size_t watchdirwslashsize;
	size_t destdirwslashsize;
	short int watchdir_dirlevel;
	char *handlerfpath;
	void *handler_handle;
	api_functs_t handler_funct;
	char *rulfpath;
	char *listoutdir;
	int notifyengine;
redmine authored
225
	int retries;
redmine authored
226 227 228 229 230 231 232 233
	size_t bfilethreshold;
	unsigned int syncdelay;
	queueinfo_t _queues[QUEUE_MAX];	// TODO: remove this from here
	unsigned int rsyncinclimit;
	time_t synctime;
	unsigned int synctimeout;
	sigset_t *sigset;
	char isignoredexitcode[(1<<8)];
redmine authored
234
#endif
redmine authored
235
	void *indexes_p;
redmine authored
236
};
redmine authored
237
typedef struct ctx ctx_t;
redmine authored
238

redmine authored
239 240
#endif