Don't enable reporting exceptions on failbit (only to then disable).
authorDavin McCall <davmac@davmac.org>
Sat, 21 Sep 2019 01:35:25 +0000 (02:35 +0100)
committerDavin McCall <davmac@davmac.org>
Sun, 6 Oct 2019 01:59:32 +0000 (02:59 +0100)
src/load-service.cc

index 7453bb3e617d05f35be24d7eea90f3cc20e11b63..612c54e51de6b4d8640cf2d2b8352c5b82496080 100644 (file)
@@ -205,7 +205,9 @@ service_record * dirload_service_set::load_service(const char * name)
     #endif
 
     string line;
-    service_file.exceptions(ios::badbit | ios::failbit);
+    // getline can set failbit if it reaches end-of-file, we don't want an exception in that case. There's
+    // no good way to handle an I/O error however, so we'll have exceptions thrown on badbit:
+    service_file.exceptions(ios::badbit);
     
     // Add a dummy service record now to prevent infinite recursion in case of cyclic dependency.
     // We replace this with the real service later (or remove it if we find a configuration error).
@@ -213,9 +215,6 @@ service_record * dirload_service_set::load_service(const char * name)
     add_service(rval);
     
     try {
-        // getline can set failbit if it reaches end-of-file, we don't want an exception in that case:
-        service_file.exceptions(ios::badbit);
-        
         process_service_file(name, service_file,
                 [&](string &line, string &setting, string_iterator &i, string_iterator &end) -> void {
             if (setting == "command") {