Skip to content

Commit

Permalink
Merge pull request #80 from ejoerns/v0/topic/status-compatible
Browse files Browse the repository at this point in the history
main: show compatible in output of rauc status
  • Loading branch information
jluebbe committed Jan 25, 2017
2 parents 9a38740 + 2dff4f1 commit fe176eb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 34 deletions.
76 changes: 43 additions & 33 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,14 @@ static gboolean checksum_start(int argc, char **argv)

/* Takes a shell variable and its desired argument as input and appends it to
* the provided text with taking care of correct shell quoting */
static void info_formatter_shell_append(GString* text, const gchar* varname, const gchar* argument) {
static void formatter_shell_append(GString* text, const gchar* varname, const gchar* argument) {
gchar* quoted = g_shell_quote (argument ?: "");
g_string_append_printf(text, "%s=%s\n", varname, quoted);
g_clear_pointer(&quoted, g_free);
}
/* Same as above, expect that it has a cnt argument to add per-slot-number
* strings */
static void info_formatter_shell_append_n(GString* text, const gchar* varname, gint cnt, const gchar* argument) {
static void formatter_shell_append_n(GString* text, const gchar* varname, gint cnt, const gchar* argument) {
gchar* quoted = g_shell_quote (argument ?: "");
g_string_append_printf(text, "%s_%d=%s\n", varname, cnt, quoted);
g_clear_pointer(&quoted, g_free);
Expand All @@ -289,10 +289,10 @@ static gchar *info_formatter_shell(RaucManifest *manifest)
gchar *hookstring = NULL;
gint cnt;

info_formatter_shell_append(text, "RAUC_MF_COMPATIBLE", manifest->update_compatible);
info_formatter_shell_append(text, "RAUC_MF_VERSION", manifest->update_version ?: "");
info_formatter_shell_append(text, "RAUC_MF_DESCRIPTION", manifest->update_description);
info_formatter_shell_append(text, "RAUC_MF_BUILD", manifest->update_build);
formatter_shell_append(text, "RAUC_MF_COMPATIBLE", manifest->update_compatible);
formatter_shell_append(text, "RAUC_MF_VERSION", manifest->update_version);
formatter_shell_append(text, "RAUC_MF_DESCRIPTION", manifest->update_description);
formatter_shell_append(text, "RAUC_MF_BUILD", manifest->update_build);
g_string_append_printf(text, "RAUC_MF_IMAGES=%d\n", g_list_length(manifest->images));
g_string_append_printf(text, "RAUC_MF_FILES=%d\n", g_list_length(manifest->files));

Expand All @@ -303,17 +303,17 @@ static gchar *info_formatter_shell(RaucManifest *manifest)
g_ptr_array_add(hooks, NULL);

hookstring = g_strjoinv(" ", (gchar**) hooks->pdata);
info_formatter_shell_append(text, "RAUC_MF_HOOKS", hookstring);
formatter_shell_append(text, "RAUC_MF_HOOKS", hookstring);
g_free(hookstring);

g_ptr_array_unref(hooks);

cnt = 0;
for (GList *l = manifest->images; l != NULL; l = l->next) {
RaucImage *img = l->data;
info_formatter_shell_append_n(text, "RAUC_IMAGE_NAME", cnt, img->filename);
info_formatter_shell_append_n(text, "RAUC_IMAGE_CLASS", cnt, img->slotclass);
info_formatter_shell_append_n(text, "RAUC_IMAGE_DIGEST", cnt, img->checksum.digest);
formatter_shell_append_n(text, "RAUC_IMAGE_NAME", cnt, img->filename);
formatter_shell_append_n(text, "RAUC_IMAGE_CLASS", cnt, img->slotclass);
formatter_shell_append_n(text, "RAUC_IMAGE_DIGEST", cnt, img->checksum.digest);
g_string_append_printf(text, "RAUC_IMAGE_SIZE_%d=%"G_GSIZE_FORMAT"\n", cnt, img->checksum.size);

hooks = g_ptr_array_new();
Expand All @@ -329,7 +329,7 @@ static gchar *info_formatter_shell(RaucManifest *manifest)
g_ptr_array_add(hooks, NULL);

hookstring = g_strjoinv(" ", (gchar**) hooks->pdata);
info_formatter_shell_append_n(text, "RAUC_IMAGE_HOOKS", cnt, hookstring);
formatter_shell_append_n(text, "RAUC_IMAGE_HOOKS", cnt, hookstring);
g_free(hookstring);

g_ptr_array_unref(hooks);
Expand Down Expand Up @@ -612,6 +612,7 @@ static gchar* r_status_formatter_readable(void)
gint slotcnt = 0;
GString *text = g_string_new(NULL);

g_string_append_printf(text, "Compatible: %s\n", r_context()->config->system_compatible);
g_string_append_printf(text, "booted from: %s\n", get_bootname());

g_string_append(text, "slot states:\n");
Expand Down Expand Up @@ -645,45 +646,51 @@ static gchar* r_status_formatter_shell(void)
{
GHashTableIter iter;
gpointer key, value;
gchar *slotlist = NULL;
gchar *tmp = NULL;
gint slotcnt = 0;
GString *text = g_string_new(NULL);
GPtrArray *slotnames, *slotnumbers = NULL;
gchar* slotstring = NULL;

g_string_append_printf(text, "RAUC_SYSTEM_BOOTED_BOOTNAME=%s\n", get_bootname());
formatter_shell_append(text, "RAUC_SYSTEM_COMPATIBLE", r_context()->config->system_compatible);
formatter_shell_append(text, "RAUC_SYSTEM_BOOTED_BOOTNAME", get_bootname());

g_string_append(text, "RAUC_SYSTEM_SLOTS=");
slotnames = g_ptr_array_new();
slotnumbers = g_ptr_array_new();
g_hash_table_iter_init(&iter, r_context()->config->slots);
while (g_hash_table_iter_next(&iter, &key, &value)) {
gchar *name = key;
g_string_append(text, name);
g_string_append_c(text, ' ');
g_ptr_array_add(slotnames, (gchar*) key);
g_ptr_array_add(slotnumbers, g_strdup_printf("%i", ++slotcnt));
}
g_string_append_c(text, '\n');
g_ptr_array_add(slotnames, NULL);
g_ptr_array_add(slotnumbers, NULL);

slotstring = g_strjoinv(" ", (gchar**) slotnames->pdata);
formatter_shell_append(text, "RAUC_SYSTEM_SLOTS", slotstring);
g_free(slotstring);
slotstring = g_strjoinv(" ", (gchar**) slotnumbers->pdata);
formatter_shell_append(text, "RAUC_SLOTS", slotstring);
g_free(slotstring);

g_ptr_array_unref(slotnumbers);
g_ptr_array_unref(slotnames);

slotcnt = 0;
g_hash_table_iter_init(&iter, r_context()->config->slots);
while (g_hash_table_iter_next(&iter, &key, &value)) {
RaucSlot *slot = value;

slotcnt++;


g_string_append_printf(text, "RAUC_SLOT_STATE_%d=%s\n", slotcnt, slotstate_to_str(slot->state));
g_string_append_printf(text, "RAUC_SLOT_CLASS_%d=%s\n", slotcnt, slot->sclass);
g_string_append_printf(text, "RAUC_SLOT_DEVICE_%d=%s\n", slotcnt, slot->device);
g_string_append_printf(text, "RAUC_SLOT_TYPE_%d=%s\n", slotcnt, slot->type);
g_string_append_printf(text, "RAUC_SLOT_BOOTNAME_%d=%s\n", slotcnt, slot->bootname);
g_string_append_printf(text, "RAUC_SLOT_PARENT_%d=%s\n", slotcnt, slot->parent ? slot->parent->name : "(none)");
g_string_append_printf(text, "RAUC_SLOT_MOUNTPOINT_%d=%s\n", slotcnt, slot->mount_point ? slot->mount_point : "(none)");

tmp = g_strdup_printf("%s%i ", slotlist ? slotlist : "", slotcnt);
g_clear_pointer(&slotlist, g_free);
slotlist = tmp;

formatter_shell_append_n(text, "RAUC_SLOT_STATE", slotcnt, slotstate_to_str(slot->state));
formatter_shell_append_n(text, "RAUC_SLOT_CLASS", slotcnt, slot->sclass);
formatter_shell_append_n(text, "RAUC_SLOT_DEVICE", slotcnt, slot->device);
formatter_shell_append_n(text, "RAUC_SLOT_TYPE", slotcnt, slot->type);
formatter_shell_append_n(text, "RAUC_SLOT_BOOTNAME", slotcnt, slot->bootname);
formatter_shell_append_n(text, "RAUC_SLOT_PARENT", slotcnt, slot->parent ? slot->parent->name : NULL);
formatter_shell_append_n(text, "RAUC_SLOT_MOUNTPOINT", slotcnt, slot->mount_point);
}

g_string_append_printf(text, "RAUC_SLOTS=%s\n", slotlist);

return g_string_free(text, FALSE);
}

Expand All @@ -699,6 +706,9 @@ static gchar* r_status_formatter_json(gboolean pretty)

json_builder_begin_object (builder);

json_builder_set_member_name (builder, "compatible");
json_builder_add_string_value (builder, r_context()->config->system_compatible);

json_builder_set_member_name (builder, "booted");
json_builder_add_string_value (builder, get_bootname());

Expand Down
3 changes: 2 additions & 1 deletion test/rauc.t
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ test_expect_success "rauc status readable" "
"

test_expect_success "rauc status shell" "
rauc -c $SHARNESS_TEST_DIRECTORY/test-temp.conf status --output-format=shell
rauc -c $SHARNESS_TEST_DIRECTORY/test-temp.conf status --output-format=shell \
| sh
"

test_expect_success JSON "rauc status json" "
Expand Down

0 comments on commit fe176eb

Please sign in to comment.