Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
emulab-devel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
143
Issues
143
List
Boards
Labels
Service Desk
Milestones
Merge Requests
6
Merge Requests
6
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
emulab
emulab-devel
Commits
c8294768
Commit
c8294768
authored
May 07, 2013
by
Leigh B Stoller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add SSHwithTimeout() utility function.
parent
ccd5fee9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
1 deletion
+44
-1
db/emutil.pm.in
db/emutil.pm.in
+44
-1
No files found.
db/emutil.pm.in
View file @
c8294768
...
...
@@ -32,12 +32,17 @@ use vars qw(@ISA @EXPORT);
@
EXPORT
=
qw
(
TBDB_CHECKDBSLOT_NOFLAGS
TBDB_CHECKDBSLOT_WARN
TBDB_CHECKDBSLOT_ERROR
TBcheck_dbslot
TBFieldErrorString
TBGetUniqueIndex
ParRun
VersionInfo
UpdateVersionInfo
SpanningTree
GenFakeMac
BackTraceOnWarning
PassWordHash
);
SpanningTree
GenFakeMac
BackTraceOnWarning
PassWordHash
SSHwithTimeout
);
use
emdb
;
use
English
;
use
Carp
;
#
Configure
variables
.
my
$
TB
=
"@prefix@"
;
#
#
Support
for
checking
field
values
against
what
is
specified
.
#
...
...
@@ -689,5 +694,43 @@ sub GenFakeMac()
return "02" . $mac;
}
#
# SSH with timeout.
#
sub SSHwithTimeout($$$$)
{
my ($host, $cmd, $timeout, $debug) = @_;
my $childpid;
my $timedout = 0;
my $SSHTB = "@prefix@/bin/sshtb";
$cmd = "$SSHTB -host $host $cmd";
print "SSHwithTimeout($timeout): $cmd\n"
if ($debug);
if ($timeout) {
$childpid = fork();
if ($childpid) {
local $SIG{ALRM} = sub { kill("TERM", $childpid); $timedout = 1; };
alarm $timeout;
waitpid($childpid, 0);
my $exitstatus = $?;
alarm 0;
if ($timedout) {
print STDERR "*** ssh timed out.\n";
return -1;
}
return $exitstatus;
}
exec($cmd);
die("Could not exec '
$
cmd
'");
}
else {
return system($cmd);
}
}
# _Always_ make sure that this 1 is at the end of the file...
1;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment