redmine

Control socket support started (option)

bin_PROGRAMS = clsync
clsync_SOURCES = sync.c cluster.c main.c output.c fileutils.c malloc.c glibex.c
clsync_SOURCES = sync.c cluster.c main.c socket.c output.c fileutils.c malloc.c glibex.c
main.o: revision.h
... ...
... ... @@ -256,4 +256,3 @@ struct sighandler_arg {
};
typedef struct sighandler_arg sighandler_arg_t;
... ...
... ... @@ -17,12 +17,14 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "common.h"
#include "output.h"
#include "sync.h"
#include "malloc.h"
#include "cluster.h"
#include "fileutils.h"
#include "socket.h"
#include "revision.h"
... ... @@ -33,6 +35,7 @@ static const struct option long_options[] =
{"rules-file", required_argument, NULL, RULESFILE},
{"destination-dir", required_argument, NULL, DESTDIR},
{"mode", required_argument, NULL, MODE},
{"socket", required_argument, NULL, SOCKETPATH},
{"status-file", required_argument, NULL, STATUSFILE},
{"background", optional_argument, NULL, BACKGROUND},
... ... @@ -302,6 +305,9 @@ static inline int parse_parameter(options_t *options_p, uint16_t param_id, char
case DESTDIR:
options_p->destdir = arg;
break;
case SOCKETPATH:
options_p->socketpath = arg;
break;
case STATUSFILE:
options_p->statusfile = arg;
break;
... ... @@ -1356,6 +1362,9 @@ preserve_fileaccess_end:
printf_ddd("Debug3: main(): Current errno is %i.\n", ret);
if(ret == 0)
if(options.socketpath != NULL)
ret = socket_run(&options);
if(ret == 0) {
ret = sync_run(&options);
... ...
... ... @@ -26,6 +26,7 @@ enum flags_enum {
SYNCHANDLER = 'S',
RULESFILE = 'R',
DESTDIR = 'D',
SOCKETPATH = 's',
HELP = 'h',
CONFIGFILE = 'H',
... ... @@ -47,7 +48,7 @@ enum flags_enum {
CLUSTERNODENAME = 'n',
CLUSTERHDLMIN = 'o',
CLUSTERHDLMAX = 'O',
CLUSTERSDLMAX = 's',
CLUSTERSDLMAX = 11|OPTION_LONGOPTONLY,
#endif
DELAY = 't',
BFILEDELAY = 'T',
... ... @@ -168,6 +169,8 @@ struct options {
char *watchdirwslash;
char *destdirwslash;
char *statusfile;
char *socketpath;
int socket;
#ifdef CLUSTER_SUPPORT
char *cluster_iface;
char *cluster_mcastipaddr;
... ...
/*
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/>.
*/
#include "common.h"
#include <sys/un.h> // for "struct sockaddr_un"
#include "sync.h"
#include "socket.h"
static pthread_t pthread_socket;
int socket_loop(options_t *options_p) {
return 0;
}
int socket_run(options_t *options_p) {
if(options_p->socketpath != NULL) {
int ret = 0;
int s = socket(AF_UNIX, SOCK_STREAM, 0);
// checking the path
if(!ret) {
// already exists? - unlink
if(!access(options_p->socketpath, F_OK))
if(unlink(options_p->socketpath)) {
printf_e("Error: Cannot unlink() \"%s\": %s (errno: %i).\n",
options_p->socketpath, strerror(errno), errno);
ret = errno;
}
}
// binding
if(!ret) {
struct sockaddr_un addr;
memset(&addr, 0, sizeof(addr));
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, options_p->socketpath, sizeof(addr.sun_path)-1);
if(bind(s, (struct sockaddr *)&addr, sizeof(addr))) {
printf_e("Error: Cannot bind() on address \"%s\": %s (errno: %i).\n",
options_p->socketpath, strerror(errno), errno);
ret = errno;
}
}
// finish
if(ret) {
close(s);
return ret;
}
options_p->socket = s;
ret = pthread_create(&pthread_socket, NULL, (void *(*)(void *))socket_loop, &options_p);
}
return 0;
}
... ...
/*
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/>.
*/
extern int socket_run(options_t *options_p);
... ...