chiark / gitweb /
make use of logging API wherever appropriate
authorLennart Poettering <lennart@poettering.net>
Wed, 20 Jan 2010 18:19:53 +0000 (19:19 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 20 Jan 2010 18:19:53 +0000 (19:19 +0100)
conf-parser.c
load-fragment.c
main.c
manager.c
test-engine.c

index 3a7da7960ca84f5f5418f95603d27beed4702808..2ea6911257db25ab302c5af7b20ffee3dfbeea9b 100644 (file)
@@ -10,6 +10,7 @@
 #include "util.h"
 #include "macro.h"
 #include "strv.h"
+#include "log.h"
 
 #define WHITESPACE " \t\n"
 #define COMMENTS "#;\n"
@@ -44,7 +45,7 @@ static int next_assignment(
                 return t->parse(filename, line, section, lvalue, rvalue, t->data, userdata);
         }
 
-        fprintf(stderr, "[%s:%u] Unknown lvalue '%s' in section '%s'.\n", filename, line, lvalue, strna(section));
+        log_error("[%s:%u] Unknown lvalue '%s' in section '%s'.", filename, line, lvalue, strna(section));
         return -EBADMSG;
 }
 
@@ -122,7 +123,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
                 assert(k > 0);
 
                 if (b[k-1] != ']') {
-                        fprintf(stderr, "[%s:%u] Invalid section header.\n", filename, line);
+                        log_error("[%s:%u] Invalid section header.", filename, line);
                         return -EBADMSG;
                 }
 
@@ -151,7 +152,7 @@ static int parse_line(const char *filename, unsigned line, char **section, const
         }
 
         if (!(e = strchr(b, '='))) {
-                fprintf(stderr, "[%s:%u] Missing '='.\n", filename, line);
+                log_error("[%s:%u] Missing '='.", filename, line);
                 return -EBADMSG;
         }
 
