Skip to content

Commit

Permalink
Merge pull request #49 from jluebbe/cleanup
Browse files Browse the repository at this point in the history
cleanup
  • Loading branch information
Enrico Jorns committed May 25, 2016
2 parents 15b74a2 + d792f30 commit 933db18
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 49 deletions.
4 changes: 2 additions & 2 deletions include/update_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

#include "manifest.h"

typedef gboolean (*img_to_fs_handler) (RaucImage *image, RaucSlot *dest_slot, GError **error);
typedef gboolean (*img_to_slot_handler) (RaucImage *image, RaucSlot *dest_slot, GError **error);

img_to_fs_handler get_update_handler(RaucImage *mfimage, RaucSlot *dest_slot, GError **error);
img_to_slot_handler get_update_handler(RaucImage *mfimage, RaucSlot *dest_slot, GError **error);
88 changes: 45 additions & 43 deletions src/install.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ gboolean determine_slot_states(GError **error) {
r_context_end_step("determine_slot_states", res);

return res;

}

/* Returns the inactive slots for a given slot class */
Expand Down Expand Up @@ -366,7 +365,6 @@ static void parse_handler_output(gchar* line) {
g_print("Unknown command: %s\n", split[1]);
}


out:
g_strfreev(split);
}
Expand All @@ -383,28 +381,18 @@ static gboolean verify_compatible(RaucManifest *manifest) {
}
}

