37 Commits

Author SHA1 Message Date
Richard W.M. Jones
47c2233026 daemon/blkid.c: Fix compilation error introduced by earlier change
blkid.c: In function ‘test_blkid_p_i_opt’:
  blkid.c:105:3: error: label ‘command_failed’ defined but not used [-Werror=unused-label]
    105 |   command_failed:
        |   ^~~~~~~~~~~~~~

Fixes: https://github.com/libguestfs/libguestfs/pull/315
Fixes: commit ff4467a1a4
2026-03-10 08:31:27 +00:00
shivanayak
ff4467a1a4 daemon: fix low severity bugs in debug, file, and blkid (#315)
- debug.c: fix memory leak of out buffer on opendir failure in
  debug_fds. After fclose on open_memstream, the out buffer is
  allocated and must be freed.

- file.c: add missing reply_with_perror on strdup failure in
  do_zfile, so callers get a proper error message instead of
  silent NULL return.

- blkid.c: fix wrong error variable used at command_failed label
  in test_blkid_p_i_opt. The second commandr stores its error in
  err2, but goto command_failed would report err from the first
  command. Inline the error reporting with the correct variable.

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-09 18:14:32 +00:00
Richard W.M. Jones
d573cfde5b daemon: Reimplement ‘vfs_type’ API in OCaml. 2017-07-27 22:31:22 +01:00
Richard W.M. Jones
381c8b68c4 daemon: Remove GUESTFSD_EXT_CMD.
GUESTFSD_EXT_CMD was used by OpenSUSE to track which external commands
are run by the daemon and package those commands into the appliance.

It is no longer used by recent SUSE builds, so remove it.

Thanks: Pino Toscano, Olaf Hering.
2017-07-27 17:31:41 +01:00
Pino Toscano
9fa8e07465 daemon: fix cleanup of stringsbuf usages
Declare most of the stringsbuf as CLEANUP_FREE_STRINGSBUF, so they are
freed completely on stack unwind: use take_stringsbuf() in return
places to take away from the stringsbuf its content, and remove all the
manual calls to free_stringslen (no more needed now).
This requires to not use free_stringslen anymore on failure in the
helper functions of stringsbuf, which now leave the content as-is (might
be still useful even on error).

This allows us to simplify the memory management of stringsbuf's, which
are not properly fully freed, fixing memory leaks in some error paths
(which were not calling free_stringslen).
2016-07-07 16:28:18 +02:00
Richard W.M. Jones
677c721e85 Fix whitespace.
Because of previous automated commits, such as changing 'guestfs___'
-> 'guestfs_int_', several function calls no longer lined up with
their parameters, and some lines were too long.

The bulk of this commit was done using emacs batch mode and the
technique described here:

  http://www.cslab.pepperdine.edu/warford/BatchIndentationEmacs.html

The changes suggested by emacs were then reviewed by hand.
2015-10-05 14:28:33 +01:00
Chen Hanxiao
c3edd076b9 daemon: add a space after func name to fit code-style
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2015-07-13 12:31:52 +01:00
Pino Toscano
8ad667f198 daemon: use ntfslabel(1) to get ntfs labels
blkid(1) (or actually, libblkid) seems to handle filesystem labels up
to 127 characters. Considering that btrfs labels can be up to 128
characters, this means long labels are not read correctly (i.e. get
truncated) by blkid.  Furthermore, ntfs labels are actually unicode,
and libblkid seems to not decode them correctly.

Hence, if ntfsprogs is available invoke `ntfslabel` to get the label
of ntfs filesystems.

Related to RHBZ#1164708.
2015-01-19 16:47:53 +01:00
Pino Toscano
6db3c100e7 daemon: use btrfs(1) to get btrfs labels
blkid(1) (or actually, libblkid) seems to handle filesystem labels up
to 127 characters. Considering that btrfs labels can be up to 255
characters, this means long labels are not read correctly (i.e. get
truncated) by blkid.

Get the filesystem type, and if btrfs is available invoke
`btrfs filesystem` to get the label of btrfs filesystems.

Related to RHBZ#1164708.
2015-01-19 16:47:53 +01:00
Pino Toscano
ad4ba5997b daemon: blkid: fix memory issues in "no -p/-i" mode
Fix the memory issues in the implementation that uses no -p nor -i:
- use add_string_nodup to add results from get_blkid_tag (which returns
  new strings), so those strings are not leaked
- use free_stringslen to clean the hash on error, as in such case the
  stringbuf will not be terminated with a null entry, thus causing
  free_strings to crash
2014-08-08 14:58:08 +02:00
Richard W.M. Jones
19dcc0de1f Annual scavange to find mixed declarations and statements.
Hopefully this is just code motion.
2014-03-17 19:54:16 +00:00
Richard W.M. Jones
8580ef7d0f New API: Implement set-uuid for ext2/3/4 and XFS (RHBZ#986877).
Also includes tests.
2013-07-22 13:52:23 +01:00
Matthew Booth
47b929b789 mountable: Implement Mountable support for all apis which take it
A Mountable is passed from the library to the daemon as a string. The daemon
stub parses it into a mountable_t, which it passes to the implementation.

Update all implementations which now take a mountable_t.
2013-02-11 15:42:58 +00: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
Richard W.M. Jones
710ec49bac daemon: Don't call reply_with_* after split_lines fails.
split_lines already sets reply_with_*, so calling it again would lose
protocol synchronization.
2012-03-16 14:11:02 +00:00
Richard W.M. Jones
14df5fa5d1 daemon: Implement a growable strings buffer type.
Previously a lot of daemon code used three variables (a string list,
'int size' and 'int alloc') to track growable strings buffers.  This
commit implements a simple struct containing the same variables, but
using size_t instead of int:

  struct stringsbuf {
    char **argv;
    size_t size;
    size_t alloc;
  };

Use it like this:

  DECLARE_STRINGSBUF (ret);
//...
  if (add_string (&ret, str) == -1)
    return NULL;
//...
  if (end_stringsbuf (&ret) == -1)
    return NULL;
  return ret.argv;
2012-03-13 08:19:11 +00:00
Richard W.M. Jones
13c2db39ab daemon: Remove unused variables. 2012-03-12 11:53:04 +00:00
Richard W.M. Jones
aa978b75ae daemon: Fix leak of strings in blkid (found by valgrind). 2012-01-24 17:00:32 +00:00
Richard W.M. Jones
43a6974cb3 daemon: blkid: Whitespace changes, and use size_t for i instead of pointer.
This is just a code clean-up with no functional change.
2012-01-24 17:00:23 +00:00
Richard W.M. Jones
fd3e3ca188 debian: Debian 6 blkid has -p but not -i.
Fix the existing test to work correctly in this case.

Other cleanups.
2012-01-23 12:18:58 +00:00
Wanlong Gao
6c5f7c954c blkid: split the RHEL5 which can't support some options
RHEL5 shoult not support '-p', '-i' and '-o export' options.
But we just split it according to the '-p' option.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-12-05 10:15:12 +00:00
Richard W.M. Jones
e18058a5a5 Revert "blkid: Use -c /dev/null because RHEL 5 blkid doesn't have -p option."
This reverts commit 6533491b17.
2011-12-04 16:47:37 +00:00
Richard W.M. Jones
7f14c042eb Revert "blkid: Fix mistake in previous commit."
This reverts commit c48226a502.
2011-12-04 16:47:29 +00:00
Richard W.M. Jones
c48226a502 blkid: Fix mistake in previous commit.
This updates commit 6533491b17.
2011-12-03 23:16:00 +00:00
Richard W.M. Jones
6533491b17 blkid: Use -c /dev/null because RHEL 5 blkid doesn't have -p option. 2011-12-03 22:58:03 +00:00
Wanlong Gao
fcb975a642 NEW API: add blkid command to print the attributes of the device
A NEW API blkid.
It can print the device attributes.
Use it after list-devices, we can list ower devices and the attributes
of each device.
Use it like:
blkid <device>
It's should be a usefull function.

Signed-off-by: Wanlong Gao <gaowanlong@cn.fujitsu.com>
2011-12-03 11:05:48 +00:00
Matthew Booth
04ea1375c5 Update FSF address. 2011-11-08 14:43:07 +00:00
Richard W.M. Jones
1d0f398d8e blkid: Use -c /dev/null option to kill the cache.
On recent Debian, /etc/blkid.tab is now a symlink to /dev/.blkid.tab.
Rather than chasing the cache file around (it may move to /run in future)
use the -c /dev/null option to stop blkid from reading the cache.
2011-07-20 15:58:38 +01:00
Richard W.M. Jones
168fd4ad5d blkid: Detect when value not found and return empty string.
If the blkid command returns 2, that means the value was not found.

Note that this changes the output of the vfs-type API when the
filesystem has no type (eg when it is empty).  Previously this would
return an error.  Now it returns empty string "".

We did not document this either way.  Making it return empty string is
consistent with vfs-label and vfs-uuid.

This change broke list-filesystems, since that code was assuming that
vfs-type could only return a filesystem type or an error.
2011-07-20 15:57:56 +01:00
Richard W.M. Jones
5d7ee3f0c5 daemon: blkid cache is at a different location on Debian.
Remove both possible cache locations.
2010-11-24 09:41:48 +00:00
Richard Jones
27b730a682 New APIs: vfs-label and vfs-uuid return label and uuid for many fs types.
These APIs generalize the existing 'get-e2label' and 'get-e2uuid'
calls, to provide calls which should be able to get the label
and UUID for most filesystem types.  These use 'blkid' to do the
work.

I have tested that the blkid commands themselves work on RHEL 5.

(Suggested by Yufang Zhang).
2010-06-01 15:30:08 +01:00
Richard Jones
21c42e9fab daemon: Kill blkid cache to improve reliability of blkid commands.
By killing the cache file, we make blkid work in situations such
as a just-created filesystem.
2010-06-01 15:29:09 +01:00
Richard Jones
85c71f8fff daemon: Generalize the implementation of vfs-type.
Note that there is no change to the semantics of the code.
2010-06-01 13:39:25 +01:00
Richard Jones
9e0b31a2af appliance: Set $PATH instead of hard-coding paths to binaries everywhere.
Change the appliance so PATH includes common directories.  Thus
we don't need to hard-code paths to binaries (eg. "/sbin/fdisk")
everywhere.
2010-03-26 13:36:30 +00: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
d609130cb6 New API: vfs_type - get the Linux VFS driver for a mounted device. 2009-10-26 15:52:40 +00:00