/* umockdev-run.c generated by valac 0.56.19, the Vala compiler
 * generated from umockdev-run.vala, do not modify */

#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include <stdio.h>
#include "config.h"
#include "umockdev-utils.h"
#include "umockdev.h"
#include <glib/gstdio.h>
#include <sys/socket.h>
#include <sys/wait.h>
#include <signal.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif
#if !defined(VALA_EXTERN)
#if defined(_MSC_VER)
#define VALA_EXTERN __declspec(dllexport) extern
#elif __GNUC__ >= 4
#define VALA_EXTERN __attribute__((visibility("default"))) extern
#else
#define VALA_EXTERN extern
#endif
#endif

#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
#define _g_option_context_free0(var) ((var == NULL) ? NULL : (var = (g_option_context_free (var), NULL)))
#define _g_free0(var) (var = (g_free (var), NULL))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_main_loop_unref0(var) ((var == NULL) ? NULL : (var = (g_main_loop_unref (var), NULL)))

VALA_EXTERN gchar** opt_device;
gchar** opt_device = NULL;
VALA_EXTERN gchar** opt_ioctl;
gchar** opt_ioctl = NULL;
VALA_EXTERN gchar** opt_pcap;
gchar** opt_pcap = NULL;
VALA_EXTERN gchar** opt_script;
gchar** opt_script = NULL;
VALA_EXTERN gchar** opt_unix_stream;
gchar** opt_unix_stream = NULL;
VALA_EXTERN gchar** opt_evemu_events;
gchar** opt_evemu_events = NULL;
VALA_EXTERN gchar** opt_program;
gchar** opt_program = NULL;
VALA_EXTERN gboolean opt_version;
gboolean opt_version = FALSE;
VALA_EXTERN GMainLoop* loop;
GMainLoop* loop = NULL;
VALA_EXTERN GPid child_pid;
GPid child_pid = 0;
VALA_EXTERN gint child_status;
gint child_status = 0;

VALA_EXTERN void child_watch_cb (GPid pid,
                     gint status);
static gint _vala_main (gchar** args,
                 gint args_length1);
static void _child_watch_cb_gchild_watch_func (GPid pid,
                                        gint wait_status,
                                        gpointer self);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);

const GOptionEntry options[9] = {{"device", 'd', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_device, "Load an umockdev-record device description into the testbed. Can be sp" \
"ecified multiple times.", "filename"}, {"ioctl", 'i', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_ioctl, "Load an umockdev-record ioctl dump into the testbed. Can be specified " \
"multiple times.", "devname=ioctlfilename"}, {"pcap", 'p', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_pcap, "Load an pcap/pcapng USB dump into the testbed. Can be specified multip" \
"le times.", "sysfs=pcapfilename"}, {"script", 's', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_script, "Load an umockdev-record script into the testbed. Can be specified mult" \
"iple times.", "devname=scriptfilename"}, {"unix-stream", 'u', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_unix_stream, "Load an umockdev-record script for a mocked Unix stream socket. Can be" \
" specified multiple times.", "socket_path=scriptfilename"}, {"evemu-events", 'e', (gint) 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_evemu_events, "Load an evemu .events file into the testbed. Can be specified multiple" \
" times.", "devname=eventsfilename"}, {"", (gchar) 0, (gint) 0, G_OPTION_ARG_STRING_ARRAY, &opt_program, "", ""}, {"version", (gchar) 0, (gint) 0, G_OPTION_ARG_NONE, &opt_version, "Output version information and exit"}, {NULL}};

void
child_watch_cb (GPid pid,
                gint status)
{
	GMainLoop* _tmp0_;
	child_status = status;
	_tmp0_ = loop;
	g_main_loop_quit (_tmp0_);
}

static void
_child_watch_cb_gchild_watch_func (GPid pid,
                                   gint wait_status,
                                   gpointer self)
{
	child_watch_cb (pid, wait_status);
}