static gboolean launch_and_wait_handler(gchar* update_source, gchar *handler_name, RaucManifest *manifest, GHashTable *target_group, GError **error) {
GSubprocessLauncher *handlelaunch = NULL;
GSubprocess *handleproc = NULL;
GError *ierror = NULL;
gboolean res = FALSE;
GInputStream *instream;
GDataInputStream *datainstream;
gchar* outline;

gchar *targetlist = NULL;
gchar *slotlist = NULL;
static void prepare_environment(GSubprocessLauncher *launcher, gchar *update_source, RaucManifest *manifest, GHashTable *target_group)
{
GHashTableIter iter;
RaucSlot *slot;
gint slotcnt = 0;
gchar *targetlist = NULL;
gchar *slotlist = NULL;


handlelaunch = g_subprocess_launcher_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_MERGE);

g_subprocess_launcher_setenv(handlelaunch, "RAUC_SYSTEM_CONFIG", r_context()->configpath, TRUE);
g_subprocess_launcher_setenv(handlelaunch, "RAUC_CURRENT_BOOTNAME", bootname_provider(), TRUE);
g_subprocess_launcher_setenv(handlelaunch, "RAUC_UPDATE_SOURCE", update_source, TRUE);
g_subprocess_launcher_setenv(handlelaunch, "RAUC_MOUNT_PREFIX", r_context()->config->mount_prefix, TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_SYSTEM_CONFIG", r_context()->configpath, TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_CURRENT_BOOTNAME", bootname_provider(), TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_UPDATE_SOURCE", update_source, TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_MOUNT_PREFIX", r_context()->config->mount_prefix, TRUE);

g_hash_table_iter_init(&iter, r_context()->config->slots);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&slot)) {
Expand All @@ -430,15 +418,15 @@ static gboolean launch_and_wait_handler(gchar* update_source, gchar *handler_nam
RaucImage *img = l->data;
if (g_str_equal(slot->sclass, img->slotclass)) {
varname = g_strdup_printf("RAUC_IMAGE_NAME_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, img->filename, TRUE);
g_subprocess_launcher_setenv(launcher, varname, img->filename, TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_IMAGE_DIGEST_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, img->checksum.digest, TRUE);
g_subprocess_launcher_setenv(launcher, varname, img->checksum.digest, TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_IMAGE_CLASS_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, img->slotclass, TRUE);
g_subprocess_launcher_setenv(launcher, varname, img->slotclass, TRUE);
g_clear_pointer(&varname, g_free);

break;
Expand All @@ -448,39 +436,57 @@ static gboolean launch_and_wait_handler(gchar* update_source, gchar *handler_nam
tmp = g_strdup_printf("%s%i ", targetlist ? targetlist : "", slotcnt);
g_clear_pointer(&targetlist, g_free);
targetlist = tmp;

}

varname = g_strdup_printf("RAUC_SLOT_NAME_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, slot->name, TRUE);
g_subprocess_launcher_setenv(launcher, varname, slot->name, TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_SLOT_CLASS_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, slot->sclass, TRUE);
g_subprocess_launcher_setenv(launcher, varname, slot->sclass, TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_SLOT_DEVICE_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, slot->device, TRUE);
g_subprocess_launcher_setenv(launcher, varname, slot->device, TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_SLOT_BOOTNAME_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, slot->bootname ? slot->bootname : "", TRUE);
g_subprocess_launcher_setenv(launcher, varname, slot->bootname ? slot->bootname : "", TRUE);
g_clear_pointer(&varname, g_free);

varname = g_strdup_printf("RAUC_SLOT_PARENT_%i", slotcnt);
g_subprocess_launcher_setenv(handlelaunch, varname, slot->parent ? slot->parent->name : "", TRUE);
g_subprocess_launcher_setenv(launcher, varname, slot->parent ? slot->parent->name : "", TRUE);
g_clear_pointer(&varname, g_free);

}

g_subprocess_launcher_setenv(handlelaunch, "RAUC_SLOTS", slotlist, TRUE);
g_subprocess_launcher_setenv(handlelaunch, "RAUC_TARGET_SLOTS", targetlist, TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_SLOTS", slotlist, TRUE);
g_subprocess_launcher_setenv(launcher, "RAUC_TARGET_SLOTS", targetlist, TRUE);
g_clear_pointer(&targetlist, g_free);
g_clear_pointer(&slotlist, g_free);
}

static gboolean launch_and_wait_handler(gchar *update_source, gchar *handler_name, RaucManifest *manifest, GHashTable *target_group, GError **error) {
GSubprocessLauncher *handlelaunch = NULL;
GSubprocess *handleproc = NULL;
GError *ierror = NULL;
gboolean res = FALSE;
GInputStream *instream = NULL;
GDataInputStream *datainstream = NULL;
gchar *outline;

handlelaunch = g_subprocess_launcher_new(G_SUBPROCESS_FLAGS_STDOUT_PIPE | G_SUBPROCESS_FLAGS_STDERR_MERGE);

prepare_environment(handlelaunch, update_source, manifest, target_group);

handleproc = g_subprocess_launcher_spawn(
handlelaunch,
&ierror, handler_name,
handlelaunch, &ierror,
handler_name,
manifest->handler_args,
NULL);
if (handleproc == NULL) {
g_propagate_error(error, ierror);
goto out;
}

instream = g_subprocess_get_stdout_pipe(handleproc);
datainstream = g_data_input_stream_new(instream);
Expand All @@ -493,12 +499,6 @@ static gboolean launch_and_wait_handler(gchar* update_source, gchar *handler_nam
parse_handler_output(outline);
} while (outline);


if (handleproc == NULL) {
g_propagate_error(error, ierror);
goto out;
}

res = g_subprocess_wait_check(handleproc, NULL, &ierror);
if (!res) {
g_propagate_error(error, ierror);
Expand All @@ -508,6 +508,8 @@ static gboolean launch_and_wait_handler(gchar* update_source, gchar *handler_nam
res = TRUE;

out:
g_clear_pointer(&handlelaunch, g_object_unref);
g_clear_pointer(&handleproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -572,7 +574,7 @@ static gboolean launch_and_wait_default_handler(RaucInstallArgs *args, gchar* bu
GFile *destdevicefile = NULL;
gchar *slotstatuspath = NULL;
RaucSlotStatus *slot_state = NULL;
img_to_fs_handler update_handler = NULL;
img_to_slot_handler update_handler = NULL;

mfimage = l->data;
dest_slot = g_hash_table_lookup(target_group, mfimage->slotclass);
Expand Down Expand Up @@ -820,7 +822,6 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
}
}


// for slot in target_group
g_hash_table_iter_init(&iter, target_group);
while (g_hash_table_iter_next(&iter, NULL, (gpointer *)&slot)) {
Expand Down Expand Up @@ -923,6 +924,7 @@ static gboolean launch_and_wait_network_handler(const gchar* base_url,
}

res = TRUE;

out:
return res;
}
Expand Down Expand Up @@ -1035,12 +1037,12 @@ gboolean do_install_bundle(RaucInstallArgs *args, GError **error) {
umount_bundle(mountpoint, NULL);
g_rmdir(mountpoint);
g_clear_pointer(&mountpoint, g_free);

out:
g_clear_pointer(&manifest, free_manifest);
r_context_end_step("do_install_bundle", res);

return res;

}

gboolean do_install_network(const gchar *url) {
Expand Down
11 changes: 8 additions & 3 deletions src/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ static gboolean ubifs_format_slot(RaucSlot *dest_slot, GError **error)

out:
g_ptr_array_unref(args);
g_clear_pointer(&sproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -171,6 +172,7 @@ static gboolean ext4_format_slot(RaucSlot *dest_slot, GError **error)

out:
g_ptr_array_unref(args);
g_clear_pointer(&sproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -209,6 +211,7 @@ static gboolean nand_format_slot(const gchar *device, GError **error)

out:
g_ptr_array_unref(args);
g_clear_pointer(&sproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -247,6 +250,7 @@ static gboolean nand_write_slot(const gchar *image, const gchar *device, GError

out:
g_ptr_array_unref(args);
g_clear_pointer(&sproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -285,6 +289,7 @@ static gboolean untar_image(RaucImage *image, gchar *dest, GError **error)

out:
g_ptr_array_unref(args);
g_clear_pointer(&sproc, g_object_unref);
return res;
}

Expand Down Expand Up @@ -461,7 +466,7 @@ static gboolean img_to_raw_handler(RaucImage *image, RaucSlot *dest_slot, GError
typedef struct {
const gchar *src;
const gchar *dest;
img_to_fs_handler handler;
img_to_slot_handler handler;
} RaucUpdatePair;

RaucUpdatePair updatepairs[] = {
Expand All @@ -476,11 +481,11 @@ RaucUpdatePair updatepairs[] = {
{0}
};

img_to_fs_handler get_update_handler(RaucImage *mfimage, RaucSlot *dest_slot, GError **error)
img_to_slot_handler get_update_handler(RaucImage *mfimage, RaucSlot *dest_slot, GError **error)
{
const gchar *src = mfimage->filename;
const gchar *dest = dest_slot->type;
img_to_fs_handler handler = NULL;
img_to_slot_handler handler = NULL;

g_message("Checking image type for slot type: %s", dest);

Expand Down
2 changes: 1 addition & 1 deletion test/update_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ static void test_get_update_handler(UpdateHandlerFixture *fixture, gconstpointer
{
RaucImage *image;
RaucSlot *targetslot;
img_to_fs_handler handler;
img_to_slot_handler handler;
UpdateHandlerTestPair *test_pair = (UpdateHandlerTestPair*) user_data;

image = g_new0(RaucImage, 1);
Expand Down

0 comments on commit 933db18

Please sign in to comment.