45 Commits

Author SHA1 Message Date
Richard W.M. Jones
0f54df53d2 build: Remove gnulib.
As part of our efforts to clean up and simplify libguestfs, removing
gnulib deletes a large dependency that we mostly no longer use and
causes problems for new users trying to build the library from source.

A few modules from gnulib are still used (under a compatible license)
and these are copied into gnulib/lib/
2021-04-08 11:36:40 +01:00
Richard W.M. Jones
4af1c631a2 daemon/command.c daemon/debug.c df/main.c: Ignore bogus GCC analyzer warnings
See upstream bug report:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99193
2021-02-22 10:37:49 +00:00
Richard W.M. Jones
d5a8f82887 Use 'const' for stack integers where possible.
May improve optimization possibilities in a few cases.
2016-07-26 10:43:45 +01:00
Richard W.M. Jones
82aa5bd25e docs: Add internal documentation for a few daemon functions. 2016-04-12 20:59:40 +01:00
Pino Toscano
d2a36f8cbe daemon: improve debugging for "stdout on stderr" flag
When the COMMAND_FLAG_FOLD_STDOUT_ON_STDERR flag is passed to
command*(), indicate that as stdout=e in debugging message.
2016-01-26 11:21:46 +01:00
Richard W.M. Jones
2cb8e5ddb8 Minor fixes to "daemon: Split out command* functions and CLEANUP_* macros."
This updates commit d94860d7e8.

Thanks: Pino Toscano.
2016-01-22 12:52:33 +00:00
Richard W.M. Jones
d94860d7e8 daemon: Split out command* functions and CLEANUP_* macros.
This allows the command* functions and CLEANUP_* macros to be used
independently from the daemon.
2016-01-22 09:12:17 +00:00
Richard W.M. Jones
b5066c67e0 daemon: Rename daemon/command.c -> daemon/sh.c.
Simply a file rename, no other change.
2016-01-21 14:25:44 +00:00
Pino Toscano
9c3b4f6ad8 daemon: improve internal commandrvf
- add a flag to request chroot for the process, which is done only as
  very last (before chdir) operation before exec'ing the process in the
  child: this avoids using CHROOT_IN & CHROOT_OUT around command*
  invocations, and reduces the code spent in chroot mode
- add failure checks for dup2, open, and chdir done in child, not
  proceeding to executing the process if they fail
- open /dev/null without O_CLOEXEC, so it stays available for the
  exec'ed process, and thus we don't need to provide an own fd for stdin

