mirror of
https://github.com/octoleo/lsyncd.git
synced 2025-01-23 07:08:33 +00:00
this time really just astyled the source, please skip last commit.
This commit is contained in:
parent
846ec0acb9
commit
c91e84045b
220
lsyncd.c
220
lsyncd.c
@ -1,12 +1,11 @@
|
|||||||
/**
|
/**
|
||||||
* lsyncd.c Live (Mirror) Syncing Demon
|
* lsyncd.c Live (Mirror) Syncing Demon
|
||||||
*
|
*
|
||||||
* License: GPLv2 (see COPYING) or any later version
|
* License: GPLv2 (see COPYING) or any later version
|
||||||
*
|
*
|
||||||
* Authors: Axel Kittenberger <axel.kittenberger@univie.ac.at>
|
* Authors: Axel Kittenberger <axel.kittenberger@univie.ac.at>
|
||||||
* Eugene Sanivsky <eugenesan@gmail.com>
|
* Eugene Sanivsky <eugenesan@gmail.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@ -64,7 +63,7 @@ char * option_target = NULL;
|
|||||||
/**
|
/**
|
||||||
* Option: rsync binary to call.
|
* Option: rsync binary to call.
|
||||||
*/
|
*/
|
||||||
char * rsync_binary = "/usr/local/bin/lsyncd.nice";
|
char * rsync_binary = "/usr/bin/rsync";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Option: the exclude-file to pass to rsync.
|
* Option: the exclude-file to pass to rsync.
|
||||||
@ -159,20 +158,22 @@ int dir_watch_num = 0;
|
|||||||
/**
|
/**
|
||||||
* lsyncd will log into this file/stream.
|
* lsyncd will log into this file/stream.
|
||||||
*/
|
*/
|
||||||
char *logfile = "/var/log/lsyncd";
|
char * logfile = "/var/log/lsyncd";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The inotify instance.
|
* The inotify instance.
|
||||||
*/
|
*/
|
||||||
int inotf;
|
int inotf;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array of strings of directory names to include.
|
* Array of strings of directory names to include.
|
||||||
* This is limited to MAX_EXCLUDES.
|
* This is limited to MAX_EXCLUDES.
|
||||||
* It's not worth to code a dynamic size handling...
|
* It's not worth to code a dynamic size handling...
|
||||||
*/
|
*/
|
||||||
#define MAX_EXCLUDES 256
|
#define MAX_EXCLUDES 256
|
||||||
char *exclude_dirs[MAX_EXCLUDES] = {NULL, };
|
char * exclude_dirs[MAX_EXCLUDES] = {NULL, };
|
||||||
int exclude_dir_n = 0;
|
int exclude_dir_n = 0;
|
||||||
|
|
||||||
volatile sig_atomic_t keep_going = 1;
|
volatile sig_atomic_t keep_going = 1;
|
||||||
@ -182,7 +183,6 @@ void catch_alarm(int sig)
|
|||||||
keep_going = 0;
|
keep_going = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a message to the log stream, preceding a timestamp.
|
* Prints a message to the log stream, preceding a timestamp.
|
||||||
* Otherwise it behaves like printf();
|
* Otherwise it behaves like printf();
|
||||||
@ -239,23 +239,6 @@ void printlogf(int level, const char *fmt, ...)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a path is a directory
|
|
||||||
* Returns true on success, false on negative and -1 on error
|
|
||||||
*/
|
|
||||||
int is_dir(char const *path)
|
|
||||||
{
|
|
||||||
|
|
||||||
struct stat statbuf;
|
|
||||||
|
|
||||||
if (lstat(path, &statbuf) == -1) {
|
|
||||||
printlogf(LOG_ERROR, "[%s]: while calling stat()", (char*)strerror);
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
return S_ISDIR(statbuf.st_mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* "secured" malloc, meaning the deamon shall kill itself
|
* "secured" malloc, meaning the deamon shall kill itself
|
||||||
* in case of out of memory.
|
* in case of out of memory.
|
||||||
@ -316,32 +299,19 @@ void *s_realloc(void *ptr, size_t size)
|
|||||||
* @param dest Destination string,
|
* @param dest Destination string,
|
||||||
* @param recursive If true -r will be handled on, -d (single directory) otherwise
|
* @param recursive If true -r will be handled on, -d (single directory) otherwise
|
||||||
*/
|
*/
|
||||||
bool rsync(char const *src, const char *dest, bool recursive)
|
bool rsync(char const * src, const char * dest, bool recursive)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status;
|
int status;
|
||||||
char const *opts, *rsync_debug;
|
char const * opts = recursive ? "-ltr" : "-ltd";
|
||||||
|
|
||||||
if (recursive) {
|
|
||||||
opts="--owner --group --devices --specials --super --perms --executability --one-file-system -ltr";
|
|
||||||
} else {
|
|
||||||
opts="--owner --group --devices --specials --super --perms --executability --one-file-system -ltd";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (LOG_DEBUG == 1) {
|
|
||||||
rsync_debug="-P";
|
|
||||||
} else {
|
|
||||||
rsync_debug="";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exclude_file) {
|
if (exclude_file) {
|
||||||
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s,%s,%s,%s)", rsync_binary, rsync_debug, "--delete", opts, "--exclude-from", exclude_file, src, dest);
|
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s,%s,%s)", rsync_binary, "--delete", opts, "--exclude-from", exclude_file, src, dest);
|
||||||
} else {
|
} else {
|
||||||
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s,%s)", rsync_binary, rsync_debug, "--delete", opts, src, dest);
|
printlogf(LOG_DEBUG, "exec %s(%s,%s,%s,%s)", rsync_binary, "--delete", opts, src, dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag_dryrun) {
|
if (flag_dryrun) {
|
||||||
printlogf(LOG_DEBUG, "Rsync skipped due to dry mode.");
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -356,7 +326,7 @@ bool rsync(char const *src, const char *dest, bool recursive)
|
|||||||
if (exclude_file) {
|
if (exclude_file) {
|
||||||
execl(rsync_binary, rsync_binary, "--delete", opts, "--exclude-from", exclude_file, src, dest, NULL);
|
execl(rsync_binary, rsync_binary, "--delete", opts, "--exclude-from", exclude_file, src, dest, NULL);
|
||||||
} else {
|
} else {
|
||||||
e xecl(rsync_binary, rsync_binary, "--delete", opts, src, dest, NULL);
|
execl(rsync_binary, rsync_binary, "--delete", opts, src, dest, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
printlogf(LOG_ERROR, "oh my god, execl returned!");
|
printlogf(LOG_ERROR, "oh my god, execl returned!");
|
||||||
@ -366,10 +336,11 @@ bool rsync(char const *src, const char *dest, bool recursive)
|
|||||||
|
|
||||||
waitpid(pid, &status, 0);
|
waitpid(pid, &status, 0);
|
||||||
|
|
||||||
printlogf(LOG_DEBUG, "Rsync of [%s] -> [%s] finished", src, dest);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a directory to watch
|
* Adds a directory to watch
|
||||||
*
|
*
|
||||||
@ -380,7 +351,7 @@ bool rsync(char const *src, const char *dest, bool recursive)
|
|||||||
*
|
*
|
||||||
* @return index to dir_watches of the new dir, -1 on error.
|
* @return index to dir_watches of the new dir, -1 on error.
|
||||||
*/
|
*/
|
||||||
int add_watch(char const *pathname, char const *dirname, char const *destname, int parent)
|
int add_watch(char const * pathname, char const * dirname, char const * destname, int parent)
|
||||||
{
|
{
|
||||||
int wd;
|
int wd;
|
||||||
char * nn;
|
char * nn;
|
||||||
@ -430,6 +401,7 @@ int add_watch(char const *pathname, char const *dirname, char const *destname, i
|
|||||||
return newdw;
|
return newdw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the abolute path name of a given directory beeing watched.
|
* Builds the abolute path name of a given directory beeing watched.
|
||||||
*
|
*
|
||||||
@ -443,10 +415,10 @@ bool buildpath(char *pathname,
|
|||||||
int pathsize,
|
int pathsize,
|
||||||
int watch,
|
int watch,
|
||||||
char const *name,
|
char const *name,
|
||||||
char const *prefix)
|
char const * prefix)
|
||||||
{
|
{
|
||||||
|
|
||||||
int j, k, p, ps;
|
int j, k, p, ps;
|
||||||
|
|
||||||
pathname[0] = 0;
|
pathname[0] = 0;
|
||||||
|
|
||||||
if (prefix) {
|
if (prefix) {
|
||||||
@ -454,14 +426,16 @@ bool buildpath(char *pathname,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// count how big the parent stack is
|
// count how big the parent stack is
|
||||||
for (p = watch, ps = 0; p != -1; p = dir_watches[p].parent, ps++) {}
|
for (p = watch, ps = 0; p != -1; p = dir_watches[p].parent, ps++) {
|
||||||
|
}
|
||||||
|
|
||||||
// now add the parent paths from back to front
|
// now add the parent paths from back to front
|
||||||
for (j = ps; j > 0; j--) {
|
for (j = ps; j > 0; j--) {
|
||||||
char * name;
|
char * name;
|
||||||
// go j steps behind stack
|
// go j steps behind stack
|
||||||
|
|
||||||
for (p = watch, k = 0; k + 1 < j; p = dir_watches[p].parent, k++) {}
|
for (p = watch, k = 0; k + 1 < j; p = dir_watches[p].parent, k++) {
|
||||||
|
}
|
||||||
|
|
||||||
name = (prefix && dir_watches[p].destname) ? dir_watches[p].destname : dir_watches[p].dirname;
|
name = (prefix && dir_watches[p].destname) ? dir_watches[p].destname : dir_watches[p].dirname;
|
||||||
|
|
||||||
@ -496,36 +470,32 @@ bool buildpath(char *pathname,
|
|||||||
* @param parent If not -1, the index in dir_watches to the parent directory already watched.
|
* @param parent If not -1, the index in dir_watches to the parent directory already watched.
|
||||||
* Must have absolute path if parent == -1.
|
* Must have absolute path if parent == -1.
|
||||||
*/
|
*/
|
||||||
bool add_dirwatch(char const *dirname, char const *destname, bool recursive, int parent)
|
bool add_dirwatch(char const * dirname, char const * destname, bool recursive, int parent)
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
|
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
int dw, i;
|
int dw, i;
|
||||||
char pathname[MAX_PATH], fullpath[MAX_PATH];
|
char pathname[MAX_PATH];
|
||||||
|
|
||||||
|
printlogf(LOG_DEBUG, "add_dirwatch(%s, %s, %d, p->dirname:%s)", dirname, destname, recursive, parent >= 0 ? dir_watches[parent].dirname : "NULL");
|
||||||
|
|
||||||
if (!buildpath(pathname, sizeof(pathname), parent, dirname, NULL)) {
|
if (!buildpath(pathname, sizeof(pathname), parent, dirname, NULL)) {
|
||||||
printlogf(LOG_ERROR, "Building path for [%s] failed.", dirname);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < exclude_dir_n; i++) {
|
for (i = 0; i < exclude_dir_n; i++) {
|
||||||
// TODO explain
|
if (!strcmp(dirname, exclude_dirs[i])) {
|
||||||
if ( (strstr(pathname, exclude_dirs[i]) - pathname) == (strlen(pathname) - strlen(exclude_dirs[i])) ) {
|
return true;
|
||||||
printlogf(LOG_DEBUG, "add_dirwatch::excluded(%s[%s], %s)", dirname, pathname, exclude_dirs[i]);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dw = add_watch(pathname, dirname, destname, parent);
|
dw = add_watch(pathname, dirname, destname, parent);
|
||||||
|
|
||||||
if (dw == -1) {
|
if (dw == -1) {
|
||||||
printlogf(LOG_ERROR, "add_watch(%s)failed.", dirname);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
printlogf(LOG_DEBUG, "add_dirwatch::added(%s[%s], %s, %d, p->dirname:%s)", dirname, pathname, destname, recursive, parent >= 0 ? dir_watches[parent].dirname : "NULL");
|
|
||||||
|
|
||||||
if (strlen(pathname) + strlen(dirname) + 2 > sizeof(pathname)) {
|
if (strlen(pathname) + strlen(dirname) + 2 > sizeof(pathname)) {
|
||||||
printlogf(LOG_ERROR, "pathname too long %s//%s", pathname, dirname);
|
printlogf(LOG_ERROR, "pathname too long %s//%s", pathname, dirname);
|
||||||
return false;
|
return false;
|
||||||
@ -538,20 +508,16 @@ bool add_dirwatch(char const *dirname, char const *destname, bool recursive, int
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (de = readdir(d)) {
|
while (keep_going) {
|
||||||
sprintf(fullpath, "%s/%s", pathname, de->d_name);
|
de = readdir(d);
|
||||||
//printlogf(LOG_DEBUG, "Checking if [%s] is a folder.", fullpath);
|
|
||||||
// why was DT_DIR not good?
|
|
||||||
|
|
||||||
if ((is_dir(fullpath) == true) && strcmp(de->d_name, "..") && strcmp(de->d_name, ".")) {
|
if (de == NULL) {
|
||||||
//printlogf(LOG_DEBUG, "Going deeper to %s.", de->d_name);
|
break;
|
||||||
add_dirwatch(de->d_name, NULL, true, dw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*else
|
if (de->d_type == DT_DIR && strcmp(de->d_name, "..") && strcmp(de->d_name, ".")) {
|
||||||
{
|
add_dirwatch(de->d_name, NULL, true, dw);
|
||||||
printlogf(LOG_DEBUG, "Not going deeper, since object %s is not folder.", de->d_name);
|
}
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
@ -575,8 +541,7 @@ bool remove_dirwatch(const char * name, int parent)
|
|||||||
// look for the child with the name
|
// look for the child with the name
|
||||||
for (i = 0; i < dir_watch_num; i++) {
|
for (i = 0; i < dir_watch_num; i++) {
|
||||||
if (dir_watches[i].wd >= 0 && dir_watches[i].parent == parent &&
|
if (dir_watches[i].wd >= 0 && dir_watches[i].parent == parent &&
|
||||||
!strcmp(name, dir_watches[i].dirname)
|
!strcmp(name, dir_watches[i].dirname)) {
|
||||||
) {
|
|
||||||
dw = i;
|
dw = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -633,7 +598,6 @@ bool handle_event(struct inotify_event *event)
|
|||||||
|
|
||||||
for (i = 0; i < exclude_dir_n; i++) {
|
for (i = 0; i < exclude_dir_n; i++) {
|
||||||
if (!strcmp(event->name, exclude_dirs[i])) {
|
if (!strcmp(event->name, exclude_dirs[i])) {
|
||||||
printlogf(LOG_DEBUG, "Event on [%s] ignored due to exclude rules", event->name);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,12 +628,9 @@ bool handle_event(struct inotify_event *event)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((IN_CREATE) & event->mask) && (IN_ISDIR & event->mask)) {
|
|
||||||
add_dirwatch(event->name, NULL, false, i);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (((IN_MOVED_TO) & event->mask) && (IN_ISDIR & event->mask)) {
|
if (((IN_CREATE | IN_MOVED_TO) & event->mask) && (IN_ISDIR & event->mask)) {
|
||||||
add_dirwatch(event->name, NULL, true, i);
|
add_dirwatch(event->name, NULL, false, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((IN_DELETE | IN_MOVED_FROM) & event->mask) && (IN_ISDIR & event->mask)) {
|
if (((IN_DELETE | IN_MOVED_FROM) & event->mask) && (IN_ISDIR & event->mask)) {
|
||||||
@ -687,13 +648,8 @@ bool handle_event(struct inotify_event *event)
|
|||||||
// call rsync to propagate changes in the directory
|
// call rsync to propagate changes in the directory
|
||||||
if ((IN_CREATE | IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_TO | IN_MOVED_FROM) & event->mask) {
|
if ((IN_CREATE | IN_CLOSE_WRITE | IN_DELETE | IN_MOVED_TO | IN_MOVED_FROM) & event->mask) {
|
||||||
printlogf(LOG_NORMAL, "%s of %s in %s --> %s", masktext, event->name, pathname, destname);
|
printlogf(LOG_NORMAL, "%s of %s in %s --> %s", masktext, event->name, pathname, destname);
|
||||||
|
|
||||||
if (IN_MOVED_TO & event->mask) {
|
|
||||||
rsync(pathname, destname, true);
|
|
||||||
} else {
|
|
||||||
rsync(pathname, destname, false);
|
rsync(pathname, destname, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -724,9 +680,7 @@ bool master_loop()
|
|||||||
while (i < len) {
|
while (i < len) {
|
||||||
|
|
||||||
struct inotify_event *event = (struct inotify_event *) &buf[i];
|
struct inotify_event *event = (struct inotify_event *) &buf[i];
|
||||||
printlogf(LOG_DEBUG, "Event [%d] started", i);
|
|
||||||
handle_event(event);
|
handle_event(event);
|
||||||
printlogf(LOG_DEBUG, "Event [%d] finished", i);
|
|
||||||
i += sizeof(struct inotify_event) + event->len;
|
i += sizeof(struct inotify_event) + event->len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -738,72 +692,51 @@ bool master_loop()
|
|||||||
* Scans all dirs in /home, looking if a www subdir exists.
|
* Scans all dirs in /home, looking if a www subdir exists.
|
||||||
* Syncs this dir immediately, and adds watches to it.
|
* Syncs this dir immediately, and adds watches to it.
|
||||||
*/
|
*/
|
||||||
bool scan_users(char *users_path, char *user_priv)
|
bool scan_homes()
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
DIR *d2;
|
DIR *d2;
|
||||||
char user_path[MAX_PATH], src_path[MAX_PATH], dest_path[MAX_PATH], dest_rel_path[MAX_PATH], src_mask[MAX_PATH], prepare_target_path[MAX_PATH];
|
char path[MAX_PATH];
|
||||||
char prepare_target_cmd[8192];
|
char destpath[MAX_PATH];
|
||||||
|
|
||||||
struct stat *de_stat;
|
|
||||||
|
|
||||||
struct dirent *de;
|
struct dirent *de;
|
||||||
int sl;
|
|
||||||
|
|
||||||
printlogf(LOG_DEBUG, "Scanning in [%s] for available users", users_path);
|
d = opendir("/home");
|
||||||
d = opendir(users_path);
|
|
||||||
|
|
||||||
if (d == NULL) {
|
if (d == NULL) {
|
||||||
printlogf(LOG_ERROR, "Cannot open [%s]", users_path);
|
printlogf(LOG_ERROR, "Cannot open /home");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
|
||||||
snprintf(prepare_target_path, sizeof(prepare_target_path), "%s/%s", option_target, users_path);
|
|
||||||
snprintf(prepare_target_cmd, sizeof(prepare_target_cmd), "mkdir -p %s; chmod 777 %s;", prepare_target_path, prepare_target_path);
|
|
||||||
printlogf(LOG_DEBUG, "exec [%s]", prepare_target_cmd);
|
|
||||||
system(prepare_target_cmd);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (de = readdir(d)) {
|
while (keep_going) {
|
||||||
snprintf(user_path, sizeof(user_path), "%s/%s", users_path, de->d_name);
|
de = readdir(d);
|
||||||
|
|
||||||
if ((is_dir(user_path) == true) && strcmp(de->d_name, "..") && strcmp(de->d_name, ".")) {
|
if (de == NULL) {
|
||||||
snprintf(src_mask, sizeof(src_mask), "%s/%s/%s", users_path, de->d_name, user_priv);
|
break;
|
||||||
snprintf(src_path, sizeof(src_path), src_mask, de->d_name);
|
}
|
||||||
sl = strlen(src_path);
|
|
||||||
|
|
||||||
if (src_path[sl - 1] == '/') {
|
if (de->d_type == DT_DIR && strcmp(de->d_name, "..") && strcmp(de->d_name, ".")) {
|
||||||
src_path[sl - 1] = 0;
|
snprintf(path, sizeof(path), "/home/%s/www/", de->d_name);
|
||||||
sl--;
|
d2 = opendir(path);
|
||||||
|
|
||||||
if (sl == 0) {
|
if (d2 == NULL) {
|
||||||
|
//has no www dir or is not readable
|
||||||
|
printlogf(LOG_NORMAL, "skipping %s. it has no readable www directory.", de->d_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!(d2 = opendir(src_path))) {
|
|
||||||
printlogf(LOG_NORMAL, "Skipping %s. Can not read priv directory.", src_path);
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
printlogf(LOG_NORMAL, "Proccessing priv directory [%s:%s].", src_mask, src_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
closedir(d2);
|
closedir(d2);
|
||||||
|
|
||||||
snprintf(dest_path, sizeof(dest_path), "%s%s/%s/", option_target, users_path, de->d_name);
|
printlogf(LOG_NORMAL, "watching %s's www directory (%s)", de->d_name, path);
|
||||||
snprintf(dest_rel_path, sizeof(dest_rel_path), "%s/%s/", users_path, de->d_name);
|
add_dirwatch(path, de->d_name, true, -1);
|
||||||
|
|
||||||
if (add_dirwatch(src_path, dest_rel_path, true, -1)) {
|
snprintf(destpath, sizeof(destpath), "%s/%s/", option_target, de->d_name);
|
||||||
// Not syncing if skipped
|
rsync(path, destpath, true);
|
||||||
rsync(src_path, dest_path, true);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
printlogf(LOG_DEBUG, "*\tSkipping [%s]", de->d_name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printlogf(LOG_DEBUG, "Finished scanning in [%s] for users", users_path);
|
|
||||||
|
|
||||||
closedir(d);
|
closedir(d);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -818,7 +751,7 @@ void print_help(char *arg0)
|
|||||||
printf("USAGE: %s [OPTION]... SOURCE TARGET\n", arg0);
|
printf("USAGE: %s [OPTION]... SOURCE TARGET\n", arg0);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("SOURCE: a directory to watch and rsync.\n");
|
printf("SOURCE: a directory to watch and rsync.\n");
|
||||||
printf(" specify special \"%users%\" to monitor all users folders. \n");
|
printf(" specify special \"%%userwww\" to scan all users in /home and watch their www directories. \n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("TARGET: can be any name accepted by rsync. e.g. \"foohost::barmodule/\"\n");
|
printf("TARGET: can be any name accepted by rsync. e.g. \"foohost::barmodule/\"\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
@ -964,11 +897,11 @@ bool parse_exclude_file()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
exclude_dirs[exclude_dir_n] = s_malloc(strlen(line) + 1);
|
printlogf(LOG_NORMAL, "Excluding directories of the name '%s'", line);
|
||||||
|
|
||||||
|
exclude_dirs[exclude_dir_n] = s_malloc(strlen(line) + 1);
|
||||||
strcpy(exclude_dirs[exclude_dir_n], line);
|
strcpy(exclude_dirs[exclude_dir_n], line);
|
||||||
exclude_dir_n++;
|
exclude_dir_n++;
|
||||||
printlogf(LOG_NORMAL, "Excluding directory [%s] from syncing.", line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -981,7 +914,6 @@ bool parse_exclude_file()
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (!parse_options(argc, argv)) {
|
if (!parse_options(argc, argv)) {
|
||||||
printlogf(LOG_ERROR, "Invalid parameters specified!");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1005,22 +937,16 @@ int main(int argc, char **argv)
|
|||||||
dir_watch_size = 2;
|
dir_watch_size = 2;
|
||||||
dir_watches = s_calloc(dir_watch_size, sizeof(struct dir_watch));
|
dir_watches = s_calloc(dir_watch_size, sizeof(struct dir_watch));
|
||||||
|
|
||||||
if (!strcmp(option_source, "%users%")) {
|
if (!strcmp(option_source, "%userwww")) {
|
||||||
printlogf(LOG_NORMAL, "Switching to users mode");
|
printlogf(LOG_NORMAL, "do userwww");
|
||||||
scan_users("/home", "");
|
scan_homes();
|
||||||
scan_users("/scratchbox/users", "home/%s/");
|
|
||||||
} else {
|
} else {
|
||||||
printlogf(LOG_NORMAL, "Watching %s", option_source);
|
printlogf(LOG_NORMAL, "watching %s", option_source);
|
||||||
|
add_dirwatch(option_source, "", true, -1);
|
||||||
if (add_dirwatch(option_source, "", true, -1) == -2) {
|
|
||||||
printlogf(LOG_ERROR, "Adding folder skipped, probably excluded. Nothing left to to, exiting.");
|
|
||||||
exit (-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
rsync(option_source, option_target, true);
|
rsync(option_source, option_target, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
printlogf(LOG_NORMAL, "--- Entering normal operation with [%d] monitored directories ---", dir_watch_num);
|
printlogf(LOG_NORMAL, "---entering normal operation---");
|
||||||
|
|
||||||
signal(SIGTERM, catch_alarm);
|
signal(SIGTERM, catch_alarm);
|
||||||
master_loop();
|
master_loop();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user