1
0
forked from cory/tildefriends
Files
apps
core
deps
codemirror
codemirror_src
crypt_blowfish
libbacktrace
libbacktrace_config
libsodium
libuv
.github
cmake-toolchains
docs
img
include
m4
src
test
fixtures
benchmark-async-pummel.c
benchmark-async.c
benchmark-fs-stat.c
benchmark-getaddrinfo.c
benchmark-list.h
benchmark-loop-count.c
benchmark-million-async.c
benchmark-million-timers.c
benchmark-multi-accept.c
benchmark-ping-pongs.c
benchmark-ping-udp.c
benchmark-pound.c
benchmark-pump.c
benchmark-queue-work.c
benchmark-sizes.c
benchmark-spawn.c
benchmark-tcp-write-batch.c
benchmark-thread.c
benchmark-udp-pummel.c
blackhole-server.c
echo-server.c
run-benchmarks.c
run-tests.c
runner-unix.c
runner-unix.h
runner-win.c
runner-win.h
runner.c
runner.h
task.h
test-active.c
test-async-null-cb.c
test-async.c
test-barrier.c
test-callback-stack.c
test-close-fd.c
test-close-order.c
test-condvar.c
test-connect-unspecified.c
test-connection-fail.c
test-cwd-and-chdir.c
test-default-loop-close.c
test-delayed-accept.c
test-dlerror.c
test-eintr-handling.c
test-embed.c
test-emfile.c
test-env-vars.c
test-error.c
test-fail-always.c
test-fork.c
test-fs-copyfile.c
test-fs-event.c
test-fs-fd-hash.c
test-fs-open-flags.c
test-fs-poll.c
test-fs-readdir.c
test-fs.c
test-get-currentexe.c
test-get-loadavg.c
test-get-memory.c
test-get-passwd.c
test-getaddrinfo.c
test-gethostname.c
test-getnameinfo.c
test-getsockname.c
test-getters-setters.c
test-gettimeofday.c
test-handle-fileno.c
test-homedir.c
test-hrtime.c
test-idle.c
test-idna.c
test-ip-name.c
test-ip4-addr.c
test-ip6-addr.c
test-ipc-heavy-traffic-deadlock-bug.c
test-ipc-send-recv.c
test-ipc.c
test-list.h
test-loop-alive.c
test-loop-close.c
test-loop-configure.c
test-loop-handles.c
test-loop-stop.c
test-loop-time.c
test-metrics.c
test-multiple-listen.c
test-mutexes.c
test-not-readable-nor-writable-on-read-error.c
test-not-writable-after-shutdown.c
test-osx-select.c
test-pass-always.c
test-ping-pong.c
test-pipe-bind-error.c
test-pipe-close-stdout-read-stdin.c
test-pipe-connect-error.c
test-pipe-connect-multiple.c
test-pipe-connect-prepare.c
test-pipe-getsockname.c
test-pipe-pending-instances.c
test-pipe-sendmsg.c
test-pipe-server-close.c
test-pipe-set-fchmod.c
test-pipe-set-non-blocking.c
test-platform-output.c
test-poll-close-doesnt-corrupt-stack.c
test-poll-close.c
test-poll-closesocket.c
test-poll-multiple-handles.c
test-poll-oob.c
test-poll.c
test-process-priority.c
test-process-title-threadsafe.c
test-process-title.c
test-queue-foreach-delete.c
test-random.c
test-readable-on-eof.c
test-ref.c
test-run-nowait.c
test-run-once.c
test-semaphore.c
test-shutdown-close.c
test-shutdown-eof.c
test-shutdown-simultaneous.c
test-shutdown-twice.c
test-signal-multiple-loops.c
test-signal-pending-on-close.c
test-signal.c
test-socket-buffer-size.c
test-spawn.c
test-stdio-over-pipes.c
test-strscpy.c
test-strtok.c
test-tcp-alloc-cb-fail.c
test-tcp-bind-error.c
test-tcp-bind6-error.c
test-tcp-close-accept.c
test-tcp-close-after-read-timeout.c
test-tcp-close-reset.c
test-tcp-close-while-connecting.c
test-tcp-close.c
test-tcp-connect-error-after-write.c
test-tcp-connect-error.c
test-tcp-connect-timeout.c
test-tcp-connect6-error.c
test-tcp-create-socket-early.c
test-tcp-flags.c
test-tcp-oob.c
test-tcp-open.c
test-tcp-read-stop-start.c
test-tcp-read-stop.c
test-tcp-rst.c
test-tcp-shutdown-after-write.c
test-tcp-try-write-error.c
test-tcp-try-write.c
test-tcp-unexpected-read.c
test-tcp-write-after-connect.c
test-tcp-write-fail.c
test-tcp-write-in-a-row.c
test-tcp-write-queue-order.c
test-tcp-write-to-half-open-connection.c
test-tcp-writealot.c
test-test-macros.c
test-thread-affinity.c
test-thread-equal.c
test-thread-priority.c
test-thread.c
test-threadpool-cancel.c
test-threadpool.c
test-timer-again.c
test-timer-from-check.c
test-timer.c
test-tmpdir.c
test-tty-duplicate-key.c
test-tty-escape-sequence-processing.c
test-tty.c
test-udp-alloc-cb-fail.c
test-udp-bind.c
test-udp-connect.c
test-udp-connect6.c
test-udp-create-socket-early.c
test-udp-dgram-too-big.c
test-udp-ipv6.c
test-udp-mmsg.c
test-udp-multicast-interface.c
test-udp-multicast-interface6.c
test-udp-multicast-join.c
test-udp-multicast-join6.c
test-udp-multicast-ttl.c
test-udp-open.c
test-udp-options.c
test-udp-recv-in-a-row.c
test-udp-send-and-recv.c
test-udp-send-hang-loop.c
test-udp-send-immediate.c
test-udp-send-unreachable.c
test-udp-sendmmsg-error.c
test-udp-try-send.c
test-uname.c
test-walk-handles.c
test-watcher-cross-stop.c
tools
.gitattributes
.gitignore
.mailmap
.readthedocs.yaml
AUTHORS
CMakeLists.txt
CONTRIBUTING.md
ChangeLog
LICENSE
LICENSE-docs
LICENSE-extra
LINKS.md
MAINTAINERS.md
Makefile.am
README.md
SECURITY.md
SUPPORTED_PLATFORMS.md
autogen.sh
configure.ac
libuv-static.pc.in
libuv.pc.in
tsansupp.txt
uv_win_longpath.manifest
lit
picohttpparser
prettier
quickjs
speedscope
sqlite
zlib
docs
src
tools
.clang-format
.dockerignore
.git-blame-ignore-revs
.gitignore
.gitmodules
.prettierignore
.prettierrc.yaml
CONTRIBUTING.md
Dockerfile
Doxyfile
GNUmakefile
LICENSE
README.md
package-lock.json
package.json
tildefriends/deps/libuv/test/test-pipe-close-stdout-read-stdin.c