Followup of commit fd2f175ee7, thanks also
to the notes and hints provided by Mateusz Guzik.
2015-12-15 15:00:11 +01:00
Pino Toscano
fd2f175ee7 daemon: always provide stdin when running chroot commands (RHBZ#1280029)
When running commands in the mounted guest (using the "command" API, and
APIs based on it), provide the /dev/null from the appliance as open fd
for stdin.  Commands usually assume stdin is open if they didn't close
it explicitly, so this should avoid crashes or misbehavings due to that.
2015-11-20 14:55:46 +01:00
Richard W.M. Jones
d9cd2dc9b0 daemon: Add a note about how 'mount --rbind' doesn't work. 2014-01-28 21:02:11 +00:00
Richard W.M. Jones
9df50877f8 daemon: If /selinux exists in the guest, bind-mount /sys/fs/selinux to there.
Commit 72afcf450a was partially
incorrect.  If the guest userspace is expecting /selinux to exist,
then we should bind-mount /sys/fs/selinux from the appliance kernel
there.
2014-01-28 21:02:11 +00:00
Richard W.M. Jones
ab33653ef3 daemon: Bind-mount /sys/fs/selinux into sysroot when running commands.
Even though we are already bind-mounting /sys, it is necessary to also
bind-mount /sys/fs/selinux in order for SELinux commands (in
particular, 'load_policy') to work.

This fixes/reverts commit 7367729ec7.
2014-01-24 19:36:33 +00:00
Olaf Hering
d87cfefcdd daemon: add missing GUESTFSD_EXT_CMD usage
Signed-off-by: Olaf Hering <olaf@aepfle.de>
2014-01-19 20:30:42 +00:00
Richard W.M. Jones
9521422ce6 daemon: command: Copy appliance /etc/resolv.conf in before running commands.
When you try to run commands for an Ubuntu guest, they fail because in
Ubuntu /etc/resolv.conf is a symlink to /run/...  and this turns out
to be a dangling symlink when the Ubuntu guest is mounted up under the
appliance.

Therefore even if the network is enabled, any command which tries to
do name resolution will fail.

Ideally we would like to bind-mount the appliance /etc/resolv.conf
into the sysroot.  However this is not possible because mount is buggy
(see comment).  So instead we use a complex hack to achieve the same
ends.

Note this is only done if the network is enabled and if /etc in the
guest actually exists.  The original /etc/resolv.conf is restored
as soon as the command has run.
2013-10-07 22:01:02 +01:00
Richard W.M. Jones
b8b1b0296b daemon: Refactor bind-mount code.
This is just code motion.
2013-10-07 21:51:29 +01:00
Richard W.M. Jones
fc2947b112 daemon: sh: Fix missing initializer which caused segfault (RHBZ#1000121).
Thanks: Olaf Hering.
2013-08-22 19:39:25 +01:00
Richard W.M. Jones
7367729ec7 daemon: Remove unnecessary sysroot_path (selinux).
This fixes commit 72afcf450a.
2013-08-10 23:02:42 +01:00
Hilko Bengen
72afcf450a Fix for changed selinux mountpoint
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=707217
2013-05-21 19:23:14 +01:00
Richard W.M. Jones
950951c67d daemon: Use the new CLEANUP_* macros to simplify code. 2013-01-28 18:01:43 +00:00
Olaf Hering
0306c98d31 daemon: collect list of called external commands
guestfsd calls many different tools. Keeping track of all of them is
error prone. This patch introduces a new helper macro to put the command
string into its own ELF section:

GUESTFSD_EXT_CMD(C_variable, command_name);

This syntax makes it still possible to grep for used command names.

The actual usage of the collected list could be like this:

  objcopy -j .guestfsd_ext_cmds -O binary daemon/guestfsd /dev/stdout |
  tr '\0' '\n' | sort -u

The resulting output will be used to tell mkinitrd which programs to
copy into the initrd.

Signed-off-by: Olaf Hering <olaf@aepfle.de>

RWMJ:
 - Move str_vgchange at request of author.
 - Fix snprintf call in daemon/debug.c
2012-08-30 20:57:07 +01:00
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00:00
Richard W.M. Jones
f5096dd546 daemon: Keep Coverity happy by ignoring some return values. 2011-06-09 10:53:52 +01:00
Richard W.M. Jones
33b638109e proto: Fix FileIn ops that abort during the chunk upload stage.
As a previous, incorrect attempt to fix RHBZ#576879 we tried to
prevent the daemon from sending an error reply if the daemon had
cancelled the transfer.  This is wrong: the daemon should send an
error reply in these cases.

A simple test case is this:

  guestfish -N fs -m /dev/sda1 upload big-file /

(This fails because the target "/" is a directory, not a file.)
Prior to this commit, libguestfs would hang instead of printing an
error.  With this commit, libguestfs prints an error.

What is happening is:

  (1) Library is uploading
  a file                          (2) In the middle of the long
                                  upload, daemon detects an error.
                                  Daemon cancels.
  (3) Library detects cancel,
  sends cancel chunk, then waits
  for the error reply from the
  daemon.                         (4) Daemon is supposed to send
                                  an error reply message.

Because step (4) wasn't happening, uploads that failed like this would
hang in the library (waiting for the error message, while the daemon
was waiting for the next request).

This also adds a regression test.

This temporarily breaks the "both ends cancel" case (RHBZ#576879c5).
Therefore the test for that is disabled, and this is fixed in the next
patch in the series.

This partially reverts commit dc706a639e.
2011-03-18 17:56:45 +00:00
Richard W.M. Jones
9ff9941836 daemon: Don't use ../src path to include generator_protocol.h
This file is already hard-linked into the current directory, so
the relative path is not required.
2010-11-03 13:15:19 +00:00
Richard Jones
dc706a639e Fix FileIn cmds losing synch if both ends send cancel messages (RHBZ#576879).
During a FileIn command (eg. upload, tar-in) if both sides
experience errors, then both sides could send cancel messages,
the result being lost synchronization.

The reason for the lost synch was because the daemon was ignoring
this case and sending an error message back which the library side
(which had cancelled) was not expecting.

Fix this by checking in the daemon for the case where the library
also cancels during daemon cancellation, and not sending an error
messages.

This also includes an enhanced regression test which checks for this
case.

This extends the original fix in
commit 5922d7084d.

More details can be found here:
https://bugzilla.redhat.com/show_bug.cgi?id=576879#c5
2010-05-13 17:08:02 +01:00
Richard Jones
5922d7084d Fix upload losing synchronization if root not mounted (RHBZ#576879).
Modify the generator so that it can correctly handle early
cancellation for Pathname|Device|.. parameters.  This fixes
the upload command, but consequently we need to fix the
parameters for tar_in and t?z_in commands.  This should also
mean that 'win:' can now be used as the second argument of
tar_in and t?z_in commands in guestfish, whereas previously
this wouldn't have worked.

Adds a regression test for the original problem.
2010-04-17 15:22:29 +01:00
Richard Jones
e9c3711310 daemon: Don't need to prefix error messages with the command name.
The RPC stubs already prefix the command name to error messages.
The daemon doesn't have to do this.  As a (small) benefit this also
makes the daemon slightly smaller.

Code in the daemon such as:

  if (argv[0] == NULL) {
    reply_with_error ("passed an empty list");
    return NULL;
  }

now results in error messages like this:

  ><fs> command ""
  libguestfs: error: command: passed an empty list

(whereas previously you would have seen ..command: command:..)
2010-02-12 16:49:00 +00:00
Richard Jones
3cf719bc07 Fix prototype of commandv to match prototype of commandrv. 2009-11-09 11:05:19 +00:00
Jim Meyering
e82d864e02 command.c: avoid shadowing a global function
* daemon/command.c (do_sh_lines, do_sh): Do not shadow global "command".
2009-08-17 11:40:24 +02:00
Jim Meyering
adf20c0c4d adjust const "**" pointers to avoid warnings
Also, ...
* src/generator.ml: Add DeviceList type, and propagate that change
out to all calling/interface code.
2009-08-17 11:40:24 +02:00
Jim Meyering
84fc760439 generator.ml: use new "Pathname" designation
Nearly every file-related function in daemons/*.c is affected:
Remove this pair of statements from each affected do_* function:
-  NEED_ROOT (return -1);
-  ABS_PATH (dir, return -1);
and change the type of the corresponding parameter to "const char *".
* src/generator.ml: Emit NEED_ROOT just once, even when there are two or
more Pathname args.
2009-08-13 14:45:34 +02:00
Jim Meyering
6bda071b5c update all NEED_ROOT uses
run this command:
  git grep -l -w NEED_ROOT|xargs perl -pi -e \
    's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
2009-08-13 14:45:34 +02:00
Richard Jones
27566d8323 Return error if allocations fail. 2009-08-12 18:23:17 +01:00
Richard Jones
2361905686 If using SELinux, mount /selinux in the appliance.
If selinux=1 on the Linux kernel command line, then we mount
/selinux in the appliance.  We will also bind-mount this
directory into guests when we run commands.
2009-08-12 17:23:58 +01:00
Richard Jones
78029b529a Make /sysroot path configurable.
Currently /sysroot is hard-coded throughout the daemon code.

This patch turns the path into a variable so that we can change
it in future, for example to allow standalone mode to be implemented.

This patch was tested by running all the C API tests successfully.
2009-07-18 10:43:52 +01:00
Jim Meyering
a7b73d4a1e remove trailing blanks 2009-07-03 17:04:21 +02:00
Richard Jones
57d2dfab18 Add 'sh' and 'sh-lines' commands. 2009-06-22 07:49:37 +01:00
Richard Jones
56bef498f4 In the daemon, change all const char * parameters to char *. 2009-06-10 14:16:47 +01:00
Richard Jones
ab81d09a71 Fix RHBZ#503169 comment 13 (regression) and add a regression test. 2009-06-04 15:06:28 +01:00
Charles Duffy
80e1575787 Use --rbind rather than --bind for bind mounting /dev (to get /dev/pts). 2009-06-04 08:45:04 +01:00
Richard Jones
b2a5fec5f8 Refactor line splitting code in the daemon, and fix it so it works. 2009-05-12 17:17:19 +01:00
Richard Jones
296b536c96 Bind-mount /dev, /proc and /sys into chroot when running commands. 2009-04-30 18:05:13 +01:00
Richard Jones
374af1d1c8 Better handling of trailing \n problem. 2009-04-14 14:38:31 +01:00
Richard Jones
5365ebd501 Add 'command' and 'command-lines'. Fix args freeing in Perl bindings. 2009-04-14 13:51:12 +01:00