Move service name duplication lookup to EndSection

This is paving the way to allow an "override" tag
in init services. This also means that errors for
part of a service definition in its section will
be shown in addition to the fact that the service
is duplicated.

Bug: 69050941
Test: boot, init_tests
Change-Id: Ic1ea8597789f45ead1083451b3e933db1524bdc9
diff --git a/init/service.cpp b/init/service.cpp
index 6d48368..65f5f50 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -1111,11 +1111,6 @@
         return Error() << "invalid service name '" << name << "'";
     }
 
-    Service* old_service = service_list_->FindService(name);
-    if (old_service) {
-        return Error() << "ignored duplicate definition of service '" << name << "'";
-    }
-
     Subcontext* restart_action_subcontext = nullptr;
     if (subcontexts_) {
         for (auto& subcontext : *subcontexts_) {
@@ -1137,6 +1132,11 @@
 
 Result<Success> ServiceParser::EndSection() {
     if (service_) {
+        Service* old_service = service_list_->FindService(service_->name());
+        if (old_service) {
+            return Error() << "ignored duplicate definition of service '" << service_->name() << "'";
+        }
+
         service_list_->AddService(std::move(service_));
     }