]> git.sesse.net Git - plocate/commitdiff
Return 1 if no matches were found
authorClément Pit-Claudel <clement.pitclaudel@live.com>
Sun, 6 Nov 2022 20:09:53 +0000 (12:09 -0800)
committerSteinar H. Gunderson <steinar+git@gunderson.no>
Mon, 7 Nov 2022 10:30:36 +0000 (11:30 +0100)
* 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.

plocate.1
plocate.cpp

index b5d04ddda54b9c226064d2b24d86d2be4c027456..03ba56e6fa2b538e7159e2def6f35f8aa0750154 100644 (file)
--- 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
index 28a9c28bfe52065b8425fffdb4ffef661b501865..7182ee892dfa839b5b50794a4e22582500759996 100644 (file)
@@ -571,7 +571,7 @@ uint64_t do_search_file(const vector<Needle> &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;
 }