Skip to content

Commit

Permalink
pingstat: Rework for Pike 8.0 compat (hopefully)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Jul 28, 2024
1 parent 64662e9 commit 1158377
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pingstat.pike
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void update_averages(int|float add) {

string stdout_buf = "", stderr_buf = "";
int seen_good = 0;
void got_stdout(string data) {
void got_stdout(mixed _, string data) {
stdout_buf += data;
while (sscanf(stdout_buf, "%s\n%s", string line, stdout_buf) == 2) {
if (sscanf(line, "%*d bytes from %*s: icmp_seq=%*d ttl=%*d time=%f ms", float tm) == 5) {
Expand All @@ -65,12 +65,20 @@ void got_stdout(string data) {
if (seen_good) update_averages(0);
}
}
void got_stderr(string data) {
void got_stderr(mixed _, string data) {
stderr_buf += data;
while (sscanf(stderr_buf, "%s\n%s", string line, stderr_buf) == 2)
bad_line(line);
}

int main(int argc, array(string) argv) {
return Process.run(({"ping"}) + argv[1..], (["stdout": got_stdout, "stderr": got_stderr]))->exitcode;
mapping modifiers = (["stdout": got_stdout, "stderr": got_stderr]);
object out = Stdio.File(), err = Stdio.File();
object proc = Process.Process(({"ping"}) + argv[1..], ([
"stdout": out->pipe(), "err": err->pipe(),
"callback": lambda() {exit(0);},
]));
out->set_read_callback(got_stdout);
err->set_read_callback(got_stderr);
return -1;
}

0 comments on commit 1158377

Please sign in to comment.