[Pkg-libvirt-commits] [libguestfs] 211/266: fish: edit: improve the editor execution
Hilko Bengen
bengen at moszumanska.debian.org
Fri Oct 3 14:42:03 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to annotated tag debian/1%1.27.35-1
in repository libguestfs.
commit 511275acb1e27b85034eb7b767dd4e93491f74a8
Author: Pino Toscano <ptoscano at redhat.com>
Date: Thu Aug 28 10:29:55 2014 +0200
fish: edit: improve the editor execution
Dynamically allocate the buffer for the command, and check also its exit
status.
Improvements taken from the current implementation in virt-edit.
---
fish/file-edit.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/fish/file-edit.c b/fish/file-edit.c
index 3412e84..408d20e 100644
--- a/fish/file-edit.c
+++ b/fish/file-edit.c
@@ -43,6 +43,7 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor)
CLEANUP_UNLINK_FREE char *tmpfilename = NULL;
char buf[256];
CLEANUP_FREE char *newname = NULL;
+ CLEANUP_FREE char *cmd = NULL;
struct stat oldstat, newstat;
int r, fd;
@@ -77,12 +78,14 @@ edit_file_editor (guestfs_h *g, const char *filename, const char *editor)
}
/* Edit it. */
- /* XXX Safe? */
- snprintf (buf, sizeof buf, "%s %s", editor, tmpfilename);
+ if (asprintf (&cmd, "%s %s", editor, tmpfilename) == -1) {
+ perror ("asprintf");
+ return -1;
+ }
- r = system (buf);
- if (r != 0) {
- perror (buf);
+ r = system (cmd);
+ if (r == -1 || WEXITSTATUS (r) != 0) {
+ perror (cmd);
return -1;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-libvirt/libguestfs.git
More information about the Pkg-libvirt-commits
mailing list