The Samba-Bugzilla – Attachment 1216 Details for
Bug 2697
CIFS driver oopses when multiple machines attempt to lock file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
This is sample program,
cifscrash.cpp (text/plain), 1.83 KB, created by
Ilya A. Volynets
on 2005-05-10 15:11:44 UTC
(
hide
)
Description:
This is sample program,
Filename:
MIME Type:
Creator:
Ilya A. Volynets
Created:
2005-05-10 15:11:44 UTC
Size:
1.83 KB
patch
obsolete
>#include <iostream> >#include <fcntl.h> >#include <sys/types.h> >#include <dirent.h> >#include <stdio.h> >#include <sys/file.h> > >int try_lock(const char* path,const char* name) >{ > struct flock fl; > fl.l_type=F_RDLCK; > fl.l_whence=SEEK_SET; > fl.l_start=0; > fl.l_len=1; > std::string p(path); > p+=name; > int fd=open(p.c_str(),O_RDONLY); > if(fd<0) { > std::cerr<<"Error opening file: "<<p<<": "<<strerror(errno)<<std::endl; > return -1; > } > //if(fcntl(fd,F_SETLK,&fl)<0){ > if(flock(fd,LOCK_EX|LOCK_NB)<0){ > std::cerr<<"Error locking file: "<<p<<": "<<strerror(errno)<<std::endl; > close(fd); > return -1; > } > return fd; >} >void unlock(int fd) >{ > struct flock fl; > fl.l_type=F_UNLCK; > fl.l_whence=SEEK_SET; > fl.l_start=0; > fl.l_len=1; > //fcntl(fd,F_SETLK,&fl); > flock(fd,LOCK_UN); > close(fd); >} > >int main(int arg, char** argv) >{ > const char *path=argv[1]; > char name[20]; > while(true) > { > std::cout<<"Openning dir "<<path<<std::endl; > DIR* d=opendir(path); > if(!d) > std::cout<<"Error openning "<<path<<": "<<strerror(errno)<<std::endl; > else > std::cout<<"Open dir "<<path<<"\n"; > struct dirent *de; > while(true){ > de=readdir(d); > if(!de){ > //std::cout<<"Error reading "<<path<<": "<<strerror(errno)<<std::endl; > break; > } else { > std::cout<<"Got dentry: "<<de->d_name<<std::endl; > } > if(de->d_name[0]=='.') > continue; > strcpy(name,de->d_name); > int fd=try_lock(path,name); > if(fd>=0){ > std::cout<<"Locked "<<path<<name<<std::endl; > if(strlen(de->d_name)>=sizeof(name)-1) > strcpy(name,"1"); > else > strncat(name,"1",sizeof(name)-1); > if(rename(de->d_name,name)<0) > std::cout<<"Error renaming: "<<strerror(errno)<<std::endl; > unlock(fd); > } else { > std::cout<<"Couldn't lock "<<path<<name<<std::endl; > } > } > closedir(d); > } > 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 2697
: 1216