Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# http://www.gnu.org/software/automake

Makefile.in
/ar-lib
/mdate-sh
/py-compile
/test-driver
/ylwrap
.deps/
.dirstamp

# http://www.gnu.org/software/autoconf

autom4te.cache
/autoscan.log
/autoscan-*.log
/aclocal.m4
/compile
/config.cache
/config.guess
/config.h.in
/config.log
/config.status
/config.sub
/configure
/configure.scan
/depcomp
/install-sh
/missing
/stamp-h1

# https://www.gnu.org/software/libtool/

/ltmain.sh

# http://www.gnu.org/software/texinfo

/texinfo.tex

# http://www.gnu.org/software/m4/

m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4

# Generated Makefile
# (meta build system like autotools,
# can automatically generate from config.status script
# (which is called by configure script))
Makefile


# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf

# Project specific
*.swp
*.swo
cfgfile_parser.c
cfgfile_parser.h
cfgfile_scanner.c
config.h
csync2
9 changes: 8 additions & 1 deletion check.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ void csync_mark(const char *file, const char *thispeer, const char *peerfilter)
}

csync_debug(1, "Marking file as dirty: %s\n", file);
for (pl_idx=0; pl[pl_idx].peername; pl_idx++)
for (pl_idx=0; pl[pl_idx].peername; pl_idx++) {
// In case of -P flag, don't mark files as dirty
if (active_peerlist && !strstr(active_peerlist, pl[pl_idx].peername)) {
csync_debug(1, "Not marking host %s as dirty because -P flag was specified\n", pl[pl_idx].peername);
continue;
}

if (!peerfilter || !strcmp(peerfilter, pl[pl_idx].peername)) {
SQL("Deleting old dirty file entries",
"DELETE FROM dirty WHERE filename = '%s' AND peername = '%s'",
Expand All @@ -113,6 +119,7 @@ void csync_mark(const char *file, const char *thispeer, const char *peerfilter)
url_encode(pl[pl_idx].myname),
url_encode(pl[pl_idx].peername));
}
}

free(pl);
}
Expand Down
7 changes: 5 additions & 2 deletions checktxt.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/

#include "csync2.h"
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
Expand Down Expand Up @@ -48,8 +49,10 @@ const char *csync_genchecktxt(const struct stat *st, const char *filename, int i
/* version 1 of this check text */
xxprintf("v1");

if ( !S_ISLNK(st->st_mode) && !S_ISDIR(st->st_mode) )
xxprintf(":mtime=%lld", ign_mtime ? (long long)0 : (long long)st->st_mtime);
if ( !S_ISLNK(st->st_mode) && !S_ISDIR(st->st_mode) ) {
int64_t timestamp = st->st_mtime * 1000000000 + st->st_mtim.tv_nsec;
xxprintf(":mtime=%lld", ign_mtime ? (long long)0 : (long long)timestamp);
}

if ( !csync_ignore_mod )
xxprintf(":mode=%d", (int)st->st_mode);
Expand Down
63 changes: 62 additions & 1 deletion csync2.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ int csync_error_count = 0;
int csync_debug_level = 0;
FILE *csync_debug_out = 0;
int csync_syslog = 0;
int csync_atomic_patch = 1; //TODO - make an inverse flag.

int csync_server_child_pid = 0;
int csync_timestamps = 0;
Expand Down Expand Up @@ -436,7 +437,7 @@ int main(int argc, char ** argv)
return 1;
}

while ( (opt = getopt(argc, argv, "W:s:Ftp:G:P:C:D:N:HBAIXULlSTMRvhcuoimfxrd")) != -1 ) {
while ( (opt = getopt(argc, argv, "W:s:Ftp:G:P:C:D:N:O::HBAIXULlSTMRavhcuoimfxrd")) != -1 ) {

switch (opt) {
case 'W':
Expand All @@ -451,6 +452,15 @@ int main(int argc, char ** argv)
csync_fatal("Can't open timestanp file `%s': %s\n",
optarg, strerror(errno));
break;
case 'O':
{
char *logname = optarg ? optarg : "/tmp/csync2_full_log.log";
if((debug_file = fopen(logname, "w+")) == NULL) {
fprintf(stderr, "Could not open full log file: %s\n", logname);
exit(1);
}
}
break;
case 'F':
csync_new_force = 1;
break;
Expand All @@ -463,6 +473,9 @@ int main(int argc, char ** argv)
case 'G':
active_grouplist = optarg;
break;
case 'a':
csync_atomic_patch = 1;
break;
case 'P':
active_peerlist = optarg;
break;
Expand Down Expand Up @@ -684,9 +697,57 @@ int main(int argc, char ** argv)
if (!csync_database || !csync_database[0] || csync_database[0] == '/')
csync_database = db_default_database(csync_database);



// If local hostname is not set, try to guess it by getting the addrinfo of every hostname in the
// group and try to bind on that address. If bind is successful set that host as local hostname.
{
struct csync_group *g;
struct csync_group_host *h;
struct csync_group_host *prev = 0;
struct addrinfo *rp, *result;
int sfd;
int bind_status;

for (g=csync_group; g; g=g->next) {
if ( !g->myname ) {
h = g->host;
while(h && !g->myname) {
getaddrinfo(h->hostname, NULL, NULL, &result);
for (rp = result; rp != NULL; rp = rp->ai_next) {
sfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
if (sfd == -1)
continue;
bind_status = bind(sfd, rp->ai_addr, rp->ai_addrlen);
close(sfd);

if (bind_status == 0) {
g->myname = h->hostname;
snprintf(myhostname, 256, "%s", h->hostname);
g->local_slave = h->slave;

if (!prev) {
g->host = h->next;
} else {
prev->next = h->next;
}
free(h);
csync_debug(1, "My hostname guessed as: %s\n", g->myname);
break;
}
}
freeaddrinfo(result);
prev = h;
h = h->next;
}
}
}
}

csync_debug(2, "My hostname is %s.\n", myhostname);
csync_debug(2, "Database-File: %s\n", csync_database);


{
const struct csync_group *g;
for (g=csync_group; g; g=g->next)
Expand Down
4 changes: 3 additions & 1 deletion csync2.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ extern int csync_perm(const char *filename, const char *key, const char *hostnam

/* error.c */

extern FILE* debug_file;
extern void csync_printtime();
extern void csync_printtotaltime();
extern void csync_fatal(const char *fmt, ...);
Expand Down Expand Up @@ -233,7 +234,7 @@ extern int db_sync_mode;
extern int csync_rs_check(const char *filename, int isreg);
extern void csync_rs_sig(const char *filename);
extern int csync_rs_delta(const char *filename);
extern int csync_rs_patch(const char *filename);
extern int csync_rs_patch(const char *filename, struct stat *atomic_stats);
extern int mkpath(const char *path, mode_t mode);
extern void split_dirname_basename(char *dirname, char* basename, const char *filepath);

Expand Down Expand Up @@ -435,6 +436,7 @@ extern int csync_messages_printed;
extern int csync_server_child_pid;
extern int csync_timestamps;
extern int csync_new_force;
extern int csync_atomic_patch;

extern char myhostname[];
extern int bind_to_myhostname;
Expand Down
Loading