make use of logging API wherever appropriate

This commit is contained in:
Lennart Poettering 2010-01-20 19:19:53 +01:00
parent 5899f3b7f6
commit 16354eff99
5 changed files with 34 additions and 19 deletions

View 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;
}

View 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;
}

15
main.c
View File

@ -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;
}

View File

@ -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;
}

View 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");