HALF ECHO LEARN / REFERENCE COLLECTION

v262.2

src/journal/journalctl.c

47,020 bytesGit mode 100644Download original fileLGPL-2.1-or-later

Git blob: 2023e3bf287919620697d269e934e8fe0077c5f1

Lines 1001–1140 of 1,140

static int run(int argc, char *argv[]) {
        _cleanup_(loop_device_unrefp) LoopDevice *loop_device = NULL;
        _cleanup_(umount_and_freep) char *mounted_dir = NULL;
        _cleanup_strv_free_ char **args = NULL;
        int r;
 
        COMPRESS_JOURNAL_NOTE;
        LIBACL_NOTE(recommended);
        LIBBLKID_NOTE(recommended);
        LIBCRYPTO_NOTE(recommended);
        LIBCRYPTSETUP_NOTE(suggested);
        LIBMOUNT_NOTE(recommended);
        LIBPCRE2_NOTE(suggested);
        LIBQRENCODE_NOTE(suggested);
 
        setlocale(LC_ALL, "");
        log_setup();
 
        r = parse_argv(argc, argv, &args);
        if (r <= 0)
                return r;
 
        if (arg_varlink)
                return vl_server();
 
        if (arg_image) {
                assert(!arg_root);
 
                r = mount_image_privately_interactively(
                                arg_image,
                                arg_image_policy,
                                DISSECT_IMAGE_GENERIC_ROOT |
                                DISSECT_IMAGE_REQUIRE_ROOT |
                                DISSECT_IMAGE_VALIDATE_OS |
                                DISSECT_IMAGE_RELAX_VAR_CHECK |
                                (arg_action == ACTION_UPDATE_CATALOG ? DISSECT_IMAGE_FSCK|DISSECT_IMAGE_GROWFS : DISSECT_IMAGE_READ_ONLY) |
                                DISSECT_IMAGE_ALLOW_USERSPACE_VERITY,
                                &mounted_dir,
                                /* ret_dir_fd= */ NULL,
                                &loop_device);
                if (r < 0)
                        return r;
 
                arg_root = strdup(mounted_dir);
                if (!arg_root)
                        return log_oom();
        }
 
        switch (arg_action) {
 
        case ACTION_SHOW:
                return action_show(args);
 
        case ACTION_NEW_ID128:
                return id128_print_new(ID128_PRINT_PRETTY);
 
        case ACTION_SETUP_KEYS:
                return action_setup_keys();
 
        case ACTION_LIST_CATALOG:
        case ACTION_DUMP_CATALOG:
                return action_list_catalog(args);
 
        case ACTION_UPDATE_CATALOG:
                return action_update_catalog();
 
        case ACTION_PRINT_HEADER:
                return action_print_header();
 
        case ACTION_VERIFY:
                return action_verify();
 
        case ACTION_DISK_USAGE:
                return action_disk_usage();
 
        case ACTION_LIST_BOOTS:
                return action_list_boots();
 
        case ACTION_LIST_FIELDS:
                return action_list_fields();
 
        case ACTION_LIST_FIELD_NAMES:
                return action_list_field_names();
 
        case ACTION_LIST_INVOCATIONS:
                return action_list_invocations();
 
        case ACTION_LIST_NAMESPACES:
                return action_list_namespaces();
 
        case ACTION_FLUSH:
                return action_flush_to_var();
 
        case ACTION_SMART_RELINQUISH_VAR: {
                int root_mnt_id, log_mnt_id;
 
                /* Try to be smart about relinquishing access to /var/log/journal/ during shutdown:
                 * if it's on the same mount as the root file system there's no point in
                 * relinquishing access and we can leave journald write to it until the very last
                 * moment. */
 
                r = path_get_mnt_id("/", &root_mnt_id);
                if (r < 0)
                        log_debug_errno(r, "Failed to get root mount ID, ignoring: %m");
                else {
                        r = path_get_mnt_id("/var/log/journal/", &log_mnt_id);
                        if (r < 0)
                                log_debug_errno(r, "Failed to get journal directory mount ID, ignoring: %m");
                        else if (root_mnt_id == log_mnt_id) {
                                log_debug("/var/log/journal/ is on root file system, not relinquishing access to /var.");
                                return 0;
                        } else
                                log_debug("/var/log/journal/ is not on the root file system, relinquishing access to it.");
                }
 
                _fallthrough_;
        }
 
        case ACTION_RELINQUISH_VAR:
                return action_relinquish_var();
 
        case ACTION_SYNC:
                return action_sync();
 
        case ACTION_ROTATE:
                return action_rotate();
 
        case ACTION_VACUUM:
                return action_vacuum();
 
        case ACTION_ROTATE_AND_VACUUM:
                return action_rotate_and_vacuum();
 
        default:
                assert_not_reached();
        }
}
 
DEFINE_MAIN_FUNCTION(run);