Warning: Can't synchronize with repository "(default)" (No changeset 96d22ec3fa3ef6de3ea8dc0d7d398adc9aa071cf in the repository). Look in the Trac log for more information.

Ticket #672 (closed defect: fixed)

Opened 15 months ago

Last modified 10 months ago

fsoraw doesn't exit anymore

Reported by: GNUtoo Owned by: slyon
Priority: major Milestone: cornucopia-0.12
Component: cornucopia/general Version: 0.12
Keywords: Cc: Martin.Jansa@…

Description

fsoraw doesn't exit when echo exits:

root@crespo:~# fsoraw -r CPU -- echo


And that prevent the release of the CPU resource in that case....

Change History

comment:1 Changed 14 months ago by morphis

  • Milestone set to 0.11

comment:2 Changed 12 months ago by morphis

  • Milestone changed from 0.11 to 0.12

comment:3 Changed 11 months ago by jama

  • Cc Martin.Jansa@… added

comment:4 Changed 11 months ago by mrmoku

If I disable the part doing the resource allocation and build fso-raw on my laptop then all is fine. It exits and does not hang. No idea why the call to posix wait could hang on the device...

comment:5 Changed 11 months ago by morphis

  • Milestone changed from cornucopia-0.12 to cornucopia-0.13

comment:6 Changed 10 months ago by GNUtoo

I found a workarround:

root@om-gta04:~# ./fso-raw-2 -r CPU ls /
[DEBUG] Before!!! running the cmdline
bin         etc         lost+found  proc        sys         var
boot        home        media       run         tmp
dev         lib         mnt         sbin        usr
skippinng free...

is produced by that source code:


/* main.c generated by valac 0.16.0, the Vala compiler
 * generated from main.vala, do not modify */


#include <glib.h>
#include <glib-object.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


#define TYPE_IUSAGE (iusage_get_type ())
#define IUSAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_IUSAGE, IUsage))
#define IS_IUSAGE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_IUSAGE))
#define IUSAGE_GET_INTERFACE(obj) (G_TYPE_INSTANCE_GET_INTERFACE ((obj), TYPE_IUSAGE, IUsageIface))

typedef struct _IUsage IUsage;
typedef struct _IUsageIface IUsageIface;

#define TYPE_IUSAGE_PROXY (iusage_proxy_get_type ())
typedef GDBusProxy IUsageProxy;
typedef GDBusProxyClass IUsageProxyClass;
#define _g_free0(var) (var = (g_free (var), NULL))

#define TYPE_COMMANDS (commands_get_type ())
#define COMMANDS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_COMMANDS, Commands))
#define COMMANDS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_COMMANDS, CommandsClass))
#define IS_COMMANDS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_COMMANDS))
#define IS_COMMANDS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_COMMANDS))
#define COMMANDS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_COMMANDS, CommandsClass))

typedef struct _Commands Commands;
typedef struct _CommandsClass CommandsClass;
typedef struct _CommandsPrivate CommandsPrivate;
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#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)))

struct _IUsageIface {
	GTypeInterface parent_iface;
	gchar** (*list_resources) (IUsage* self, int* result_length1, GError** error);
	void (*request_resource) (IUsage* self, const gchar* name, GError** error);
};

struct _Commands {
	GObject parent_instance;
	CommandsPrivate * priv;
};

struct _CommandsClass {
	GObjectClass parent_class;
};

struct _CommandsPrivate {
	IUsage* usage;
};


extern GMainLoop* mainloop;
GMainLoop* mainloop = NULL;
static gpointer commands_parent_class = NULL;
extern gboolean force;
extern gboolean listresources;
gboolean listresources = FALSE;
gboolean force = FALSE;
extern gboolean timeout;
gboolean timeout = FALSE;
extern gchar** resources;
extern gint resources_length1;
gchar** resources = NULL;
gint resources_length1 = 0;
static gint _resources_size_ = 0;
extern gchar** command;
extern gint command_length1;
gchar** command = NULL;
gint command_length1 = 0;
static gint _command_size_ = 0;

