Add support for "internal" services (which don't actually run any
authorDavin McCall <davmac@davmac.org>
Fri, 25 Sep 2015 19:59:16 +0000 (20:59 +0100)
committerDavin McCall <davmac@davmac.org>
Fri, 25 Sep 2015 19:59:16 +0000 (20:59 +0100)
external process) and enhance config file parsing a little.

load_service.cc
service.cc
service.h

index 24aa98c63c34bdb5b10921dcd9e58b5a3a73ed1e..c0a0457fc9b4bfaa24df03fde234a2bec5c5083d 100644 (file)
@@ -53,15 +53,48 @@ static string read_setting_value(string_iterator * const i, string_iterator end)
     *i = skipws(*i, end);
     
     string rval;
-    // bool quoting = false;
     
     while (*i != end) {
         char c = **i;
         if (c == '\"') {
-            // quoted ...
-            // TODO
+            // quoted string
+            ++(*i);
+            while (*i != end) {
+                c = **i;
+                if (c == '\"') break;
+                if (c == '\n') {
+                    // TODO error here.
+                }
+                else if (c == '\\') {
+                    // A backslash escapes the following character.
+                    ++(*i);
+                    if (*i != end) {
+                        c = **i;
+                        rval += c;
+                    }
+                }
+                else {
+                    rval += c;
+                }
+                ++(*i);
+            }
+            if (*i == end) {
+                // String wasn't terminated
+                // TODO error here
+                break;
+            }
         }
-        if (isspace(c, locale::classic())) {
+        else if (c == '\\') {
+            // A backslash escapes the next character
+            ++(*i);
+            if (*i != end) {
+                rval += **i;
+            }
+            else {
+                // TODO error here
+            }
+        }
+        else if (isspace(c, locale::classic())) {
             *i = skipws(*i, end);
             if (*i == end) break;
             if (**i == '#') break; // comment
@@ -153,7 +186,7 @@ ServiceRecord * ServiceSet::loadServiceRecord(const char * name)
             }
             string setting = read_setting_name(&i, end);
             i = skipws(i, end);
-            if (i == end || *i != '=') {
+            if (i == end || (*i != '=' && *i != ':')) {
                 throw ServiceDescriptionExc(name, "Badly formed line.");
             }
             i = skipws(++i, end);
@@ -184,9 +217,12 @@ ServiceRecord * ServiceSet::loadServiceRecord(const char * name)
                 else if (type_str == "process") {
                     service_type = SVC_PROCESS;
                 }
+                else if (type_str == "internal") {
+                    service_type = SVC_INTERNAL;
+                }
                 else {
                     throw ServiceDescriptionExc(name, "Service type must be \"scripted\""
-                        " or \"process\"");
+                        " or \"process\" or \"internal\"");
                 }
             }
             else {
index 27a3a1ea898cc5567d8f7f3dd3a1881ad96408ae..5fedffecd0ed183e5d0dcd43c4785c97539117d5 100644 (file)
@@ -202,13 +202,17 @@ void ServiceRecord::start()
             failed_to_start();
         }
     }
-    else {
+    else if (service_type == SVC_SCRIPTED) {
         // Script-controlled service
         bool start_success = start_ps_process(std::vector<std::string>(1, "start"));
         if (! start_success) {
             failed_to_start();
         }
     }
+    else {
+        // "internal" service
+        started();
+    }
 }
 
 void ServiceRecord::started()
index 081b135f23f37b321c20bb17252e9ff442f9d129..ee2833c75dac1f08c4f7ff01330463bba3cc595a 100644 (file)
--- a/service.h
+++ b/service.h
@@ -38,7 +38,7 @@ constexpr static int SVC_STOPPING = 3;  // service script is stopping and will s
                            by sending the process a signal */
 #define SVC_SCRIPTED 2  /* service requires a command to start, and another
                            command to stop */
-
+#define SVC_INTERNAL 3  /* internal service, runs no external process */
 
 // Exception loading service
 class ServiceLoadExc