| 1597 | |
| 1598 | |
| 1599 | Future<vector<Docker::Container>> Docker::ps( |
| 1600 | bool all, |
| 1601 | const Option<string>& prefix) const |
| 1602 | { |
| 1603 | vector<string> argv; |
| 1604 | argv.push_back(path); |
| 1605 | argv.push_back("-H"); |
| 1606 | argv.push_back(socket); |
| 1607 | argv.push_back("ps"); |
| 1608 | |
| 1609 | if (all) { |
| 1610 | argv.push_back("-a"); |
| 1611 | } |
| 1612 | |
| 1613 | const string cmd = strings::join(" ", argv); |
| 1614 | |
| 1615 | VLOG(1) << "Running " << cmd; |
| 1616 | |
| 1617 | Try<Subprocess> s = subprocess( |
| 1618 | cmd, |
| 1619 | Subprocess::PATH(os::DEV_NULL), |
| 1620 | Subprocess::PIPE(), |
| 1621 | Subprocess::PIPE(), |
| 1622 | None(), |
| 1623 | None(), |
| 1624 | createParentHooks()); |
| 1625 | |
| 1626 | if (s.isError()) { |
| 1627 | return Failure("Failed to create subprocess '" + cmd + "': " + s.error()); |
| 1628 | } |
| 1629 | |
| 1630 | // Start reading from stdout so writing to the pipe won't block |
| 1631 | // to handle cases where the output is larger than the pipe |
| 1632 | // capacity. |
| 1633 | const Future<string>& output = io::read(s->out().get()); |
| 1634 | |
| 1635 | return s->status() |
| 1636 | .then(lambda::bind(&Docker::_ps, *this, cmd, s.get(), prefix, output)); |
| 1637 | } |
| 1638 | |
| 1639 | |
| 1640 | Future<vector<Docker::Container>> Docker::_ps( |