#define FSO_USAGE_BUS "org.freesmartphone.ousaged"
#define FSO_USAGE_PATH "/org/freesmartphone/Usage"
GType iusage_proxy_get_type (void) G_GNUC_CONST;
guint iusage_register_object (void* object, GDBusConnection* connection, const gchar* path, GError** error);
GType iusage_get_type (void) G_GNUC_CONST;
gchar** iusage_list_resources (IUsage* self, int* result_length1, GError** error);
void iusage_request_resource (IUsage* self, const gchar* name, GError** error);
static void iusage_proxy_g_signal (GDBusProxy* proxy, const gchar* sender_name, const gchar* signal_name, GVariant* parameters);
static gchar** iusage_proxy_list_resources (IUsage* self, int* result_length1, GError** error);
static void iusage_proxy_request_resource (IUsage* self, const gchar* name, GError** error);
static void iusage_proxy_iusage_interface_init (IUsageIface* iface);
static void _dbus_iusage_list_resources (IUsage* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void _dbus_iusage_request_resource (IUsage* self, GVariant* parameters, GDBusMethodInvocation* invocation);
static void iusage_dbus_interface_method_call (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* method_name, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer user_data);
static GVariant* iusage_dbus_interface_get_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GError** error, gpointer user_data);
static gboolean iusage_dbus_interface_set_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GVariant* value, GError** error, gpointer user_data);
static void _iusage_unregister_object (gpointer user_data);
GType commands_get_type (void) G_GNUC_CONST;
#define COMMANDS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), TYPE_COMMANDS, CommandsPrivate))
enum  {
	COMMANDS_DUMMY_PROPERTY
};
Commands* commands_new (void);
Commands* commands_construct (GType object_type);
void commands_listResources (Commands* self);
void commands_allocateResources (Commands* self, gchar** resources, int resources_length1);
static void commands_finalize (GObject* obj);
gint _vala_main (gchar** args, int args_length1);
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);

static const GDBusArgInfo _iusage_dbus_arg_info_list_resources_result = {-1, "result", "as"};
static const GDBusArgInfo * const _iusage_dbus_arg_info_list_resources_in[] = {NULL};
static const GDBusArgInfo * const _iusage_dbus_arg_info_list_resources_out[] = {&_iusage_dbus_arg_info_list_resources_result, NULL};
static const GDBusMethodInfo _iusage_dbus_method_info_list_resources = {-1, "ListResources", (GDBusArgInfo **) (&_iusage_dbus_arg_info_list_resources_in), (GDBusArgInfo **) (&_iusage_dbus_arg_info_list_resources_out)};
static const GDBusArgInfo _iusage_dbus_arg_info_request_resource_name = {-1, "name", "s"};
static const GDBusArgInfo * const _iusage_dbus_arg_info_request_resource_in[] = {&_iusage_dbus_arg_info_request_resource_name, NULL};
static const GDBusArgInfo * const _iusage_dbus_arg_info_request_resource_out[] = {NULL};
static const GDBusMethodInfo _iusage_dbus_method_info_request_resource = {-1, "RequestResource", (GDBusArgInfo **) (&_iusage_dbus_arg_info_request_resource_in), (GDBusArgInfo **) (&_iusage_dbus_arg_info_request_resource_out)};
static const GDBusMethodInfo * const _iusage_dbus_method_info[] = {&_iusage_dbus_method_info_list_resources, &_iusage_dbus_method_info_request_resource, NULL};
static const GDBusSignalInfo * const _iusage_dbus_signal_info[] = {NULL};
static const GDBusPropertyInfo * const _iusage_dbus_property_info[] = {NULL};
static const GDBusInterfaceInfo _iusage_dbus_interface_info = {-1, "org.freesmartphone.Usage", (GDBusMethodInfo **) (&_iusage_dbus_method_info), (GDBusSignalInfo **) (&_iusage_dbus_signal_info), (GDBusPropertyInfo **) (&_iusage_dbus_property_info)};
static const GDBusInterfaceVTable _iusage_dbus_interface_vtable = {iusage_dbus_interface_method_call, iusage_dbus_interface_get_property, iusage_dbus_interface_set_property};
const GOptionEntry options[6] = {{"listresources", 'l', 0, G_OPTION_ARG_NONE, &listresources, "List resources (do not mix with -r)", NULL}, {"resources", 'r', 0, G_OPTION_ARG_STRING_ARRAY, &resources, "Allocate resources during program execution", "RESOURCE..."}, {"force", 'f', 0, G_OPTION_ARG_NONE, &force, "Continue execution, even if (some) resources can't be allocated.", NULL}, {"timeout", 't', 0, G_OPTION_ARG_INT, &timeout, "Override default dbus timeout", "MSECS"}, {"", (gchar) 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &command, NULL, "[--] COMMAND [ARGS]..."}, {NULL}};

gchar** iusage_list_resources (IUsage* self, int* result_length1, GError** error) {
	g_return_val_if_fail (self != NULL, NULL);
	return IUSAGE_GET_INTERFACE (self)->list_resources (self, result_length1, error);
}


void iusage_request_resource (IUsage* self, const gchar* name, GError** error) {
	g_return_if_fail (self != NULL);
	IUSAGE_GET_INTERFACE (self)->request_resource (self, name, error);
}


