Prev: FAQ 7.4 How do I skip some return values?
Next: Does this match any number or just single digit ones?
From: Marc Girod on 6 Aug 2010 13:06 Hello, A script saves mails sent by a crontab--so, there may be bursts... It uses sysopen, I assume to make sure it doesn't overwrite existing files. At times, we get bursts of errors (File exists), which I trace to the sysopen call. However, I cannot find that all the corresponding files would have existed. I read the doc and get to: In many systems the "O_EXCL" flag is available for opening files in exclusive mode. This is not locking: exclusiveness means here that if the file already exists, sysopen() fails. "O_EXCL" may not work on network filesystems, and has no effect unless the "O_CREAT" flag is set as well. The script does write to a network filesystems (home directory on a remote filer, 4 ms round-trip). Shoud I look for a replacement for sysopen? Or for an other theory to explain the problem? The bit of code doing the open: if(defined($mode)? sysopen(FILE, $file, O_EXCL | O_CREAT | O_WRONLY, $mode): sysopen(FILE, $file, O_EXCL | O_CREAT | O_WRONLY)) { _dump(*FILE, @$r_lines); return close(FILE); } return(0); Thanks, Marc
From: John W. Krahn on 7 Aug 2010 02:40 Marc Girod wrote: > > A script saves mails sent by a crontab--so, there may be bursts... > It uses sysopen, I assume to make sure it doesn't overwrite existing > files. > At times, we get bursts of errors (File exists), which I trace to the > sysopen call. > However, I cannot find that all the corresponding files would have > existed. > I read the doc and get to: > > In many systems the "O_EXCL" flag is available for opening > files > in exclusive mode. This is not locking: exclusiveness > means here > that if the file already exists, sysopen() fails. "O_EXCL" > may > not work on network filesystems, and has no effect unless > the > "O_CREAT" flag is set as well. > > The script does write to a network filesystems (home directory on a > remote filer, 4 ms round-trip). > > Shoud I look for a replacement for sysopen? > Or for an other theory to explain the problem? > > The bit of code doing the open: > > if(defined($mode)? sysopen(FILE, $file, O_EXCL | O_CREAT | O_WRONLY, > $mode): > sysopen(FILE, $file, O_EXCL | O_CREAT | O_WRONLY)) > { Your code does not check the return value from sysopen() so the error message you are receiving is not related to sysopen(). > _dump(*FILE, @$r_lines); > return close(FILE); > } > return(0); John -- Any intelligent fool can make things bigger and more complex... It takes a touch of genius - and a lot of courage to move in the opposite direction. -- Albert Einstein
From: Marc Girod on 7 Aug 2010 04:55 On Aug 7, 7:40 am, "John W. Krahn" <jwkr...(a)example.com> wrote: > Your code does not check the return value from sysopen() so the error > message you are receiving is not related to sysopen(). Doesn't it? The block is an if block. If the condition (the return from sysopen) is false, the function returns 0 unconditionally. Besides, the error I get from $!, at the time of reporting in the calling function is, as I wrote it, 'File exists'. And last: it is not *my* code. Marc
From: Peter J. Holzer on 7 Aug 2010 07:56 On 2010-08-07 08:55, Marc Girod <marc.girod(a)gmail.com> wrote: > On Aug 7, 7:40 am, "John W. Krahn" <jwkr...(a)example.com> wrote: >> Your code does not check the return value from sysopen() so the error >> message you are receiving is not related to sysopen(). > > Doesn't it? > The block is an if block. > If the condition (the return from sysopen) is false, the function > returns 0 unconditionally. But you haven't shown where the error is reported. We could only guess that it's the next thing after “return 0”. > Besides, the error I get from $!, at the time of reporting in the > calling function is, as I wrote it, 'File exists'. There may be something between the sysopen and the printing of $! which causes that error. Since we haven't seen that code we can't tell. I do agree that it's very likely that “File exists” is set by sysopen in this case. > And last: it is not *my* code. You posted it, so in the context of this thread it's your code. :-P hp
From: Peter J. Holzer on 7 Aug 2010 08:10 On 2010-08-06 17:06, Marc Girod <marc.girod(a)gmail.com> wrote: > A script saves mails sent by a crontab--so, there may be bursts... > It uses sysopen, I assume to make sure it doesn't overwrite existing > files. > At times, we get bursts of errors (File exists), which I trace to the > sysopen call. > However, I cannot find that all the corresponding files would have > existed. > I read the doc and get to: > > In many systems the "O_EXCL" flag is available for opening > files > in exclusive mode. This is not locking: exclusiveness > means here > that if the file already exists, sysopen() fails. "O_EXCL" > may > not work on network filesystems, and has no effect unless > the > "O_CREAT" flag is set as well. If the network filesystem doesn't support O_EXCL, then the open will succeed even though it shouldn't (or it will fail every time with EINVAL), it won't fail when the file doesn't exist. > The script does write to a network filesystems (home directory on a > remote filer, 4 ms round-trip). > > Shoud I look for a replacement for sysopen? No. sysopen is the closest you can get to the OS. If sysopen reporte EEXIST, then the OS really thinks the file exists at the time. > Or for an other theory to explain the problem? Yes. Most likely causes are IMHO: * The file really exists at the time. You have to find out why (maybe your script is supposed to remove the file before it terminates and it either doesn't do it or a previous invocation hasn't finished yet). If you know why the solution is probably obvious. * The file did exist and has already been removed at the time the script runs, but the information about the file's existence is still cached by the OS. In this case you should check the configuration of the file system (on both the client and the server). hp
|
Next
|
Last
Pages: 1 2 3 4 Prev: FAQ 7.4 How do I skip some return values? Next: Does this match any number or just single digit ones? |