mirror of
https://github.com/SCST-project/scst.git
synced 2026-07-20 06:52:18 +00:00
scstadmin: Make _syswrite() translate EBUSY into "writing failed"
_syswrite() callers check whether writing into an SCST sysfs attribute succeeded by checking whether the value returned by this function is defined(). Return undef (failed) instead of -1 (success) if syswrite() returned error code EBUSY (found this through source reading). Return $length instead of length($cmd) if the initial write triggered EAGAIN. Remove a superfluous $bytes = undef statement. Eliminate the variable $wait. git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4400 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
@@ -4855,6 +4855,8 @@ sub errorString {
|
||||
return $string;
|
||||
}
|
||||
|
||||
# Write the first $3 bytes of $2 into the SCST sysfs file $1. Return either
|
||||
# the number of bytes written or undef if writing failed.
|
||||
sub _syswrite {
|
||||
my $io = shift;
|
||||
my $cmd = shift;
|
||||
@@ -4865,35 +4867,32 @@ sub _syswrite {
|
||||
|
||||
my $bytes = syswrite($io, $cmd, $length);
|
||||
|
||||
if (!defined($bytes) && defined($res_file)) {
|
||||
if ($! == EAGAIN) {
|
||||
my $res = new IO::File $res_file, O_RDONLY;
|
||||
if (!defined($bytes) && defined($res_file) && $! == EAGAIN) {
|
||||
my $res_io = new IO::File $res_file, O_RDONLY;
|
||||
|
||||
if (!$res) {
|
||||
cluck("FATAL: Failed opening $res_file: $!");
|
||||
return undef;
|
||||
}
|
||||
if (!$res_io) {
|
||||
cluck("FATAL: Failed opening $res_file: $!");
|
||||
return undef;
|
||||
}
|
||||
|
||||
my $wait = TRUE;
|
||||
my $result;
|
||||
my $res_val;
|
||||
|
||||
while ($wait && (($now + $TIMEOUT) > time())) {
|
||||
sysread($res, $result, 8);
|
||||
$wait = FALSE if ($! != EAGAIN);
|
||||
while (($now + $TIMEOUT) > time()) {
|
||||
if (!defined(sysread($res_io, $res_val, 8)) &&
|
||||
$! == EAGAIN) {
|
||||
sleep 1;
|
||||
}
|
||||
|
||||
if ($wait) {
|
||||
my $_cmd = $cmd; chomp $_cmd;
|
||||
cluck("Timeout while waiting for command '$_cmd' to complete");
|
||||
$bytes = undef;
|
||||
} else {
|
||||
$bytes = length($cmd) if ($result == 0);
|
||||
last;
|
||||
}
|
||||
}
|
||||
|
||||
close $res;
|
||||
} elsif ($! == EBUSY) {
|
||||
return -1;
|
||||
close $res_io;
|
||||
|
||||
if (!defined($res_val)) {
|
||||
my $_cmd = $cmd; chomp $_cmd;
|
||||
cluck("Timeout while waiting for command '$_cmd' to complete");
|
||||
} elsif ($res_val == 0) {
|
||||
$bytes = $length;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user