FreeBSD Bugzilla – Attachment 171448 Details for
Bug 210288
File descriptors created by pipe are both read/write
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test program demonstrating the issue
pipedream.c (text/plain), 1.46 KB, created by
kwilliams@qnx.com
on 2016-06-14 22:07:12 UTC
(
hide
)
Description:
test program demonstrating the issue
Filename:
MIME Type:
Creator:
kwilliams@qnx.com
Created:
2016-06-14 22:07:12 UTC
Size:
1.46 KB
patch
obsolete
>/* > ============================================================================ > Name : pipedream.c > Author : > Version : > Copyright : Your copyright notice > Description : Hello World in C, Ansi-style > ============================================================================ > */ > >#include <stdio.h> >#include <stdlib.h> >#include <fcntl.h> >#include <unistd.h> > >int filedes[2]; >#define BSIZE 100 >const int bsz = BSIZE; >char b[BSIZE]; >size_t nbytes; > >int main(void) { > puts("!!!Hello World!!!"); /* prints !!!Hello World!!! */ > if (pipe(filedes) == -1) { > printf("Crap pipe failed\n"); > return EXIT_FAILURE; > } > > switch(fork()) { > case -1: > printf("Crap fork failed\n"); > return EXIT_FAILURE; > break; > case 0: > // child > nbytes = read(filedes[0], b, bsz); > if (nbytes < 0) > printf("Child read failed\n"); > else > printf("Child read OK\n"); > nbytes = write(filedes[0], b, bsz); > if (nbytes < 0) > printf("Child write failed\n"); > else > printf("Child write OK fd %d\n", filedes[0]); > close(filedes[0]); > close(filedes[1]); // deliberately do this late > break; > default: > // parent > close(filedes[0]); > nbytes = write(filedes[1], b, bsz); > if (nbytes < 0) > printf("parent write failed\n"); > else > printf("parent write OK fd %d\n", filedes[1]); > nbytes = read(filedes[1], b, bsz); > if (nbytes < 0) > printf("parent read failed\n"); > else > printf("parent read OK\n"); > close(filedes[0]); > close(filedes[1]); > break; > } > return EXIT_SUCCESS; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 210288
: 171448