static void iusage_base_init (IUsageIface * iface) {
	static gboolean initialized = FALSE;
	if (!initialized) {
		initialized = TRUE;
	}
}


GType iusage_get_type (void) {
	static volatile gsize iusage_type_id__volatile = 0;
	if (g_once_init_enter (&iusage_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (IUsageIface), (GBaseInitFunc) iusage_base_init, (GBaseFinalizeFunc) NULL, (GClassInitFunc) NULL, (GClassFinalizeFunc) NULL, NULL, 0, 0, (GInstanceInitFunc) NULL, NULL };
		GType iusage_type_id;
		iusage_type_id = g_type_register_static (G_TYPE_INTERFACE, "IUsage", &g_define_type_info, 0);
		g_type_interface_add_prerequisite (iusage_type_id, G_TYPE_OBJECT);
		g_type_set_qdata (iusage_type_id, g_quark_from_static_string ("vala-dbus-proxy-type"), (void*) iusage_proxy_get_type);
		g_type_set_qdata (iusage_type_id, g_quark_from_static_string ("vala-dbus-interface-name"), "org.freesmartphone.Usage");
		g_type_set_qdata (iusage_type_id, g_quark_from_static_string ("vala-dbus-register-object"), (void*) iusage_register_object);
		g_once_init_leave (&iusage_type_id__volatile, iusage_type_id);
	}
	return iusage_type_id__volatile;
}


G_DEFINE_TYPE_EXTENDED (IUsageProxy, iusage_proxy, G_TYPE_DBUS_PROXY, 0, G_IMPLEMENT_INTERFACE (TYPE_IUSAGE, iusage_proxy_iusage_interface_init) )
static void iusage_proxy_class_init (IUsageProxyClass* klass) {
	G_DBUS_PROXY_CLASS (klass)->g_signal = iusage_proxy_g_signal;
}


static void iusage_proxy_g_signal (GDBusProxy* proxy, const gchar* sender_name, const gchar* signal_name, GVariant* parameters) {
}


static void iusage_proxy_init (IUsageProxy* self) {
}


static gchar** iusage_proxy_list_resources (IUsage* self, int* result_length1, GError** error) {
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	GVariant *_reply;
	GVariantIter _reply_iter;
	gchar** _result;
	int _result_length1;
	GVariant* _tmp0_;
	gchar** _tmp1_;
	int _tmp1__length;
	int _tmp1__size;
	int _tmp1__length1;
	GVariantIter _tmp2_;
	GVariant* _tmp3_;
	G_DBUS_ERROR;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freesmartphone.Usage", "ListResources");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return NULL;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return NULL;
	}
	_reply = g_dbus_message_get_body (_reply_message);
	g_variant_iter_init (&_reply_iter, _reply);
	_result_length1 = 0;
	_tmp0_ = g_variant_iter_next_value (&_reply_iter);
	_tmp1_ = g_new (gchar*, 5);
	_tmp1__length = 0;
	_tmp1__size = 4;
	_tmp1__length1 = 0;
	g_variant_iter_init (&_tmp2_, _tmp0_);
	for (; (_tmp3_ = g_variant_iter_next_value (&_tmp2_)) != NULL; _tmp1__length1++) {
		if (_tmp1__size == _tmp1__length) {
			_tmp1__size = 2 * _tmp1__size;
			_tmp1_ = g_renew (gchar*, _tmp1_, _tmp1__size + 1);
		}
		_tmp1_[_tmp1__length++] = g_variant_dup_string (_tmp3_, NULL);
		g_variant_unref (_tmp3_);
	}
	_result_length1 = _tmp1__length1;
	_tmp1_[_tmp1__length] = NULL;
	_result = _tmp1_;
	g_variant_unref (_tmp0_);
	*result_length1 = _result_length1;
	g_object_unref (_reply_message);
	return _result;
}


static void iusage_proxy_request_resource (IUsage* self, const gchar* name, GError** error) {
	GDBusMessage *_message;
	GVariant *_arguments;
	GVariantBuilder _arguments_builder;
	GDBusMessage *_reply_message;
	G_DBUS_ERROR;
	G_IO_ERROR;
	_message = g_dbus_message_new_method_call (g_dbus_proxy_get_name ((GDBusProxy *) self), g_dbus_proxy_get_object_path ((GDBusProxy *) self), "org.freesmartphone.Usage", "RequestResource");
	g_variant_builder_init (&_arguments_builder, G_VARIANT_TYPE_TUPLE);
	g_variant_builder_add_value (&_arguments_builder, g_variant_new_string (name));
	_arguments = g_variant_builder_end (&_arguments_builder);
	g_dbus_message_set_body (_message, _arguments);
	_reply_message = g_dbus_connection_send_message_with_reply_sync (g_dbus_proxy_get_connection ((GDBusProxy *) self), _message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, g_dbus_proxy_get_default_timeout ((GDBusProxy *) self), NULL, NULL, error);
	g_object_unref (_message);
	if (!_reply_message) {
		return;
	}
	if (g_dbus_message_to_gerror (_reply_message, error)) {
		g_object_unref (_reply_message);
		return;
	}
	g_object_unref (_reply_message);
}


