{
if (fds[i].revents & POLLIN)
{
- // XXX should we do line-buffering?
char buf[4096];
- size_t rc = fread(buf, 1, sizeof(buf), OUT);
- if (rc > 0)
+ if (!prefix.empty())
{
- cout.write(buf, rc);
- continue;
+ // If we have a line prefix, then read lines one at a
+ // time and copy out with the prefix.
+ errno = 0;
+ while (fgets(buf, sizeof(buf), OUT))
+ cout << prefix << buf;
+ if (errno == EAGAIN)
+ continue;
+ }
+ else
+ {
+ // Otherwise read an entire block of data at once.
+ size_t rc = fread(buf, 1, sizeof(buf), OUT);
+ if (rc > 0)
+ {
+ // NB: The buf could contain binary data,
+ // including \0, so write as a block instead of
+ // the usual <<string.
+ cout.write(buf, rc);
+ continue;
+ }
}
}
close();
for (unsigned i = 0; i < remotes.size() && !pending_interrupts; ++i)
{
- remotes[i]->s->verbose = remotes[i]->s->perpass_verbose[4];
- rc = remotes[i]->prepare();
+ remote *r = remotes[i];
+ r->s->verbose = r->s->perpass_verbose[4];
+ if (r->s->use_remote_prefix)
+ r->prefix = lex_cast(i) + ": ";
+ rc = r->prepare();
if (rc)
return rc;
}
server_cache = NULL;
use_server_on_error = false;
try_server_status = try_server_unset;
+ use_remote_prefix = false;
systemtap_v_check = false;
/* adding in the XDG_DATA_DIRS variable path,
server_cache = NULL;
use_server_on_error = other.use_server_on_error;
try_server_status = other.try_server_status;
+ use_remote_prefix = other.use_remote_prefix;
systemtap_v_check = other.systemtap_v_check;
include_path = other.include_path;
#endif
" --remote=HOSTNAME\n"
" run pass 5 on the specified ssh host.\n"
- " may be repeated for targeting multiple hosts.", compatible.c_str()) << endl
+ " may be repeated for targeting multiple hosts.\n"
+ " --remote-prefix\n"
+ " prefix each line of remote output with a host index."
+ , compatible.c_str()) << endl
;
time_t now;
#define LONG_OPT_CHECK_VERSION 21
#define LONG_OPT_USE_SERVER_ON_ERROR 22
#define LONG_OPT_VERSION 23
+#define LONG_OPT_REMOTE_PREFIX 24
// NB: also see find_hash(), usage(), switch stmt below, stap.1 man page
static struct option long_options[] = {
{ "kelf", 0, &long_opt, LONG_OPT_KELF },
{ "use-server-on-error", 2, &long_opt, LONG_OPT_USE_SERVER_ON_ERROR },
{ "all-modules", 0, &long_opt, LONG_OPT_ALL_MODULES },
{ "remote", 1, &long_opt, LONG_OPT_REMOTE },
+ { "remote-prefix", 0, &long_opt, LONG_OPT_REMOTE_PREFIX },
{ "check-version", 0, &long_opt, LONG_OPT_CHECK_VERSION },
{ "version", 0, &long_opt, LONG_OPT_VERSION },
{ NULL, 0, NULL, 0 }
remote_uris.push_back(optarg);
break;
+ case LONG_OPT_REMOTE_PREFIX:
+ if (client_options) {
+ cerr << _F("ERROR: %s is invalid with %s", "--remote-prefix", "--client-options") << endl;
+ return 1;
+ }
+
+ use_remote_prefix = true;
+ break;
+
case LONG_OPT_CHECK_VERSION:
push_server_opt = true;
systemtap_v_check = true;