size_t len = 0;
prepare_message(&len, 0);
- char *m = xmalloc(len + 4);
+ size_t tlen = len + 4;
+ char *m = xmalloc(tlen);
char *p = m;
prepare_length(0, &p, len);
prepare_message(0, &p);
- assert(p == m + len + 4);
+ assert(p == m + tlen);
- ssize_t sr = fwrite(p, len, 1, call_sock);
+ ssize_t sr = fwrite(m, tlen, 1, call_sock);
if (sr != 1) diee("write request (buffer)");
if (fflush(call_sock)) diee("write request");
if (errno==EINTR) continue;
diee("stat socket: %s", socket_path);
}
- if (!(now_stab.st_dev == initial_stab.st_dev &&
- now_stab.st_ino == initial_stab.st_ino))
+ if (!stabs_same_inode(&now_stab, &initial_stab))
_exit(0);
}
}
uv_fs_event_t uvhandle_sockpath;
int r;
- if (fcntl(0, F_SETFL, O_NONBLOCK)) diee("watcher set stdin nonblocking");
+ nonblock(0);
errno= -uv_loop_init(&loop);
if (errno) diee("watcher: uv_loop_init");
int null_0 = open("/dev/null", O_RDONLY); if (null_0 < 0) diee("open null");
if (dup2(null_0, 0)) diee("dup2 /dev/null onto stdin");
+ close(null_0);
if (dup2(2, 1) != 1) die("dup2 stderr onto stdout");
+ nonblock(sfd);
+
// Extension could work like this:
//
// We advertise a new protocol (perhaps one which is nearly entirely
// different after the connect) by putting a name for it comma-separated
// next to "v1". Simple extension can be done by having the script
// side say something about it in the ack xdata, which we currently ignore.
- putenv(m_asprintf("PREFORK_INTERP=v1 %d,%d %s",
- sfd, call_fd, socket_path, watcher_stdin, watcher_stderr));
+ putenv(m_asprintf("PREFORK_INTERP=v1 %d,%d,%d,%d",
+ sfd, call_fd, watcher_stdin, watcher_stderr));
execvp(executor_argv[0], (char**)executor_argv);
diee("execute %s", executor_argv[0]);
close(watcher_stdin[1]);
close(watcher_stderr[0]);
if (dup2(watcher_stdin[0], 0) != 0 ||
- dup2(watcher_stderr[1], 1) != 0)
+ dup2(watcher_stderr[1], 1) != 1)
diee("initial dup2() for watcher");
close(watcher_stdin[0]);
close(watcher_stderr[1]);
close(watcher_stdin[0]);
close(watcher_stderr[1]);
- if (fcntl(watcher_stderr[0], F_SETFL, O_NONBLOCK))
- diee("parent set watcher stderr nonblocking");
+ nonblock(watcher_stderr[0]);
// Fork setup