[Spice-devel,v2] reds: Assure we don't have stale statistic files before trying to create a new one

Submitted by Frediano Ziglio on July 15, 2015, 1:15 p.m.

Details

Message ID 1436966152-2845-1-git-send-email-fziglio@redhat.com
State Accepted
Headers show

Not browsing as part of any series.

Commit Message

Frediano Ziglio July 15, 2015, 1:15 p.m.
If a previous Qemu executable is not able to delete the statistic file
on the next creation with same name (statitics file are based on pid
numbers so if pid get reused for another Qemu process you get the same
name) it fails as you can't open a file with 0444 permissions (these
are the permission used to create these files).
This patch assure there are no stale file trying to remove it before the
creation of the new one. As file is based on pid and name used for spice
you are not deleting another file.

Fixes: rhbz#1177326

Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
---
 server/reds.c | 1 +
 1 file changed, 1 insertion(+)

Changes since v1:
- added reference to bugzilla in comment

Patch hide | download patch | download mbox

diff --git a/server/reds.c b/server/reds.c
index 0867edb..d1edc06 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3291,6 +3291,7 @@  static int do_spice_init(SpiceCoreInterface *core_interface)
     shm_name_len = strlen(SPICE_STAT_SHM_NAME) + 20;
     reds->stat_shm_name = (char *)spice_malloc(shm_name_len);
     snprintf(reds->stat_shm_name, shm_name_len, SPICE_STAT_SHM_NAME, getpid());
+    shm_unlink(reds->stat_shm_name);
     if ((fd = shm_open(reds->stat_shm_name, O_CREAT | O_RDWR, 0444)) == -1) {
         spice_error("statistics shm_open failed, %s", strerror(errno));
     }

Comments

ack

(is anybody using the state code shm, should it be disabled for regular builds?)

----- Original Message -----
> If a previous Qemu executable is not able to delete the statistic file
> on the next creation with same name (statitics file are based on pid
> numbers so if pid get reused for another Qemu process you get the same
> name) it fails as you can't open a file with 0444 permissions (these
> are the permission used to create these files).
> This patch assure there are no stale file trying to remove it before the
> creation of the new one. As file is based on pid and name used for spice
> you are not deleting another file.
> 
> Fixes: rhbz#1177326
> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  server/reds.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> Changes since v1:
> - added reference to bugzilla in comment
> 
> diff --git a/server/reds.c b/server/reds.c
> index 0867edb..d1edc06 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -3291,6 +3291,7 @@ static int do_spice_init(SpiceCoreInterface
> *core_interface)
>      shm_name_len = strlen(SPICE_STAT_SHM_NAME) + 20;
>      reds->stat_shm_name = (char *)spice_malloc(shm_name_len);
>      snprintf(reds->stat_shm_name, shm_name_len, SPICE_STAT_SHM_NAME,
>      getpid());
> +    shm_unlink(reds->stat_shm_name);
>      if ((fd = shm_open(reds->stat_shm_name, O_CREAT | O_RDWR, 0444)) == -1)
>      {
>          spice_error("statistics shm_open failed, %s", strerror(errno));
>      }
> --
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel
>
Thanks, pushed.

Christophe

On Wed, Jul 15, 2015 at 02:15:52PM +0100, Frediano Ziglio wrote:
> If a previous Qemu executable is not able to delete the statistic file
> on the next creation with same name (statitics file are based on pid
> numbers so if pid get reused for another Qemu process you get the same
> name) it fails as you can't open a file with 0444 permissions (these
> are the permission used to create these files).
> This patch assure there are no stale file trying to remove it before the
> creation of the new one. As file is based on pid and name used for spice
> you are not deleting another file.
> 
> Fixes: rhbz#1177326
> 
> Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
> ---
>  server/reds.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> Changes since v1:
> - added reference to bugzilla in comment
> 
> diff --git a/server/reds.c b/server/reds.c
> index 0867edb..d1edc06 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -3291,6 +3291,7 @@ static int do_spice_init(SpiceCoreInterface *core_interface)
>      shm_name_len = strlen(SPICE_STAT_SHM_NAME) + 20;
>      reds->stat_shm_name = (char *)spice_malloc(shm_name_len);
>      snprintf(reds->stat_shm_name, shm_name_len, SPICE_STAT_SHM_NAME, getpid());
> +    shm_unlink(reds->stat_shm_name);
>      if ((fd = shm_open(reds->stat_shm_name, O_CREAT | O_RDWR, 0444)) == -1) {
>          spice_error("statistics shm_open failed, %s", strerror(errno));
>      }
> -- 
> 2.1.0
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/spice-devel