Re: [PATCHv2 obexd] Add cleanup of '.pcsuite' file on pcsuite_init

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

 



Hi Radek,

On Wed, Nov 9, 2011 at 12:55 PM, Radoslaw Jablonski
<radoslawjablonski@xxxxxxxxx> wrote:
> File named '.pcsuite' is used to show to other applications
> that PC-Suite connection is active - some operations shouldn't
> be performed on device when synchronization is in progress.
> In scenario when obexd will be killed or crashed during PC-Suite
> connection this file will stay forever in filestystem, because
> pcsuite_disconnect won't be called to do clean-up.
>
> This patch adds function which will remove '.pcsuite' file
> in such problematic scenarios on pcsuite_init.
> ---
>  plugins/pcsuite.c |   24 +++++++++++++++++++++++-
>  1 files changed, 23 insertions(+), 1 deletions(-)
>
> diff --git a/plugins/pcsuite.c b/plugins/pcsuite.c
> index 27a3496..69e184f 100644
> --- a/plugins/pcsuite.c
> +++ b/plugins/pcsuite.c
> @@ -55,6 +55,7 @@
>
>  #define PCSUITE_CHANNEL 24
>  #define PCSUITE_WHO_SIZE 8
> +#define PCSUITE_FILE_NAME ".pcsuite"
>
>  #define PCSUITE_RECORD "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>    \
>  <record>                                                               \
> @@ -130,7 +131,7 @@ static void *pcsuite_connect(struct obex_session *os, int *err)
>        if (ftp == NULL)
>                return NULL;
>
> -       filename = g_build_filename(g_get_home_dir(), ".pcsuite", NULL);
> +       filename = g_build_filename(g_get_home_dir(), PCSUITE_FILE_NAME, NULL);
>
>        fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0644);
>        if (fd < 0 && errno != EEXIST) {
> @@ -497,10 +498,31 @@ static struct obex_mime_type_driver backup = {
>        .flush = backup_flush,
>  };
>
> +static void pcsuite_file_cleanup(void)
> +{
> +       char *filename;
> +       struct stat buf;
> +
> +       filename = g_build_filename(g_get_home_dir(), PCSUITE_FILE_NAME, NULL);
> +
> +       if (stat(filename, &buf) == 0) {
> +               DBG("Removing unneeded pcsuite-file: %s", filename);
> +               remove(filename);
> +       }
> +
> +       g_free(filename);
> +}
> +
>  static int pcsuite_init(void)
>  {
>        int err;
>
> +       /* In some cases '.pcsuite' file will be present on device even if
> +        * there is no PC-Suite connection active in the moment(eg. obexd
> +        * crashed or was killed while pcsuite connection was active)
> +        * Removing this file if not needed. */
> +       pcsuite_file_cleanup();
> +
>        err = obex_service_driver_register(&pcsuite);
>        if (err < 0)
>                return err;
> --
> 1.7.0.4

Ack, this should really be a pid file created by the service we
communicate but since this is probably not gonna be fixed then it
seems this workaround is the only thing that can be done.

-- 
Luiz Augusto von Dentz
--
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