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

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

#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 _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

extern gchar** opt_device;
gchar** opt_device = NULL;
extern gchar** opt_ioctl;
gchar** opt_ioctl = NULL;
extern gchar** opt_script;
gchar** opt_script = NULL;
extern gchar** opt_unix_stream;
gchar** opt_unix_stream = NULL;
extern gchar** opt_evemu_events;
gchar** opt_evemu_events = NULL;
extern gchar** opt_program;
gchar** opt_program = NULL;
extern gboolean opt_version;
gboolean opt_version = FALSE;
extern GPid child_pid;
GPid child_pid = 0;

void child_sig_handler (gint sig);
gint _vala_main (gchar** args,
                 gint args_length1);
static void _child_sig_handler_sighandler_t (gint signal);
static void _vala_array_destroy (gpointer array,
                          gint array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gint array_length,
                       GDestroyNotify destroy_func);
static gint _vala_array_length (gpointer array);

const GOptionEntry options[8] = {{"device", 'd', 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', 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_ioctl, "Load an umockdev-record ioctl dump into the testbed. Can be specified " \
"multiple times.", "devname=ioctlfilename"}, {"script", 's', 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', 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', 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, 0, G_OPTION_ARG_STRING_ARRAY, &opt_program, "", ""}, {"version", (gchar) 0, 0, G_OPTION_ARG_NONE, &opt_version, "Output version information and exit"}, {NULL}};

void
child_sig_handler (gint sig)
{
	g_debug ("umockdev-run.vala:61: umockdev-run: caught signal %i, propagating to c" \
"hild\n", sig);
	if (kill ((pid_t) child_pid, sig) != 0) {
		FILE* _tmp0_;
		const gchar* _tmp1_;
		_tmp0_ = stderr;
		_tmp1_ = g_strerror (errno);
		fprintf (_tmp0_, "umockdev-run: unable to propagate signal %i to child %i: %s\n", sig, (gint) child_pid, _tmp1_);
	}
}

static void
_child_sig_handler_sighandler_t (gint signal)
{
	child_sig_handler (signal);
}

gint
_vala_main (gchar** args,
            gint args_length1)
{
	gint result = 0;
	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;
	gint status = 0;
	struct sigaction act = {0};
	struct sigaction _tmp125_ = {0};
	sigset_t _tmp126_ = {0};
	struct sigaction _tmp127_;
	struct sigaction _tmp128_;
	struct sigaction _tmp129_;
	struct sigaction _tmp130_;
	struct sigaction _tmp131_;
	gint _tmp132_ = 0;
	GError* _inner_error0_ = NULL;
	_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_;
	g_setenv ("LD_PRELOAD", _tmp18_, TRUE);
	_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_script;
	_tmp56__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 = _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: --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* _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_script (_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_unix_stream;
	_tmp76__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 = _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: --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* _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_socket_script (_tmp83_, _tmp85_, SOCK_STREAM, _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 stream socket %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_evemu_events;
	_tmp96__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 = _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: --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* _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_evemu_events (_tmp103_, _tmp105_, _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 device %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_program;
	_tmp116__length1 = _vala_array_length (opt_program);
	if (_tmp116__length1 == 0) {
		FILE* _tmp117_;
		_tmp117_ = stderr;
		fprintf (_tmp117_, "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;
	}
	{
		gchar** _tmp118_;
		gint _tmp118__length1;
		GPid _tmp119_ = 0;
		_tmp118_ = opt_program;
		_tmp118__length1 = _vala_array_length (opt_program);
		g_spawn_async (NULL, _tmp118_, NULL, (G_SPAWN_SEARCH_PATH | G_SPAWN_CHILD_INHERITS_STDIN) | G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &_tmp119_, &_inner_error0_);
		child_pid = _tmp119_;
		if (G_UNLIKELY (_inner_error0_ != NULL)) {
			goto __catch7_g_error;
		}
	}
	goto __finally7;
	__catch7_g_error:
	{
		GError* e = NULL;
		FILE* _tmp120_;
		gchar** _tmp121_;
		gint _tmp121__length1;
		const gchar* _tmp122_;
		const gchar* _tmp123_;
		e = _inner_error0_;
		_inner_error0_ = NULL;
		_tmp120_ = stderr;
		_tmp121_ = opt_program;
		_tmp121__length1 = _vala_array_length (opt_program);
		_tmp122_ = _tmp121_[0];
		_tmp123_ = e->message;
		fprintf (_tmp120_, "Cannot run %s: %s\n", _tmp122_, _tmp123_);
		exit (1);
		_g_error_free0 (e);
	}
	__finally7:
	if (G_UNLIKELY (_inner_error0_ != NULL)) {
		gint _tmp124_ = -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 _tmp124_;
	}
	memset (&_tmp125_, 0, sizeof (struct sigaction));
	_tmp125_.sa_handler = _child_sig_handler_sighandler_t;
	_tmp125_.sa_flags = SA_RESETHAND;
	act = _tmp125_;
	sigemptyset (&_tmp126_);
	act.sa_mask = _tmp126_;
	_tmp127_ = act;
	_vala_assert (sigaction ((gint) SIGTERM, &_tmp127_, NULL) == 0, "Posix.sigaction (Posix.Signal.TERM, act, null) == 0");
	_tmp128_ = act;
	_vala_assert (sigaction ((gint) SIGHUP, &_tmp128_, NULL) == 0, "Posix.sigaction (Posix.Signal.HUP, act, null) == 0");
	_tmp129_ = act;
	_vala_assert (sigaction ((gint) SIGINT, &_tmp129_, NULL) == 0, "Posix.sigaction (Posix.Signal.INT, act, null) == 0");
	_tmp130_ = act;
	_vala_assert (sigaction ((gint) SIGQUIT, &_tmp130_, NULL) == 0, "Posix.sigaction (Posix.Signal.QUIT, act, null) == 0");
	_tmp131_ = act;
	_vala_assert (sigaction ((gint) SIGABRT, &_tmp131_, NULL) == 0, "Posix.sigaction (Posix.Signal.ABRT, act, null) == 0");
	waitpid ((pid_t) child_pid, &_tmp132_, 0);
	status = _tmp132_;
	g_spawn_close_pid (child_pid);
	_g_object_unref0 (testbed);
	testbed = NULL;
	if (WIFEXITED (status)) {
		result = WEXITSTATUS (status);
		_g_object_unref0 (testbed);
		_g_free0 (preload);
		_g_option_context_free0 (oc);
		return result;
	}
	if (WIFSIGNALED (status)) {
		raise (WTERMSIG (status));
	}
	result = 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,
                     gint array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		int 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,
                  gint array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

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

