Blame view

privileged.h 3.91 KB
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 inotify/kqueue
    
    Copyright (C) 2013-2014 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 21 22 23 24 25
#ifdef HL_LOCK_TRIES_AUTO
# define IF_HL_LOCK_TRIES_AUTO(a) a
#else
# define IF_HL_LOCK_TRIES_AUTO(a) {}
#endif

redmine authored
26 27
#ifdef CAPABILITIES_SUPPORT

redmine authored
28 29 30 31 32 33 34 35 36 37 38 39 40 41
enum priv_callid {
	PC_DEFAULT = 0,
	PC_SYNC_INIIALSYNC_WALK_FTS_OPEN,
	PC_SYNC_INIIALSYNC_WALK_FTS_READ,
	PC_SYNC_INIIALSYNC_WALK_FTS_CLOSE,
	PC_SYNC_MARK_WALK_FTS_OPEN,
	PC_SYNC_MARK_WALK_FTS_READ,
	PC_SYNC_MARK_WALK_FTS_CLOSE,
	PC_INOTIFY_ADD_WATCH_DIR,

	PC_MAX
};

extern FTS *(*_privileged_fts_open)		(
redmine authored
42 43 44
		char * const *path_argv,
		int options,
		int (*compar)(const FTSENT **, const FTSENT **)
redmine authored
45 46 47 48 49 50 51 52 53 54
# ifdef HL_LOCK_TRIES_AUTO
		, int callid
# endif
	);

extern FTSENT *(*_privileged_fts_read)		(
		FTS *ftsp
# ifdef HL_LOCK_TRIES_AUTO
		, int callid
# endif
redmine authored
55 56
	);

redmine authored
57 58 59 60 61 62
extern int (*_privileged_fts_close)		(
		FTS *ftsp
# ifdef HL_LOCK_TRIES_AUTO
		, int callid
# endif
	);
redmine authored
63

redmine authored
64 65 66 67
extern int (*_privileged_inotify_init)		();
extern int (*_privileged_inotify_init1)		(int flags);

extern int (*_privileged_inotify_add_watch)	(
redmine authored
68 69 70
		int fd,
		const char *pathname,
		uint32_t mask
redmine authored
71 72 73
# ifdef HL_LOCK_TRIES_AUTO
		, int callid
# endif
redmine authored
74 75
	);

redmine authored
76
extern int (*_privileged_inotify_rm_watch)	(
redmine authored
77 78 79 80
		int fd,
		int wd
	);

redmine authored
81
#ifdef CGROUP_SUPPORT
redmine authored
82
extern int (*_privileged_clsync_cgroup_deinit)	(ctx_t *ctx_p);
redmine authored
83 84
#endif

redmine authored
85 86
extern pid_t (*_privileged_waitpid)		(pid_t pid, int *status, int options);

redmine authored
87 88
extern int privileged_check();

redmine authored
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
# ifdef HL_LOCK_TRIES_AUTO
#  define privileged_fts_open(a,b,c,d)		_privileged_fts_open(a,b,c,d)
#  define privileged_fts_read(a,b)		_privileged_fts_read(a,b)
#  define privileged_fts_close(a,b)		_privileged_fts_close(a,b)
#  define privileged_inotify_add_watch(a,b,c,d)	_privileged_inotify_add_watch(a,b,c,d)
# else
#  define privileged_fts_open(a,b,c,d)		_privileged_fts_open(a,b,c)
#  define privileged_fts_read(a,b)		_privileged_fts_read(a)
#  define privileged_fts_close(a,b)		_privileged_fts_close(a)
#  define privileged_inotify_add_watch(a,b,c,d)	_privileged_inotify_add_watch(a,b,c)
# endif

# define privileged_inotify_init		_privileged_inotify_init
# define privileged_inotify_init1		_privileged_inotify_init1
# define privileged_inotify_rm_watch		_privileged_inotify_rm_watch
redmine authored
104
# define privileged_clsync_cgroup_deinit	_privileged_clsync_cgroup_deinit
redmine authored
105
# define privileged_waitpid			_privileged_waitpid
redmine authored
106

redmine authored
107 108
#else

redmine authored
109 110
# define privileged_check(...)			{}

redmine authored
111 112 113 114 115 116 117
# define privileged_fts_open(a,b,c,d)		fts_open(a,b,c)
# define privileged_fts_read(a,b)		fts_read(a)
# define privileged_fts_close(a,b)		fts_close(a)
# define privileged_inotify_init		inotify_init
# define privileged_inotify_init1		inotify_init1
# define privileged_inotify_add_watch(a,b,c,d)	inotify_add_watch(a,b,c)
# define privileged_inotify_rm_watch		inotify_rm_watch
redmine authored
118 119 120
# ifdef CGROUP_SUPPORT
#  define privileged_clsync_cgroup_deinit	clsync_cgroup_deinit
# endif
redmine authored
121
# define privileged_waitpid			waitpid
redmine authored
122 123
#endif

redmine authored
124 125
extern int (*_privileged_kill_child)(
		pid_t pid,
redmine authored
126 127
		int   sig,
		char  ignoreerrors
redmine authored
128 129 130 131 132 133 134 135 136
	);

extern int (*_privileged_fork_execvp)(
		const char *file,
		char *const argv[]
	);

#define privileged_kill_child			_privileged_kill_child
#define privileged_fork_execvp			_privileged_fork_execvp
redmine authored
137

redmine authored
138 139 140
extern int privileged_init(struct ctx *ctx_p);
extern int privileged_deinit(struct ctx *ctx_p);