--- lsyncd.c.orig	2009-01-05 14:39:41.000000000 +0100
+++ lsyncd.c	2009-08-05 23:30:59.481114931 +0200
@@ -1,4 +1,4 @@
-/** 
+/**
  * lsyncd.c   Live (Mirror) Syncing Demon
  *
  * License: GPLv2 (see COPYING) or any later version
@@ -76,7 +76,7 @@
 };
 
 /**
- * An option paramater for the action call can either be: 
+ * An option paramater for the action call can either be:
  */
 enum call_option_kind {
 	CO_EOL,                 // end of list,
@@ -221,7 +221,7 @@
 /**
  * Global Option: this binary is used if no other specified in dir_conf.
  */
-char * default_binary = "/usr/bin/rsync"; 
+char * default_binary = "/usr/bin/rsync";
 
 /**
  * Global Option: default exclude file
@@ -268,7 +268,7 @@
 /**
  * The pointer of the current tosync position.
  */
-int tosync_pos = 0; 
+int tosync_pos = 0;
 
 /**
  * A constant that assigns every inotify mask a printable string.
@@ -276,19 +276,19 @@
  */
 
 struct inotify_mask_text mask_texts[] = {
-	{ IN_ACCESS,        "ACCESS"        }, 
-	{ IN_ATTRIB,        "ATTRIB"        }, 
-	{ IN_CLOSE_WRITE,   "CLOSE_WRITE"   }, 
-	{ IN_CLOSE_NOWRITE, "CLOSE_NOWRITE" }, 
-	{ IN_CREATE,        "CREATE"        }, 
-	{ IN_DELETE,        "DELETE"        }, 
-	{ IN_DELETE_SELF,   "DELETE_SELF"   }, 
-	{ IN_IGNORED,       "IGNORED"       }, 
-	{ IN_MODIFY,        "MODIFY"        }, 
-	{ IN_MOVE_SELF,     "MOVE_SELF"     }, 
-	{ IN_MOVED_FROM,    "MOVED_FROM"    }, 
-	{ IN_MOVED_TO,      "MOVED_TO"      }, 
-	{ IN_OPEN,          "OPEN"          }, 
+	{ IN_ACCESS,        "ACCESS"        },
+	{ IN_ATTRIB,        "ATTRIB"        },
+	{ IN_CLOSE_WRITE,   "CLOSE_WRITE"   },
+	{ IN_CLOSE_NOWRITE, "CLOSE_NOWRITE" },
+	{ IN_CREATE,        "CREATE"        },
+	{ IN_DELETE,        "DELETE"        },
+	{ IN_DELETE_SELF,   "DELETE_SELF"   },
+	{ IN_IGNORED,       "IGNORED"       },
+	{ IN_MODIFY,        "MODIFY"        },
+	{ IN_MOVE_SELF,     "MOVE_SELF"     },
+	{ IN_MOVED_FROM,    "MOVED_FROM"    },
+	{ IN_MOVED_TO,      "MOVED_TO"      },
+	{ IN_OPEN,          "OPEN"          },
 	{ 0, "" },
 };
 
@@ -328,7 +328,7 @@
 int exclude_dir_n = 0;
 
 /*--------------------------------------------------------------------------*
- * Small generic helper routines. 
+ * Small generic helper routines.
  *    (signal catching, memory fetching, message output)
  *--------------------------------------------------------------------------*/
 
@@ -469,10 +469,10 @@
 }
 
 /**
- * Returns the canonicalized path of a directory with a final '/', 
+ * Returns the canonicalized path of a directory with a final '/',
  * Makes sure it is a directory.
  */
-char *realdir(const char * dir) 
+char *realdir(const char * dir)
 {
 	char* cs = s_malloc(PATH_MAX+1);
 	cs = realpath(dir, cs);
@@ -498,7 +498,7 @@
 }
 
 /*--------------------------------------------------------------------------*
- * dir_configuration handling. 
+ * dir_configuration handling.
  *--------------------------------------------------------------------------*/
 
 /**
@@ -506,7 +506,7 @@
  *
  * (Yes we know, its a bit unoptimal, since when 6 dir_confs are given
  * in the config file, lsyncd will reallocate dir_confs 6 times. Well we
- * can live with that.) 
+ * can live with that.)
  *
  * @return the pointer to the newly allocated dir_conf
  */