static void iusage_proxy_iusage_interface_init (IUsageIface* iface) {
	iface->list_resources = iusage_proxy_list_resources;
	iface->request_resource = iusage_proxy_request_resource;
}


static void _dbus_iusage_list_resources (IUsage* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	gchar** result;
	int result_length1 = 0;
	gchar** _tmp4_;
	GVariantBuilder _tmp5_;
	int _tmp6_;
	g_variant_iter_init (&_arguments_iter, parameters);
	result = iusage_list_resources (self, &result_length1, &error);
	if (error) {
		g_dbus_method_invocation_return_gerror (invocation, error);
		return;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_tmp4_ = result;
	g_variant_builder_init (&_tmp5_, G_VARIANT_TYPE ("as"));
	for (_tmp6_ = 0; _tmp6_ < result_length1; _tmp6_++) {
		g_variant_builder_add_value (&_tmp5_, g_variant_new_string (*_tmp4_));
		_tmp4_++;
	}
	g_variant_builder_add_value (&_reply_builder, g_variant_builder_end (&_tmp5_));
	result = (_vala_array_free (result, result_length1, (GDestroyNotify) g_free), NULL);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void _dbus_iusage_request_resource (IUsage* self, GVariant* parameters, GDBusMethodInvocation* invocation) {
	GError* error = NULL;
	GVariantIter _arguments_iter;
	gchar* name = NULL;
	GVariant* _tmp7_;
	GDBusMessage* _reply_message;
	GVariant* _reply;
	GVariantBuilder _reply_builder;
	g_variant_iter_init (&_arguments_iter, parameters);
	_tmp7_ = g_variant_iter_next_value (&_arguments_iter);
	name = g_variant_dup_string (_tmp7_, NULL);
	g_variant_unref (_tmp7_);
	iusage_request_resource (self, name, &error);
	if (error) {
		g_dbus_method_invocation_return_gerror (invocation, error);
		return;
	}
	_reply_message = g_dbus_message_new_method_reply (g_dbus_method_invocation_get_message (invocation));
	g_variant_builder_init (&_reply_builder, G_VARIANT_TYPE_TUPLE);
	_reply = g_variant_builder_end (&_reply_builder);
	g_dbus_message_set_body (_reply_message, _reply);
	_g_free0 (name);
	g_dbus_connection_send_message (g_dbus_method_invocation_get_connection (invocation), _reply_message, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, NULL);
	g_object_unref (invocation);
	g_object_unref (_reply_message);
}


static void iusage_dbus_interface_method_call (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* method_name, GVariant* parameters, GDBusMethodInvocation* invocation, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	if (strcmp (method_name, "ListResources") == 0) {
		_dbus_iusage_list_resources (object, parameters, invocation);
	} else if (strcmp (method_name, "RequestResource") == 0) {
		_dbus_iusage_request_resource (object, parameters, invocation);
	} else {
		g_object_unref (invocation);
	}
}


static GVariant* iusage_dbus_interface_get_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GError** error, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return NULL;
}


static gboolean iusage_dbus_interface_set_property (GDBusConnection* connection, const gchar* sender, const gchar* object_path, const gchar* interface_name, const gchar* property_name, GVariant* value, GError** error, gpointer user_data) {
	gpointer* data;
	gpointer object;
	data = user_data;
	object = data[0];
	return FALSE;
}


guint iusage_register_object (gpointer object, GDBusConnection* connection, const gchar* path, GError** error) {
	guint result;
	gpointer *data;
	data = g_new (gpointer, 3);
	data[0] = g_object_ref (object);
	data[1] = g_object_ref (connection);
	data[2] = g_strdup (path);
	result = g_dbus_connection_register_object (connection, path, (GDBusInterfaceInfo *) (&_iusage_dbus_interface_info), &_iusage_dbus_interface_vtable, data, _iusage_unregister_object, error);
	if (!result) {
		return 0;
	}
	return result;
}


static void _iusage_unregister_object (gpointer user_data) {
	gpointer* data;
	data = user_data;
	g_object_unref (data[0]);
	g_object_unref (data[1]);
	g_free (data[2]);
	g_free (data);
}


Commands* commands_construct (GType object_type) {
	Commands * self = NULL;
	GError * _inner_error_ = NULL;
	self = (Commands*) g_object_new (object_type, NULL);
	{
		IUsage* _tmp0_ = NULL;
		IUsage* _tmp1_;
		_tmp0_ = g_initable_new (TYPE_IUSAGE_PROXY, NULL, &_inner_error_, "g-flags", 0, "g-name", FSO_USAGE_BUS, "g-bus-type", G_BUS_TYPE_SYSTEM, "g-object-path", FSO_USAGE_PATH, "g-interface-name", "org.freesmartphone.Usage", NULL);
		_tmp1_ = (IUsage*) _tmp0_;
		if (_inner_error_ != NULL) {
			goto __catch0_g_error;
		}
		_g_object_unref0 (self->priv->usage);
		self->priv->usage = _tmp1_;
	}
	goto __finally0;
	__catch0_g_error:
	{
		GError* e = NULL;
		GError* _tmp2_;
		const gchar* _tmp3_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp2_ = e;
		_tmp3_ = _tmp2_->message;
		g_critical ("main.vala:53: dbus error: %s", _tmp3_);
		_g_error_free0 (e);
	}
	__finally0:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return NULL;
	}
	return self;
}


