Blame view

common.h 4.24 KB
redmine authored
1
/*
redmine authored
2
    clsync - file tree sync utility based on inotify
redmine authored
3

redmine authored
4
    Copyright (C) 2013  Dmitry Yu Okunev <dyokunev@ut.mephi.ru> 0x8E30679C
redmine authored
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    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 23
#ifndef __CLSYNC_COMMON_H
#define __CLSYNC_COMMON_H

redmine authored
24
#ifndef __linux__
redmine authored
25 26 27 28
#	ifdef HAVE_CAPABILITIES
#		undef HAVE_CAPABILITIES
#		warning Capabilities support can be built only on Linux
#	endif
redmine authored
29 30
#endif

redmine authored
31
#define _GNU_SOURCE
redmine authored
32
//#define _XOPEN_SOURCE 700
redmine authored
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
#define _LARGEFILE64_SOURCE

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <getopt.h>
#include <limits.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <errno.h>
#include <ctype.h>
#include <signal.h>
redmine authored
51 52 53 54 55 56 57 58
#ifdef KQUEUE_SUPPORT
#	include <sys/event.h>
#endif
#ifdef INOTIFY_SUPPORT
#	include <sys/inotify.h>
#endif
#ifdef FANOTIFY_SUPPORT
#	include <sys/fanotify.h>
redmine authored
59 60 61
#endif
#include <sys/wait.h>
#include <fts.h>
redmine authored
62
#include <sys/time.h>
redmine authored
63
#include <dirent.h>
redmine authored
64
#include <sys/utsname.h>
redmine authored
65 66 67
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
redmine authored
68
#include <libgen.h>
redmine authored
69
#include <pthread.h>
redmine authored
70

redmine authored
71 72
#define CLSYNC_ITSELF

Barak A. Pearlmutter authored
73
#include "configuration.h"
Barak A. Pearlmutter authored
74
#ifdef HAVE_CONFIG_H
redmine authored
75
#	include "config.h"
Barak A. Pearlmutter authored
76
#endif
redmine authored
77

redmine authored
78
#include "clsync.h"
redmine authored
79
#include "port-hacks.h"
redmine authored
80
#include "posix-hacks.h"
redmine authored
81
#include "ctx.h"
Andrew Savchenko authored
82
#include "program.h"
redmine authored
83

Andrew Savchenko authored
84
#include <sys/param.h>
redmine authored
85

redmine authored
86
#ifndef IN_CREATE_SELF
redmine authored
87
#	define IN_CREATE_SELF IN_CREATE
redmine authored
88 89
#endif

redmine authored
90
#include "macros.h"
redmine authored
91

redmine authored
92 93 94
enum paramsource_enum {
	PS_UNKNOWN	 = 0,
	PS_ARGUMENT,
redmine authored
95
	PS_CONFIG,
redmine authored
96
	PS_CONTROL,
redmine authored
97
	PS_DEFAULTS,
redmine authored
98 99
//	PS_REHASH,
	PS_CORRECTION,
redmine authored
100 101 102
};
typedef enum paramsource_enum paramsource_t;

redmine authored
103 104 105 106

enum notifyengine_enum {
	NE_UNDEFINED = 0,
	NE_FANOTIFY,
redmine authored
107 108
	NE_INOTIFY,
	NE_KQUEUE,
redmine authored
109
	NE_BSM,
redmine authored
110
	NE_BSM_PREFETCH,
redmine authored
111
	NE_DTRACEPIPE,
redmine authored
112
	NE_GIO,
redmine authored
113
};
redmine authored
114
typedef enum notifyengine_enum notifyengine_t;
redmine authored
115

redmine authored
116 117 118 119 120 121 122
enum threadingmode {
	PM_OFF	= 0,
	PM_SAFE,
	PM_FULL
};
typedef enum threadingmode threadingmode_t;

redmine authored
123 124 125 126 127 128 129
enum splittingmode_enum {
	SM_OFF		= 0,
	SM_THREAD,
	SM_PROCESS,
};
typedef enum splittingmode_enum splittingmode_t;

redmine authored
130
/*
redmine authored
131 132 133 134 135 136 137 138
struct excludeinfo {
	unsigned int	seqid_min;
	unsigned int	seqid_max;
	eventobjtype_t	objtype_old;
	eventobjtype_t	objtype_new;
	uint32_t	flags;
};
typedef struct eventinfo eventinfo_t;
redmine authored
139
*/
redmine authored
140 141
struct eventinfo {
	uint32_t	evmask;
redmine authored
142 143
	unsigned int	seqid_min;
	unsigned int	seqid_max;
redmine authored
144 145
	eventobjtype_t	objtype_old;
	eventobjtype_t	objtype_new;
redmine authored
146 147
	int		wd;
	size_t		fsize;
redmine authored
148
	uint32_t	flags;
redmine authored
149 150 151
};
typedef struct eventinfo eventinfo_t;

redmine authored
152
enum pthread_mutex_id {
redmine authored
153
	PTHREAD_MUTEX_STATE,
redmine authored
154 155
	PTHREAD_MUTEX_SELECT,
	PTHREAD_MUTEX_THREADSINFO,
redmine authored
156 157 158 159
	PTHREAD_MUTEX_MAX
};


redmine authored
160 161
struct dosync_arg {
	int evcount;
redmine authored
162
	char excf_path[PATH_MAX+1];
redmine authored
163
	char outf_path[PATH_MAX+1];
redmine authored
164
	FILE *outf;
redmine authored
165
	ctx_t *ctx_p;
redmine authored
166
	struct indexes *indexes_p;
redmine authored
167
	void *data;
redmine authored
168
	int linescount;
redmine authored
169
	api_eventinfo_t *api_ei;
redmine authored
170
	int api_ei_count;
redmine authored
171
	char buf[BUFSIZ+1];
redmine authored
172 173 174 175 176 177

// for be read by sync_parameter_get():
	const char *include_list[MAXARGUMENTS+2];
	size_t      include_list_count;
	const char *list_type_str;
	const char *evmask_str;
redmine authored
178 179
};

redmine authored
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
struct doubleentry {
	size_t  size0;
	size_t  size1;
	size_t  alloc0;
	size_t  alloc1;
	void   *dat0;
	void   *dat1;
};

struct pushdoubleentry_arg {
	int			 allocated;
	int			 total;
	size_t			 size;
	struct doubleentry	*entry;
};

redmine authored
196
struct myentry {
redmine authored
197 198 199 200 201 202 203 204 205
	size_t  size;
	size_t  alloc;
	void   *dat;
};

struct pushentry_arg {
	int		 allocated;
	int		 total;
	size_t		 size;
redmine authored
206
	struct myentry	*entry;
redmine authored
207 208
};

redmine authored
209 210
enum initsync {
	INITSYNC_UNKNOWN = 0,
redmine authored
211 212
	INITSYNC_FULL,
	INITSYNC_SUBDIR
redmine authored
213 214 215
};
typedef enum initsync initsync_t;

redmine authored
216
struct sighandler_arg {
redmine authored
217
	ctx_t     *ctx_p;
redmine authored
218 219 220 221 222 223 224
//	indexes_t *indexes_p;
	pthread_t  pthread_parent;
	int	  *exitcode_p;
	sigset_t  *sigset_p;
};
typedef struct sighandler_arg sighandler_arg_t;

redmine authored
225 226
#endif