@@ -548,7 +548,7 @@
 }
 
 /*--------------------------------------------------------------------------*
- * ToSync Stack handling. 
+ * ToSync Stack handling.
  *--------------------------------------------------------------------------*/
 
 /**
@@ -564,7 +564,7 @@
 	for(i = 0; i < tosync_pos; i++) {
 		if (tosync[i] == watch) {
 			return true;
-		} 
+		}
 	}
 
 	if (tosync_pos + 1 >= tosync_size) {
@@ -593,8 +593,8 @@
 }
 
 /**
- * Parses an option text, replacing all '%' specifiers with 
- * elaborated stuff. duh, currently there is only one, so this 
+ * Parses an option text, replacing all '%' specifiers with
+ * elaborated stuff. duh, currently there is only one, so this
  * fuction is a bit overkill but oh well :-)
  *
  * @param text      string to parse.
@@ -620,7 +620,7 @@
 			break;
 		case 0:    // wtf, '%' was at the end of the string!
 		default :  // unknown char
-			printlogf(LOG_ERROR, 
+			printlogf(LOG_ERROR,
 			          "don't know how to handle '\%' specifier in \"%s\"!", *text);
 			exit(LSYNCD_BADPARAMETERS);
 		}
@@ -638,9 +638,9 @@
  * @param recursive If true -r will be handled on, -d (single directory) otherwise
  * @return true if successful, false if not.
  */
