Re: [PATCH 1/4] android/bluetooth: Add initial support for permanent storage

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Johan,


> Hi Szymon,
> 
> On Wed, Dec 18, 2013, Szymon Janc wrote:
> > +static void store_adapter_config(void)
> > +{
> > +	GKeyFile *key_file;
> > +	gsize length = 0;
> > +	char addr[18];
> > +	char *data;
> > +
> > +	key_file = g_key_file_new();
> > +
> > +	if (!g_key_file_load_from_file(key_file, ANDROID_STORAGEDIR"/settings",
> > +								0, NULL)) {
> > +		int fd = open(ANDROID_STORAGEDIR"/settings", O_CREAT, 0600);
> > +		if (fd < 0) {
> > +			error("Failed to create adapter config file: %d (%s)",
> > +							errno, strerror(errno));
> > +			return;
> > +		}
> > +
> > +		close(fd);
> > +	}
> > +
> > +	ba2str(&adapter.bdaddr, addr);
> > +
> > +	g_key_file_set_string(key_file, "General", "Address", addr);
> > +	g_key_file_set_string(key_file, "General", "Name", adapter.name);
> > +	g_key_file_set_integer(key_file, "General", "DiscoverableTimeout",
> > +						adapter.discoverable_timeout);
> > +
> > +	data = g_key_file_to_data(key_file, &length, NULL);
> > +
> > +	g_file_set_contents(ANDROID_STORAGEDIR"/settings", data, length, NULL);
> 
> The whole open(..., O_CREAT, ...) trick you do seems completely
> unnecessary as g_key_file_to_data will create the file if it doesn't
> exist. Instead, if you want to log an error you'd need to check if
> g_key_file_contents failed or not. Adding a GError into the mix and
> logging the exact error message would be even better.

This was done only to make sure proper permissions are used for file. Since
glib doens't offer any API (at least I couldn't find any) for that in g_file_*
(other than wrappers to standard unix calls)

-- 
BR
Szymon Janc

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux