git.annexia.org
/
libguestfs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
daemon: Don't use files with fixed names in /tmp (thanks Steve Kemp).
[libguestfs.git]
/
daemon
/
inotify.c
diff --git
a/daemon/inotify.c
b/daemon/inotify.c
index
ec3aa64
..
27fe4b0
100644
(file)
--- a/
daemon/inotify.c
+++ b/
daemon/inotify.c
@@
-1,5
+1,5
@@
/* libguestfs - the guestfsd daemon
/* 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
*
* 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
@@
-28,7
+28,7
@@
#include <sys/inotify.h>
#endif
#include <sys/inotify.h>
#endif
-#include "
../src/
guestfs_protocol.h"
+#include "guestfs_protocol.h"
#include "daemon.h"
#include "actions.h"
#include "optgroups.h"
#include "daemon.h"
#include "actions.h"
#include "optgroups.h"
@@
-70,7
+70,7
@@
do_inotify_init (int max_events)
#ifdef HAVE_SYS_INOTIFY_H
FILE *fp;
#ifdef HAVE_SYS_INOTIFY_H
FILE *fp;
- NEED_ROOT (return -1);
+ NEED_ROOT (
,
return -1);
if (max_events < 0) {
reply_with_error ("max_events < 0");
if (max_events < 0) {
reply_with_error ("max_events < 0");
@@
-314,13
+314,24
@@
do_inotify_files (void)
char **ret = NULL;
int size = 0, alloc = 0;
unsigned int i;
char **ret = NULL;
int size = 0, alloc = 0;
unsigned int i;
- FILE *fp;
+ FILE *fp
= NULL
;
guestfs_int_inotify_event_list *events;
char buf[PATH_MAX];
guestfs_int_inotify_event_list *events;
char buf[PATH_MAX];
+ char tempfile[] = "/tmp/inotifyXXXXXX";
+ int fd;
+ char cmd[64];
NEED_INOTIFY (NULL);
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;
if (fp == NULL) {
reply_with_perror ("sort");
return NULL;
@@
-349,9
+360,11
@@
do_inotify_files (void)
pclose (fp);
pclose (fp);
- fp = f
open ("/tmp/inotify"
, "r");
+ fp = f
dopen (fd
, "r");
if (fp == NULL) {
if (fp == NULL) {
- reply_with_perror ("/tmp/inotify");
+ reply_with_perror ("%s", tempfile);
+ unlink (tempfile);
+ close (fd);
return NULL;
}
return NULL;
}
@@
-361,22
+374,24
@@
do_inotify_files (void)
if (len > 0 && buf[len-1] == '\n')
buf[len-1] = '\0';
if (len > 0 && buf[len-1] == '\n')
buf[len-1] = '\0';
- if (add_string (&ret, &size, &alloc, buf) == -1) {
- fclose (fp);
+ if (add_string (&ret, &size, &alloc, buf) == -1)
goto error;
goto error;
- }
}
}
- fclose (fp);
+ fclose (fp); /* implicitly closes fd */
+ fp = NULL;
if (add_string (&ret, &size, &alloc, NULL) == -1)
goto error;
if (add_string (&ret, &size, &alloc, NULL) == -1)
goto error;
- unlink (
"/tmp/inotify"
);
+ unlink (
tempfile
);
return ret;
error:
return ret;
error:
- unlink ("/tmp/inotify");
+ if (fp != NULL)
+ fclose (fp);
+
+ unlink (tempfile);
return NULL;
#else
NOT_AVAILABLE (NULL);
return NULL;
#else
NOT_AVAILABLE (NULL);