FreeBSD Bugzilla – Attachment 153164 Details for
Bug 197695
Fix broken KERN_PROC_FILEDESC sysctl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
test case
bug_197695.c (text/x-csrc), 1.95 KB, created by
Niall Douglas
on 2015-02-19 04:57:48 UTC
(
hide
)
Description:
test case
Filename:
MIME Type:
Creator:
Niall Douglas
Created:
2015-02-19 04:57:48 UTC
Size:
1.95 KB
patch
obsolete
>#include <stdio.h> >#include <stdlib.h> >#include <string.h> >#include <unistd.h> >#include <fcntl.h> >#include <sys/types.h> >#include <sys/sysctl.h> >#include <sys/user.h> >#include <sys/stat.h> > >static void print_fd_table() >{ > size_t len; > int mib[4]={CTL_KERN, KERN_PROC, KERN_PROC_FILEDESC, getpid()}; > sysctl(mib, 4, NULL, &len, NULL, 0); > len*=2; > char *buffer=(char *) calloc(1, len); > sysctl(mib, 4, buffer, &len, NULL, 0); > for(char *p=buffer; p<buffer+len;) > { > struct kinfo_file *kif=(struct kinfo_file *) p; > printf("%d %d %s\n", kif->kf_type, kif->kf_fd, kif->kf_path); > p+=kif->kf_structsize; > } > free(buffer); >} > >int main(void) >{ > const char buf[]="Niall"; > char cwd[PATH_MAX], path[PATH_MAX], path2[PATH_MAX]; > int h[4]; > getcwd(cwd, sizeof(cwd)); > for(size_t n=0; n<sizeof(h)/sizeof(h[0]); n++) > { > if(n&1) > { > sprintf(path, "dir%zu", n); > mkdir(path, 0x1f8); > h[n]=open(path, O_RDONLY); > } > else > { > sprintf(path, "file%zu", n); > // Handles which create don't get a path :( > h[n]=open(path, O_CREAT|O_RDWR, 0x1b0); > close(h[n]); > h[n]=open(path, O_RDONLY); > } > } > printf("\nfd table after file opens:\n"); > print_fd_table(); > for(size_t n=0; n<sizeof(h)/sizeof(h[0]); n++) > { > if(n&1) > sprintf(path, "dir%zu", n); > else > sprintf(path, "file%zu", n); > sprintf(path2, "boo%zu", n); > if(-1==rename(path, path2)) abort(); > printf("\nfd table after file rename of fd %d (none should be null!):\n", h[n]); > print_fd_table(); > } > for(size_t n=0; n<sizeof(h)/sizeof(h[0]); n++) > { > sprintf(path, "boo%zu", n); > if(n&1) > { > if(-1==rmdir(path)) abort(); > } > else > { > if(-1==unlink(path)) abort(); > } > printf("\nfd table after file unlink of fd %d:\n", h[n]); > print_fd_table(); > } > for(size_t n=0; n<sizeof(h)/sizeof(h[0]); n++) > { > close(h[n]); > printf("\nfd table after file close:\n"); > print_fd_table(); > } > 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 197695
: 153164 |
153165