diff --git a/lsyncd.c b/lsyncd.c index 23d83ca..ef43f00 100644 --- a/lsyncd.c +++ b/lsyncd.c @@ -171,6 +171,21 @@ char * logfile = "/var/log/lsyncd"; */ int inotf; +/** + * Possible Exit codes for this application + */ +enum lsyncd_exit_code +{ + LSYNCD_SUCCESS = 0, + LSYNCD_OUTOFMEMORY = 1, /* out-of memory */ + LSYNCD_FILENOTFOUND = 2, /* file was not found, or failed to write */ + LSYNCD_EXECRSYNCFAIL = 3, /* rsync execution somehow failed */ + LSYNCD_NOTENOUGHARGUMENTS = 4, /* Not enough command-line arguments were given to lsyncd invocation */ + LSYNCD_TOOMANYDIRECTORYEXCLUDES = 5, /* Too many excludes files were specified */ +}; + + + /** * Array of strings of directory names to include. @@ -208,7 +223,7 @@ void printlogf(int level, const char *fmt, ...) if (flog == NULL) { printf("cannot open logfile [%s]!\n", logfile); - exit(-1); + exit(LSYNCD_FILENOTFOUND); } } else { flog = stdout; @@ -260,7 +275,7 @@ void *s_malloc(size_t size) if (r == NULL) { printlogf(LOG_ERROR, "Out of memory!"); - exit(-1); + exit(LSYNCD_OUTOFMEMORY); } return r; @@ -275,7 +290,7 @@ void *s_calloc(size_t nmemb, size_t size) if (r == NULL) { printlogf(LOG_ERROR, "Out of memory!"); - exit(-1); + exit(LSYNCD_OUTOFMEMORY); } return r; @@ -290,7 +305,7 @@ void *s_realloc(void *ptr, size_t size) if (r == NULL) { printlogf(LOG_ERROR, "Out of memory!"); - exit(-1); + exit(LSYNCD_OUTOFMEMORY); } return r; @@ -305,7 +320,7 @@ char *s_strdup(const char* src) if (s == NULL) { printlogf(LOG_ERROR, "Out of memory!"); - exit(-1); + exit(LSYNCD_OUTOFMEMORY); } return s; @@ -396,7 +411,7 @@ bool rsync(char const * src, const char * dest, bool recursive) printlogf(LOG_ERROR, "Failed executing [%s]", rsync_binary); - exit(-1); + exit(LSYNCD_EXECRSYNCFAIL); } for (i=0; i %s\n", option_source, option_target); @@ -971,7 +986,7 @@ bool parse_exclude_file() if (ef == NULL) { printlogf(LOG_ERROR, "Meh, cannot open exclude file '%s'\n", exclude_file); - exit(-1); + exit(LSYNCD_FILENOTFOUND); } while (1) { @@ -983,7 +998,7 @@ bool parse_exclude_file() printlogf(LOG_ERROR, "Reading file '%s' (%d=%s)\n", exclude_file, errno, strerror(errno)); - exit(-1); + exit(LSYNCD_FILENOTFOUND); } sl = strlen(line); @@ -1004,7 +1019,7 @@ bool parse_exclude_file() 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", MAX_EXCLUDES); - exit(-1); + exit(LSYNCD_TOOMANYDIRECTORYEXCLUDES); } line[sl - 1] = 0; @@ -1030,7 +1045,7 @@ void write_pidfile() { FILE* f = fopen(pidfile, "w"); if (!f) { printlogf(LOG_ERROR, "Error: cannot write pidfile [%s]\n", pidfile); - exit(-1); + exit(LSYNCD_FILENOTFOUND); } fprintf(f, "%i\n", getpid()); @@ -1075,7 +1090,7 @@ int main(int argc, char **argv) add_dirwatch(option_source, "", true, -1); if (!rsync(option_source, option_target, true)) { printlogf(LOG_ERROR, "Initial rsync from %s to %s failed", option_source, option_target); - exit(-1); + exit(LSYNCD_EXECRSYNCFAIL); } printlogf(LOG_NORMAL, "--- Entering normal operation with [%d] monitored directories ---", dir_watch_num); diff --git a/manpage.xml b/manpage.xml index 2883bd5..2ae0c52 100644 --- a/manpage.xml +++ b/manpage.xml @@ -256,9 +256,26 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/ Program exited successfully. - -1 (255) - Something bad has happened. + 1 + Out of memory. + + 2 + File was not found, or failed to write. + + + 3 + rsync execution somehow failed. + + + 4 + Not enough command-line arguments were given to lsyncd invocation. + + + 5 + Too many exclude files were specified. + +