Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON output support #190

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

JSON output support #190

wants to merge 2 commits into from

Conversation

pvxe
Copy link

@pvxe pvxe commented Jul 28, 2023

(JSON output support has been discussed in the past. #70)

Add --json option to enable JSON output support when compiling efibootmgr with it.
This output is compact and intended to be fed to other programs that want to interface with efibootmgr.

To enable JSON support, simply compile with make ... JSON=1 compilation flag.

Adds a new optional dependency with libjansson.

If the user runs efibootmgr --json without json support being compiled, it will print the following message:

JSON support is not built-in

The rationale behind this change is that I'd like to avoid parsing textual output from efibootmgr.

As additional context for these changes: I'm working on the development of a python program used for remote management of computers. This python program needs to retrieve BootOrder, BootNext and the boot entries of the machine it's running on. The program runs an efibootmgr subprocess for such tasks.


Example:

./src/efibootmgr --json | python -m json.tool
{
    "BootCurrent": "000D",
    "Timeout": 1,
    "BootOrder": [
        "0000",
        "000D",
        "0001",
        "000F",
        "0010",
    ],
    "vars": [
        {
            "name": "Boot0000",
            "active": true,
            "description": "Windows Boot Manager"
        },
        {
            "name": "Boot0001",
            "active": true,
            "description": "UEFI iPXE"
        },
        {
            "name": "Boot000D",
            "active": true,
            "description": "UEFI OS"
        },
        {
            "name": "Boot000F",
            "active": true,
            "description": "UEFI: IP4 Qualcomm Atheros PCIe Network Controller"
        },
        {
            "name": "Boot0010",
            "active": true,
            "description": "UEFI: IP6 Qualcomm Atheros PCIe Network Controller"
        },
    ]
}

@pvxe
Copy link
Author

pvxe commented Feb 27, 2024

I've decided to temporarily revert commit 5ce076c, while issue #204 is still present.

I will rebase my changes as soon as a fix is pushed into efibootmgr tree or a new efivar release is pushed with rhboot/efivar#217 merged.

Make read_u16 and read_order available to call outside efibootmgr.c.

Make var_entry_t public to be used by other source files.

Prepare efibootmgr for JSON output support by making required utility
functions and types publicly available to other source files.

Signed-off-by: Jose M. Guisado <jguisado@soleta.eu>
Enable JSON output for efibootmgr. This provides an interface for third
party tools so they do not need to scrap the existing textual output.

This feature is optional and is enabled by using JSON=1 when compiling:

	make ... JSON=1

Add parameter '-j'/--json' to use JSON output. If efibootmgr is not
built with JSON output support it will print out this instead:

	"JSON support is not built-in"

This feature adds a new optional dependency with libjansson.

Signed-off-by: Jose M. Guisado <jguisado@soleta.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant