| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include "sd-json.h" |
| 4 |
|
| 5 |
#include "json-util.h" |
| 6 |
#include "mount.h" |
| 7 |
#include "user-util.h" |
| 8 |
#include "varlink-common.h" |
| 9 |
#include "varlink-mount.h" |
| 10 |
|
| 11 |
int mount_context_build_json(sd_json_variant **ret, const char *name, void *userdata) { |
| 12 |
Mount *m = ASSERT_PTR(MOUNT(userdata)); |
| 13 |
_cleanup_free_ char *what = NULL, *where = NULL, *options = NULL; |
| 14 |
|
| 15 |
what = mount_get_what_escaped(m); |
| 16 |
if (!what) |
| 17 |
return -ENOMEM; |
| 18 |
|
| 19 |
where = mount_get_where_escaped(m); |
| 20 |
if (!where) |
| 21 |
return -ENOMEM; |
| 22 |
|
| 23 |
options = mount_get_options_escaped(m); |
| 24 |
if (!options) |
| 25 |
return -ENOMEM; |
| 26 |
|
| 27 |
return sd_json_buildo( |
| 28 |
ASSERT_PTR(ret), |
| 29 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("What", what), |
| 30 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("Where", where), |
| 31 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("Type", mount_get_fstype(m)), |
| 32 |
JSON_BUILD_PAIR_STRING_NON_EMPTY("Options", options), |
| 33 |
SD_JSON_BUILD_PAIR_BOOLEAN("SloppyOptions", m->sloppy_options), |
| 34 |
SD_JSON_BUILD_PAIR_BOOLEAN("LazyUnmount", m->lazy_unmount), |
| 35 |
SD_JSON_BUILD_PAIR_BOOLEAN("ReadWriteOnly", m->read_write_only), |
| 36 |
SD_JSON_BUILD_PAIR_BOOLEAN("ForceUnmount", m->force_unmount), |
| 37 |
SD_JSON_BUILD_PAIR_UNSIGNED("DirectoryMode", m->directory_mode), |
| 38 |
JSON_BUILD_PAIR_FINITE_USEC("TimeoutUSec", m->timeout_usec), |
| 39 |
JSON_BUILD_PAIR_CALLBACK_NON_NULL("ExecMount", exec_command_build_json, &m->exec_command[MOUNT_EXEC_MOUNT]), |
| 40 |
JSON_BUILD_PAIR_CALLBACK_NON_NULL("ExecUnmount", exec_command_build_json, &m->exec_command[MOUNT_EXEC_UNMOUNT]), |
| 41 |
JSON_BUILD_PAIR_CALLBACK_NON_NULL("ExecRemount", exec_command_build_json, &m->exec_command[MOUNT_EXEC_REMOUNT])); |
| 42 |
} |
| 43 |
|
| 44 |
int mount_runtime_build_json(sd_json_variant **ret, const char *name, void *userdata) { |
| 45 |
Unit *u = ASSERT_PTR(userdata); |
| 46 |
Mount *m = ASSERT_PTR(MOUNT(u)); |
| 47 |
return sd_json_buildo( |
| 48 |
ASSERT_PTR(ret), |
| 49 |
SD_JSON_BUILD_PAIR_CONDITION(pidref_is_set(&m->control_pid), "ControlPID", JSON_BUILD_PIDREF(&m->control_pid)), |
| 50 |
JSON_BUILD_PAIR_ENUM("Result", mount_result_to_string(m->result)), |
| 51 |
JSON_BUILD_PAIR_ENUM("ReloadResult", mount_result_to_string(m->reload_result)), |
| 52 |
JSON_BUILD_PAIR_ENUM("CleanResult", mount_result_to_string(m->clean_result)), |
| 53 |
SD_JSON_BUILD_PAIR_CONDITION(uid_is_valid(u->ref_uid), "UID", SD_JSON_BUILD_UNSIGNED(u->ref_uid)), |
| 54 |
SD_JSON_BUILD_PAIR_CONDITION(gid_is_valid(u->ref_gid), "GID", SD_JSON_BUILD_UNSIGNED(u->ref_gid))); |
| 55 |
} |