| 668 | |
| 669 | |
| 670 | Try<bool> mounted(const string& hierarchy, const string& subsystems) |
| 671 | { |
| 672 | if (!os::exists(hierarchy)) { |
| 673 | return false; |
| 674 | } |
| 675 | |
| 676 | // We compare canonicalized absolute paths. |
| 677 | Result<string> realpath = os::realpath(hierarchy); |
| 678 | if (!realpath.isSome()) { |
| 679 | return Error( |
| 680 | "Failed to determine canonical path of '" + hierarchy + "': " + |
| 681 | (realpath.isError() |
| 682 | ? realpath.error() |
| 683 | : "No such file or directory")); |
| 684 | } |
| 685 | |
| 686 | Try<set<string>> hierarchies = cgroups::hierarchies(); |
| 687 | if (hierarchies.isError()) { |
| 688 | return Error( |
| 689 | "Failed to get mounted hierarchies: " + hierarchies.error()); |
| 690 | } |
| 691 | |
| 692 | if (hierarchies->count(realpath.get()) == 0) { |
| 693 | return false; |
| 694 | } |
| 695 | |
| 696 | // Now make sure all the specified subsytems are attached. |
| 697 | Try<set<string>> attached = cgroups::subsystems(hierarchy); |
| 698 | if (attached.isError()) { |
| 699 | return Error( |
| 700 | "Failed to get subsystems attached to hierarchy '" + |
| 701 | hierarchy + "': " + attached.error()); |
| 702 | } |
| 703 | |
| 704 | foreach (const string& subsystem, strings::tokenize(subsystems, ",")) { |
| 705 | if (attached->count(subsystem) == 0) { |
| 706 | return false; |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | return true; |
| 711 | } |
| 712 | |
| 713 | |
| 714 | Try<Nothing> create( |