Commands* commands_new (void) {
	return commands_construct (TYPE_COMMANDS);
}


void commands_listResources (Commands* self) {
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	{
		IUsage* _tmp0_;
		gint _tmp1_ = 0;
		gchar** _tmp2_ = NULL;
		gchar** res;
		gint res_length1;
		gint _res_size_;
		_tmp0_ = self->priv->usage;
		_tmp2_ = iusage_list_resources (_tmp0_, &_tmp1_, &_inner_error_);
		res = _tmp2_;
		res_length1 = _tmp1_;
		_res_size_ = res_length1;
		if (_inner_error_ != NULL) {
			goto __catch1_g_error;
		}
		{
			gchar** r_collection = NULL;
			gint r_collection_length1 = 0;
			gint _r_collection_size_ = 0;
			gint r_it = 0;
			r_collection = res;
			r_collection_length1 = res_length1;
			for (r_it = 0; r_it < res_length1; r_it = r_it + 1) {
				gchar* _tmp3_;
				gchar* r = NULL;
				_tmp3_ = g_strdup (r_collection[r_it]);
				r = _tmp3_;
				{
					FILE* _tmp4_;
					const gchar* _tmp5_;
					_tmp4_ = stdout;
					_tmp5_ = r;
					fprintf (_tmp4_, "%s\n", _tmp5_);
					_g_free0 (r);
				}
			}
		}
		res = (_vala_array_free (res, res_length1, (GDestroyNotify) g_free), NULL);
	}
	goto __finally1;
	__catch1_g_error:
	{
		GError* e = NULL;
		FILE* _tmp6_;
		GError* _tmp7_;
		const gchar* _tmp8_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp6_ = stderr;
		_tmp7_ = e;
		_tmp8_ = _tmp7_->message;
		fprintf (_tmp6_, "%s\n", _tmp8_);
		_g_error_free0 (e);
	}
	__finally1:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return;
	}
}


void commands_allocateResources (Commands* self, gchar** resources, int resources_length1) {
	gchar** _tmp0_;
	gint _tmp0__length1;
	GError * _inner_error_ = NULL;
	g_return_if_fail (self != NULL);
	_tmp0_ = resources;
	_tmp0__length1 = resources_length1;
	{
		gchar** resource_collection = NULL;
		gint resource_collection_length1 = 0;
		gint _resource_collection_size_ = 0;
		gint resource_it = 0;
		resource_collection = _tmp0_;
		resource_collection_length1 = _tmp0__length1;
		for (resource_it = 0; resource_it < _tmp0__length1; resource_it = resource_it + 1) {
			gchar* _tmp1_;
			gchar* resource = NULL;
			_tmp1_ = g_strdup (resource_collection[resource_it]);
			resource = _tmp1_;
			{
				{
					IUsage* _tmp2_;
					const gchar* _tmp3_;
					_tmp2_ = self->priv->usage;
					_tmp3_ = resource;
					iusage_request_resource (_tmp2_, _tmp3_, &_inner_error_);
					if (_inner_error_ != NULL) {
						goto __catch2_g_error;
					}
				}
				goto __finally2;
				__catch2_g_error:
				{
					GError* e = NULL;
					gboolean _tmp4_;
					e = _inner_error_;
					_inner_error_ = NULL;
					_tmp4_ = force;
					if (_tmp4_) {
						const gchar* _tmp5_;
						GError* _tmp6_;
						const gchar* _tmp7_;
						_tmp5_ = resource;
						_tmp6_ = e;
						_tmp7_ = _tmp6_->message;
						g_warning ("main.vala:82: Could not request resource '%s': %s", _tmp5_, _tmp7_);
					} else {
						const gchar* _tmp8_;
						GError* _tmp9_;
						const gchar* _tmp10_;
						_tmp8_ = resource;
						_tmp9_ = e;
						_tmp10_ = _tmp9_->message;
						g_critical ("main.vala:84: Could not request resource '%s' : %s", _tmp8_, _tmp10_);
					}
					_g_error_free0 (e);
				}
				__finally2:
				if (_inner_error_ != NULL) {
					_g_free0 (resource);
					g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
					g_clear_error (&_inner_error_);
					return;
				}
				_g_free0 (resource);
			}
		}
	}
}


