On Mon, Oct 19, 2020 at 9:23 PM Renato Maia <maia.ren...@gmail.com> wrote:
> The attached code illustrates the behavior. The output is:

Sorry, I forgot to attach the file. Here it is.

-- 
Renato Maia

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to libuv+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/libuv/CAB-PuDrb953b9XFYVdrOQ2XQUBOBdPBHJMUCsi5GL0KT3j7K5w%40mail.gmail.com.
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <uv.h>

#define NFD 3
#define CMD "echo \"Hello, world!\""

static uv_loop_t uvloop;

int main(int argc, char const *argv[])
{
	int err, i;
	uv_tty_t tty[NFD];

	printf("libuv %s\n", uv_version_string());

	err = uv_loop_init(&uvloop);
	assert(err >= 0);

	for (i = 0; i < NFD; ++i) {
		err = uv_tty_init(&uvloop, tty+i, i, 0);
		assert(err >= 0);
		printf("%s:%d: uv_tty_init(loop, tty, %d, 0)\n", __FILE__, __LINE__, i);
	}

	err = system(CMD);
	if (err != 0 && errno != 0) 
		printf("%s:%d: system('"CMD"') = %s\n", __FILE__, __LINE__, strerror(errno));
	else if (WIFEXITED(err))
		printf("%s:%d: system('"CMD"') = exit(%d)\n", __FILE__, __LINE__, WEXITSTATUS(err));
	else if (WIFSIGNALED(err))
		printf("%s:%d: system('"CMD"') = signal(%d)\n", __FILE__, __LINE__, WTERMSIG(err));

	for (i = 0; i < NFD; ++i) {
		uv_close((uv_handle_t *)(tty+i), NULL);
		printf("%s:%d: uv_close(tty) /* fd=%d */\n", __FILE__, __LINE__, i);
	}

	err = uv_run(&uvloop, UV_RUN_DEFAULT);
	assert(err >= 0);

	err = uv_loop_close(&uvloop);
	assert(err >= 0);

	return 0;
}

Reply via email to