@@ -173,7 +174,7 @@ int config_parse(const char *filename, const char* const * sections, const Confi
 
         if (!(f = fopen(filename, "re"))) {
                 r = -errno;
-                fprintf(stderr, "Failed to open configuration file '%s': %s\n", filename, strerror(-r));
+                log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
                 goto finish;
         }
 
@@ -185,7 +186,7 @@ int config_parse(const char *filename, const char* const * sections, const Confi
                                 break;
 
                         r = -errno;
-                        fprintf(stderr, "Failed to read configuration file '%s': %s\n", filename, strerror(-r));
+                        log_error("Failed to read configuration file '%s': %s", filename, strerror(-r));
                         goto finish;
                 }
 
@@ -222,7 +223,7 @@ int config_parse_int(
         assert(data);
 
         if ((r = safe_atoi(rvalue, i)) < 0) {
-                fprintf(stderr, "[%s:%u] Failed to parse numeric value: %s\n", filename, line, rvalue);
+                log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
                 return r;
         }
 
@@ -247,7 +248,7 @@ int config_parse_unsigned(
         assert(data);
 
         if ((r = safe_atou(rvalue, u)) < 0) {
-                fprintf(stderr, "[%s:%u] Failed to parse numeric value: %s\n", filename, line, rvalue);
+                log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
                 return r;
         }
 
@@ -273,7 +274,7 @@ int config_parse_size(
         assert(data);
 
         if ((r = safe_atou(rvalue, &u)) < 0) {
-                fprintf(stderr, "[%s:%u] Failed to parse numeric value: %s\n", filename, line, rvalue);
+                log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
                 return r;
         }
 
@@ -299,7 +300,7 @@ int config_parse_bool(
         assert(data);
 
         if ((k = parse_boolean(rvalue)) < 0) {
-                fprintf(stderr, "[%s:%u] Failed to parse boolean value: %s\n", filename, line, rvalue);
+                log_error("[%s:%u] Failed to parse boolean value: %s", filename, line, rvalue);
                 return k;
         }
 
index ed96865248d106210163baea7f169a0b4741bc94..ed046d0356e5628e795cf79347f5d05c0e79466c 100644 (file)
@@ -8,6 +8,7 @@
 #include "strv.h"
 #include "conf-parser.h"
 #include "load-fragment.h"
+#include "log.h"
 
 static int config_parse_deps(
                 const char *filename,
@@ -130,12 +131,19 @@ static int config_parse_listen(
                 void *data,
                 void *userdata) {
 
+        int r;
+
         assert(filename);
         assert(lvalue);
         assert(rvalue);
         assert(data);
 
-        return address_parse(data, rvalue);
+        if ((r = address_parse(data, rvalue)) < 0) {
+                log_error("[%s:%u] Failed to parse address value: %s", filename, line, rvalue);
+                return r;
+        }
+
+        return 0;
 }
 
 static int config_parse_type(
@@ -158,8 +166,10 @@ static int config_parse_type(
                 *type = SOCK_STREAM;
         else if (streq(rvalue, "dgram"))
                 *type = SOCK_DGRAM;
-        else
+        else {
+                log_error("[%s:%u] Failed to parse socket type value: %s", filename, line, rvalue);
                 return -EINVAL;
+        }
 
         return 0;
 }
diff --git a/main.c b/main.c
index f42710b64bdc75e2425bff9094dbc11d6e5c23ab..b22a639396d8b99e74436b9877bbbc62bff0a942 100644 (file)
--- a/main.c
+++ b/main.c
@@ -3,8 +3,10 @@
 #include <stdio.h>
 #include <errno.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "manager.h"
+#include "log.h"
 
 int main(int argc, char *argv[]) {
         Manager *m = NULL;
@@ -12,24 +14,25 @@ int main(int argc, char *argv[]) {
         Job *job = NULL;
         int r, retval = 1;
 
+        assert_se(chdir("test1") == 0);
+
         if (!(m = manager_new()) < 0) {
-                fprintf(stderr, "Failed to allocate manager object: %s\n", strerror(ENOMEM));
+                log_error("Failed to allocate manager object: %s", strerror(ENOMEM));
                 goto finish;
         }
 
-
         if ((r = manager_load_name(m, "default.milestone", &milestone)) < 0) {
-                fprintf(stderr, "Failed to load default milestone: %s\n", strerror(-r));
+                log_error("Failed to load default milestone: %s", strerror(-r));
                 goto finish;
         }
 
         if ((r = manager_load_name(m, "syslog.socket", &syslog)) < 0) {
-                fprintf(stderr, "Failed to load syslog socket: %s\n", strerror(-r));
+                log_error("Failed to load syslog socket: %s", strerror(-r));
                 goto finish;
         }
 
         if ((r = manager_add_job(m, JOB_START, milestone, JOB_REPLACE, false, &job)) < 0) {
-                fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r));
+                log_error("Failed to start default milestone: %s", strerror(-r));
                 goto finish;
         }
 
@@ -40,7 +43,7 @@ int main(int argc, char *argv[]) {
         manager_dump_jobs(m, stdout, "\t");
 
         if ((r = manager_add_job(m, JOB_STOP, syslog, JOB_REPLACE, false, &job)) < 0) {
-                fprintf(stderr, "Failed to start default milestone: %s\n", strerror(-r));
+                log_error("Failed to start default milestone: %s", strerror(-r));
                 goto finish;
         }
 
index a104e2f401c8689ec572558206ad37699a776020..456eb8db1cc5ce703b8d975c143d2b3c90cc9acb 100644 (file)
--- a/manager.c
+++ b/manager.c
@@ -8,6 +8,7 @@
 #include "hashmap.h"
 #include "macro.h"
 #include "strv.h"
+#include "log.h"
 
 Manager* manager_new(void) {
         Manager *m;
@@ -166,7 +167,6 @@ static void transaction_merge_and_delete_job(Manager *m, Job *j, Job *other, Job
                 j->object_list = other->object_list;
         }
 
-
         /* Kill the other job */
         other->subject_list = NULL;
         other->object_list = NULL;
@@ -221,6 +221,7 @@ static int transaction_verify_order_one(Manager *m, Job *j, Job *from, unsigned
 
                 for (k = from; k; k = (k->generation == generation ? k->marker : NULL)) {
                         if (!k->matters_to_anchor) {
+                                log_debug("Breaking order cycle by deleting job %s", name_id(k->name));
                                 manager_transaction_delete_job(m, k);
                                 return -EAGAIN;
                         }
index 61882a960f5f0ed3146a74678d8998c342e34b2d..15ce70f1acb6a8ee67881018c2e36a173ac51ddf 100644 (file)
@@ -36,7 +36,7 @@ int main(int argc, char *argv[]) {
         assert_se(manager_add_job(m, JOB_START, d, JOB_REPLACE, false, &j) == -ELOOP);
         manager_dump_jobs(m, stdout, "\t");
 
-        printf("Test2: (Cyclic Order, Fixable)\n");
+        printf("Test3: (Cyclic Order, Fixable)\n");
         assert_se(manager_add_job(m, JOB_START, e, JOB_REPLACE, false, &j) == 0);
         manager_dump_jobs(m, stdout, "\t");