static void commands_class_init (CommandsClass * klass) {
	commands_parent_class = g_type_class_peek_parent (klass);
	g_type_class_add_private (klass, sizeof (CommandsPrivate));
	G_OBJECT_CLASS (klass)->finalize = commands_finalize;
}


static void commands_instance_init (Commands * self) {
	self->priv = COMMANDS_GET_PRIVATE (self);
}


static void commands_finalize (GObject* obj) {
	Commands * self;
	self = COMMANDS (obj);
	_g_object_unref0 (self->priv->usage);
	G_OBJECT_CLASS (commands_parent_class)->finalize (obj);
}


GType commands_get_type (void) {
	static volatile gsize commands_type_id__volatile = 0;
	if (g_once_init_enter (&commands_type_id__volatile)) {
		static const GTypeInfo g_define_type_info = { sizeof (CommandsClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) commands_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (Commands), 0, (GInstanceInitFunc) commands_instance_init, NULL };
		GType commands_type_id;
		commands_type_id = g_type_register_static (G_TYPE_OBJECT, "Commands", &g_define_type_info, 0);
		g_once_init_leave (&commands_type_id__volatile, commands_type_id);
	}
	return commands_type_id__volatile;
}


static gboolean string_contains (const gchar* self, const gchar* needle) {
	gboolean result = FALSE;
	const gchar* _tmp0_;
	gchar* _tmp1_ = NULL;
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (needle != NULL, FALSE);
	_tmp0_ = needle;
	_tmp1_ = strstr ((gchar*) self, (gchar*) _tmp0_);
	result = _tmp1_ != NULL;
	return result;
}


