redmine

glob -> ctx

... ... @@ -39,7 +39,7 @@ clsync_include_HEADERS = \
clsync.h \
malloc.h \
indexes.h \
glob.h \
ctx.h \
error.h \
socket.h \
libclsync.h
... ...
ctx - context
... ...
... ... @@ -41,9 +41,9 @@ struct api_eventinfo {
};
typedef struct api_eventinfo api_eventinfo_t;
struct glob;
struct ctx;
struct indexes;
typedef int(*api_funct_init) (struct glob *, struct indexes *);
typedef int(*api_funct_init) (struct ctx *, struct indexes *);
typedef int(*api_funct_sync) (int n, api_eventinfo_t *);
typedef int(*api_funct_rsync) (const char *inclist, const char *exclist);
typedef int(*api_funct_deinit)();
... ... @@ -80,12 +80,12 @@ extern int clsyncapi_getapiversion();
/**
* @brief clsync's wrapper for function "fork()". Should be used instead of "fork()" directly, to notify clsync about child's pid.
*
* @param[in] glob_p Pointer to "glob"
* @param[in] ctx_p Pointer to "ctx"
*
* @retval -1 If error (see "man 2 fork", added error code "ECANCELED" if too many children)
* @retval 0 If child
* @retval pid Pid of child of parent. (see "man 2 fork")
*
*/
extern pid_t clsyncapi_fork(struct glob *glob_p);
extern pid_t clsyncapi_fork(struct ctx *ctx_p);
... ...
... ... @@ -53,7 +53,7 @@ struct sockaddr_in sa_i = {0};
int sock_o = -1;
struct sockaddr_in sa_o = {0};
glob_t *glob_p = NULL;
ctx_t *ctx_p = NULL;
indexes_t *indexes_p = NULL;
pthread_t pthread_cluster = 0;
... ... @@ -875,11 +875,11 @@ static int cluster_recvproc_setid(clustercmd_t *clustercmd_p) {
// Is the node name length in message equals to our node name length? Skipping if not.
uint32_t recv_nodename_len;
recv_nodename_len = CLUSTER_RESTDATALEN(clustercmd_p, clustercmd_setiddata_t);
if(recv_nodename_len != glob_p->cluster_nodename_len)
if(recv_nodename_len != ctx_p->cluster_nodename_len)
return 0;
// Is the node name equals to ours? Skipping if not.
if(memcmp(data_setid_p->node_name, glob_p->cluster_nodename, recv_nodename_len))
if(memcmp(data_setid_p->node_name, ctx_p->cluster_nodename, recv_nodename_len))
return 0;
// Remembering the node that answered us
... ... @@ -897,7 +897,7 @@ extern int cluster_loop();
/**
* @brief Initializes cluster subsystem.
*
* @param[in] _glob_p Pointer to "glob" variable, defined in main().
* @param[in] _ctx_p Pointer to "glob" variable, defined in main().
* @param[in] _indexes_p Pointer to "indexes" variable, defined in sync_run().
*
* @retval zero Successfully initialized.
... ... @@ -905,19 +905,19 @@ extern int cluster_loop();
*
*/
int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
int cluster_init(ctx_t *_ctx_p, indexes_t *_indexes_p) {
int ret;
// Preventing double initializing
if(glob_p != NULL) {
if(ctx_p != NULL) {
error("cluster subsystem is already initialized.");
return EALREADY;
}
// Initializing global variables, pt. 1
glob_p = _glob_p;
ctx_p = _ctx_p;
indexes_p = _indexes_p;
cluster_timeout = glob_p->cluster_timeout;
cluster_timeout = ctx_p->cluster_timeout;
node_status_change(NODEID_NOID, NODESTATUS_ONLINE);
// Initializing network routines
... ... @@ -944,7 +944,7 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
// Binding
sa_i.sin_family = AF_INET;
sa_i.sin_port = htons(glob_p->cluster_mcastipport);
sa_i.sin_port = htons(ctx_p->cluster_mcastipport);
sa_i.sin_addr.s_addr = INADDR_ANY;
if(bind(sock_i, (struct sockaddr*)&sa_i, sizeof(sa_i))) {
... ... @@ -955,13 +955,13 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
// Joining to multicast group
struct ip_mreq group;
group.imr_interface.s_addr = inet_addr(glob_p->cluster_iface);
group.imr_multiaddr.s_addr = inet_addr(glob_p->cluster_mcastipaddr);
group.imr_interface.s_addr = inet_addr(ctx_p->cluster_iface);
group.imr_multiaddr.s_addr = inet_addr(ctx_p->cluster_mcastipaddr);
if(setsockopt(sock_i, IPPROTO_IP, IP_ADD_MEMBERSHIP,
(char *)&group, sizeof(group)) < 0) {
error("Cannot setsockopt() to enter to membership %s -> %s",
glob_p->cluster_iface, glob_p->cluster_mcastipaddr);
ctx_p->cluster_iface, ctx_p->cluster_mcastipaddr);
return errno;
}
... ... @@ -978,8 +978,8 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
// Initializing the group sockaddr structure
sa_o.sin_family = AF_INET;
sa_o.sin_port = htons(glob_p->cluster_mcastipport);
sa_o.sin_addr.s_addr = inet_addr(glob_p->cluster_mcastipaddr);
sa_o.sin_port = htons(ctx_p->cluster_mcastipport);
sa_o.sin_addr.s_addr = inet_addr(ctx_p->cluster_mcastipaddr);
// Disable looping back output datagrams
... ... @@ -995,7 +995,7 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
{
struct in_addr addr_o;
addr_o.s_addr = inet_addr(glob_p->cluster_iface);
addr_o.s_addr = inet_addr(ctx_p->cluster_iface);
if(setsockopt(sock_o, IPPROTO_IP, IP_MULTICAST_IF, &addr_o, sizeof(addr_o)) < 0) {
error("Cannot set local interface for outbound traffic");
return errno;
... ... @@ -1011,10 +1011,10 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
// Trying to preserve my node_id after restart. :)
// Asking another nodes about my previous node_id
{
clustercmd_t *clustercmd_p = CLUSTER_ALLOCA(clustercmd_getmyid_t, glob_p->cluster_nodename_len);
clustercmd_t *clustercmd_p = CLUSTER_ALLOCA(clustercmd_getmyid_t, ctx_p->cluster_nodename_len);
clustercmd_p->h.data_len = glob_p->cluster_nodename_len;
memcpy(clustercmd_p->data.getmyid.node_name, glob_p->cluster_nodename, clustercmd_p->h.data_len+1);
clustercmd_p->h.data_len = ctx_p->cluster_nodename_len;
memcpy(clustercmd_p->data.getmyid.node_name, ctx_p->cluster_nodename, clustercmd_p->h.data_len+1);
clustercmd_p->h.cmd_id = CLUSTERCMDID_GETMYID;
clustercmd_p->h.dst_node_id = NODEID_NOID; // broadcast
... ... @@ -1054,12 +1054,12 @@ int cluster_init(glob_t *_glob_p, indexes_t *_indexes_p) {
// Sending registration information
node_status_change(node_id_my, NODESTATUS_SEEMSONLINE);
{
clustercmd_t *clustercmd_p = CLUSTER_ALLOCA(clustercmd_reg_t, glob_p->cluster_nodename_len);
clustercmd_t *clustercmd_p = CLUSTER_ALLOCA(clustercmd_reg_t, ctx_p->cluster_nodename_len);
clustercmd_reg_t *data_reg_p = &clustercmd_p->data.reg;
memcpy(data_reg_p->node_name, glob_p->cluster_nodename, glob_p->cluster_nodename_len+1);
memcpy(data_reg_p->node_name, ctx_p->cluster_nodename, ctx_p->cluster_nodename_len+1);
clustercmd_p->h.data_len = glob_p->cluster_nodename_len+1;
clustercmd_p->h.data_len = ctx_p->cluster_nodename_len+1;
clustercmd_p->h.cmd_id = CLUSTERCMDID_REG;
clustercmd_p->h.dst_node_id = NODEID_NOID; // broadcast
if((ret=cluster_send(clustercmd_p)))
... ... @@ -1284,13 +1284,13 @@ int cluster_modtime_update(const char *path, short int dirlevel, mode_t st_mode)
int ret;
// Getting relative directory level (depth)
short int dirlevel_rel = dirlevel - glob_p->watchdir_dirlevel;
short int dirlevel_rel = dirlevel - ctx_p->watchdir_dirlevel;
if((st_mode & S_IFMT) == S_IFDIR)
dirlevel_rel++;
// Don't remembering information about directories with level beyond the limits
if((dirlevel_rel > glob_p->cluster_scan_dl_max) || (dirlevel_rel < glob_p->cluster_hash_dl_min))
if((dirlevel_rel > ctx_p->cluster_scan_dl_max) || (dirlevel_rel < ctx_p->cluster_hash_dl_min))
return 0;
... ... @@ -1318,8 +1318,8 @@ int cluster_modtime_update(const char *path, short int dirlevel, mode_t st_mode)
char *dirpath_rel_p = xmalloc(dirpath_len+1);
char *dirpath_rel = dirpath_rel_p;
const char *dirpath_rel_full = &dirpath[glob_p->watchdirlen];
size_t dirpath_rel_full_len = dirpath_len - glob_p->watchdirlen;
const char *dirpath_rel_full = &dirpath[ctx_p->watchdirlen];
size_t dirpath_rel_full_len = dirpath_len - ctx_p->watchdirlen;
// Getting coodinate of the end (directory path is already canonized, so we can simply count number of slashes to get directory level)
int slashcount=0;
... ... @@ -1327,7 +1327,7 @@ int cluster_modtime_update(const char *path, short int dirlevel, mode_t st_mode)
while(dirpath_rel_full[dirpath_rel_end] && (dirpath_rel_end < dirpath_rel_full_len)) {
if(dirpath_rel_full[dirpath_rel_end] == '/') {
slashcount++;
if(slashcount >= glob_p->cluster_hash_dl_max)
if(slashcount >= ctx_p->cluster_hash_dl_max)
break;
}
dirpath_rel_end++;
... ...
... ... @@ -244,7 +244,7 @@ typedef int (*cluster_recvproc_funct_t)(clustercmd_t *clustercmd_p);
// Externs
extern int cluster_init(glob_t *glob_p, indexes_t *indexes_p);
extern int cluster_init(ctx_t *ctx_p, indexes_t *indexes_p);
extern int cluster_deinit();
extern int cluster_lock(const char *fpath);
... ...
... ... @@ -69,7 +69,7 @@
#endif
#include "clsync.h"
#include "glob.h"
#include "ctx.h"
#include "indexes.h"
#ifndef MIN
... ... @@ -172,7 +172,7 @@ struct eventinfo {
typedef struct eventinfo eventinfo_t;
typedef int (*thread_callbackfunct_t)(glob_t *glob_p, char **argv);
typedef int (*thread_callbackfunct_t)(ctx_t *ctx_p, char **argv);
struct threadinfo {
int thread_num;
thread_callbackfunct_t callback;
... ... @@ -181,7 +181,7 @@ struct threadinfo {
int exitcode;
int errcode;
state_t state;
glob_t *glob_p;
ctx_t *ctx_p;
time_t starttime;
time_t expiretime;
int child_pid;
... ... @@ -219,7 +219,7 @@ struct dosync_arg {
char excf_path[PATH_MAX+1];
char outf_path[PATH_MAX+1];
FILE *outf;
glob_t *glob_p;
ctx_t *ctx_p;
indexes_t *indexes_p;
void *data;
int linescount;
... ... @@ -265,7 +265,7 @@ enum initsync {
typedef enum initsync initsync_t;
struct sighandler_arg {
glob_t *glob_p;
ctx_t *ctx_p;
// indexes_t *indexes_p;
pthread_t pthread_parent;
int *exitcode_p;
... ...
... ... @@ -30,11 +30,11 @@ static pthread_t pthread_control;
int control_procclsyncsock(socket_sockthreaddata_t *arg, sockcmd_t *sockcmd_p) {
clsyncsock_t *clsyncsock_p = arg->clsyncsock_p;
glob_t *glob_p = (glob_t *)arg->arg;
ctx_t *ctx_p = (ctx_t *)arg->arg;
switch(sockcmd_p->cmd_id) {
case SOCKCMD_REQUEST_INFO: {
socket_send(clsyncsock_p, SOCKCMD_REPLY_INFO, glob_p->config_block, glob_p->label, glob_p->flags, glob_p->flags_set);
socket_send(clsyncsock_p, SOCKCMD_REPLY_INFO, ctx_p->config_block, ctx_p->label, ctx_p->flags, ctx_p->flags_set);
break;
}
case SOCKCMD_REQUEST_DIE: {
... ... @@ -48,26 +48,26 @@ int control_procclsyncsock(socket_sockthreaddata_t *arg, sockcmd_t *sockcmd_p) {
return 0;
}
static inline void closecontrol(glob_t *glob_p) {
if(glob_p->socket) {
close(glob_p->socket);
glob_p->socket = 0;
static inline void closecontrol(ctx_t *ctx_p) {
if(ctx_p->socket) {
close(ctx_p->socket);
ctx_p->socket = 0;
}
}
int control_loop(glob_t *glob_p) {
int control_loop(ctx_t *ctx_p) {
// Starting
debug(1, "started (glob_p->socket == %u)", glob_p->socket);
debug(1, "started (ctx_p->socket == %u)", ctx_p->socket);
int s;
while((s=glob_p->socket)) {
while((s=ctx_p->socket)) {
// Check if the socket is still alive
if(socket_check_bysock(s)) {
debug(1, "Control socket closed [case 0]: %s", strerror(errno));
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
... ... @@ -91,13 +91,13 @@ int control_loop(glob_t *glob_p) {
if(count < 0) {
debug(1, "Got negative events count. Closing the socket.");
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
if(!FD_ISSET(s, &rfds)) {
error("Got event, but not on the control socket. Closing the socket (cannot use \"select()\").");
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
... ... @@ -111,7 +111,7 @@ int control_loop(glob_t *glob_p) {
// Got unknown error. Closing control socket just in case.
error("Cannot socket_accept()");
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
... ... @@ -120,20 +120,20 @@ int control_loop(glob_t *glob_p) {
if (threaddata_p == NULL) {
error("Cannot create a thread for connection");
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
threaddata_p->procfunct = control_procclsyncsock;
threaddata_p->clsyncsock_p = clsyncsock_p;
threaddata_p->arg = glob_p;
threaddata_p->running = &glob_p->socket;
threaddata_p->authtype = glob_p->flags[SOCKETAUTH];
threaddata_p->arg = ctx_p;
threaddata_p->running = &ctx_p->socket;
threaddata_p->authtype = ctx_p->flags[SOCKETAUTH];
threaddata_p->flags = 0;
if (socket_thread_start(threaddata_p)) {
error("Cannot start a thread for connection");
closecontrol(glob_p);
closecontrol(ctx_p);
continue;
}
#ifdef DEBUG
... ... @@ -148,8 +148,8 @@ int control_loop(glob_t *glob_p) {
return 0;
}
int control_run(glob_t *glob_p) {
if(glob_p->socketpath != NULL) {
int control_run(ctx_t *ctx_p) {
if(ctx_p->socketpath != NULL) {
int ret = 0;
int s = -1;
... ... @@ -159,7 +159,7 @@ int control_run(glob_t *glob_p) {
if (!ret) {
clsyncsock_t *clsyncsock = socket_listen_unix(glob_p->socketpath);
clsyncsock_t *clsyncsock = socket_listen_unix(ctx_p->socketpath);
if (clsyncsock == NULL) {
ret = errno;
} else {
... ... @@ -170,16 +170,16 @@ int control_run(glob_t *glob_p) {
// fixing privileges
if (!ret) {
if(glob_p->flags[SOCKETMOD])
if(chmod(glob_p->socketpath, glob_p->socketmod)) {
if(ctx_p->flags[SOCKETMOD])
if(chmod(ctx_p->socketpath, ctx_p->socketmod)) {
error("Error, Cannot chmod(\"%s\", %o)",
glob_p->socketpath, glob_p->socketmod);
ctx_p->socketpath, ctx_p->socketmod);
ret = errno;
}
if(glob_p->flags[SOCKETOWN])
if(chown(glob_p->socketpath, glob_p->socketuid, glob_p->socketgid)) {
if(ctx_p->flags[SOCKETOWN])
if(chown(ctx_p->socketpath, ctx_p->socketuid, ctx_p->socketgid)) {
error("Error, Cannot chown(\"%s\", %u, %u)",
glob_p->socketpath, glob_p->socketuid, glob_p->socketgid);
ctx_p->socketpath, ctx_p->socketuid, ctx_p->socketgid);
ret = errno;
}
}
... ... @@ -190,20 +190,20 @@ int control_run(glob_t *glob_p) {
return ret;
}
glob_p->socket = s;
ctx_p->socket = s;
debug(2, "glob_p->socket = %u", glob_p->socket);
debug(2, "ctx_p->socket = %u", ctx_p->socket);
ret = pthread_create(&pthread_control, NULL, (void *(*)(void *))control_loop, glob_p);
ret = pthread_create(&pthread_control, NULL, (void *(*)(void *))control_loop, ctx_p);
}
return 0;
}
int control_cleanup(glob_t *glob_p) {
if(glob_p->socketpath != NULL) {
unlink(glob_p->socketpath);
closecontrol(glob_p);
int control_cleanup(ctx_t *ctx_p) {
if(ctx_p->socketpath != NULL) {
unlink(ctx_p->socketpath);
closecontrol(ctx_p);
// TODO: kill pthread_control and join
// pthread_join(pthread_control, NULL);
socket_deinit();
... ...
... ... @@ -20,8 +20,8 @@
#ifndef __CLSYNC_CONTROL_H
#define __CLSYNC_CONTROL_H
extern int control_run(glob_t *glob_p);
extern int control_cleanup(glob_t *glob_p);
extern int control_run(ctx_t *ctx_p);
extern int control_cleanup(ctx_t *ctx_p);
#endif
... ...
... ... @@ -18,8 +18,8 @@
*/
#ifndef __CLSYNC_GLOB_H
#define __CLSYNC_GLOB_H
#ifndef __CLSYNC_CTX_H
#define __CLSYNC_CTX_H
#include <regex.h>
... ... @@ -160,7 +160,7 @@ struct api_functs {
};
typedef struct api_functs api_functs_t;
struct glob {
struct ctx {
#ifndef LIBCLSYNC
uid_t uid;
gid_t gid;
... ... @@ -224,7 +224,7 @@ struct glob {
char isignoredexitcode[(1<<8)];
#endif
};
typedef struct glob glob_t;
typedef struct ctx ctx_t;
#endif
... ...
This diff is collapsed. Click to expand it.
... ... @@ -17,6 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
extern int main_rehash(glob_t *glob_p);
extern int main_status_update(glob_t *glob_p, state_t state);
extern int main_rehash(ctx_t *ctx_p);
extern int main_status_update(ctx_t *ctx_p, state_t state);
... ...
... ... @@ -122,7 +122,7 @@ struct sockcmd_dat_version {
};
typedef struct sockcmd_dat_version sockcmd_dat_version_t;
#ifdef __CLSYNC_GLOB_H
#ifdef __CLSYNC_CTX_H
struct sockcmd_dat_info {
char config_block[1<<8];
char label[1<<8];
... ...
This diff is collapsed. Click to expand it.
... ... @@ -17,6 +17,6 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
extern int sync_run(struct glob *glob);
extern int sync_run(struct ctx *ctx);
extern int sync_term(int exitcode);
... ...