static int process_backtrace(int argc, char *argv[]) {
        char *context[_CONTEXT_MAX] = {};
        _cleanup_free_ char *message = NULL;
        _cleanup_free_ struct iovec *iovec = NULL;
        size_t n_iovec, n_allocated, n_to_free = 0, i;
        int r;
        JournalImporter importer = {
                .fd = STDIN_FILENO,
        };

        log_debug("Processing backtrace on stdin...");

        if (argc < CONTEXT_COMM + 1)
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                       "Not enough arguments passed (%i, expected %i).",
                                       argc - 1, CONTEXT_COMM + 1 - 1);

        context[CONTEXT_PID]       = argv[2 + CONTEXT_PID];
        context[CONTEXT_UID]       = argv[2 + CONTEXT_UID];
        context[CONTEXT_GID]       = argv[2 + CONTEXT_GID];
        context[CONTEXT_SIGNAL]    = argv[2 + CONTEXT_SIGNAL];
        context[CONTEXT_TIMESTAMP] = argv[2 + CONTEXT_TIMESTAMP];
        context[CONTEXT_RLIMIT]    = argv[2 + CONTEXT_RLIMIT];
        context[CONTEXT_HOSTNAME]  = argv[2 + CONTEXT_HOSTNAME];

        n_allocated = 34 + COREDUMP_STORAGE_EXTERNAL;
        /* 26 metadata, 2 static, +unknown input, 4 storage, rounded up */
        iovec = new(struct iovec, n_allocated);
        if (!iovec)
                return log_oom();

        r = gather_pid_metadata(context, argv + 2 + CONTEXT_COMM, iovec, &n_to_free);
        if (r < 0)
                goto finish;
        if (r > 0) {
                /* This was a special crash, and has already been processed. */
                r = 0;
                goto finish;
        }
        n_iovec = n_to_free;

        for (;;) {
                r = journal_importer_process_data(&importer);
                if (r < 0) {
                        log_error_errno(r, "Failed to parse journal entry on stdin: %m");
                        goto finish;
                }
                if (r == 1 ||                        /* complete entry */
                    journal_importer_eof(&importer)) /* end of data */
                        break;
        }

        if (!GREEDY_REALLOC(iovec, n_allocated, n_iovec + importer.iovw.count + 2))
                return log_oom();

        if (journal_importer_eof(&importer)) {
                log_warning("Did not receive a full journal entry on stdin, ignoring message sent by reporter");

                message = strjoin("MESSAGE=Process ", context[CONTEXT_PID],
                                  " (", context[CONTEXT_COMM], ")"
                                  " of user ", context[CONTEXT_UID],
                                  " failed with ", context[CONTEXT_SIGNAL]);
                if (!message) {
                        r = log_oom();
                        goto finish;
                }
                iovec[n_iovec++] = IOVEC_MAKE_STRING(message);
        } else {
                for (i = 0; i < importer.iovw.count; i++)
                        iovec[n_iovec++] = importer.iovw.iovec[i];
        }

        iovec[n_iovec++] = IOVEC_MAKE_STRING("MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR);
        assert_cc(2 == LOG_CRIT);
        iovec[n_iovec++] = IOVEC_MAKE_STRING("PRIORITY=2");

        assert(n_iovec <= n_allocated);

        r = sd_journal_sendv(iovec, n_iovec);
        if (r < 0)
                log_error_errno(r, "Failed to log backtrace: %m");

 finish:
        for (i = 0; i < n_to_free; i++)
                free(iovec[i].iov_base);

        /* Those fields are allocated by gather_pid_metadata */
        free(context[CONTEXT_COMM]);
        free(context[CONTEXT_EXE]);
        free(context[CONTEXT_UNIT]);

        return r;
}
static int process_backtrace(int argc, char *argv[]) {
        char *context[_CONTEXT_MAX] = {};
        _cleanup_free_ char *message = NULL;
        _cleanup_free_ struct iovec *iovec = NULL;
        size_t n_iovec, n_allocated, n_to_free = 0, i;
        int r;
        JournalImporter importer = {
                .fd = STDIN_FILENO,
        };

        log_debug("Processing backtrace on stdin...");

        if (argc < CONTEXT_COMM + 1)
                return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                       "Not enough arguments passed (%i, expected %i).",
                                       argc - 1, CONTEXT_COMM + 1 - 1);

        context[CONTEXT_PID]       = argv[2 + CONTEXT_PID];
        context[CONTEXT_UID]       = argv[2 + CONTEXT_UID];
        context[CONTEXT_GID]       = argv[2 + CONTEXT_GID];
        context[CONTEXT_SIGNAL]    = argv[2 + CONTEXT_SIGNAL];
        context[CONTEXT_TIMESTAMP] = argv[2 + CONTEXT_TIMESTAMP];
        context[CONTEXT_RLIMIT]    = argv[2 + CONTEXT_RLIMIT];
        context[CONTEXT_HOSTNAME]  = argv[2 + CONTEXT_HOSTNAME];

        n_allocated = 34 + COREDUMP_STORAGE_EXTERNAL;
         
        iovec = new(struct iovec, n_allocated);
        if (!iovec)
                return log_oom();

        r = gather_pid_metadata(context, argv + 2 + CONTEXT_COMM, iovec, &n_to_free);
        if (r < 0)
                goto finish;
        if (r > 0) {
                 
                r = 0;
                goto finish;
        }
        n_iovec = n_to_free;

        for (;;) {
                r = journal_importer_process_data(&importer);
                if (r < 0) {
                        log_error_errno(r, "Failed to parse journal entry on stdin: %m");
                        goto finish;
                }
                if (r == 1 ||                         
                    journal_importer_eof(&importer))  
                        break;
        }

        if (!GREEDY_REALLOC(iovec, n_allocated, n_iovec + importer.iovw.count + 2))
                return log_oom();

        if (journal_importer_eof(&importer)) {
                log_warning("Did not receive a full journal entry on stdin, ignoring message sent by reporter");

                message = strjoin("MESSAGE=Process ", context[CONTEXT_PID],
                                  " (", context[CONTEXT_COMM], ")"
                                  " of user ", context[CONTEXT_UID],
                                  " failed with ", context[CONTEXT_SIGNAL]);
                if (!message) {
                        r = log_oom();
                        goto finish;
                }
                iovec[n_iovec++] = IOVEC_MAKE_STRING(message);
        } else {
                for (i = 0; i < importer.iovw.count; i++)
                        iovec[n_iovec++] = importer.iovw.iovec[i];
        }

        iovec[n_iovec++] = IOVEC_MAKE_STRING("MESSAGE_ID=" SD_MESSAGE_BACKTRACE_STR);
        assert_cc(2 == LOG_CRIT);
        iovec[n_iovec++] = IOVEC_MAKE_STRING("PRIORITY=2");

        assert(n_iovec <= n_allocated);

        r = sd_journal_sendv(iovec, n_iovec);
        if (r < 0)
                log_error_errno(r, "Failed to log backtrace: %m");

 finish:
        for (i = 0; i < n_to_free; i++)
                free(iovec[i].iov_base);

         
        free(context[CONTEXT_COMM]);
        free(context[CONTEXT_EXE]);
        free(context[CONTEXT_UNIT]);

        return r;
}