fixing pipes

This commit is contained in:
Axel Kittenberger 2011-01-20 18:55:46 +00:00
parent 9104e5d87e
commit 1733f8a0b1

View File

@ -411,7 +411,7 @@ pipe_writey(lua_State *L, struct observance *observance)
logstring("Normal", "broken pipe."); logstring("Normal", "broken pipe.");
nonobserve_fd(fd); nonobserve_fd(fd);
} else if (pm->pos >= pm->tlen) { } else if (pm->pos >= pm->tlen) {
logstring("Debug", "finished pipe."); logstring("Exec", "finished pipe.");
nonobserve_fd(fd); nonobserve_fd(fd);
} }
} }
@ -616,6 +616,9 @@ nonobserve_fd(int fd)
exit(-1); //ERRNO exit(-1); //ERRNO
} }
/* tidy up the observance */
observances[pos].tidy(observances + pos);
/* and moves the list down */ /* and moves the list down */
memmove(observances + pos, observances + pos + 1, memmove(observances + pos, observances + pos + 1,
(observances_len - pos) * (sizeof(struct observance))); (observances_len - pos) * (sizeof(struct observance)));
@ -860,6 +863,7 @@ l_exec(lua_State *L)
exit(-1); // ERRNO exit(-1); // ERRNO
} }
pipe_text = lua_tolstring(L, 3, &pipe_len); pipe_text = lua_tolstring(L, 3, &pipe_len);
if (strlen(pipe_text) > 0) {
/* creates the pipe */ /* creates the pipe */
if (pipe(pipefd) == -1) { if (pipe(pipefd) == -1) {
logstring("Error", "cannot create a pipe!"); logstring("Error", "cannot create a pipe!");
@ -869,7 +873,9 @@ l_exec(lua_State *L)
close_exec_fd(pipefd[1]); close_exec_fd(pipefd[1]);
/* set the write end on non-blocking */ /* set the write end on non-blocking */
non_block_fd(pipefd[1]); non_block_fd(pipefd[1]);
} else {
pipe_text = NULL;
}
argc -= 2; argc -= 2;
li += 2; li += 2;
} }
@ -891,6 +897,7 @@ l_exec(lua_State *L)
if (pipe_text) { if (pipe_text) {
dup2(pipefd[0], STDIN_FILENO); dup2(pipefd[0], STDIN_FILENO);
} }
close_exec_fd(pipefd[0]);
/* if lsyncd runs as a daemon and has a logfile it will redirect /* if lsyncd runs as a daemon and has a logfile it will redirect
stdout/stderr of child processes to the logfile. */ stdout/stderr of child processes to the logfile. */
if (is_daemon && settings.log_file) { if (is_daemon && settings.log_file) {
@ -919,9 +926,8 @@ l_exec(lua_State *L)
len = write(pipefd[1], pipe_text, pipe_len); len = write(pipefd[1], pipe_text, pipe_len);
if (len < 0) { if (len < 0) {
logstring("Normal", "immediatly broken pipe."); logstring("Normal", "immediatly broken pipe.");
close(pipefd[0]); close(pipefd[1]);
} } else if (len == pipe_len) {
if (len == pipe_len) {
/* usual and best case, the pipe accepted all input -> close */ /* usual and best case, the pipe accepted all input -> close */
close(pipefd[1]); close(pipefd[1]);
logstring("Exec", "one-sweeped pipe"); logstring("Exec", "one-sweeped pipe");