]>
sourceware.org Git - systemtap.git/blob - remote.cxx
1 // systemtap remote execution
2 // Copyright (C) 2010 Red Hat Inc.
4 // This file is part of systemtap, and is free software. You can
5 // redistribute it and/or modify it under the terms of the GNU General
6 // Public License (GPL); either version 2, or (at your option) any
10 #include <sys/utsname.h>
24 // loopback target for running locally
25 class direct
: public remote
{
27 direct(systemtap_session
& s
)
31 arch
= normalize_machine(buf
.machine
);
32 release
= buf
.release
;
37 int run(systemtap_session
& s
) {
38 string module
= s
.tmpdir
+ "/" + s
.module_name
+ ".ko";
39 return stap_system (s
.verbose
, make_run_command (s
, module
));
43 class ssh_remote
: public remote
{
44 // NB: ssh commands use a tty (-t) so signals are passed along to the remote
47 ssh_remote(systemtap_session
& s
, const string
& uri
): uri(uri
)
51 string uname_cmd
= "ssh -t -q " + lex_cast_qstring(uri
) + " uname -rm";
52 int rc
= stap_system_read(s
.verbose
, uname_cmd
, out
);
54 tokenize(out
.str(), uname
, " \t\r\n");
55 if (uname
.size() != 2)
56 throw runtime_error("failed to get uname from " + uri
57 + " : rc=" + lex_cast(rc
));
64 int run(systemtap_session
& s
)
67 string localmodule
= s
.tmpdir
+ "/" + s
.module_name
+ ".ko";
68 string tmpdir
, tmpmodule
;
69 string quri
= lex_cast_qstring(uri
);
71 // Make a remote tempdir.
75 string cmd
= "ssh -t -q " + quri
+ " mktemp -d -t stapXXXXXX";
76 rc
= stap_system_read(s
.verbose
, cmd
, out
);
78 tokenize(out
.str(), vout
, "\r\n");
81 cerr
<< "failed to make a tempdir on " << uri
82 << " : rc=" << rc
<< endl
;
86 tmpmodule
= tmpdir
+ "/" + s
.module_name
+ ".ko";
89 // Transfer the module. XXX and uprobes.ko, sigs, etc.
91 string cmd
= "scp -q " + localmodule
+ " " + quri
+ ":" + tmpmodule
;
92 rc
= stap_system(s
.verbose
, cmd
);
94 cerr
<< "failed to copy the module to " << uri
95 << " : rc=" << rc
<< endl
;
98 // Run the module on the remote.
100 string cmd
= "ssh -t -q " + quri
+ " "
101 + lex_cast_qstring(make_run_command(s
, tmpmodule
));
102 rc
= stap_system(s
.verbose
, cmd
);
104 cerr
<< "failed to run the module on " << uri
105 << " : rc=" << rc
<< endl
;
108 // Remove the tempdir.
109 // XXX need to make sure this runs even with e.g. CTRL-C exits
111 string cmd
= "ssh -t -q " + quri
+ " rm -r " + tmpdir
;
112 int rc2
= stap_system(s
.verbose
, cmd
);
114 cerr
<< "failed to delete the tempdir on " << uri
115 << " : rc=" << rc2
<< endl
;
126 remote::create(systemtap_session
& s
, const string
& uri
)
131 return new direct(s
);
133 // XXX assuming everything else is ssh for now...
134 return new ssh_remote(s
, uri
);
136 catch (std::runtime_error
& e
)
138 cerr
<< e
.what() << endl
;
144 /* vim: set sw=2 ts=8 cino=>4,n-2,{2,^-2,t0,(0,u0,w1,M1 : */
This page took 0.04449 seconds and 6 git commands to generate.