X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=daemon%2Finotify.c;h=3fc7b92b437bda6ce43429b77a1d7950dc138438;hb=182c25b2a42e9a8f76beba440da328e37f18c9b9;hp=c8862e552cc4c5d7448a47aae8e4fe0a4d30360c;hpb=346c5b0ebf58c81f657540eeb72abaa41bfc4e3f;p=libguestfs.git diff --git a/daemon/inotify.c b/daemon/inotify.c index c8862e5..3fc7b92 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -1,5 +1,5 @@ /* libguestfs - the guestfsd daemon - * Copyright (C) 2009 Red Hat Inc. + * Copyright (C) 2009-2011 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -13,7 +13,7 @@ * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #include @@ -317,10 +317,21 @@ do_inotify_files (void) FILE *fp = NULL; guestfs_int_inotify_event_list *events; char buf[PATH_MAX]; + char tempfile[] = "/tmp/inotifyXXXXXX"; + int fd; + char cmd[64]; NEED_INOTIFY (NULL); - fp = popen ("sort -u > /tmp/inotify", "w"); + fd = mkstemp (tempfile); + if (fd == -1) { + reply_with_perror ("mkstemp"); + return NULL; + } + + snprintf (cmd, sizeof cmd, "sort -u > %s", tempfile); + + fp = popen (cmd, "w"); if (fp == NULL) { reply_with_perror ("sort"); return NULL; @@ -349,9 +360,11 @@ do_inotify_files (void) pclose (fp); - fp = fopen ("/tmp/inotify", "r"); + fp = fdopen (fd, "r"); if (fp == NULL) { - reply_with_perror ("/tmp/inotify"); + reply_with_perror ("%s", tempfile); + unlink (tempfile); + close (fd); return NULL; } @@ -365,20 +378,20 @@ do_inotify_files (void) goto error; } - fclose (fp); + fclose (fp); /* implicitly closes fd */ fp = NULL; if (add_string (&ret, &size, &alloc, NULL) == -1) goto error; - unlink ("/tmp/inotify"); + unlink (tempfile); return ret; error: if (fp != NULL) fclose (fp); - unlink ("/tmp/inotify"); + unlink (tempfile); return NULL; #else NOT_AVAILABLE (NULL);