123 lines
3.3 KiB
C
Raw Normal View History

/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
#ifndef _WIN32
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>
#include <sys/types.h>
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#include "uv.h"
#include "task.h"
void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t* buf)
{
static char buffer[1024];
buf->base = buffer;
buf->len = sizeof(buffer);
}
void read_stdin(uv_stream_t *stream, ssize_t nread, const uv_buf_t* buf)
{
if (nread < 0) {
uv_close((uv_handle_t*)stream, NULL);
return;
}
}
/*
* This test is a reproduction of joyent/libuv#1419 .
*/
TEST_IMPL(pipe_close_stdout_read_stdin) {
int r = -1;
int pid;
int fd[2];
int status;
char buf;
uv_pipe_t stdin_pipe;
r = pipe(fd);
ASSERT_OK(r);
#if defined(__APPLE__) && (TARGET_OS_TV || TARGET_OS_WATCH)
pid = -1;
#else
pid = fork();
#endif
if (pid == 0) {
/*
* Make the read side of the pipe our stdin.
* The write side will be closed by the parent process.
*/
close(fd[1]);
/* block until write end of pipe is closed */
r = read(fd[0], &buf, 1);
ASSERT(-1 <= r && r <= 1);
close(0);
r = dup(fd[0]);
ASSERT_NE(r, -1);
/* Create a stream that reads from the pipe. */
r = uv_pipe_init(uv_default_loop(), (uv_pipe_t *)&stdin_pipe, 0);
ASSERT_OK(r);
r = uv_pipe_open((uv_pipe_t *)&stdin_pipe, 0);
ASSERT_OK(r);
r = uv_read_start((uv_stream_t *)&stdin_pipe, alloc_buffer, read_stdin);
ASSERT_OK(r);
/*
* Because the other end of the pipe was closed, there should
* be no event left to process after one run of the event loop.
* Otherwise, it means that events were not processed correctly.
*/
ASSERT_OK(uv_run(uv_default_loop(), UV_RUN_NOWAIT));
} else {
/*
* Close both ends of the pipe so that the child
* get a POLLHUP event when it tries to read from
* the other end.
*/
close(fd[1]);
close(fd[0]);
waitpid(pid, &status, 0);
ASSERT(WIFEXITED(status) && WEXITSTATUS(status) == 0);
}
MAKE_VALGRIND_HAPPY(uv_default_loop());
return 0;
}
#else
typedef int file_has_no_tests; /* ISO C forbids an empty translation unit. */
#endif /* ifndef _WIN32 */