Add --progress-json parameter to utilities.

Progress data can now be printed out in json format
suitable for machine processing.
This commit is contained in:
Ondrej Kozina
2022-02-15 12:33:59 +01:00
parent 6852c49d0c
commit 3cd5d83ee9
13 changed files with 188 additions and 42 deletions

View File

@@ -1179,11 +1179,14 @@ static int _wipe_data_device(struct crypt_device *cd)
{
char tmp_name[64], tmp_path[128], tmp_uuid[40];
uuid_t tmp_uuid_bin;
int r;
int r = -EINVAL;
char *backing_file = NULL;
struct tools_progress_params prog_parms = {
.frequency = ARG_UINT32(OPT_PROGRESS_FREQUENCY_ID),
.batch_mode = ARG_SET(OPT_BATCH_MODE_ID),
.interrupt_message = _("\nWipe interrupted.")
.json_output = ARG_SET(OPT_PROGRESS_JSON_ID),
.interrupt_message = _("\nWipe interrupted."),
.device = tools_get_device_name(crypt_get_device_name(cd), &backing_file)
};
if (!ARG_SET(OPT_BATCH_MODE_ID))
@@ -1195,14 +1198,14 @@ static int _wipe_data_device(struct crypt_device *cd)
uuid_generate(tmp_uuid_bin);
uuid_unparse(tmp_uuid_bin, tmp_uuid);
if (snprintf(tmp_name, sizeof(tmp_name), "temporary-cryptsetup-%s", tmp_uuid) < 0)
return -EINVAL;
goto out;
if (snprintf(tmp_path, sizeof(tmp_path), "%s/%s", crypt_get_dir(), tmp_name) < 0)
return -EINVAL;
goto out;
r = crypt_activate_by_volume_key(cd, tmp_name, NULL, 0,
CRYPT_ACTIVATE_PRIVATE | CRYPT_ACTIVATE_NO_JOURNAL);
if (r < 0)
return r;
goto out;
/* Wipe the device */
set_int_handler(0);
@@ -1212,6 +1215,8 @@ static int _wipe_data_device(struct crypt_device *cd)
log_err(_("Cannot deactivate temporary device %s."), tmp_path);
set_int_block(0);
out:
free(backing_file);
return r;
}