FreeBSD Bugzilla – Attachment 52757 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]
pr79887.c
pr79887.c (text/x-csrc; charset=us-ascii), 1.50 KB, created by
Vasil Dimov
on 2010-12-07 07:42:02 UTC
(
hide
)
Description:
pr79887.c
Filename:
MIME Type:
Creator:
Vasil Dimov
Created:
2010-12-07 07:42:02 UTC
Size:
1.50 KB
patch
obsolete
>#include <sys/types.h> >#include <sys/uio.h> > >#include <errno.h> >#include <fcntl.h> >#include <pthread.h> >#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> > >FILE* l; > >void* >openmany(void* p) >{ > int fds[1500]; > unsigned long long i, j; > char filename[100]; > > for (i = 0; ; i++) { > for (j = 0; j < 1500; j++) { > > snprintf(filename, sizeof(filename), > "/tmp/ib%04llu", j); > fds[j] = open(filename, O_RDWR | O_CREAT, 0644); > fprintf(l, "open(): %s: %d\n", filename, fds[j]); > if (fds[j] == -1) { > fprintf(l, "open(): %s: %s\n", filename, > strerror(errno)); > exit(1); > } > write(fds[j], "ABCABCABC", 9); > } > > for (j = 0; j < 1500; j++) { > int ret; > > ret = close(fds[j]); > > fprintf(l, "close(): %d: %d\n", fds[j], ret); > > if (ret == -1) { > fprintf(l, "error: close(%d): %s\n", fds[j], > strerror(errno)); > exit(1); > } > } > } >} > >void* >reopenstd(void* p) >{ > unsigned long long i; > > for (i = 0; ; i++) { > freopen("/tmp/std_redirected", "a+", stdout); > freopen("/tmp/std_redirected", "a+", stderr); > printf("XXXXXXXXXXX %llu\n", i); > } > > return(NULL); >} > >int >main(int argc, char **argv, char **envp) >{ > pthread_t t1; > pthread_t t2; > void* ret; > > l = fopen("/tmp/log", "w"); > if (l == NULL) { > fprintf(stderr, "error: fopen(): /tmp/log: %s\n", > strerror(errno)); > exit(1); > } > > pthread_create(&t1, NULL, reopenstd, NULL); > pthread_create(&t2, NULL, openmany, NULL); > > pthread_join(t1, &ret); > pthread_join(t2, &ret); > > fclose(l); > > 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