| 91 | |
| 92 | |
| 93 | Result<pid_t> getContainerPid( |
| 94 | const string& runtimeDir, |
| 95 | const ContainerID& containerId) |
| 96 | { |
| 97 | const string path = path::join( |
| 98 | getRuntimePath(runtimeDir, containerId), |
| 99 | PID_FILE); |
| 100 | |
| 101 | if (!os::exists(path)) { |
| 102 | // This is possible because we don't atomically create the |
| 103 | // directory and write the 'pid' file and thus we might |
| 104 | // terminate/restart after we've created the directory but |
| 105 | // before we've written the file. |
| 106 | return None(); |
| 107 | } |
| 108 | |
| 109 | Result<string> read = state::read<string>(path); |
| 110 | if (read.isError()) { |
| 111 | return Error("Failed to recover pid of container: " + read.error()); |
| 112 | } |
| 113 | |
| 114 | Try<pid_t> pid = numify<pid_t>(read.get()); |
| 115 | if (pid.isError()) { |
| 116 | return Error( |
| 117 | "Failed to numify pid '" + read.get() + |
| 118 | "' of container at '" + path + "': " + pid.error()); |
| 119 | } |
| 120 | |
| 121 | return pid.get(); |
| 122 | } |
| 123 | |
| 124 | |
| 125 | Result<int> getContainerStatus( |