Linux bluetooth development
 help / color / mirror / Atom feed
From: Szymon Janc <szymon.janc@tieto.com>
To: Johan Hedberg <johan.hedberg@gmail.com>
Cc: linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH 1/4] android/bluetooth: Add initial support for permanent storage
Date: Thu, 19 Dec 2013 10:46:23 +0100	[thread overview]
Message-ID: <1539507.GD54UJZ94B@uw000953> (raw)
In-Reply-To: <20131219091423.GC6199@x220.p-661hnu-f1>

Hi Johan,

> Hi Szymon,
> 
> On Thu, Dec 19, 2013, Szymon Janc wrote:
> > > 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)
> 
> What permissions does the file get created with if you omit this? Maybe
> the right fix is to set the umask explicitly in our main() or to modify
> how the daemon gets executed?

It was 0600 on Android so it looks like Android init is setting good mask, but
it was 0644 on Linux host.

I suppose we could fix system-emulator to set umask to have correct permissions
on host.

Will send V2.

-- 
BR
Szymon Janc



  reply	other threads:[~2013-12-19  9:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-18 14:05 [PATCH 0/4] android: Permanent storage support Szymon Janc
2013-12-18 14:05 ` [PATCH 1/4] android/bluetooth: Add initial support for permanent storage Szymon Janc
2013-12-19  8:29   ` Johan Hedberg
2013-12-19  8:35     ` Szymon Janc
2013-12-19  9:14       ` Johan Hedberg
2013-12-19  9:46         ` Szymon Janc [this message]
2013-12-18 14:05 ` [PATCH 2/4] android/bluetooth: Add initial support for storing device info Szymon Janc
2013-12-18 14:05 ` [PATCH 3/4] android/bluetooth: Add support for storing link keys Szymon Janc
2013-12-18 14:05 ` [PATCH 4/4] android/bluetooth: Add support for restoring devices from storage Szymon Janc

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1539507.GD54UJZ94B@uw000953 \
    --to=szymon.janc@tieto.com \
    --cc=johan.hedberg@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox