chiark / gitweb /
machined: add logic to query IP addresses of containers
[elogind.git] / src / shared / logs-show.c
index df49375724d5fce7f2c4a8630a817ab0d5ec7310..c3578ac9181ca65d63177bf57b3dafbb4210407c 100644 (file)
@@ -301,8 +301,8 @@ static int output_short(
                 }
 
                 fprintf(f, "[%5llu.%06llu]",
-                        (unsigned long long) (t / USEC_PER_SEC),
-                        (unsigned long long) (t % USEC_PER_SEC));
+                        t / USEC_PER_SEC,
+                        t % USEC_PER_SEC);
 
                 n += 1 + 5 + 1 + 6 + 1;
 
@@ -531,12 +531,12 @@ static int output_export(
 
         fprintf(f,
                 "__CURSOR=%s\n"
-                "__REALTIME_TIMESTAMP=%llu\n"
-                "__MONOTONIC_TIMESTAMP=%llu\n"
+                "__REALTIME_TIMESTAMP="USEC_FMT"\n"
+                "__MONOTONIC_TIMESTAMP="USEC_FMT"\n"
                 "_BOOT_ID=%s\n",
                 cursor,
-                (unsigned long long) realtime,
-                (unsigned long long) monotonic,
+                realtime,
+                monotonic,
                 sd_id128_to_string(boot_id, sid));
 
         JOURNAL_FOREACH_DATA_RETVAL(j, data, length, r) {
@@ -547,7 +547,9 @@ static int output_export(
                     startswith(data, "_BOOT_ID="))
                         continue;
 
-                if (!utf8_is_printable(data, length)) {
+                if (utf8_is_printable_newline(data, length, false))
+                        fwrite(data, length, 1, f);
+                else {
                         const char *c;
                         uint64_t le64;
 
@@ -562,8 +564,7 @@ static int output_export(
                         le64 = htole64(length - (c - (const char*) data) - 1);
                         fwrite(&le64, sizeof(le64), 1, f);
                         fwrite(c + 1, length - (c - (const char*) data) - 1, 1, f);
-                } else
-                        fwrite(data, length, 1, f);
+                }
 
                 fputc('\n', f);
         }
@@ -672,12 +673,12 @@ static int output_json(
                 fprintf(f,
                         "{\n"
                         "\t\"__CURSOR\" : \"%s\",\n"
-                        "\t\"__REALTIME_TIMESTAMP\" : \"%llu\",\n"
-                        "\t\"__MONOTONIC_TIMESTAMP\" : \"%llu\",\n"
+                        "\t\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\",\n"
+                        "\t\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\",\n"
                         "\t\"_BOOT_ID\" : \"%s\"",
                         cursor,
-                        (unsigned long long) realtime,
-                        (unsigned long long) monotonic,
+                        realtime,
+                        monotonic,
                         sd_id128_to_string(boot_id, sid));
         else {
                 if (mode == OUTPUT_JSON_SSE)
@@ -685,12 +686,12 @@ static int output_json(
 
                 fprintf(f,
                         "{ \"__CURSOR\" : \"%s\", "
-                        "\"__REALTIME_TIMESTAMP\" : \"%llu\", "
-                        "\"__MONOTONIC_TIMESTAMP\" : \"%llu\", "
+                        "\"__REALTIME_TIMESTAMP\" : \""USEC_FMT"\", "
+                        "\"__MONOTONIC_TIMESTAMP\" : \""USEC_FMT"\", "
                         "\"_BOOT_ID\" : \"%s\"",
                         cursor,
-                        (unsigned long long) realtime,
-                        (unsigned long long) monotonic,
+                        realtime,
+                        monotonic,
                         sd_id128_to_string(boot_id, sid));
         }
 
@@ -1099,7 +1100,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
         m2 = strappenda("USER_UNIT=", unit);
         m3 = strappenda("COREDUMP_USER_UNIT=", unit);
         m4 = strappenda("OBJECT_SYSTEMD_USER_UNIT=", unit);
-        sprintf(muid, "_UID=%lu", (unsigned long) uid);
+        sprintf(muid, "_UID="UID_FMT, uid);
 
         (void) (
                 /* Look for messages from the user service itself */
@@ -1139,7 +1140,7 @@ int add_matches_for_user_unit(sd_journal *j, const char *unit, uid_t uid) {
 }
 
 static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
-        _cleanup_close_pipe_ int pair[2] = { -1, -1 };
+        _cleanup_close_pair_ int pair[2] = { -1, -1 };
         _cleanup_close_ int pidnsfd = -1, mntnsfd = -1, rootfd = -1;
         pid_t pid, child;
         siginfo_t si;
@@ -1157,7 +1158,7 @@ static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
         if (r < 0)
                 return r;
 
-        r = namespace_open(pid, &pidnsfd, &mntnsfd, &rootfd);
+        r = namespace_open(pid, &pidnsfd, &mntnsfd, NULL, &rootfd);
         if (r < 0)
                 return r;
 
@@ -1173,7 +1174,7 @@ static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
 
                 pair[0] = safe_close(pair[0]);
 
-                r = namespace_enter(pidnsfd, mntnsfd, rootfd);
+                r = namespace_enter(pidnsfd, mntnsfd, -1, rootfd);
                 if (r < 0)
                         _exit(EXIT_FAILURE);