FreeBSD Bugzilla – Attachment 52758 Details for
Bug 79887
[patch] freopen() isn't thread-safe
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
dup2.c
dup2.c (text/x-csrc; charset=us-ascii), 1.21 KB, created by
Vasil Dimov
on 2010-12-07 09:52:00 UTC
(
hide
)
Description:
dup2.c
Filename:
MIME Type:
Creator:
Vasil Dimov
Created:
2010-12-07 09:52:00 UTC
Size:
1.21 KB
patch
obsolete
>#include <sys/types.h> >#include <sys/uio.h> > >#include <fcntl.h> >#include <stdio.h> >#include <unistd.h> > >int >main(int argc, char **argv) >{ > int fd1; > int fd1_orig; > int fd_other; > int ret; > > fd1 = open("/tmp/f1", O_RDWR | O_CREAT, 0644); > printf("open(): /tmp/f1: %d\n", fd1); > > printf("trx1: freopen() begins, will associate fd=%d with /tmp/f2\n", > fd1); > > fd1_orig = fd1; > > fd1 = open("/tmp/f2", O_RDWR | O_CREAT, 0644); > printf("trx1: freopen(): open(): /tmp/f2: %d\n", fd1); > > ret = close(fd1_orig); > printf("trx1: freopen(): close(): %d: %d\n", fd1_orig, ret); > > /* another thread executes in the meantime, opening some file */ > fd_other = open("/tmp/f_other", O_RDWR | O_CREAT, 0644); > printf("trx2: open(): /tmp/f_other: %d\n", fd_other); > /* end of another thread, freopen() continues */ > > ret = dup2(fd1, fd1_orig); > printf("trx1: freopen(): dup2(): %d,%d: %d\n", fd1, fd1_orig, ret); > fd1 = fd1_orig; > > printf("trx1: freopen(): end, now fd=%d is associated with /tmp/f2\n", > fd1); > > printf("trx1: write to fd=%d (supposed to be /tmp/f2)\n", fd1); > write(fd1, "ABC", 3); > > printf("trx2: write to fd=%d (supposed to be /tmp/f_other)\n", fd_other); > write(fd_other, "XYZ", 3); > > close(fd1); > close(fd_other); > > return(0); >}
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 79887
:
52756
|
52757
| 52758