1 /* libguestfs - the guestfsd daemon
2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "../src/guestfs_protocol.h"
30 do_command (char * const * const argv)
35 /* We need a root filesystem mounted to do this. */
38 /* Conveniently, argv is already a NULL-terminated argv-style array
39 * of parameters, so we can pass it straight in to our internal
40 * commandv. We just have to check the list is non-empty.
42 if (argv[0] == NULL) {
43 reply_with_error ("command: passed an empty list");
48 r = commandv (&out, &err, argv);
52 reply_with_error ("%s", err);
60 return out; /* Caller frees. */
64 do_command_lines (char * const * const argv)
68 int size = 0, alloc = 0;
71 out = do_command (argv);
75 /* Now convert the output to a list of lines. */
78 pend = strchr (p, '\n');
83 /* Final \n? Don't return an empty final element. */
84 if (*pend == '\0') break;
87 if (add_string (&lines, &size, &alloc, p) == -1) {
97 if (add_string (&lines, &size, &alloc, NULL) == -1)
100 return lines; /* Caller frees. */