gint _vala_main (gchar** args, int args_length1) {
	gint result = 0;
	gboolean _tmp10_ = FALSE;
	gboolean _tmp11_;
	gboolean _tmp13_;
	gboolean _tmp15_ = FALSE;
	gboolean _tmp16_;
	gboolean _tmp18_;
	gboolean _tmp20_ = FALSE;
	gchar** _tmp21_;
	gint _tmp21__length1;
	gboolean _tmp23_;
	Commands* _tmp25_;
	Commands* commands;
	gboolean _tmp26_;
	gint i;
	gint _tmp32_;
	gint _tmp33_;
	gboolean _tmp34_ = FALSE;
	gchar** _tmp35_;
	gint _tmp35__length1;
	gboolean _tmp39_;
	Commands* _tmp44_;
	gchar** _tmp45_;
	gint _tmp45__length1;
	pid_t _tmp46_ = 0;
	pid_t child;
	pid_t _tmp47_;
	pid_t _tmp48_;
	FILE* _tmp65_;
	GError * _inner_error_ = NULL;
	{
		GOptionContext* _tmp0_;
		GOptionContext* opt_context;
		GOptionContext* _tmp1_;
		GOptionContext* _tmp2_;
		GOptionContext* _tmp3_;
		_tmp0_ = g_option_context_new ("- FSO Resource Allocation Wrapper");
		opt_context = _tmp0_;
		_tmp1_ = opt_context;
		g_option_context_set_help_enabled (_tmp1_, TRUE);
		_tmp2_ = opt_context;
		g_option_context_add_main_entries (_tmp2_, options, NULL);
		_tmp3_ = opt_context;
		g_option_context_parse (_tmp3_, &args_length1, &args, &_inner_error_);
		if (_inner_error_ != NULL) {
			_g_option_context_free0 (opt_context);
			if (_inner_error_->domain == G_OPTION_ERROR) {
				goto __catch3_g_option_error;
			}
			_g_option_context_free0 (opt_context);
			g_critical ("file %s: line %d: unexpected error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
			g_clear_error (&_inner_error_);
			return 0;
		}
		_g_option_context_free0 (opt_context);
	}
	goto __finally3;
	__catch3_g_option_error:
	{
		GError* e = NULL;
		FILE* _tmp4_;
		GError* _tmp5_;
		const gchar* _tmp6_;
		FILE* _tmp7_;
		gchar** _tmp8_;
		gint _tmp8__length1;
		const gchar* _tmp9_;
		e = _inner_error_;
		_inner_error_ = NULL;
		_tmp4_ = stdout;
		_tmp5_ = e;
		_tmp6_ = _tmp5_->message;
		fprintf (_tmp4_, "%s\n", _tmp6_);
		_tmp7_ = stdout;
		_tmp8_ = args;
		_tmp8__length1 = args_length1;
		_tmp9_ = _tmp8_[0];
		fprintf (_tmp7_, "Run '%s --help' to see a full list of available command line options.\n", _tmp9_);
		result = 1;
		_g_error_free0 (e);
		return result;
	}
	__finally3:
	if (_inner_error_ != NULL) {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code);
		g_clear_error (&_inner_error_);
		return 0;
	}
	_tmp11_ = listresources;
	if (_tmp11_) {
		gchar** _tmp12_;
		gint _tmp12__length1;
		_tmp12_ = resources;
		_tmp12__length1 = resources_length1;
		_tmp10_ = _tmp12_ != NULL;
	} else {
		_tmp10_ = FALSE;
	}
	_tmp13_ = _tmp10_;
	if (_tmp13_) {
		FILE* _tmp14_;
		_tmp14_ = stdout;
		fprintf (_tmp14_, "ERROR: Listing resources is not possible in the same call as requestin" \
"g resources.\n");
		result = 1;
		return result;
	}
	_tmp16_ = listresources;
	if (!_tmp16_) {
		gchar** _tmp17_;
		gint _tmp17__length1;
		_tmp17_ = resources;
		_tmp17__length1 = resources_length1;
		_tmp15_ = _tmp17_ == NULL;
	} else {
		_tmp15_ = FALSE;
	}
	_tmp18_ = _tmp15_;
	if (_tmp18_) {
		FILE* _tmp19_;
		_tmp19_ = stdout;
		fprintf (_tmp19_, "ERROR: Either one of '-l' or '-r' must be supplied.\n");
		result = 1;
		return result;
	}
	_tmp21_ = resources;
	_tmp21__length1 = resources_length1;
	if (_tmp21_ != NULL) {
		gchar** _tmp22_;
		gint _tmp22__length1;
		_tmp22_ = command;
		_tmp22__length1 = command_length1;
		_tmp20_ = _tmp22_ == NULL;
	} else {
		_tmp20_ = FALSE;
	}
	_tmp23_ = _tmp20_;
	if (_tmp23_) {
		FILE* _tmp24_;
		_tmp24_ = stdout;
		fprintf (_tmp24_, "ERROR: Need also a command when -r is supplied.\n");
		result = 1;
		return result;
	}
	_tmp25_ = commands_new ();
	commands = _tmp25_;
	_tmp26_ = listresources;
	if (_tmp26_) {
		Commands* _tmp27_;
		_tmp27_ = commands;
		commands_listResources (_tmp27_);
		result = 0;
		_g_object_unref0 (commands);
		return result;
	}
	i = 0;
	while (TRUE) {
		gchar** _tmp28_;
		gint _tmp28__length1;
		gint _tmp29_;
		const gchar* _tmp30_;
		gint _tmp31_;
		_tmp28_ = resources;
		_tmp28__length1 = resources_length1;
		_tmp29_ = i;
		_tmp30_ = _tmp28_[_tmp29_];
		if (!(_tmp30_ != NULL)) {
			break;
		}
		_tmp31_ = i;
		i = _tmp31_ + 1;
	}
	_tmp32_ = i;
	resources_length1 = _tmp32_;
	_tmp33_ = resources_length1;
	_tmp35_ = resources;
	_tmp35__length1 = resources_length1;
	if (_tmp35__length1 == 1) {
		gchar** _tmp36_;
		gint _tmp36__length1;
		const gchar* _tmp37_;
		gboolean _tmp38_ = FALSE;
		_tmp36_ = resources;
		_tmp36__length1 = resources_length1;
		_tmp37_ = _tmp36_[0];
		_tmp38_ = string_contains (_tmp37_, ",");
		_tmp34_ = _tmp38_;
	} else {
		_tmp34_ = FALSE;
	}
	_tmp39_ = _tmp34_;
	if (_tmp39_) {
		gchar** _tmp40_;
		gint _tmp40__length1;
		const gchar* _tmp41_;
		gchar** _tmp42_;
		gchar** _tmp43_ = NULL;
		_tmp40_ = resources;
		_tmp40__length1 = resources_length1;
		_tmp41_ = _tmp40_[0];
		_tmp43_ = _tmp42_ = g_strsplit (_tmp41_, ",", 0);
		resources = (_vala_array_free (resources, resources_length1, (GDestroyNotify) g_free), NULL);
		resources = _tmp43_;
		resources_length1 = _vala_array_length (_tmp42_);
		_resources_size_ = resources_length1;
	}
	_tmp44_ = commands;
	_tmp45_ = resources;
	_tmp45__length1 = resources_length1;
	commands_allocateResources (_tmp44_, _tmp45_, _tmp45__length1);
	_tmp46_ = fork ();
	child = _tmp46_;
	_tmp47_ = child;
	if (_tmp47_ < ((pid_t) 0)) {
		g_critical ("main.vala:164: Could not fork.");
	}
	_tmp48_ = child;
	if (_tmp48_ > ((pid_t) 0)) {
		gint status = 0;
		gint _tmp49_ = 0;
		pid_t _tmp50_ = 0;
		pid_t pid;
		_tmp50_ = wait (&_tmp49_);
		status = _tmp49_;
		pid = _tmp50_;
		result = 0;
		_g_object_unref0 (commands);
		return result;
	} else {
		gchar* _tmp51_;
		gchar* cmdline;
		FILE* _tmp62_;
		const gchar* _tmp63_;
		gint _tmp64_ = 0;
		_tmp51_ = g_strdup ("");
		cmdline = _tmp51_;
		i = 0;
		while (TRUE) {
			gchar** _tmp52_;
			gint _tmp52__length1;
			gint _tmp53_;
			const gchar* _tmp54_;
			const gchar* _tmp55_;
			gchar** _tmp56_;
			gint _tmp56__length1;
			gint _tmp57_;
			const gchar* _tmp58_;
			gchar* _tmp59_;
			const gchar* _tmp60_;
			gchar* _tmp61_;
			_tmp52_ = command;
			_tmp52__length1 = command_length1;
			_tmp53_ = i;
			i = _tmp53_ + 1;
			_tmp54_ = _tmp52_[_tmp53_];
			if (!(_tmp54_ != NULL)) {
				break;
			}
			_tmp55_ = cmdline;
			_tmp56_ = command;
			_tmp56__length1 = command_length1;
			_tmp57_ = i;
			_tmp58_ = _tmp56_[_tmp57_ - 1];
			_tmp59_ = g_strconcat (_tmp55_, _tmp58_, NULL);
			_g_free0 (cmdline);
			cmdline = _tmp59_;
			_tmp60_ = cmdline;
			_tmp61_ = g_strconcat (_tmp60_, " ", NULL);
			_g_free0 (cmdline);
			cmdline = _tmp61_;
		}
		_tmp62_ = stderr;
		fprintf (_tmp62_, "[DEBUG] Before!!! running the cmdline\n");
		_tmp63_ = cmdline;
		_tmp64_ = system (_tmp63_);
		result = _tmp64_;
		printf("skippinng free...\n");
//		_g_free0 (cmdline);
//		_g_object_unref0 (commands);
		return result;
	}
	_tmp65_ = stderr;
	fprintf (_tmp65_, "[DEBUG]  before return\n");
	result = 0;
	_g_object_unref0 (commands);
	return result;
}


