j***g 发帖数: 19 | 1 1 int
2 delete_range(filename,id1,id2)
3 char *filename ;
4 int id1,id2 ;
5 {
6 struct fileheader fhdr;
7 char tmpfile[ STRLEN ], deleted[ STRLEN ];
8 int fdr, fdw, fd;
9 int count;
10
11 tmpfilename( filename, tmpfile, deleted );
12 if((fd = open(".dellock",O_RDWR|O_CREAT|O_APPEND, 0644)) == -1)
13 return -1;
14 flock(fd,LOCK_EX);
15
16 if((fdr | j***g 发帖数: 19 | 2
get two file names: deleted=".deleted" | "xxx/.deleted"
tmpfile=".tmpfile" | "xxx/.tmpfile"
if ".dellock" cannot be created, return
what if ".dellock" already existed?
Lock ".dellock" QUESTION: can we guarantee ".dellock" to be locked?
why not check the return value? such as
if (flock(fd,LOCK_EX)==-1) return -1;
If that board is readonly, unlock ".dellock" and return.
create tmpfile ".tmpfile"
【在 j***g 的大作中提到】 : 1 int : 2 delete_range(filename,id1,id2) : 3 char *filename ; : 4 int id1,id2 ; : 5 { : 6 struct fileheader fhdr; : 7 char tmpfile[ STRLEN ], deleted[ STRLEN ]; : 8 int fdr, fdw, fd; : 9 int count; : 10
| j***g 发帖数: 19 | 3 是不是象这样的长操作应该交给一个demean去做呢?否则你中断telnet,
操作就中断了,然后目录没有更新过来(两个rename干的活)
就是说作成client/server的模式,登陆近来的用户向BBS demean提出请求
【在 j***g 的大作中提到】 : : get two file names: deleted=".deleted" | "xxx/.deleted" : tmpfile=".tmpfile" | "xxx/.tmpfile" : if ".dellock" cannot be created, return : what if ".dellock" already existed? : Lock ".dellock" QUESTION: can we guarantee ".dellock" to be locked? : why not check the return value? such as : if (flock(fd,LOCK_EX)==-1) return -1; : If that board is readonly, unlock ".dellock" and return. : create tmpfile ".tmpfile"
| j***g 发帖数: 19 | 4
或者是在telnetd的cleanup中加个判断(???I am not sure)
在delete_range中设一个标志,然后在telnetd中判断:
如果该标志存在,就等待(等删除结束);否则就继续
【在 j***g 的大作中提到】 : 是不是象这样的长操作应该交给一个demean去做呢?否则你中断telnet, : 操作就中断了,然后目录没有更新过来(两个rename干的活) : 就是说作成client/server的模式,登陆近来的用户向BBS demean提出请求
|
|