From bb9956cc7aa2e90d138e33694500bd7cb535fe81 Mon Sep 17 00:00:00 2001 From: Axel Kittenberger Date: Sat, 13 Dec 2008 22:14:58 +0000 Subject: [PATCH] moved manpage stuff into doc subdir to less confuse users, fixed some warnings on intrepid ubuntu, fixed some non documented return codes --- Makefile.am | 16 ++++---- .../manpage.lsyncd.conf.xml | 0 manpage.lsyncd.xml => doc/manpage.lsyncd.xml | 7 +++- lsyncd.c | 37 ++++++++++++------- 4 files changed, 38 insertions(+), 22 deletions(-) rename manpage.lsyncd.conf.xml => doc/manpage.lsyncd.conf.xml (100%) rename manpage.lsyncd.xml => doc/manpage.lsyncd.xml (98%) diff --git a/Makefile.am b/Makefile.am index 6dfbc0f..6a419b5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -11,11 +11,11 @@ TESTS = tests/help.sh \ datarootdir = @datarootdir@ -EXTRA_DIST = config.h.in inotify-nosys.h \ - manpage.lsyncd.xml manpage.lsyncd.conf.xml lsyncd.conf.xml \ - lsyncd.1 lsyncd.conf.xml.5 +EXTRA_DIST = config.h.in inotify-nosys.h lsyncd.conf.xml \ + doc/manpage.lsyncd.xml doc/manpage.lsyncd.conf.xml \ + doc/lsyncd.1 doc/lsyncd.conf.xml.5 -nodist_man1_MANS = lsyncd.1 lsyncd.conf.xml.5 +nodist_man1_MANS = doc/lsyncd.1 doc/lsyncd.conf.xml.5 check-syntax: $(CC) -c -O2 -Wall $(CHK_SOURCES) -o/dev/null @@ -26,11 +26,11 @@ XP = xsltproc -''-nonet \ -''-param make.year.ranges "1" \ -''-param make.single.year.ranges "1" -lsyncd.1: manpage.lsyncd.xml - $(XP) $(DB2MAN) $< +doc/lsyncd.1: doc/manpage.lsyncd.xml + $(XP) -o $@ $(DB2MAN) $< -lsyncd.conf.xml.5: manpage.lsyncd.conf.xml - $(XP) $(DB2MAN) $< +doc/lsyncd.conf.xml.5: doc/manpage.lsyncd.conf.xml + $(XP) -o $@ $(DB2MAN) $< AM_CFLAGS=-Wall AM_LDFLAGS= diff --git a/manpage.lsyncd.conf.xml b/doc/manpage.lsyncd.conf.xml similarity index 100% rename from manpage.lsyncd.conf.xml rename to doc/manpage.lsyncd.conf.xml diff --git a/manpage.lsyncd.xml b/doc/manpage.lsyncd.xml similarity index 98% rename from manpage.lsyncd.xml rename to doc/manpage.lsyncd.xml index 54f4f7e..bb75091 100644 --- a/manpage.lsyncd.xml +++ b/doc/manpage.lsyncd.xml @@ -62,7 +62,7 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Axel Kittenberger - Strives to keep this uptodate. + Strives to keep this up to date.
axel.kittenberger@univie.ac.at
@@ -301,6 +301,11 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ 6 Something wrong with the config file. + + + 7 + Kernel cannot do inotify. + 255 diff --git a/lsyncd.c b/lsyncd.c index 55d4419..5aaf8ec 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -68,7 +68,10 @@ enum lsyncd_exit_code /* something wrong with the config file */ LSYNCD_BADCONFIGFILE = 6, - /* Internal exit code to denote that execv failed */ + /* cannot open inotify instance */ + LSYNCD_NOINOTIFY = 7, + + /* something internal went really wrong */ LSYNCD_INTERNALFAIL = 255, }; @@ -697,8 +700,12 @@ bool action(struct dir_conf * dir_conf, if (pid == 0) { char * binary = dir_conf->binary ? dir_conf->binary : default_binary; if (!flag_nodaemon) { - freopen(logfile, "a", stdout); - freopen(logfile, "a", stderr); + if (!freopen(logfile, "a", stdout)) { + printlogf(LOG_ERROR, "cannot redirect stdout to [%s].", logfile); + } + if (!freopen(logfile, "a", stderr)) { + printlogf(LOG_ERROR, "cannot redirect stderr to [%s].", logfile); + } } execv(binary, argv); // in a sane world does not return! @@ -1505,8 +1512,11 @@ bool parse_config(bool fullparse) { /** * Parses the command line options. + * + * exits() in some cases of badparameters, or on + * --version or --help */ -bool parse_options(int argc, char **argv) +void parse_options(int argc, char **argv) { char **target; @@ -1546,7 +1556,7 @@ bool parse_options(int argc, char **argv) break; } if (c == '?') { - return false; + exit(LSYNCD_BADPARAMETERS); } if (c == 0) { // longoption if (!strcmp("conf", long_options[oi].name)) { @@ -1584,7 +1594,7 @@ bool parse_options(int argc, char **argv) } if (c == '?') { - return false; + exit(LSYNCD_BADPARAMETERS); } if (c == 0) { // longoption @@ -1656,7 +1666,6 @@ bool parse_options(int argc, char **argv) if (pidfile) { check_absolute_path(pidfile); } - return true; } /** @@ -1748,27 +1757,28 @@ int main(int argc, char **argv) { int i; - if (!parse_options(argc, argv)) { - return -1; - } + parse_options(argc, argv); if (default_exclude_file) { parse_exclude_file(default_exclude_file); } inotf = inotify_init(); - if (inotf == -1) { printlogf(LOG_ERROR, "Cannot create inotify instance! (%d:%s)", errno, strerror(errno)); - return -1; + return LSYNCD_NOINOTIFY; } if (!flag_nodaemon) { // this will make this process child of init // close stdin/stdout/stderr and // chdir to / - daemon(0, 0); + if (daemon(0, 0)) { + printlogf(LOG_ERROR, "Cannot daemonize! (%d:%s)", + errno, strerror(errno)); + return LSYNCD_INTERNALFAIL; + } } printlogf(LOG_NORMAL, "Starting up"); @@ -1814,6 +1824,7 @@ int main(int argc, char **argv) dir_watch_num); signal(SIGTERM, catch_alarm); + master_loop(); return 0;