fixing pipes

This commit is contained in:
Axel Kittenberger 2011-01-20 18:55:46 +00:00
parent 9104e5d87e
commit 1733f8a0b1
1 changed files with 20 additions and 14 deletions

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);
} }
} }
@ -555,7 +555,7 @@ observe_fd(int fd,
if (observance_action) { if (observance_action) {
// TODO // TODO
logstring("Error", logstring("Error",
"internal, New observances in ready/writey handlers not yet supported"); "internal, New observances in ready/writey handlers not yet supported");
exit(-1); // ERRNO exit(-1); // ERRNO
} }
@ -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,16 +863,19 @@ 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);
/* creates the pipe */ if (strlen(pipe_text) > 0) {
if (pipe(pipefd) == -1) { /* creates the pipe */
logstring("Error", "cannot create a pipe!"); if (pipe(pipefd) == -1) {
exit(-1); // ERRNO logstring("Error", "cannot create a pipe!");
exit(-1); // ERRNO
}
/* always close the write end for child processes */
close_exec_fd(pipefd[1]);
/* set the write end on non-blocking */
non_block_fd(pipefd[1]);
} else {
pipe_text = NULL;
} }
/* always close the write end for child processes */
close_exec_fd(pipefd[1]);
/* set the write end on non-blocking */
non_block_fd(pipefd[1]);
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");