glasswalk3r has asked for the wisdom of the Perl Monks concerning the following question:
Greetings,
I'm testing the Perl file locking features against programs like useradd and Samba smbpasswd program to be sure that those programs won't mess the passwords files while my Perl CGI at working in them.
For my surprise, both programs were able to change the respective files while the script code below is running (and keeping the file locked).
#!/usr/bin/perl use strict; use warnings; use Fcntl qw(:DEFAULT :flock); my $sec = 30; print 'Please type the file that I should lock for $sec: '; my $file = <STDIN>; chomp $file; sysopen( FH, $file, O_RDWR ) or die "Cannot edit $file: $!\n"; flock( FH, LOCK_EX ) or die "Cannot lock $file: $!\n"; print 'Ok, holding the file for $sec seconds. I will not change anythingin the file', "\n"; sleep $sec; close(FH); print "Finished\n";
Any sugestion to solve this issue without having to checking the source code of these programs that are, for sure, written in C or C++ and probably are using flock or lockf or fcntl functions to get file locking features?
Thanks in advance.
Regards,
|
---|