filewatcherd

FreeBSD daemon that watches files and runs commands when they change
git clone https://git.instinctive.eu/filewatcherd.git
Log | Files | Refs | README | LICENSE

commit 57179a18400bdf2b0af7ef18ba72339d00e94102
parent f5872d1ed200e5a7b33b01949343f19a0b5d918b
Author: Natasha Kerensikova <natacha@instinctive.eu>
Date:   Thu,  8 Aug 2013 21:09:40 +0200

Fix implicit $HOME setting

Diffstat:
MTODO | 1-
Mwatchtab.c | 13+++++++++----
Mwatchtab.h | 3++-
3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/TODO b/TODO @@ -1,5 +1,4 @@ * document the internals - * fix implicit HOME in first entry considered as explicit in following entries * deal with command output * check how signals interfere with current code * think about how to handle multiple watchtabs diff --git a/watchtab.c b/watchtab.c @@ -215,7 +215,8 @@ wentry_free(struct watch_entry *wentry) { /* Return 0 on success or -1 on failure. */ int wentry_readline(struct watch_entry *dest, char *line, - struct watch_env *base_env, const char *filename, unsigned line_no) { + struct watch_env *base_env, int has_home, + const char *filename, unsigned line_no) { size_t path_len = 0; size_t event_first = 0, event_len = 0; size_t delay_first = 0, delay_len = 0; @@ -390,7 +391,7 @@ wentry_readline(struct watch_entry *dest, char *line, /* Setup environment */ wenv_set(base_env, "LOGNAME", pw->pw_name, 1); wenv_set(base_env, "USER", pw->pw_name, 1); - wenv_set(base_env, "HOME", pw->pw_dir, 0); + wenv_set(base_env, "HOME", pw->pw_dir, !has_home); wenv_set(base_env, "TRIGGER", dest->path, 1); dest->envp = wenv_dup(base_env); @@ -579,7 +580,7 @@ wtab_readfile(struct watchtab *tab, FILE *input, const char *filename) { ssize_t linelen; unsigned line_no = 0; struct watch_entry *entry = 0; - int result = 0; + int result = 0, has_home = 0; size_t i, skip; struct watch_env env; @@ -629,6 +630,10 @@ wtab_readfile(struct watchtab *tab, FILE *input, const char *filename) { while (line[j] == ' ' && j > skip) j--; if (j + 1 < i) line[j + 1] = 0; + /* Check whether this explicitly sets HOME */ + if (strcmp(line + skip, "HOME") == 0) + has_home = 1; + /* Compute bounds of variable value */ j = i + 1; while (line[j] == ' ') j++; @@ -645,7 +650,7 @@ wtab_readfile(struct watchtab *tab, FILE *input, const char *filename) { return -1; } wentry_init(entry); - if (wentry_readline(entry, line + skip, &env, + if (wentry_readline(entry, line + skip, &env, has_home, filename, line_no) < 0) { /* propagate an error but keep parsing */ result = -1; diff --git a/watchtab.h b/watchtab.h @@ -73,7 +73,8 @@ wentry_free(struct watch_entry *wentry); /* wentry_readline - parse a config file line and fill a struct watch_entry */ int wentry_readline(struct watch_entry *dest, char *line, - struct watch_env *base_env, const char *filename, unsigned line_no); + struct watch_env *base_env, int has_home, + const char *filename, unsigned line_no); /* wenv_init - create an empty environment list */