]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
rfkill: Output in JSON format if -J is provided.
authorXing Guo <higuoxing@gmail.com>
Fri, 26 Dec 2025 12:25:54 +0000 (20:25 +0800)
committerXing Guo <higuoxing@gmail.com>
Fri, 26 Dec 2025 12:25:54 +0000 (20:25 +0800)
This patch teaches rfkill output in JSON format if -J is provided.

E.g.,

```
$ ./rfkill -J list
{
   "rfkilldevices": [
      {
         "id": 0,
         "type": "bluetooth",
         "device": "tpacpi_bluetooth_sw",
         "soft": "unblocked",
         "hard": "unblocked"
      },{
         "id": 1,
         "type": "wwan",
         "device": "tpacpi_wwan_sw",
         "soft": "unblocked",
         "hard": "unblocked"
      },{
         "id": 3,
         "type": "wlan",
         "device": "phy0",
         "soft": "unblocked",
         "hard": "unblocked"
      },{
         "id": 4,
         "type": "bluetooth",
         "device": "hci0",
         "soft": "unblocked",
         "hard": "unblocked"
      }
   ]
}

$ ./rfkill -J list bluetooth
{
   "rfkilldevices": [
      {
         "id": 0,
         "type": "bluetooth",
         "device": "tpacpi_bluetooth_sw",
         "soft": "unblocked",
         "hard": "unblocked"
      },{
         "id": 4,
         "type": "bluetooth",
         "device": "hci0",
         "soft": "unblocked",
         "hard": "unblocked"
      }
   ]
}
```

sys-utils/rfkill.c

index d1c38b0c0cb38436809abd06f6532cdc58aac676..88a8a9d4cd361fa30f209a7eff5a5e224234bfe7 100644 (file)
@@ -740,7 +740,7 @@ int main(int argc, char **argv)
                 * For backward compatibility we use old output format if
                 * "list" explicitly specified and --output not defined.
                 */
-               if (!outarg && act == ACT_LIST)
+               if (!outarg && !ctrl.json && act == ACT_LIST)
                        act = ACT_LIST_OLD;
        }