-bool action(struct dir_conf * dir_conf, 
-            char const * src, 
-            const char * dest, 
+bool action(struct dir_conf * dir_conf,
+            char const * src,
+            const char * dest,
             bool recursive)
 {
 	pid_t pid;
@@ -679,7 +679,7 @@
 		}
 		if (argc >= MAX_ARGS) {
 			/* check for error condition */
-			printlogf(LOG_ERROR, 
+			printlogf(LOG_ERROR,
 			          "Internal error: too many (>%i) options passed", argc);
 			return false;
 		}
@@ -722,13 +722,13 @@
 	waitpid(pid, &status, 0);
 	assert(WIFEXITED(status));
 	if (WEXITSTATUS(status)==LSYNCD_INTERNALFAIL){
-		printlogf(LOG_ERROR, 
-		          "Fork exit code of %i, execv failure", 
+		printlogf(LOG_ERROR,
+		          "Fork exit code of %i, execv failure",
 		          WEXITSTATUS(status));
 		return false;
 	} else if (WEXITSTATUS(status)) {
-		printlogf(LOG_NORMAL, 
-		          "Forked binary process returned non-zero return code: %i", 
+		printlogf(LOG_NORMAL,
+		          "Forked binary process returned non-zero return code: %i",
 		          WEXITSTATUS(status));
 		return false;
 	}
@@ -747,21 +747,21 @@
  *
  * @return index to dir_watches of the new dir, -1 on error.
  */
-int add_watch(char const * pathname, 
-              char const * dirname, 
-              int parent, 
+int add_watch(char const * pathname,
+              char const * dirname,
+              int parent,
               struct dir_conf * dir_conf)
 {
 	int wd;
 	int newdw;
 
 	wd = inotify_add_watch(inotf, pathname,
-	                       IN_ATTRIB | IN_CLOSE_WRITE | IN_CREATE | 
-	                       IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM | 
+	                       IN_ATTRIB | IN_CLOSE_WRITE | IN_CREATE |
+	                       IN_DELETE | IN_DELETE_SELF | IN_MOVED_FROM |
 	                       IN_MOVED_TO | IN_DONT_FOLLOW | IN_ONLYDIR);
 
 	if (wd == -1) {
-		printlogf(LOG_ERROR, "Cannot add watch %s (%d:%s)", 
+		printlogf(LOG_ERROR, "Cannot add watch %s (%d:%s)",
 		          pathname, errno, strerror(errno));
 		return -1;
 	}
@@ -776,7 +776,7 @@
 	if (newdw == dir_watch_num) {
 		if (dir_watch_num + 1 >= dir_watch_size) {
 			dir_watch_size *= 2;
-			dir_watches = s_realloc(dir_watches, 
+			dir_watches = s_realloc(dir_watches,
 			                        dir_watch_size * sizeof(struct dir_watch));
 		}
 
@@ -799,7 +799,7 @@
  * @param watch index of watched dir to build path for
  * @param prefix replace root dir with this (as target)
  *
- * @return -1 if pathname buffer was too small 
+ * @return -1 if pathname buffer was too small
  *            contents of pathname will be garbled then.
  *         strlen(pathname) if successful
  */
@@ -922,7 +922,7 @@
 	int dw, i;
 	char pathname[PATH_MAX+1];
 
-	printlogf(LOG_DEBUG, "add_dirwatch(%s, p->dirname:%s, ...)", 
+	printlogf(LOG_DEBUG, "add_dirwatch(%s, p->dirname:%s, ...)",
 	          dirname,
 	          parent >= 0 ? dir_watches[parent].dirname : "NULL");
 
@@ -968,16 +968,16 @@
 		} else if (de->d_type == DT_UNKNOWN) {
 			// in case of reiserfs, d_type will be UNKNOWN, how evil! :-(
 			// use traditional means to determine if its a directory.
-			isdir = buildpath(subdir, sizeof(subdir), dw, de->d_name, NULL) && 
-			        !stat(subdir, &st) && 
+			isdir = buildpath(subdir, sizeof(subdir), dw, de->d_name, NULL) &&
+			        !stat(subdir, &st) &&
 			        S_ISDIR(st.st_mode);
 		} else {
 			isdir = false;
 		}
 		if (isdir && strcmp(de->d_name, "..") && strcmp(de->d_name, ".")) {
 			int ndw = add_dirwatch(de->d_name, dw, dir_conf);
-			printlogf(LOG_NORMAL, 
-			          "found new directory: %s in %s -- added on tosync stack.", 
+			printlogf(LOG_NORMAL,
+			          "found new directory: %s in %s -- added on tosync stack.",
 			          de->d_name, dirname);
 			append_tosync_watch(ndw);
 		}
@@ -1011,7 +1011,7 @@
 		}
 
 		if (i >= dir_watch_num) {
-			printlogf(LOG_ERROR, "Cannot find entry for %s:/:%s :-(", 
+			printlogf(LOG_ERROR, "Cannot find entry for %s:/:%s :-(",
 			          dir_watches[parent].dirname, name);
 			return false;
 		}
@@ -1116,8 +1116,8 @@
 
 	watch = get_dirwatch_offset(event->wd);
 	if (watch == -1) {
-		printlogf(LOG_ERROR, 
-		          "received an inotify event that doesnt match any watched directory :-(%d,%d)", 
+		printlogf(LOG_ERROR,
+		          "received an inotify event that doesnt match any watched directory :-(%d,%d)",
 		          event->mask, event->wd);
 		return false;
 	}
@@ -1130,7 +1130,7 @@
 		remove_dirwatch(event->name, watch);
 	}
 	
-	if ((IN_CREATE | IN_CLOSE_WRITE | IN_DELETE | 
+	if ((IN_CREATE | IN_CLOSE_WRITE | IN_DELETE |
 	     IN_MOVED_TO | IN_MOVED_FROM) & event->mask
 	   ) {
 		printlogf(LOG_NORMAL, "event %s:%s triggered.", masktext, event->name);
@@ -1231,7 +1231,7 @@
 #endif
 	printf("\n");
 	printf("OPTIONS:\n");
-	printf("  --binary FILE          Call this binary to sync (DEFAULT: %s)\n", 
+	printf("  --binary FILE          Call this binary to sync (DEFAULT: %s)\n",
 	       default_binary);
 #ifdef XML_CONFIG
 	printf("   --conf FILE           Load configuration from this file\n");
@@ -1241,7 +1241,7 @@
 	printf("  --dryrun               Do not call any actions, run dry only\n");
 	printf("  --exclude-from FILE    Exclude file handled to rsync (DEFAULT: None)\n");
 	printf("  --help                 Print this help text and exit.\n");
-	printf("  --logfile FILE         Put log here (DEFAULT: %s)\n", 
+	printf("  --logfile FILE         Put log here (DEFAULT: %s)\n",
 	       logfile);
 	printf("  --no-daemon            Do not detach, log to stdout/stderr\n");
 	printf("  --pidfile FILE         Create a file containing pid of the daemon\n");
@@ -1513,7 +1513,7 @@
 /**
  * Parses the command line options.
  *
- * exits() in some cases of badparameters, or on 
+ * exits() in some cases of badparameters, or on
  * --version or --help
  */
 void parse_options(int argc, char **argv)
@@ -1521,20 +1521,20 @@
 	char **target;
 
 	static struct option long_options[] = {
-		{"binary",       1, NULL,           0}, 
+		{"binary",       1, NULL,           0},
 #ifdef XML_CONFIG
-		{"conf",         1, NULL,           0}, 
+		{"conf",         1, NULL,           0},
 #endif
-		{"debug",        0, &loglevel,      1}, 
-		{"dryrun",       0, &flag_dryrun,   1}, 
-		{"exclude-from", 1, NULL,           0}, 
-		{"help",         0, NULL,           0}, 
-		{"logfile",      1, NULL,           0}, 
-		{"no-daemon",    0, &flag_nodaemon, 1}, 
-		{"pidfile",      1, NULL,           0}, 
+		{"debug",        0, &loglevel,      1},
+		{"dryrun",       0, &flag_dryrun,   1},
+		{"exclude-from", 1, NULL,           0},
+		{"help",         0, NULL,           0},
+		{"logfile",      1, NULL,           0},
+		{"no-daemon",    0, &flag_nodaemon, 1},
+		{"pidfile",      1, NULL,           0},
 		{"scarce",       0, &loglevel,      3},
 		{"stubborn",     0, &flag_stubborn, 1},
-		{"version",      0, NULL,           0}, 
+		{"version",      0, NULL,           0},
 		{NULL, 0, NULL, 0}
 	};
 
@@ -1544,8 +1544,8 @@
 	// First determine if the config file should be read at all. If read it
 	// before parsing all options in detail, because command line options
 	// should overwrite global settings in the conf file.
-	// There are 2 conditions in which the conf file is read, either 
-	// --conf FILE is given as option, or there isn't a SOURCE and 
+	// There are 2 conditions in which the conf file is read, either
+	// --conf FILE is given as option, or there isn't a SOURCE and
 	// DESTINATION given, in which getting the config from the conf
 	// file will be the default option.
 	
@@ -1562,16 +1562,16 @@
 			if (!strcmp("conf", long_options[oi].name)) {
 				read_conf = true;
 				conf_filename = s_strdup(optarg);
-			} 
+			}
 			
 			if (!strcmp("help", long_options[oi].name)) {
-				// in case --help do not go further, or else 
+				// in case --help do not go further, or else
 				// lsyncd would complain of not being configured ...
 				print_help(argv[0]);
 			}
 
 			if (!strcmp("version", long_options[oi].name)) {
-				// same here 
+				// same here
 				printf("Version: %s\n", VERSION);
 				exit(LSYNCD_SUCCESS);
 			}
@@ -1652,7 +1652,7 @@
 				          odc->source, *target);
 				first_target = false;
 			} else {
-				printlogf(LOG_NORMAL, "                             and -> %s\n", 
+				printlogf(LOG_NORMAL, "                             and -> %s\n",
 				          *target);
 			}
 		}
@@ -1688,7 +1688,7 @@
 				fclose(ef);
 				return true;
 			}
-			printlogf(LOG_ERROR, "Reading file '%s' (%d:%s)\n", 
+			printlogf(LOG_ERROR, "Reading file '%s' (%d:%s)\n",
 			          filename, errno, strerror(errno));
 
 			exit(LSYNCD_FILENOTFOUND);
@@ -1711,8 +1711,8 @@
 
 		if (line[sl - 1] == '/') {
 			if (exclude_dir_n + 1 >= MAX_EXCLUDES) {
-				printlogf(LOG_ERROR, 
-				          "Too many directory excludes, can only have %d at the most", 
+				printlogf(LOG_ERROR,
+				          "Too many directory excludes, can only have %d at the most",
 				          MAX_EXCLUDES);
 				exit(LSYNCD_TOOMANYDIRECTORYEXCLUDES);
 			}
@@ -1747,7 +1747,7 @@
 	}
 	
 	fprintf(f, "%i\n", getpid());
-	fclose(f); 
+	fclose(f);
 }
 
 /**
@@ -1765,14 +1765,14 @@
 
 	inotf = inotify_init();
 	if (inotf == -1) {
-		printlogf(LOG_ERROR, "Cannot create inotify instance! (%d:%s)", 
+		printlogf(LOG_ERROR, "Cannot create inotify instance! (%d:%s)",
 		          errno, strerror(errno));
 		return LSYNCD_NOINOTIFY;
 	}
 
 	if (!flag_nodaemon) {
 		// this will make this process child of init
-		// close stdin/stdout/stderr and 
+		// close stdin/stdout/stderr and
 		// chdir to /
 		if (daemon(0, 0)) {
 			printlogf(LOG_ERROR, "Cannot daemonize! (%d:%s)",
@@ -1799,7 +1799,7 @@
 		add_dirwatch(dir_confs[i].source, -1, &dir_confs[i]);
 	}
 
-	// clears tosync stack again, because the startup 
+	// clears tosync stack again, because the startup
 	// super recursive rsync will handle it eitherway.
 	printlogf(LOG_DEBUG, "dumped tosync stack.");
 	tosync_pos = 0;
@@ -1809,17 +1809,17 @@
 		char **target;
 		for (target = dir_confs[i].targets; *target; ++target) {
 			if (!action(&dir_confs[i], dir_confs[i].source, *target, true)) {
-				printlogf(LOG_ERROR, "Initial rsync from %s to %s failed%s", 
+				printlogf(LOG_ERROR, "Initial rsync from %s to %s failed%s",
 				          dir_confs[i].source, *target,
 				          flag_stubborn ? ", but continuing because being stubborn." : ".");
 				if (!flag_stubborn) {
 					exit(LSYNCD_EXECFAIL);
-				} 
+				}
 			}
 		}
 	}
 
-	printlogf(LOG_NORMAL, 
+	printlogf(LOG_NORMAL,
 	          "--- Entering normal operation with [%d] monitored directories ---",
 	          dir_watch_num);
 
