(callback)
| 111 | // Returns all data for processes managed by forever. |
| 112 | // |
| 113 | function getAllProcesses(callback) { |
| 114 | const sockPath = forever.config.get("sockPath"); |
| 115 | |
| 116 | function getProcess(name, next) { |
| 117 | let fullPath = path.join(sockPath, name); |
| 118 | const socket = new nssocket.NsSocket(); |
| 119 | |
| 120 | if (process.platform === 'win32') { |
| 121 | // it needs the prefix |
| 122 | fullPath = '\\\\.\\pipe\\' + fullPath; |
| 123 | } |
| 124 | |
| 125 | socket.connect(fullPath, function (err) { |
| 126 | if (err) { |
| 127 | next(err); |
| 128 | } |
| 129 | |
| 130 | socket.dataOnce(['data'], function (data) { |
| 131 | data.socket = fullPath; |
| 132 | next(null, data); |
| 133 | socket.end(); |
| 134 | }); |
| 135 | |
| 136 | socket.send(['data']); |
| 137 | }); |
| 138 | |
| 139 | socket.on('error', function (err) { |
| 140 | if (err.code === 'ECONNREFUSED') { |
| 141 | fs.unlink(fullPath, function () { |
| 142 | next(); |
| 143 | }); |
| 144 | } |
| 145 | else { |
| 146 | next(); |
| 147 | } |
| 148 | }); |
| 149 | } |
| 150 | |
| 151 | getSockets(sockPath, function (err, sockets) { |
| 152 | if (err || (sockets && sockets.length === 0)) { |
| 153 | return callback(err); |
| 154 | } |
| 155 | |
| 156 | async.map(sockets, getProcess, function (err, processes) { |
| 157 | callback(err, processes.filter(Boolean)); |
| 158 | }); |
| 159 | }); |
| 160 | } |
| 161 | |
| 162 | // |
| 163 | // ### function getAllPids () |
no test coverage detected