static gint
_vala_main (gchar** args,
            gint args_length1)
{
	GOptionContext* oc = NULL;
	GOptionContext* _tmp0_;
	GOptionContext* _tmp1_;
	GOptionContext* _tmp2_;
	gchar* preload = NULL;
	const gchar* _tmp10_;
	gchar* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp16_;
	gchar* _tmp17_;
	gchar* _tmp18_;
	UMockdevTestbed* testbed = NULL;
	UMockdevTestbed* _tmp19_;
	gchar** _tmp20_;
	gint _tmp20__length1;
	gchar** _tmp36_;
	gint _tmp36__length1;
	gchar** _tmp56_;
	gint _tmp56__length1;
	gchar** _tmp76_;
	gint _tmp76__length1;
	gchar** _tmp96_;
	gint _tmp96__length1;
	gchar** _tmp116_;
	gint _tmp116__length1;
	gchar** _tmp136_;
	gint _tmp136__length1;
	GMainLoop* _tmp138_;
	GMainLoop* _tmp145_;
	GError* _inner_error0_ = NULL;
	gint result;
	_tmp0_ = g_option_context_new ("-- program [args..]");
	oc = _tmp0_;
	_tmp1_ = oc;
	g_option_context_set_summary (_tmp1_, "Run a program under an umockdev testbed.");
	_tmp2_ = oc;
	g_option_context_add_main_entries (_tmp2_, options, NULL);
	{
		GOptionContext* _tmp3_;
		_tmp3_ = oc;
		g_option_context_parse (_tmp3_, (gint*) (&args_length1), &args, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch0_g_error;
		}
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		FILE* _tmp4_;
		GError* _tmp5_;
		const gchar* _tmp6_;
		const gchar* _tmp7_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp4_ = stderr;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		_tmp7_ = args[0];
		fprintf (_tmp4_, "Error: %s\nRun %s --help for how to use this program\n", _tmp6_, _tmp7_);
		result = 1;
		_g_error_free0 (e);
		_g_option_context_free0 (oc);
		return result;
	}
	__finally0:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp8_ = -1;
		_g_option_context_free0 (oc);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp8_;
	}
	if (opt_version) {
		FILE* _tmp9_;
		_tmp9_ = stdout;
		fprintf (_tmp9_, "%s\n", VERSION);
		result = 0;
		_g_option_context_free0 (oc);
		return result;
	}
	_tmp10_ = g_getenv ("LD_PRELOAD");
	_tmp11_ = g_strdup (_tmp10_);
	preload = _tmp11_;
	_tmp12_ = preload;
	if (_tmp12_ == NULL) {
		gchar* _tmp13_;
		_tmp13_ = g_strdup ("");
		_g_free0 (preload);
		preload = _tmp13_;
	} else {
		const gchar* _tmp14_;
		gchar* _tmp15_;
		_tmp14_ = preload;
		_tmp15_ = g_strconcat (_tmp14_, ":", NULL);
		_g_free0 (preload);
		preload = _tmp15_;
	}
	_tmp16_ = preload;
	_tmp17_ = g_strconcat (_tmp16_, "libumockdev-preload.so.0", NULL);
	_tmp18_ = _tmp17_;
	umockdev_utils_checked_setenv ("LD_PRELOAD", _tmp18_);
	_g_free0 (_tmp18_);
	_tmp19_ = umockdev_testbed_new ();
	testbed = _tmp19_;
	_tmp20_ = opt_device;
	_tmp20__length1 = _vala_array_length (opt_device);
	{
		gchar** path_collection = NULL;
		gint path_collection_length1 = 0;
		gint _path_collection_size_ = 0;
		gint path_it = 0;
		path_collection = _tmp20_;
		path_collection_length1 = _tmp20__length1;
		for (path_it = 0; path_it < path_collection_length1; path_it = path_it + 1) {
			gchar* _tmp21_;
			gchar* path = NULL;
			_tmp21_ = g_strdup (path_collection[path_it]);
			path = _tmp21_;
			{
				gchar* record = NULL;
				{
					const gchar* _tmp22_;
					gchar* _tmp23_ = NULL;
					_tmp22_ = path;
					g_file_get_contents (_tmp22_, &_tmp23_, NULL, &_inner_error0_);
					_g_free0 (record);
					record = _tmp23_;
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch1_g_error;
					}
				}
				goto __finally1;
				__catch1_g_error:
				{
					GError* e = NULL;
					FILE* _tmp24_;
					const gchar* _tmp25_;
					GError* _tmp26_;
					const gchar* _tmp27_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp24_ = stderr;
					_tmp25_ = path;
					_tmp26_ = e;
					_tmp27_ = _tmp26_->message;
					fprintf (_tmp24_, "Error: Cannot open %s: %s\n", _tmp25_, _tmp27_);
					result = 1;
					_g_error_free0 (e);
					_g_free0 (record);
					_g_free0 (path);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally1:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp28_ = -1;
					_g_free0 (record);
					_g_free0 (path);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp28_;
				}
				{
					UMockdevTestbed* _tmp29_;
					const gchar* _tmp30_;
					_tmp29_ = testbed;
					_tmp30_ = record;
					umockdev_testbed_add_from_string (_tmp29_, _tmp30_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch2_g_error;
					}
				}
				goto __finally2;
				__catch2_g_error:
				{
					GError* e = NULL;
					FILE* _tmp31_;
					const gchar* _tmp32_;
					GError* _tmp33_;
					const gchar* _tmp34_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp31_ = stderr;
					_tmp32_ = path;
					_tmp33_ = e;
					_tmp34_ = _tmp33_->message;
					fprintf (_tmp31_, "Error: Invalid record file %s: %s\n", _tmp32_, _tmp34_);
					result = 1;
					_g_error_free0 (e);
					_g_free0 (record);
					_g_free0 (path);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally2:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp35_ = -1;
					_g_free0 (record);
					_g_free0 (path);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp35_;
				}
				_g_free0 (record);
				_g_free0 (path);
			}
		}
	}
	_tmp36_ = opt_ioctl;
	_tmp36__length1 = _vala_array_length (opt_ioctl);
	{
		gchar** i_collection = NULL;
		gint i_collection_length1 = 0;
		gint _i_collection_size_ = 0;
		gint i_it = 0;
		i_collection = _tmp36_;
		i_collection_length1 = _tmp36__length1;
		for (i_it = 0; i_it < i_collection_length1; i_it = i_it + 1) {
			gchar* _tmp37_;
			gchar* i = NULL;
			_tmp37_ = g_strdup (i_collection[i_it]);
			i = _tmp37_;
			{
				gchar** parts = NULL;
				const gchar* _tmp38_;
				gchar** _tmp39_;
				gchar** _tmp40_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp41_;
				gint _tmp41__length1;
				_tmp38_ = i;
				_tmp40_ = _tmp39_ = g_strsplit (_tmp38_, "=", 2);
				parts = _tmp40_;
				parts_length1 = _vala_array_length (_tmp39_);
				_parts_size_ = parts_length1;
				_tmp41_ = parts;
				_tmp41__length1 = parts_length1;
				if (_tmp41__length1 != 2) {
					FILE* _tmp42_;
					_tmp42_ = stderr;
					fprintf (_tmp42_, "Error: --ioctl argument must be devname=filename\n");
					result = 1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				{
					UMockdevTestbed* _tmp43_;
					gchar** _tmp44_;
					gint _tmp44__length1;
					const gchar* _tmp45_;
					gchar** _tmp46_;
					gint _tmp46__length1;
					const gchar* _tmp47_;
					_tmp43_ = testbed;
					_tmp44_ = parts;
					_tmp44__length1 = parts_length1;
					_tmp45_ = _tmp44_[0];
					_tmp46_ = parts;
					_tmp46__length1 = parts_length1;
					_tmp47_ = _tmp46_[1];
					umockdev_testbed_load_ioctl (_tmp43_, _tmp45_, _tmp47_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch3_g_error;
					}
				}
				goto __finally3;
				__catch3_g_error:
				{
					GError* e = NULL;
					FILE* _tmp48_;
					gchar** _tmp49_;
					gint _tmp49__length1;
					const gchar* _tmp50_;
					gchar** _tmp51_;
					gint _tmp51__length1;
					const gchar* _tmp52_;
					GError* _tmp53_;
					const gchar* _tmp54_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp48_ = stderr;
					_tmp49_ = parts;
					_tmp49__length1 = parts_length1;
					_tmp50_ = _tmp49_[1];
					_tmp51_ = parts;
					_tmp51__length1 = parts_length1;
					_tmp52_ = _tmp51_[0];
					_tmp53_ = e;
					_tmp54_ = _tmp53_->message;
					fprintf (_tmp48_, "Error: Cannot install %s for device %s: %s\n", _tmp50_, _tmp52_, _tmp54_);
					result = 1;
					_g_error_free0 (e);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally3:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp55_ = -1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp55_;
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (i);
			}
		}
	}
	_tmp56_ = opt_pcap;
	_tmp56__length1 = _vala_array_length (opt_pcap);
	{
		gchar** i_collection = NULL;
		gint i_collection_length1 = 0;
		gint _i_collection_size_ = 0;
		gint i_it = 0;
		i_collection = _tmp56_;
		i_collection_length1 = _tmp56__length1;
		for (i_it = 0; i_it < i_collection_length1; i_it = i_it + 1) {
			gchar* _tmp57_;
			gchar* i = NULL;
			_tmp57_ = g_strdup (i_collection[i_it]);
			i = _tmp57_;
			{
				gchar** parts = NULL;
				const gchar* _tmp58_;
				gchar** _tmp59_;
				gchar** _tmp60_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp61_;
				gint _tmp61__length1;
				_tmp58_ = i;
				_tmp60_ = _tmp59_ = g_strsplit (_tmp58_, "=", 2);
				parts = _tmp60_;
				parts_length1 = _vala_array_length (_tmp59_);
				_parts_size_ = parts_length1;
				_tmp61_ = parts;
				_tmp61__length1 = parts_length1;
				if (_tmp61__length1 != 2) {
					FILE* _tmp62_;
					_tmp62_ = stderr;
					fprintf (_tmp62_, "Error: --ioctl argument must be devname=filename\n");
					result = 1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				{
					UMockdevTestbed* _tmp63_;
					gchar** _tmp64_;
					gint _tmp64__length1;
					const gchar* _tmp65_;
					gchar** _tmp66_;
					gint _tmp66__length1;
					const gchar* _tmp67_;
					_tmp63_ = testbed;
					_tmp64_ = parts;
					_tmp64__length1 = parts_length1;
					_tmp65_ = _tmp64_[0];
					_tmp66_ = parts;
					_tmp66__length1 = parts_length1;
					_tmp67_ = _tmp66_[1];
					umockdev_testbed_load_pcap (_tmp63_, _tmp65_, _tmp67_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch4_g_error;
					}
				}
				goto __finally4;
				__catch4_g_error:
				{
					GError* e = NULL;
					FILE* _tmp68_;
					gchar** _tmp69_;
					gint _tmp69__length1;
					const gchar* _tmp70_;
					gchar** _tmp71_;
					gint _tmp71__length1;
					const gchar* _tmp72_;
					GError* _tmp73_;
					const gchar* _tmp74_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp68_ = stderr;
					_tmp69_ = parts;
					_tmp69__length1 = parts_length1;
					_tmp70_ = _tmp69_[1];
					_tmp71_ = parts;
					_tmp71__length1 = parts_length1;
					_tmp72_ = _tmp71_[0];
					_tmp73_ = e;
					_tmp74_ = _tmp73_->message;
					fprintf (_tmp68_, "Error: Cannot install %s for device %s: %s\n", _tmp70_, _tmp72_, _tmp74_);
					result = 1;
					_g_error_free0 (e);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally4:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp75_ = -1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp75_;
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (i);
			}
		}
	}
	_tmp76_ = opt_script;
	_tmp76__length1 = _vala_array_length (opt_script);
	{
		gchar** i_collection = NULL;
		gint i_collection_length1 = 0;
		gint _i_collection_size_ = 0;
		gint i_it = 0;
		i_collection = _tmp76_;
		i_collection_length1 = _tmp76__length1;
		for (i_it = 0; i_it < i_collection_length1; i_it = i_it + 1) {
			gchar* _tmp77_;
			gchar* i = NULL;
			_tmp77_ = g_strdup (i_collection[i_it]);
			i = _tmp77_;
			{
				gchar** parts = NULL;
				const gchar* _tmp78_;
				gchar** _tmp79_;
				gchar** _tmp80_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp81_;
				gint _tmp81__length1;
				_tmp78_ = i;
				_tmp80_ = _tmp79_ = g_strsplit (_tmp78_, "=", 2);
				parts = _tmp80_;
				parts_length1 = _vala_array_length (_tmp79_);
				_parts_size_ = parts_length1;
				_tmp81_ = parts;
				_tmp81__length1 = parts_length1;
				if (_tmp81__length1 != 2) {
					FILE* _tmp82_;
					_tmp82_ = stderr;
					fprintf (_tmp82_, "Error: --script argument must be devname=filename\n");
					result = 1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				{
					UMockdevTestbed* _tmp83_;
					gchar** _tmp84_;
					gint _tmp84__length1;
					const gchar* _tmp85_;
					gchar** _tmp86_;
					gint _tmp86__length1;
					const gchar* _tmp87_;
					_tmp83_ = testbed;
					_tmp84_ = parts;
					_tmp84__length1 = parts_length1;
					_tmp85_ = _tmp84_[0];
					_tmp86_ = parts;
					_tmp86__length1 = parts_length1;
					_tmp87_ = _tmp86_[1];
					umockdev_testbed_load_script (_tmp83_, _tmp85_, _tmp87_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch5_g_error;
					}
				}
				goto __finally5;
				__catch5_g_error:
				{
					GError* e = NULL;
					FILE* _tmp88_;
					gchar** _tmp89_;
					gint _tmp89__length1;
					const gchar* _tmp90_;
					gchar** _tmp91_;
					gint _tmp91__length1;
					const gchar* _tmp92_;
					GError* _tmp93_;
					const gchar* _tmp94_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp88_ = stderr;
					_tmp89_ = parts;
					_tmp89__length1 = parts_length1;
					_tmp90_ = _tmp89_[1];
					_tmp91_ = parts;
					_tmp91__length1 = parts_length1;
					_tmp92_ = _tmp91_[0];
					_tmp93_ = e;
					_tmp94_ = _tmp93_->message;
					fprintf (_tmp88_, "Error: Cannot install %s for device %s: %s\n", _tmp90_, _tmp92_, _tmp94_);
					result = 1;
					_g_error_free0 (e);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally5:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp95_ = -1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp95_;
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (i);
			}
		}
	}
	_tmp96_ = opt_unix_stream;
	_tmp96__length1 = _vala_array_length (opt_unix_stream);
	{
		gchar** i_collection = NULL;
		gint i_collection_length1 = 0;
		gint _i_collection_size_ = 0;
		gint i_it = 0;
		i_collection = _tmp96_;
		i_collection_length1 = _tmp96__length1;
		for (i_it = 0; i_it < i_collection_length1; i_it = i_it + 1) {
			gchar* _tmp97_;
			gchar* i = NULL;
			_tmp97_ = g_strdup (i_collection[i_it]);
			i = _tmp97_;
			{
				gchar** parts = NULL;
				const gchar* _tmp98_;
				gchar** _tmp99_;
				gchar** _tmp100_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp101_;
				gint _tmp101__length1;
				_tmp98_ = i;
				_tmp100_ = _tmp99_ = g_strsplit (_tmp98_, "=", 2);
				parts = _tmp100_;
				parts_length1 = _vala_array_length (_tmp99_);
				_parts_size_ = parts_length1;
				_tmp101_ = parts;
				_tmp101__length1 = parts_length1;
				if (_tmp101__length1 != 2) {
					FILE* _tmp102_;
					_tmp102_ = stderr;
					fprintf (_tmp102_, "Error: --unix-stream argument must be socket_path=filename\n");
					result = 1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				{
					UMockdevTestbed* _tmp103_;
					gchar** _tmp104_;
					gint _tmp104__length1;
					const gchar* _tmp105_;
					gchar** _tmp106_;
					gint _tmp106__length1;
					const gchar* _tmp107_;
					_tmp103_ = testbed;
					_tmp104_ = parts;
					_tmp104__length1 = parts_length1;
					_tmp105_ = _tmp104_[0];
					_tmp106_ = parts;
					_tmp106__length1 = parts_length1;
					_tmp107_ = _tmp106_[1];
					umockdev_testbed_load_socket_script (_tmp103_, _tmp105_, SOCK_STREAM, _tmp107_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch6_g_error;
					}
				}
				goto __finally6;
				__catch6_g_error:
				{
					GError* e = NULL;
					FILE* _tmp108_;
					gchar** _tmp109_;
					gint _tmp109__length1;
					const gchar* _tmp110_;
					gchar** _tmp111_;
					gint _tmp111__length1;
					const gchar* _tmp112_;
					GError* _tmp113_;
					const gchar* _tmp114_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp108_ = stderr;
					_tmp109_ = parts;
					_tmp109__length1 = parts_length1;
					_tmp110_ = _tmp109_[1];
					_tmp111_ = parts;
					_tmp111__length1 = parts_length1;
					_tmp112_ = _tmp111_[0];
					_tmp113_ = e;
					_tmp114_ = _tmp113_->message;
					fprintf (_tmp108_, "Error: Cannot install %s for stream socket %s: %s\n", _tmp110_, _tmp112_, _tmp114_);
					result = 1;
					_g_error_free0 (e);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally6:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp115_ = -1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp115_;
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (i);
			}
		}
	}
	_tmp116_ = opt_evemu_events;
	_tmp116__length1 = _vala_array_length (opt_evemu_events);
	{
		gchar** i_collection = NULL;
		gint i_collection_length1 = 0;
		gint _i_collection_size_ = 0;
		gint i_it = 0;
		i_collection = _tmp116_;
		i_collection_length1 = _tmp116__length1;
		for (i_it = 0; i_it < i_collection_length1; i_it = i_it + 1) {
			gchar* _tmp117_;
			gchar* i = NULL;
			_tmp117_ = g_strdup (i_collection[i_it]);
			i = _tmp117_;
			{
				gchar** parts = NULL;
				const gchar* _tmp118_;
				gchar** _tmp119_;
				gchar** _tmp120_;
				gint parts_length1;
				gint _parts_size_;
				gchar** _tmp121_;
				gint _tmp121__length1;
				_tmp118_ = i;
				_tmp120_ = _tmp119_ = g_strsplit (_tmp118_, "=", 2);
				parts = _tmp120_;
				parts_length1 = _vala_array_length (_tmp119_);
				_parts_size_ = parts_length1;
				_tmp121_ = parts;
				_tmp121__length1 = parts_length1;
				if (_tmp121__length1 != 2) {
					FILE* _tmp122_;
					_tmp122_ = stderr;
					fprintf (_tmp122_, "Error: --evemu-events argument must be devname=filename\n");
					result = 1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				{
					UMockdevTestbed* _tmp123_;
					gchar** _tmp124_;
					gint _tmp124__length1;
					const gchar* _tmp125_;
					gchar** _tmp126_;
					gint _tmp126__length1;
					const gchar* _tmp127_;
					_tmp123_ = testbed;
					_tmp124_ = parts;
					_tmp124__length1 = parts_length1;
					_tmp125_ = _tmp124_[0];
					_tmp126_ = parts;
					_tmp126__length1 = parts_length1;
					_tmp127_ = _tmp126_[1];
					umockdev_testbed_load_evemu_events (_tmp123_, _tmp125_, _tmp127_, &_inner_error0_);
					if (G_UNLIKELY (_inner_error0_ != NULL)) {
						goto __catch7_g_error;
					}
				}
				goto __finally7;
				__catch7_g_error:
				{
					GError* e = NULL;
					FILE* _tmp128_;
					gchar** _tmp129_;
					gint _tmp129__length1;
					const gchar* _tmp130_;
					gchar** _tmp131_;
					gint _tmp131__length1;
					const gchar* _tmp132_;
					GError* _tmp133_;
					const gchar* _tmp134_;
					e = _inner_error0_;
					_inner_error0_ = NULL;
					_tmp128_ = stderr;
					_tmp129_ = parts;
					_tmp129__length1 = parts_length1;
					_tmp130_ = _tmp129_[1];
					_tmp131_ = parts;
					_tmp131__length1 = parts_length1;
					_tmp132_ = _tmp131_[0];
					_tmp133_ = e;
					_tmp134_ = _tmp133_->message;
					fprintf (_tmp128_, "Error: Cannot install %s for device %s: %s\n", _tmp130_, _tmp132_, _tmp134_);
					result = 1;
					_g_error_free0 (e);
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					return result;
				}
				__finally7:
				if (G_UNLIKELY (_inner_error0_ != NULL)) {
					gint _tmp135_ = -1;
					parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
					_g_free0 (i);
					_g_object_unref0 (testbed);
					_g_free0 (preload);
					_g_option_context_free0 (oc);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
					g_clear_error (&_inner_error0_);
					return _tmp135_;
				}
				parts = (_vala_array_free (parts, parts_length1, (GDestroyNotify) g_free), NULL);
				_g_free0 (i);
			}
		}
	}
	_tmp136_ = opt_program;
	_tmp136__length1 = _vala_array_length (opt_program);
	if (_tmp136__length1 == 0) {
		FILE* _tmp137_;
		_tmp137_ = stderr;
		fprintf (_tmp137_, "No program specified. See --help for how to use umockdev-run\n");
		result = 1;
		_g_object_unref0 (testbed);
		_g_free0 (preload);
		_g_option_context_free0 (oc);
		return result;
	}
	_tmp138_ = g_main_loop_new (NULL, FALSE);
	_g_main_loop_unref0 (loop);
	loop = _tmp138_;
	{
		GPid _tmp139_ = 0;
		gchar** _tmp140_;
		gint _tmp140__length1;
		_tmp140_ = opt_program;
		_tmp140__length1 = _vala_array_length (opt_program);
		_tmp139_ = umockdev_utils_spawn_process_under_test (_tmp140_, (gint) _tmp140__length1, _child_watch_cb_gchild_watch_func, NULL, NULL, &_inner_error0_);
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch8_g_error;
		}
		child_pid = _tmp139_;
	}
	goto __finally8;
	__catch8_g_error:
	{
		GError* e = NULL;
		gchar** _tmp141_;
		gint _tmp141__length1;
		const gchar* _tmp142_;
		const gchar* _tmp143_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp141_ = opt_program;
		_tmp141__length1 = _vala_array_length (opt_program);
		_tmp142_ = _tmp141_[0];
		_tmp143_ = e->message;
		g_error ("umockdev-run.vala:199: Cannot run %s: %s", _tmp142_, _tmp143_);
		_g_error_free0 (e);
	}
	__finally8:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp144_ = -1;
		_g_object_unref0 (testbed);
		_g_free0 (preload);
		_g_option_context_free0 (oc);
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error0_->message, g_quark_to_string (_inner_error0_->domain), _inner_error0_->code);
		g_clear_error (&_inner_error0_);
		return _tmp144_;
	}
	_tmp145_ = loop;
	g_main_loop_run (_tmp145_);
	_g_object_unref0 (testbed);
	testbed = NULL;
	if (WIFEXITED (child_status)) {
		result = WEXITSTATUS (child_status);
		_g_object_unref0 (testbed);
		_g_free0 (preload);
		_g_option_context_free0 (oc);
		return result;
	}
	if (WIFSIGNALED (child_status)) {
		raise (WTERMSIG (child_status));
	}
	result = child_status;
	_g_object_unref0 (testbed);
	_g_free0 (preload);
	_g_option_context_free0 (oc);
	return result;
}

int
main (int argc,
      char ** argv)
{
	return _vala_main (argv, argc);
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