int main (int argc, char ** argv) {
	g_type_init ();
	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;
}

see the commented code :

		printf("skippinng free...\n");
//		_g_free0 (cmdline);
//		_g_object_unref0 (commands);

Denis.

comment:7 Changed 10 months ago by GNUtoo

with:

		printf("skippinng free...\n");
		_g_free0 (cmdline);
//		_g_object_unref0 (commands);

it still work(doesn't block)

but with

		printf("skippinng free...\n");
//		_g_free0 (cmdline);
		_g_object_unref0 (commands);

it blocks.

Denis

comment:8 Changed 10 months ago by GNUtoo

Also I forgott to tell that under strace it(the original unmodified binary) doesn't block.

Denis.

comment:9 Changed 10 months ago by slyon

  • Owner changed from mickey to slyon
  • Status changed from new to accepted

comment:10 Changed 10 months ago by slyon

  • Status changed from accepted to closed
  • Version changed from milestone5.5 to 0.12
  • Resolution set to fixed
  • Milestone changed from cornucopia-0.13 to cornucopia-0.12

We're using GLib.Process.spawn_sync now (which is GLib internal anyway) instead of the Posix functions which had a race condition.

Fixed in: http://git.freesmartphone.org/?p=cornucopia.git;a=commit;h=5cc47db49f3044ed829734df82db6760b77921b8

Note: See TracTickets for help on using tickets.