chiark / gitweb /
treewide: use log_*_errno whenever %m is in the format string
[elogind.git] / src / journal-remote / journal-gatewayd.c
index db07700111410be2f46bf55ee615d392ab262406..7a99430a63c951e9b1556cb92bf3b60e7ba0f190 100644 (file)
@@ -155,14 +155,14 @@ static ssize_t request_reader_entries(
                         r = sd_journal_next(m->journal);
 
                 if (r < 0) {
-                        log_error("Failed to advance journal pointer: %s", strerror(-r));
+                        log_error_errno(r, "Failed to advance journal pointer: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 } else if (r == 0) {
 
                         if (m->follow) {
                                 r = sd_journal_wait(m->journal, (uint64_t) -1);
                                 if (r < 0) {
-                                        log_error("Couldn't wait for journal event: %s", strerror(-r));
+                                        log_error_errno(r, "Couldn't wait for journal event: %m");
                                         return MHD_CONTENT_READER_END_WITH_ERROR;
                                 }
 
@@ -177,7 +177,7 @@ static ssize_t request_reader_entries(
 
                         r = sd_journal_test_cursor(m->journal, m->cursor);
                         if (r < 0) {
-                                log_error("Failed to test cursor: %s", strerror(-r));
+                                log_error_errno(r, "Failed to test cursor: %m");
                                 return MHD_CONTENT_READER_END_WITH_ERROR;
                         }
 
@@ -198,20 +198,20 @@ static ssize_t request_reader_entries(
                 else {
                         m->tmp = tmpfile();
                         if (!m->tmp) {
-                                log_error("Failed to create temporary file: %m");
+                                log_error_errno(errno, "Failed to create temporary file: %m");
                                 return MHD_CONTENT_READER_END_WITH_ERROR;
                         }
                 }
 
                 r = output_journal(m->tmp, m->journal, m->mode, 0, OUTPUT_FULL_WIDTH, NULL);
                 if (r < 0) {
-                        log_error("Failed to serialize item: %s", strerror(-r));
+                        log_error_errno(r, "Failed to serialize item: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 }
 
                 sz = ftello(m->tmp);
                 if (sz == (off_t) -1) {
-                        log_error("Failed to retrieve file position: %m");
+                        log_error_errno(errno, "Failed to retrieve file position: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 }
 
@@ -219,7 +219,7 @@ static ssize_t request_reader_entries(
         }
 
         if (fseeko(m->tmp, pos, SEEK_SET) < 0) {
-                log_error("Failed to seek to position: %m");
+                log_error_errno(errno, "Failed to seek to position: %m");
                 return MHD_CONTENT_READER_END_WITH_ERROR;
         }
 
@@ -394,7 +394,7 @@ static int request_parse_arguments_iterator(
 
                         r = sd_id128_get_boot(&bid);
                         if (r < 0) {
-                                log_error("Failed to get boot ID: %s", strerror(-r));
+                                log_error_errno(r, "Failed to get boot ID: %m");
                                 return MHD_NO;
                         }
 
@@ -543,7 +543,7 @@ static ssize_t request_reader_fields(
 
                 r = sd_journal_enumerate_unique(m->journal, &d, &l);
                 if (r < 0) {
-                        log_error("Failed to advance field index: %s", strerror(-r));
+                        log_error_errno(r, "Failed to advance field index: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 } else if (r == 0)
                         return MHD_CONTENT_READER_END_OF_STREAM;
@@ -559,20 +559,20 @@ static ssize_t request_reader_fields(
                 else {
                         m->tmp = tmpfile();
                         if (!m->tmp) {
-                                log_error("Failed to create temporary file: %m");
+                                log_error_errno(errno, "Failed to create temporary file: %m");
                                 return MHD_CONTENT_READER_END_WITH_ERROR;
                         }
                 }
 
                 r = output_field(m->tmp, m->mode, d, l);
                 if (r < 0) {
-                        log_error("Failed to serialize item: %s", strerror(-r));
+                        log_error_errno(r, "Failed to serialize item: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 }
 
                 sz = ftello(m->tmp);
                 if (sz == (off_t) -1) {
-                        log_error("Failed to retrieve file position: %m");
+                        log_error_errno(errno, "Failed to retrieve file position: %m");
                         return MHD_CONTENT_READER_END_WITH_ERROR;
                 }
 
@@ -580,7 +580,7 @@ static ssize_t request_reader_fields(
         }
 
         if (fseeko(m->tmp, pos, SEEK_SET) < 0) {
-                log_error("Failed to seek to position: %m");
+                log_error_errno(errno, "Failed to seek to position: %m");
                 return MHD_CONTENT_READER_END_WITH_ERROR;
         }
 
@@ -834,7 +834,7 @@ static int request_handler(
         }
 
         if (trust_pem) {
-                r = check_permissions(connection, &code);
+                r = check_permissions(connection, &code, NULL);
                 if (r < 0)
                         return code;
         }
@@ -857,8 +857,7 @@ static int request_handler(
         return mhd_respond(connection, MHD_HTTP_NOT_FOUND, "Not found.\n");
 }
 
-static int help(void) {
-
+static void help(void) {
         printf("%s [OPTIONS...] ...\n\n"
                "HTTP server for journal events.\n\n"
                "  -h --help           Show this help\n"
@@ -867,8 +866,6 @@ static int help(void) {
                "     --key=KEY.PEM    Server key in PEM format\n"
                "     --trust=CERT.PEM Certificat authority certificate in PEM format\n",
                program_invocation_short_name);
-
-        return 0;
 }
 
 static int parse_argv(int argc, char *argv[]) {
@@ -898,7 +895,8 @@ static int parse_argv(int argc, char *argv[]) {
                 switch(c) {
 
                 case 'h':
-                        return help();
+                        help();
+                        return 0;
 
                 case ARG_VERSION:
                         puts(PACKAGE_STRING);
@@ -911,10 +909,8 @@ static int parse_argv(int argc, char *argv[]) {
                                 return -EINVAL;
                         }
                         r = read_full_file(optarg, &key_pem, NULL);
-                        if (r < 0) {
-                                log_error("Failed to read key file: %s", strerror(-r));
-                                return r;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to read key file: %m");
                         assert(key_pem);
                         break;
 
@@ -924,10 +920,8 @@ static int parse_argv(int argc, char *argv[]) {
                                 return -EINVAL;
                         }
                         r = read_full_file(optarg, &cert_pem, NULL);
-                        if (r < 0) {
-                                log_error("Failed to read certificate file: %s", strerror(-r));
-                                return r;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to read certificate file: %m");
                         assert(cert_pem);
                         break;
 
@@ -938,10 +932,8 @@ static int parse_argv(int argc, char *argv[]) {
                                 return -EINVAL;
                         }
                         r = read_full_file(optarg, &trust_pem, NULL);
-                        if (r < 0) {
-                                log_error("Failed to read CA certificate file: %s", strerror(-r));
-                                return r;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "Failed to read CA certificate file: %m");
                         assert(trust_pem);
                         break;
 #else
@@ -994,7 +986,7 @@ int main(int argc, char *argv[]) {
 
         n = sd_listen_fds(1);
         if (n < 0) {
-                log_error("Failed to determine passed sockets: %s", strerror(-n));
+                log_error_errno(n, "Failed to determine passed sockets: %m");
                 goto finish;
         } else if (n > 1) {
                 log_error("Can't listen on more than one socket.");