diff options
author | bptato <nincsnevem662@gmail.com> | 2024-10-06 20:18:53 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-10-06 20:22:01 +0200 |
commit | 179343ce47fb3e4c7320ce44b2b49b657fa6b4fc (patch) | |
tree | 6fbed3bfdd31df37a69263c1d03a36d972ca1dff /adapter/protocol/man.nim | |
parent | c9cb63074160fd52dd061f82b9132bdc7e720d2b (diff) | |
download | chawan-179343ce47fb3e4c7320ce44b2b49b657fa6b4fc.tar.gz |
man: check exit code after reading first line
Diffstat (limited to 'adapter/protocol/man.nim')
-rw-r--r-- | adapter/protocol/man.nim | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/adapter/protocol/man.nim b/adapter/protocol/man.nim index 50521ca1..1b0724ad 100644 --- a/adapter/protocol/man.nim +++ b/adapter/protocol/man.nim @@ -125,10 +125,13 @@ proc processManpage(ofile, efile: File; header, keyword: string) = # message to stdout. But it's much better (faster) than not streaming the # output. if not ofile.readLine(line) or ofile.endOfFile(): - stdout.write("Cha-Control: ConnectionError 4 " & efile.readErrorMsg(line)) - ofile.close() - efile.close() - quit(1) + var wstatus: cint + discard wait(addr wstatus) + if not WIFEXITED(wstatus) or WEXITSTATUS(wstatus) != 0: + stdout.write("Cha-Control: ConnectionError 4 " & efile.readErrorMsg(line)) + ofile.close() + efile.close() + quit(1) # skip formatting of line 0, like w3mman does # this is useful because otherwise the header would get caught in the man # regex, and that makes navigation slightly more annoying @@ -301,10 +304,13 @@ proc doKeyword(man, keyword, section: string) = quit(1) var line: string if not ofile.readLine(line) or ofile.endOfFile(): - stdout.write("Cha-Control: ConnectionError 4 " & efile.readErrorMsg(line)) - ofile.close() - efile.close() - quit(1) + var wstatus: cint + discard wait(addr wstatus) + if not WIFEXITED(wstatus) or WEXITSTATUS(wstatus) != 0: + stdout.write("Cha-Control: ConnectionError 4 " & efile.readErrorMsg(line)) + ofile.close() + efile.close() + quit(1) stdout.write("Content-Type: text/html\n\n") stdout.write("<title>man" & sectionOpt & " -k " & keyword & "</title>\n") stdout.write("<h1>man" & sectionOpt & " -k <b>" & keyword & "</b></h1>\n") |