From: Clément Pit-Claudel Date: Sun, 6 Nov 2022 20:09:53 +0000 (-0800) Subject: Return 1 if no matches were found X-Git-Tag: 1.1.17~1 X-Git-Url: https://git.sesse.net/?p=plocate;a=commitdiff_plain;h=31641da5750ed2b80697e605bf5b50c0a92264af Return 1 if no matches were found * plocate.1: Document this new behavior. * plocate.cpp (do_search_file, main): Exit with code 1 if no matches were found. This behavior is consistent with that of mlocate except with --limit=0, which plocate rejects. --- diff --git a/plocate.1 b/plocate.1 index b5d04dd..03ba56e 100644 --- a/plocate.1 +++ b/plocate.1 @@ -57,6 +57,16 @@ and none that are not, by means of running with the setgid bit set to access the index (which is built as root), but by testing visibility as the calling user. +.SH EXIT STATUS +.B plocate +exits with 0 to indicate that a match was found or that +.B --help +or +.B --version +were passed. Otherwise, +.B plocate +exits with status code 1, indicating that an error occurred or that no matches were found. + .SH OPTIONS .TP \fB\-A\fR, \fB\-\-all\fR diff --git a/plocate.cpp b/plocate.cpp index 28a9c28..7182ee8 100644 --- a/plocate.cpp +++ b/plocate.cpp @@ -571,7 +571,7 @@ uint64_t do_search_file(const vector &needles, const std::string &filena if (only_count) { printf("0\n"); } - exit(0); + exit(1); } } } @@ -972,7 +972,7 @@ int main(int argc, char **argv) } if (needles.empty()) { fprintf(stderr, "plocate: no pattern to search for specified\n"); - exit(0); + exit(1); } if (dbpaths.empty()) { @@ -1000,4 +1000,6 @@ int main(int argc, char **argv) if (only_count) { printf("%" PRId64 "\n", matched); } + + return matched == 0; }