Go to the documentation of this file.
32 # if defined(__MINGW32__)
33 # include <basetyps.h>
35 # include <shellapi.h>
39 # include <sys/wait.h>
57 #define OUTPUT_SIZE 1024
81 ASSERT(0 &&
"fail_cb called");
97 #if defined(__APPLE__) || defined(__MVS__)
126 size_t suggested_size,
136 }
else if (nread < 0) {
194 ASSERT(
r == UV_ENOENT ||
r == UV_EACCES);
214 ASSERT(
r == UV_ENOENT ||
r == UV_EACCES);
221 while (
err == -1 && errno == EINTR);
243 if (NULL !=
getenv(
"DYLD_LIBRARY_PATH") ||
244 NULL !=
getenv(
"LD_LIBRARY_PATH") ||
245 NULL !=
getenv(
"LIBPATH")) {
246 RETURN_SKIP(
"doesn't work with DYLD_LIBRARY_PATH/LD_LIBRARY_PATH/LIBPATH");
329 S_IRUSR | S_IWUSR, NULL);
383 S_IRUSR | S_IWUSR, NULL);
416 ASSERT(strcmp(
"hello world\nhello errworld\n",
output) == 0);
448 file = dup2(
r, STDERR_FILENO);
478 ASSERT(strcmp(
"hello world\nhello errworld\n",
output) == 0);
515 stdout_file = dup2(
r, STDOUT_FILENO);
516 ASSERT(stdout_file != -1);
520 S_IRUSR | S_IWUSR, NULL);
523 stderr_file = dup2(
r, STDERR_FILENO);
524 ASSERT(stderr_file != -1);
590 char buffer[] =
"hello-from-spawn_stdin";
670 handle = _get_osfhandle(3);
689 struct sockaddr_in
addr;
800 r = putenv(
"ENV_TEST=testval");
859 char message[] =
"Nancy's joining me because the message this evening is "
860 "not my message but ours.";
1013 static char buffer[] =
"hello-from-spawn_stdin\n";
1054 sigaddset(&
set, SIGTERM);
1055 ASSERT(0 == pthread_sigmask(SIG_BLOCK, &
set, NULL));
1067 sigaddset(&
set, SIGTERM);
1068 ASSERT(0 == pthread_sigmask(SIG_UNBLOCK, &
set, NULL));
1095 TEST_IMPL(spawn_detect_pipe_name_collisions_on_windows) {
1114 "\\\\.\\pipe\\uv\\%p-%d",
1116 GetCurrentProcessId());
1118 PIPE_ACCESS_INBOUND | FILE_FLAG_OVERLAPPED,
1119 PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1146 #if !defined(USING_UV_SHARED)
1161 L"c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\""
1164 WCHAR** test_output;
1165 WCHAR* command_line;
1167 size_t total_size = 0;
1172 char* verbatim[] = {
1175 "c:\\path\\to\\node.exe --eval \"require('c:\\\\path\\\\to\\\\test.js')\"",
1178 WCHAR* verbatim_output;
1179 WCHAR* non_verbatim_output;
1181 test_output = calloc(
count,
sizeof(WCHAR*));
1182 ASSERT(test_output != NULL);
1184 test_output[
i] = calloc(2 * (wcslen(
test_str[
i]) + 2),
sizeof(WCHAR));
1187 wprintf(
L"output: %s\n", test_output[
i]);
1188 total_size += wcslen(test_output[
i]) + 1;
1190 command_line = calloc(total_size + 1,
sizeof(WCHAR));
1191 ASSERT(command_line != NULL);
1193 wcscat(command_line, test_output[
i]);
1194 wcscat(command_line,
L" ");
1196 command_line[total_size - 1] =
L'\0';
1198 wprintf(
L"command_line: %s\n", command_line);
1200 cracked = CommandLineToArgvW(command_line, &num_args);
1201 for (
i = 0;
i < num_args; ++
i) {
1208 free(test_output[
i]);
1217 wprintf(
L" verbatim_output: %s\n", verbatim_output);
1218 wprintf(
L"non_verbatim_output: %s\n", non_verbatim_output);
1220 ASSERT(wcscmp(verbatim_output,
1221 L"cmd.exe /c c:\\path\\to\\node.exe --eval "
1222 L"\"require('c:\\\\path\\\\to\\\\test.js')\"") == 0);
1223 ASSERT(wcscmp(non_verbatim_output,
1224 L"cmd.exe /c \"c:\\path\\to\\node.exe --eval "
1225 L"\\\"require('c:\\\\path\\\\to\\\\test.js')\\\"\"") == 0);
1227 free(verbatim_output);
1228 free(non_verbatim_output);
1237 char* environment[] = {
1245 "B\xe2\x82\xacZ=QUX",
1246 "B\xf0\x90\x80\x82Z=QUX",
1247 "B\xef\xbd\xa1Z=QUX",
1248 "B\xf0\xa3\x91\x96Z=QUX",
1252 WCHAR* wenvironment[] = {
1256 L"B\xd800\xdc02Z=QUX",
1257 L"B\xd84d\xdc56Z=QUX",
1261 L"SYSTEMROOTED=OMG",
1264 WCHAR* from_env[] = {
1279 L"ZTHIS_ENV_VARIABLE_DOES_NOT_EXIST",
1281 int found_in_loc_env[
ARRAY_SIZE(wenvironment)] = {0};
1282 int found_in_usr_env[
ARRAY_SIZE(from_env)] = {0};
1291 size_t len = GetEnvironmentVariableW(from_env[
i], NULL, 0);
1293 found_in_usr_env[
i] = 1;
1294 str = malloc(1 *
sizeof(WCHAR));
1298 size_t name_len = wcslen(from_env[
i]);
1299 str = malloc((name_len+1+
len) *
sizeof(WCHAR));
1300 wmemcpy(
str, from_env[
i], name_len);
1304 GetEnvironmentVariableW(from_env[
i],
str,
len);
1318 if (!wcscmp(
str, wenvironment[
i])) {
1320 found_in_loc_env[
i] = 1;
1325 if (!wcscmp(
str, expected[
i])) {
1327 found_in_usr_env[
i] = 1;
1332 #if _WIN32_WINNT >= 0x0600 && \
1333 (!defined(__MINGW32__) || defined(__MINGW64_VERSION_MAJOR))
1359 snprintf(newpath, 2048,
";.;%s",
path);
1360 SetEnvironmentVariable(
"PATH", newpath);
1365 ASSERT(
r == UV_ENOENT ||
r == UV_EACCES);
1391 pw = getpwnam(
"nobody");
1395 snprintf(uidstr,
sizeof(uidstr),
"%d", pw->pw_uid);
1396 snprintf(gidstr,
sizeof(gidstr),
"%d", pw->pw_gid);
1403 RETURN_SKIP(
"user 'nobody' cannot access the test runner");
1429 pw = getpwnam(
"nobody");
1431 ASSERT(0 == setgid(pw->pw_gid));
1432 ASSERT(0 == setuid(pw->pw_uid));
1442 #if defined(__PASE__)
1455 #if defined(__CYGWIN__) || defined(__PASE__)
1480 pw = getpwnam(
"nobody");
1482 ASSERT(0 == setgid(pw->pw_gid));
1483 ASSERT(0 == setuid(pw->pw_uid));
1493 #if defined(__MVS__) || defined(__PASE__)
1500 #if defined(__CYGWIN__) || defined(__MVS__) || defined(__PASE__)
1522 ASSERT(0 &&
"should not have been called");
1690 #if defined(__APPLE__)
1691 static const char dyld_path_var[] =
"DYLD_LIBRARY_PATH";
1692 #elif defined __MVS__
1693 static const char dyld_path_var[] =
"LIBPATH";
1695 static const char dyld_path_var[] =
"LD_LIBRARY_PATH";
1708 strcpy(
path,
"PATH=");
1710 #if defined(__CYGWIN__) || defined(__MSYS__)
1714 char* syspath =
getenv(
"PATH");
1715 if (syspath != NULL) {
1717 strcat(
path, syspath);
1726 if (
env[1] != NULL) {
1727 static char buf[1024 +
sizeof(dyld_path_var)];
1728 snprintf(
buf,
sizeof(
buf),
"%s=%s", dyld_path_var,
env[1]);
1751 if (pipe(fds) == -1)
1753 if (fcntl(fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
1754 fcntl(fds[1], F_SETFD, FD_CLOEXEC) == -1) {
1762 static int mpipe(
int *fds) {
1763 SECURITY_ATTRIBUTES
attr;
1764 HANDLE readh, writeh;
1766 attr.lpSecurityDescriptor = NULL;
1768 if (!CreatePipe(&readh, &writeh, &
attr, 0))
1770 fds[0] = _open_osfhandle((
intptr_t)readh, 0);
1771 fds[1] = _open_osfhandle((
intptr_t)writeh, 0);
1772 if (fds[0] == -1 || fds[1] == -1) {
1774 CloseHandle(writeh);
1838 for (
i = 0;
i <
sizeof ubuf; ++
i)
1858 r = memcmp(ubuf,
output,
sizeof ubuf);
1869 char* quoted_path_env[2];
1870 args[0] =
"not_existing";
1878 quoted_path_env[0] =
"PATH=\"xyz:\\test;\";xyz:\\other";
1879 quoted_path_env[1] = NULL;
1899 }
while (
r == -1 && errno == EINTR);
1908 w =
write(1, pbuf, (
size_t)
c);
1909 }
while (w == -1 && errno == EINTR);
1920 HANDLE h_stdin = GetStdHandle(STD_INPUT_HANDLE);
1921 HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
1929 ASSERT(GetLastError() == ERROR_BROKEN_PIPE);
1935 ASSERT(WriteFile(h_stdout, pbuf, to_write, &n_written, NULL));
1936 to_write -= n_written;
static void timer_cb(uv_timer_t *handle)
static char output[OUTPUT_SIZE]
static void timer_counter_cb(uv_timer_t *handle)
int make_program_args(char **args, int verbatim_arguments, WCHAR **dst_ptr)
#define ARRAY_SIZE(array)
UV_EXTERN int uv_fs_open(uv_loop_t *loop, uv_fs_t *req, const char *path, int flags, int mode, uv_fs_cb cb)
static void on_read_once(uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
static void on_alloc(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
return memset(p, 0, total)
const grpc_generator::File * file
static void close_cb(uv_handle_t *handle)
UV_EXTERN int uv_pipe_init(uv_loop_t *, uv_pipe_t *handle, int ipc)
static void kill_cb(uv_process_t *process, int64_t exit_status, int term_signal)
def ReadFile(filename, print_error=True)
UV_EXTERN int uv_kill(int pid, int signum)
UV_EXTERN int uv_listen(uv_stream_t *stream, int backlog, uv_connection_cb cb)
_Use_decl_annotations_ int __cdecl printf(const char *_Format,...)
static char exepath[1024]
static void init_process_options(char *test, uv_exit_cb exit_cb)
OPENSSL_EXPORT pem_password_cb void * u
static int no_term_signal
static void exit_cb(uv_process_t *process, int64_t exit_status, int term_signal)
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
UV_EXTERN int uv_is_closing(const uv_handle_t *handle)
static uv_process_t process
UV_EXTERN void uv_unref(uv_handle_t *)
UV_EXTERN int uv_tcp_bind(uv_tcp_t *handle, const struct sockaddr *addr, unsigned int flags)
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
static int mpipe(int *fds)
static int close_cb_called
UV_EXTERN int uv_tcp_open(uv_tcp_t *handle, uv_os_sock_t sock)
UV_EXTERN int uv_ip4_addr(const char *ip, int port, struct sockaddr_in *addr)
UV_EXTERN uv_loop_t * uv_default_loop(void)
uv_stdio_container_t * stdio
static void signal(notification *n)
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
UV_EXTERN int uv_is_readable(const uv_stream_t *handle)
UV_EXTERN int uv_is_active(const uv_handle_t *handle)
UV_EXTERN int uv_read_start(uv_stream_t *, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
UV_EXTERN int uv_tcp_init(uv_loop_t *, uv_tcp_t *handle)
void(* uv_exit_cb)(uv_process_t *, int64_t exit_status, int term_signal)
void spawn_stdin_stdout(void)
static uv_process_options_t options
UV_EXTERN int uv_fs_close(uv_loop_t *loop, uv_fs_t *req, uv_file file, uv_fs_cb cb)
UV_EXTERN int uv_spawn(uv_loop_t *loop, uv_process_t *handle, const uv_process_options_t *options)
UV_EXTERN int uv_exepath(char *buffer, size_t *size)
int spawn_tcp_server_helper(void)
UV_EXTERN int uv_fs_read(uv_loop_t *loop, uv_fs_t *req, uv_file file, const uv_buf_t bufs[], unsigned int nbufs, int64_t offset, uv_fs_cb cb)
static size_t exepath_size
#define MAKE_VALGRIND_HAPPY()
@ UV_PROCESS_WINDOWS_HIDE
UV_EXTERN int uv_tcp_init_ex(uv_loop_t *, uv_tcp_t *handle, unsigned int flags)
OPENSSL_EXPORT X509_ATTRIBUTE * attr
int read(izstream &zs, T *x, Items items)
UV_EXTERN int uv_fileno(const uv_handle_t *handle, uv_os_fd_t *fd)
static uv_tcp_t tcp_server
static void detach_failure_cb(uv_process_t *process, int64_t exit_status, int term_signal)
@ UV_PROCESS_WINDOWS_HIDE_GUI
static uv_pipe_t pipe_handle
static int exit_cb_called
#define INVALID_HANDLE_VALUE
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
UV_EXTERN void uv_fs_req_cleanup(uv_fs_t *req)
#define RETURN_SKIP(explanation)
union uv_stdio_container_s::@399 data
@ UV_PROCESS_WINDOWS_VERBATIM_ARGUMENTS
static void write_cb(uv_write_t *req, int status)
UV_EXTERN int uv_timer_start(uv_timer_t *handle, uv_timer_cb cb, uint64_t timeout, uint64_t repeat)
UV_EXTERN int uv_timer_init(uv_loop_t *, uv_timer_t *handle)
UV_EXTERN int uv_is_writable(const uv_stream_t *handle)
static void fail_cb(uv_process_t *process, int64_t exit_status, int term_signal)
@ UV_PROCESS_WINDOWS_HIDE_CONSOLE
UV_EXTERN int uv_process_kill(uv_process_t *, int signum)
WCHAR * quote_cmd_arg(const WCHAR *source, WCHAR *target)
UV_EXTERN int uv_read_stop(uv_stream_t *)
UV_EXTERN int uv_pipe_open(uv_pipe_t *, uv_file file)
int make_program_env(char *env_block[], WCHAR **dst_ptr)
static void on_read(uv_stream_t *tcp, ssize_t nread, const uv_buf_t *buf)
UV_EXTERN uv_pid_t uv_process_get_pid(const uv_process_t *)
grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:01:30