From: Jim Meyering <meyering(a)redhat.com>
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.
---
daemon/augeas.c | 23 +++++++++-----------
daemon/blockdev.c | 22 ++++++++++----------
daemon/checksum.c | 5 +---
daemon/cmp.c | 2 +-
daemon/command.c | 4 +-
daemon/cpmv.c | 6 ++--
daemon/debug.c | 2 +-
daemon/devsparts.c | 2 +-
daemon/dir.c | 25 ++++------------------
daemon/du.c | 5 +---
daemon/ext2.c | 14 ++++++------
daemon/fallocate.c | 5 +---
daemon/file.c | 57 +++++++++++-----------------------------------------
daemon/find.c | 5 +---
daemon/fsck.c | 2 +-
daemon/glob.c | 5 +---
daemon/grep.c | 29 +++++++++++--------------
daemon/grub.c | 5 +---
daemon/headtail.c | 13 ++++-------
daemon/hexdump.c | 5 +---
daemon/initrd.c | 5 +---
daemon/inotify.c | 2 +-
daemon/link.c | 17 ++++-----------
daemon/ls.c | 10 +-------
daemon/lvm.c | 20 ++++++++----------
daemon/mknod.c | 11 +++------
daemon/mount.c | 26 +++++++++--------------
daemon/ntfs.c | 2 +-
daemon/readdir.c | 5 +---
daemon/realpath.c | 5 +---
daemon/scrub.c | 12 ++--------
daemon/sfdisk.c | 18 ++++++++--------
daemon/stat.c | 15 ++-----------
daemon/strings.c | 7 +----
daemon/swap.c | 35 +++++++++++--------------------
daemon/tar.c | 14 +++---------
daemon/upload.c | 4 +-
daemon/wc.c | 11 +++------
daemon/xattr.c | 39 ++++++++++++++++-------------------
daemon/zero.c | 2 +-
daemon/zerofree.c | 2 +-
src/generator.ml | 45 ++++++++++++++++++++++++++++------------
42 files changed, 205 insertions(+), 338 deletions(-)
diff --git a/daemon/augeas.c b/daemon/augeas.c
index b6cc8f0..7de3624 100644
--- a/daemon/augeas.c
+++ b/daemon/augeas.c
@@ -49,14 +49,11 @@ static augeas *aug = NULL;
/* We need to rewrite the root path so it is based at /sysroot. */
int
-do_aug_init (char *root, int flags)
+do_aug_init (const char *root, int flags)
{
#ifdef HAVE_AUGEAS
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (root, return -1);
-
if (aug) {
aug_close (aug);
aug = NULL;
@@ -100,7 +97,7 @@ do_aug_close (void)
}
int
-do_aug_defvar (char *name, char *expr)
+do_aug_defvar (const char *name, const char *expr)
{
#ifdef HAVE_AUG_DEFVAR
int r;
@@ -120,7 +117,7 @@ do_aug_defvar (char *name, char *expr)
}
guestfs_int_int_bool *
-do_aug_defnode (char *name, char *expr, char *val)
+do_aug_defnode (const char *name, const char *expr, const char *val)
{
#ifdef HAVE_AUG_DEFNODE
static guestfs_int_int_bool r;
@@ -142,7 +139,7 @@ do_aug_defnode (char *name, char *expr, char *val)
}
char *
-do_aug_get (char *path)
+do_aug_get (const char *path)
{
#ifdef HAVE_AUGEAS
const char *value = NULL;
@@ -185,7 +182,7 @@ do_aug_get (char *path)
}
int
-do_aug_set (char *path, char *val)
+do_aug_set (const char *path, const char *val)
{
#ifdef HAVE_AUGEAS
int r;
@@ -206,7 +203,7 @@ do_aug_set (char *path, char *val)
}
int
-do_aug_insert (char *path, char *label, int before)
+do_aug_insert (const char *path, const char *label, int before)
{
#ifdef HAVE_AUGEAS
int r;
@@ -227,7 +224,7 @@ do_aug_insert (char *path, char *label, int before)
}
int
-do_aug_rm (char *path)
+do_aug_rm (const char *path)
{
#ifdef HAVE_AUGEAS
int r;
@@ -248,7 +245,7 @@ do_aug_rm (char *path)
}
int
-do_aug_mv (char *src, char *dest)
+do_aug_mv (const char *src, const char *dest)
{
#ifdef HAVE_AUGEAS
int r;
@@ -269,7 +266,7 @@ do_aug_mv (char *src, char *dest)
}
char **
-do_aug_match (char *path)
+do_aug_match (const char *path)
{
#ifdef HAVE_AUGEAS
char **matches = NULL;
@@ -341,7 +338,7 @@ do_aug_load (void)
/* Simpler version of aug-match, which also sorts the output. */
char **
-do_aug_ls (char *path)
+do_aug_ls (const char *path)
{
#ifdef HAVE_AUGEAS
char **matches;
diff --git a/daemon/blockdev.c b/daemon/blockdev.c
index 46ee994..0745007 100644
--- a/daemon/blockdev.c
+++ b/daemon/blockdev.c
@@ -32,7 +32,7 @@
* we centralize it in one call.
*/
static int64_t
-call_blockdev (char *device, char *switc, int extraarg, int prints)
+call_blockdev (const char *device, char *switc, int extraarg, int prints)
{
int r;
int64_t rv;
@@ -78,37 +78,37 @@ call_blockdev (char *device, char *switc, int extraarg, int prints)
}
int
-do_blockdev_setro (char *device)
+do_blockdev_setro (const char *device)
{
return (int) call_blockdev (device, "--setro", 0, 0);
}
int
-do_blockdev_setrw (char *device)
+do_blockdev_setrw (const char *device)
{
return (int) call_blockdev (device, "--setrw", 0, 0);
}
int
-do_blockdev_getro (char *device)
+do_blockdev_getro (const char *device)
{
return (int) call_blockdev (device, "--getro", 0, 1);
}
int
-do_blockdev_getss (char *device)
+do_blockdev_getss (const char *device)
{
return (int) call_blockdev (device, "--getss", 0, 1);
}
int
-do_blockdev_getbsz (char *device)
+do_blockdev_getbsz (const char *device)
{
return (int) call_blockdev (device, "--getbsz", 0, 1);
}
int
-do_blockdev_setbsz (char *device, int blocksize)
+do_blockdev_setbsz (const char *device, int blocksize)
{
if (blocksize <= 0 /* || blocksize >= what? */) {
reply_with_error ("blockdev_setbsz: blocksize must be > 0");
@@ -118,25 +118,25 @@ do_blockdev_setbsz (char *device, int blocksize)
}
int64_t
-do_blockdev_getsz (char *device)
+do_blockdev_getsz (const char *device)
{
return call_blockdev (device, "--getsz", 0, 1);
}
int64_t
-do_blockdev_getsize64 (char *device)
+do_blockdev_getsize64 (const char *device)
{
return call_blockdev (device, "--getsize64", 0, 1);
}
int
-do_blockdev_flushbufs (char *device)
+do_blockdev_flushbufs (const char *device)
{
return call_blockdev (device, "--flushbufs", 0, 0);
}
int
-do_blockdev_rereadpt (char *device)
+do_blockdev_rereadpt (const char *device)
{
return call_blockdev (device, "--rereadpt", 0, 0);
}
diff --git a/daemon/checksum.c b/daemon/checksum.c
index c06a697..2423265 100644
--- a/daemon/checksum.c
+++ b/daemon/checksum.c
@@ -28,7 +28,7 @@
#include "actions.h"
char *
-do_checksum (char *csumtype, char *path)
+do_checksum (const char *csumtype, const char *path)
{
const char *program;
char *buf;
@@ -36,9 +36,6 @@ do_checksum (char *csumtype, char *path)
int r;
int len;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
if (strcasecmp (csumtype, "crc") == 0)
program = "cksum";
else if (strcasecmp (csumtype, "md5") == 0)
diff --git a/daemon/cmp.c b/daemon/cmp.c
index a48e924..56717c5 100644
--- a/daemon/cmp.c
+++ b/daemon/cmp.c
@@ -28,7 +28,7 @@
#include "actions.h"
int
-do_equal (char *file1, char *file2)
+do_equal (const char *file1, const char *file2)
{
char *file1buf, *file2buf;
char *err;
diff --git a/daemon/command.c b/daemon/command.c
index 7f5fc95..88c500a 100644
--- a/daemon/command.c
+++ b/daemon/command.c
@@ -114,7 +114,7 @@ do_command_lines (char **argv)
}
char *
-do_sh (char *command)
+do_sh (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };
@@ -122,7 +122,7 @@ do_sh (char *command)
}
char **
-do_sh_lines (char *command)
+do_sh_lines (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };
diff --git a/daemon/cpmv.c b/daemon/cpmv.c
index 4fdee6b..1007203 100644
--- a/daemon/cpmv.c
+++ b/daemon/cpmv.c
@@ -28,19 +28,19 @@
static int cpmv_cmd (const char *cmd, const char *flags, const char *src, const char
*dest);
int
-do_cp (char *src, char *dest)
+do_cp (const char *src, const char *dest)
{
return cpmv_cmd ("cp", NULL, src, dest);
}
int
-do_cp_a (char *src, char *dest)
+do_cp_a (const char *src, const char *dest)
{
return cpmv_cmd ("cp", "-a", src, dest);
}
int
-do_mv (char *src, char *dest)
+do_mv (const char *src, const char *dest)
{
return cpmv_cmd ("mv", NULL, src, dest);
}
diff --git a/daemon/debug.c b/daemon/debug.c
index 5083398..58a5061 100644
--- a/daemon/debug.c
+++ b/daemon/debug.c
@@ -67,7 +67,7 @@ static struct cmd cmds[] = {
#endif
char *
-do_debug (char *subcmd MAYBE_UNUSED, char **argv MAYBE_UNUSED)
+do_debug (const char *subcmd MAYBE_UNUSED, char **argv MAYBE_UNUSED)
{
#if ENABLE_DEBUG_COMMAND
int argc, i;
diff --git a/daemon/devsparts.c b/daemon/devsparts.c
index 04585ed..b4ea578 100644
--- a/daemon/devsparts.c
+++ b/daemon/devsparts.c
@@ -188,7 +188,7 @@ do_list_partitions (void)
}
int
-do_mkfs (char *fstype, char *device)
+do_mkfs (const char *fstype, const char *device)
{
char *err;
int r;
diff --git a/daemon/dir.c b/daemon/dir.c
index ec072dd..ad1c7c9 100644
--- a/daemon/dir.c
+++ b/daemon/dir.c
@@ -30,13 +30,10 @@
#include "actions.h"
int
-do_rmdir (char *path)
+do_rmdir (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = rmdir (path);
CHROOT_OUT;
@@ -54,14 +51,11 @@ do_rmdir (char *path)
* do stupid stuff, who are we to try to stop them?
*/
int
-do_rm_rf (char *path)
+do_rm_rf (const char *path)
{
int r;
char *buf, *err;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
if (strcmp (path, "/") == 0) {
reply_with_error ("rm -rf: cannot remove root directory");
return -1;
@@ -89,13 +83,10 @@ do_rm_rf (char *path)
}
int
-do_mkdir (char *path)
+do_mkdir (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = mkdir (path, 0777);
CHROOT_OUT;
@@ -155,13 +146,10 @@ recursive_mkdir (const char *path)
}
int
-do_mkdir_p (char *path)
+do_mkdir_p (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = recursive_mkdir (path);
CHROOT_OUT;
@@ -175,14 +163,11 @@ do_mkdir_p (char *path)
}
int
-do_is_dir (char *path)
+do_is_dir (const char *path)
{
int r;
struct stat buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = lstat (path, &buf);
CHROOT_OUT;
diff --git a/daemon/du.c b/daemon/du.c
index f5f083d..e6df245 100644
--- a/daemon/du.c
+++ b/daemon/du.c
@@ -29,16 +29,13 @@
#include "actions.h"
int64_t
-do_du (char *path)
+do_du (const char *path)
{
int r;
int64_t rv;
char *out, *err;
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
diff --git a/daemon/ext2.c b/daemon/ext2.c
index 04869da..f181b8d 100644
--- a/daemon/ext2.c
+++ b/daemon/ext2.c
@@ -28,7 +28,7 @@
#include "actions.h"
char **
-do_tune2fs_l (char *device)
+do_tune2fs_l (const char *device)
{
int r;
char *out, *err;
@@ -115,7 +115,7 @@ do_tune2fs_l (char *device)
}
int
-do_set_e2label (char *device, char *label)
+do_set_e2label (const char *device, const char *label)
{
int r;
char *err;
@@ -132,7 +132,7 @@ do_set_e2label (char *device, char *label)
}
char *
-do_get_e2label (char *device)
+do_get_e2label (const char *device)
{
int r, len;
char *out, *err;
@@ -156,7 +156,7 @@ do_get_e2label (char *device)
}
int
-do_set_e2uuid (char *device, char *uuid)
+do_set_e2uuid (const char *device, const char *uuid)
{
int r;
char *err;
@@ -173,7 +173,7 @@ do_set_e2uuid (char *device, char *uuid)
}
char *
-do_get_e2uuid (char *device)
+do_get_e2uuid (const char *device)
{
int r;
char *out, *err, *p, *q;
@@ -234,7 +234,7 @@ do_get_e2uuid (char *device)
}
int
-do_resize2fs (char *device)
+do_resize2fs (const char *device)
{
char *err;
int r;
@@ -251,7 +251,7 @@ do_resize2fs (char *device)
}
int
-do_e2fsck_f (char *device)
+do_e2fsck_f (const char *device)
{
char *err;
int r;
diff --git a/daemon/fallocate.c b/daemon/fallocate.c
index 9c5a3dd..eb84145 100644
--- a/daemon/fallocate.c
+++ b/daemon/fallocate.c
@@ -28,13 +28,10 @@
#include "actions.h"
int
-do_fallocate (char *path, int len)
+do_fallocate (const char *path, int len)
{
int fd, r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
fd = open (path, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
CHROOT_OUT;
diff --git a/daemon/file.c b/daemon/file.c
index d8425e9..ed3221d 100644
--- a/daemon/file.c
+++ b/daemon/file.c
@@ -30,14 +30,11 @@
#include "actions.h"
int
-do_touch (char *path)
+do_touch (const char *path)
{
int fd;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666);
CHROOT_OUT;
@@ -67,15 +64,12 @@ do_touch (char *path)
}
char *
-do_cat (char *path)
+do_cat (const char *path)
{
int fd;
int alloc, size, r, max;
char *buf, *buf2;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fd = open (path, O_RDONLY);
CHROOT_OUT;
@@ -138,7 +132,7 @@ do_cat (char *path)
}
char **
-do_read_lines (char *path)
+do_read_lines (const char *path)
{
char **r = NULL;
int size = 0, alloc = 0;
@@ -147,9 +141,6 @@ do_read_lines (char *path)
size_t len = 0;
ssize_t n;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fp = fopen (path, "r");
CHROOT_OUT;
@@ -190,13 +181,10 @@ do_read_lines (char *path)
}
int
-do_rm (char *path)
+do_rm (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = unlink (path);
CHROOT_OUT;
@@ -210,13 +198,10 @@ do_rm (char *path)
}
int
-do_chmod (int mode, char *path)
+do_chmod (int mode, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = chmod (path, mode);
CHROOT_OUT;
@@ -230,13 +215,10 @@ do_chmod (int mode, char *path)
}
int
-do_chown (int owner, int group, char *path)
+do_chown (int owner, int group, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = chown (path, owner, group);
CHROOT_OUT;
@@ -250,13 +232,10 @@ do_chown (int owner, int group, char *path)
}
int
-do_exists (char *path)
+do_exists (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = access (path, F_OK);
CHROOT_OUT;
@@ -265,14 +244,11 @@ do_exists (char *path)
}
int
-do_is_file (char *path)
+do_is_file (const char *path)
{
int r;
struct stat buf;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = lstat (path, &buf);
CHROOT_OUT;
@@ -290,13 +266,10 @@ do_is_file (char *path)
}
int
-do_write_file (char *path, char *content, int size)
+do_write_file (const char *path, const char *content, int size)
{
int fd;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
if (size == 0)
size = strlen (content);
@@ -324,15 +297,12 @@ do_write_file (char *path, char *content, int size)
}
char *
-do_read_file (char *path, size_t *size_r)
+do_read_file (const char *path, size_t *size_r)
{
int fd;
struct stat statbuf;
char *r;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
fd = open (path, O_RDONLY);
CHROOT_OUT;
@@ -384,7 +354,7 @@ do_read_file (char *path, size_t *size_r)
/* This runs the 'file' command. */
char *
-do_file (char *path)
+do_file (const char *path)
{
char *out, *err;
int r, freeit = 0;
@@ -436,7 +406,7 @@ do_file (char *path)
/* zcat | file */
char *
-do_zfile (char *method, char *path)
+do_zfile (const char *method, const char *path)
{
int len;
const char *zcat;
@@ -444,9 +414,6 @@ do_zfile (char *method, char *path)
FILE *fp;
char line[256];
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") ==
0)
zcat = "zcat";
else if (strcmp (method, "bzip2") == 0)
diff --git a/daemon/find.c b/daemon/find.c
index 950a0fc..2147c57 100644
--- a/daemon/find.c
+++ b/daemon/find.c
@@ -48,7 +48,7 @@ input_to_nul (FILE *fp, char *buf, int maxlen)
}
char **
-do_find (char *dir)
+do_find (const char *dir)
{
struct stat statbuf;
int r, len, sysrootdirlen;
@@ -59,9 +59,6 @@ do_find (char *dir)
char *sysrootdir;
char str[PATH_MAX];
- NEED_ROOT (return NULL);
- ABS_PATH (dir, return NULL);
-
sysrootdir = sysroot_path (dir);
if (!sysrootdir) {
reply_with_perror ("malloc");
diff --git a/daemon/fsck.c b/daemon/fsck.c
index 825f97e..7139094 100644
--- a/daemon/fsck.c
+++ b/daemon/fsck.c
@@ -27,7 +27,7 @@
#include "actions.h"
int
-do_fsck (char *fstype, char *device)
+do_fsck (const char *fstype, const char *device)
{
char *err;
int r;
diff --git a/daemon/glob.c b/daemon/glob.c
index 40b7c50..4fe76f3 100644
--- a/daemon/glob.c
+++ b/daemon/glob.c
@@ -26,14 +26,11 @@
#include "actions.h"
char **
-do_glob_expand (char *pattern)
+do_glob_expand (const char *pattern)
{
int r;
glob_t buf;
- NEED_ROOT (return NULL);
- ABS_PATH (pattern, return NULL); /* Required so chroot can be used. */
-
/* glob(3) in glibc never calls chdir, so this seems to be safe: */
CHROOT_IN;
r = glob (pattern, GLOB_MARK|GLOB_BRACE, NULL, &buf);
diff --git a/daemon/grep.c b/daemon/grep.c
index f0dbefd..d1f5a3f 100644
--- a/daemon/grep.c
+++ b/daemon/grep.c
@@ -28,16 +28,13 @@
#include "actions.h"
static char **
-grep (const char *prog, const char *flag, char *regex, char *path)
+grep (const char *prog, const char *flag, const char *regex, const char *path)
{
char *buf;
char *out, *err;
int r;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
@@ -67,74 +64,74 @@ grep (const char *prog, const char *flag, char *regex, char *path)
}
char **
-do_grep (char *regex, char *path)
+do_grep (const char *regex, const char *path)
{
/* The "--" is not really needed, but it helps when we don't need a flag.
*/
return grep ("grep", "--", regex, path);
}
char **
-do_egrep (char *regex, char *path)
+do_egrep (const char *regex, const char *path)
{
return grep ("egrep", "--", regex, path);
}
char **
-do_fgrep (char *regex, char *path)
+do_fgrep (const char *regex, const char *path)
{
return grep ("fgrep", "--", regex, path);
}
char **
-do_grepi (char *regex, char *path)
+do_grepi (const char *regex, const char *path)
{
return grep ("grep", "-i", regex, path);
}
char **
-do_egrepi (char *regex, char *path)
+do_egrepi (const char *regex, const char *path)
{
return grep ("egrep", "-i", regex, path);
}
char **
-do_fgrepi (char *regex, char *path)
+do_fgrepi (const char *regex, const char *path)
{
return grep ("fgrep", "-i", regex, path);
}
char **
-do_zgrep (char *regex, char *path)
+do_zgrep (const char *regex, const char *path)
{
return grep ("zgrep", "--", regex, path);
}
char **
-do_zegrep (char *regex, char *path)
+do_zegrep (const char *regex, const char *path)
{
return grep ("zegrep", "--", regex, path);
}
char **
-do_zfgrep (char *regex, char *path)
+do_zfgrep (const char *regex, const char *path)
{
return grep ("zfgrep", "--", regex, path);
}
char **
-do_zgrepi (char *regex, char *path)
+do_zgrepi (const char *regex, const char *path)
{
return grep ("zgrep", "-i", regex, path);
}
char **
-do_zegrepi (char *regex, char *path)
+do_zegrepi (const char *regex, const char *path)
{
return grep ("zegrep", "-i", regex, path);
}
char **
-do_zfgrepi (char *regex, char *path)
+do_zfgrepi (const char *regex, const char *path)
{
return grep ("zfgrep", "-i", regex, path);
}
diff --git a/daemon/grub.c b/daemon/grub.c
index 8476619..657abbb 100644
--- a/daemon/grub.c
+++ b/daemon/grub.c
@@ -26,15 +26,12 @@
#include "actions.h"
int
-do_grub_install (char *root, char *device)
+do_grub_install (const char *root, const char *device)
{
int r;
char *err;
char *buf;
- NEED_ROOT (return -1);
- ABS_PATH (root, return -1);
-
if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) {
reply_with_perror ("asprintf");
return -1;
diff --git a/daemon/headtail.c b/daemon/headtail.c
index 79dcfbb..9175cf0 100644
--- a/daemon/headtail.c
+++ b/daemon/headtail.c
@@ -28,16 +28,13 @@
#include "actions.h"
static char **
-headtail (const char *prog, const char *flag, const char *n, char *path)
+headtail (const char *prog, const char *flag, const char *n, const char *path)
{
char *buf;
char *out, *err;
int r;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
@@ -70,19 +67,19 @@ headtail (const char *prog, const char *flag, const char *n, char
*path)
}
char **
-do_head (char *path)
+do_head (const char *path)
{
return headtail ("head", "-n", "10", path);
}
char **
-do_tail (char *path)
+do_tail (const char *path)
{
return headtail ("tail", "-n", "10", path);
}
char **
-do_head_n (int n, char *path)
+do_head_n (int n, const char *path)
{
char nbuf[16];
@@ -92,7 +89,7 @@ do_head_n (int n, char *path)
}
char **
-do_tail_n (int n, char *path)
+do_tail_n (int n, const char *path)
{
char nbuf[16];
diff --git a/daemon/hexdump.c b/daemon/hexdump.c
index faf3dc5..7016faf 100644
--- a/daemon/hexdump.c
+++ b/daemon/hexdump.c
@@ -26,15 +26,12 @@
#include "actions.h"
char *
-do_hexdump (char *path)
+do_hexdump (const char *path)
{
char *buf;
int r;
char *out, *err;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
diff --git a/daemon/initrd.c b/daemon/initrd.c
index c1c7ce0..9431ef1 100644
--- a/daemon/initrd.c
+++ b/daemon/initrd.c
@@ -28,7 +28,7 @@
#include "actions.h"
char **
-do_initrd_list (char *path)
+do_initrd_list (const char *path)
{
FILE *fp;
char *cmd;
@@ -37,9 +37,6 @@ do_initrd_list (char *path)
int size = 0, alloc = 0;
size_t len;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
/* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted.
*/
if (asprintf_nowarn (&cmd, "zcat %R | cpio --quiet -it", path) == -1) {
reply_with_perror ("asprintf");
diff --git a/daemon/inotify.c b/daemon/inotify.c
index 96b9681..7834dcb 100644
--- a/daemon/inotify.c
+++ b/daemon/inotify.c
@@ -123,7 +123,7 @@ do_inotify_close (void)
}
int64_t
-do_inotify_add_watch (char *path, int mask)
+do_inotify_add_watch (const char *path, int mask)
{
int64_t r;
char *buf;
diff --git a/daemon/link.c b/daemon/link.c
index 9129b5c..a77c2e8 100644
--- a/daemon/link.c
+++ b/daemon/link.c
@@ -28,15 +28,12 @@
#include "actions.h"
char *
-do_readlink (char *path)
+do_readlink (const char *path)
{
ssize_t r;
char *ret;
char link[PATH_MAX];
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = readlink (path, link, sizeof link);
CHROOT_OUT;
@@ -62,10 +59,6 @@ _link (const char *flag, int symbolic, const char *target, const char
*linkname)
char *buf_linkname;
char *buf_target;
- NEED_ROOT (return -1);
- ABS_PATH (linkname, return -1);
- /* but target does not need to be absolute */
-
/* Prefix linkname with sysroot. */
buf_linkname = sysroot_path (linkname);
if (!buf_linkname) {
@@ -113,25 +106,25 @@ _link (const char *flag, int symbolic, const char *target, const
char *linkname)
}
int
-do_ln (char *target, char *linkname)
+do_ln (const char *target, const char *linkname)
{
return _link (NULL, 0, target, linkname);
}
int
-do_ln_f (char *target, char *linkname)
+do_ln_f (const char *target, const char *linkname)
{
return _link ("-f", 0, target, linkname);
}
int
-do_ln_s (char *target, char *linkname)
+do_ln_s (const char *target, const char *linkname)
{
return _link ("-s", 1, target, linkname);
}
int
-do_ln_sf (char *target, char *linkname)
+do_ln_sf (const char *target, const char *linkname)
{
return _link ("-sf", 1, target, linkname);
}
diff --git a/daemon/ls.c b/daemon/ls.c
index 8dba1bf..9d2ca89 100644
--- a/daemon/ls.c
+++ b/daemon/ls.c
@@ -30,16 +30,13 @@
#include "actions.h"
char **
-do_ls (char *path)
+do_ls (const char *path)
{
char **r = NULL;
int size = 0, alloc = 0;
DIR *dir;
struct dirent *d;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
dir = opendir (path);
CHROOT_OUT;
@@ -84,15 +81,12 @@ do_ls (char *path)
*/
char *
-do_ll (char *path)
+do_ll (const char *path)
{
int r;
char *out, *err;
char *spath;
- NEED_ROOT (NULL);
- ABS_PATH (path, NULL);
-
spath = sysroot_path (path);
if (!spath) {
reply_with_perror ("malloc");
diff --git a/daemon/lvm.c b/daemon/lvm.c
index bee62d4..ddc125c 100644
--- a/daemon/lvm.c
+++ b/daemon/lvm.c
@@ -32,7 +32,7 @@
*/
static char **
-convert_lvm_output (char *out, char *prefix)
+convert_lvm_output (char *out, const char *prefix)
{
char *p, *pend;
char **r = NULL;
@@ -171,7 +171,7 @@ do_lvs_full (void)
}
int
-do_pvcreate (char *device)
+do_pvcreate (const char *device)
{
char *err;
int r;
@@ -192,7 +192,7 @@ do_pvcreate (char *device)
}
int
-do_vgcreate (char *volgroup, char **physvols)
+do_vgcreate (const char *volgroup, char **physvols)
{
char *err;
int r, argc, i;
@@ -229,7 +229,7 @@ do_vgcreate (char *volgroup, char **physvols)
}
int
-do_lvcreate (char *logvol, char *volgroup, int mbytes)
+do_lvcreate (const char *logvol, const char *volgroup, int mbytes)
{
char *err;
int r;
@@ -254,14 +254,12 @@ do_lvcreate (char *logvol, char *volgroup, int mbytes)
}
int
-do_lvresize (char *logvol, int mbytes)
+do_lvresize (const char *logvol, int mbytes)
{
char *err;
int r;
char size[64];
- RESOLVE_DEVICE (logvol, return -1);
-
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
@@ -345,7 +343,7 @@ do_lvm_remove_all (void)
}
int
-do_lvremove (char *device)
+do_lvremove (const char *device)
{
char *err;
int r;
@@ -366,7 +364,7 @@ do_lvremove (char *device)
}
int
-do_vgremove (char *device)
+do_vgremove (const char *device)
{
char *err;
int r;
@@ -387,7 +385,7 @@ do_vgremove (char *device)
}
int
-do_pvremove (char *device)
+do_pvremove (const char *device)
{
char *err;
int r;
@@ -408,7 +406,7 @@ do_pvremove (char *device)
}
int
-do_pvresize (char *device)
+do_pvresize (const char *device)
{
char *err;
int r;
diff --git a/daemon/mknod.c b/daemon/mknod.c
index a6e6eca..adaeb80 100644
--- a/daemon/mknod.c
+++ b/daemon/mknod.c
@@ -31,13 +31,10 @@
#include "actions.h"
int
-do_mknod (int mode, int devmajor, int devminor, char *path)
+do_mknod (int mode, int devmajor, int devminor, const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = mknod (path, mode, makedev (devmajor, devminor));
CHROOT_OUT;
@@ -51,19 +48,19 @@ do_mknod (int mode, int devmajor, int devminor, char *path)
}
int
-do_mkfifo (int mode, char *path)
+do_mkfifo (int mode, const char *path)
{
return do_mknod (mode | S_IFIFO, 0, 0, path);
}
int
-do_mknod_b (int mode, int devmajor, int devminor, char *path)
+do_mknod_b (int mode, int devmajor, int devminor, const char *path)
{
return do_mknod (mode | S_IFBLK, devmajor, devminor, path);
}
int
-do_mknod_c (int mode, int devmajor, int devminor, char *path)
+do_mknod_c (int mode, int devmajor, int devminor, const char *path)
{
return do_mknod (mode | S_IFCHR, devmajor, devminor, path);
}
diff --git a/daemon/mount.c b/daemon/mount.c
index 4f60682..89bef34 100644
--- a/daemon/mount.c
+++ b/daemon/mount.c
@@ -41,8 +41,8 @@ int root_mounted = 0;
*/
int
-do_mount_vfs (char *options, char *vfstype,
- char *device, char *mountpoint)
+do_mount_vfs (const char *options, const char *vfstype,
+ const char *device, const char *mountpoint)
{
int r, is_root;
char *mp;
@@ -81,20 +81,20 @@ do_mount_vfs (char *options, char *vfstype,
}
int
-do_mount (char *device, char *mountpoint)
+do_mount (const char *device, const char *mountpoint)
{
return do_mount_vfs ("sync,noatime", NULL, device, mountpoint);
}
int
-do_mount_ro (char *device, char *mountpoint)
+do_mount_ro (const char *device, const char *mountpoint)
{
return do_mount_vfs ("ro", NULL, device, mountpoint);
}
int
-do_mount_options (char *options, char *device,
- char *mountpoint)
+do_mount_options (const char *options, const char *device,
+ const char *mountpoint)
{
return do_mount_vfs (options, NULL, device, mountpoint);
}
@@ -103,7 +103,7 @@ do_mount_options (char *options, char *device,
* is kept updated.
*/
int
-do_umount (char *pathordevice)
+do_umount (const char *pathordevice)
{
int freeit = 0, r;
char *buf;
@@ -311,15 +311,12 @@ do_umount_all (void)
* device.
*/
int
-do_mount_loop (char *file, char *mountpoint)
+do_mount_loop (const char *file, const char *mountpoint)
{
int r;
char *buf, *mp;
char *error;
- NEED_ROOT (return -1);
- ABS_PATH (file, return -1);
-
/* We have to prefix /sysroot on both the filename and the mountpoint. */
mp = sysroot_path (mountpoint);
if (!mp) {
@@ -351,7 +348,7 @@ do_mount_loop (char *file, char *mountpoint)
* mkmountpoint case) set the root_mounted flag.
*/
int
-do_mkmountpoint (char *path)
+do_mkmountpoint (const char *path)
{
int r;
@@ -376,13 +373,10 @@ do_mkmountpoint (char *path)
}
int
-do_rmmountpoint (char *path)
+do_rmmountpoint (const char *path)
{
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
CHROOT_IN;
r = rmdir (path);
CHROOT_OUT;
diff --git a/daemon/ntfs.c b/daemon/ntfs.c
index 1d73f2e..85deb65 100644
--- a/daemon/ntfs.c
+++ b/daemon/ntfs.c
@@ -27,7 +27,7 @@
#include "actions.h"
int
-do_ntfs_3g_probe (int rw, char *device)
+do_ntfs_3g_probe (int rw, const char *device)
{
char *err;
int r;
diff --git a/daemon/readdir.c b/daemon/readdir.c
index 45256b2..ab42dfd 100644
--- a/daemon/readdir.c
+++ b/daemon/readdir.c
@@ -28,7 +28,7 @@
#include "actions.h"
guestfs_int_dirent_list *
-do_readdir (char *path)
+do_readdir (const char *path)
{
guestfs_int_dirent_list *ret;
guestfs_int_dirent v;
@@ -36,9 +36,6 @@ do_readdir (char *path)
struct dirent *d;
int i;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
ret = malloc (sizeof *ret);
if (ret == NULL) {
reply_with_perror ("malloc");
diff --git a/daemon/realpath.c b/daemon/realpath.c
index c081a45..706af42 100644
--- a/daemon/realpath.c
+++ b/daemon/realpath.c
@@ -28,13 +28,10 @@
#include "actions.h"
char *
-do_realpath (char *path)
+do_realpath (const char *path)
{
char *ret;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
ret = realpath (path, NULL);
CHROOT_OUT;
diff --git a/daemon/scrub.c b/daemon/scrub.c
index 5530c69..15c8b6c 100644
--- a/daemon/scrub.c
+++ b/daemon/scrub.c
@@ -28,7 +28,7 @@
#include "actions.h"
int
-do_scrub_device (char *device)
+do_scrub_device (const char *device)
{
char *err;
int r;
@@ -46,15 +46,12 @@ do_scrub_device (char *device)
}
int
-do_scrub_file (char *file)
+do_scrub_file (const char *file)
{
char *buf;
char *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (file, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (file);
if (!buf) {
@@ -76,15 +73,12 @@ do_scrub_file (char *file)
}
int
-do_scrub_freespace (char *dir)
+do_scrub_freespace (const char *dir)
{
char *buf;
char *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (dir);
if (!buf) {
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c
index fe58d96..141ea5e 100644
--- a/daemon/sfdisk.c
+++ b/daemon/sfdisk.c
@@ -30,7 +30,7 @@
#include "actions.h"
static int
-sfdisk (char *device, int n, int cyls, int heads, int sectors,
+sfdisk (const char *device, int n, int cyls, int heads, int sectors,
const char *extra_flag,
char * const* const lines)
{
@@ -82,15 +82,15 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors,
}
int
-do_sfdisk (char *device, int cyls, int heads, int sectors,
+do_sfdisk (const char *device, int cyls, int heads, int sectors,
char **lines)
{
return sfdisk (device, 0, cyls, heads, sectors, NULL, lines);
}
int
-do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors,
- char *line)
+do_sfdisk_N (const char *device, int n, int cyls, int heads, int sectors,
+ const char *line)
{
const char *lines[2] = { line, NULL };
@@ -98,13 +98,13 @@ do_sfdisk_N (char *device, int n, int cyls, int heads, int sectors,
}
int
-do_sfdiskM (char *device, char **lines)
+do_sfdiskM (const char *device, char **lines)
{
return sfdisk (device, 0, 0, 0, 0, "-uM", lines);
}
static char *
-sfdisk_flag (char *device, const char *flag)
+sfdisk_flag (const char *device, const char *flag)
{
char *out, *err;
int r;
@@ -125,19 +125,19 @@ sfdisk_flag (char *device, const char *flag)
}
char *
-do_sfdisk_l (char *device)
+do_sfdisk_l (const char *device)
{
return sfdisk_flag (device, "-l");
}
char *
-do_sfdisk_kernel_geometry (char *device)
+do_sfdisk_kernel_geometry (const char *device)
{
return sfdisk_flag (device, "-g");
}
char *
-do_sfdisk_disk_geometry (char *device)
+do_sfdisk_disk_geometry (const char *device)
{
return sfdisk_flag (device, "-G");
}
diff --git a/daemon/stat.c b/daemon/stat.c
index 4845851..4ff2711 100644
--- a/daemon/stat.c
+++ b/daemon/stat.c
@@ -31,15 +31,12 @@
#include "actions.h"
guestfs_int_stat *
-do_stat (char *path)
+do_stat (const char *path)
{
int r;
guestfs_int_stat *ret;
struct stat statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = stat (path, &statbuf);
CHROOT_OUT;
@@ -73,15 +70,12 @@ do_stat (char *path)
}
guestfs_int_stat *
-do_lstat (char *path)
+do_lstat (const char *path)
{
int r;
guestfs_int_stat *ret;
struct stat statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = lstat (path, &statbuf);
CHROOT_OUT;
@@ -115,15 +109,12 @@ do_lstat (char *path)
}
guestfs_int_statvfs *
-do_statvfs (char *path)
+do_statvfs (const char *path)
{
int r;
guestfs_int_statvfs *ret;
struct statvfs statbuf;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
r = statvfs (path, &statbuf);
CHROOT_OUT;
diff --git a/daemon/strings.c b/daemon/strings.c
index e5aefca..d7dc392 100644
--- a/daemon/strings.c
+++ b/daemon/strings.c
@@ -26,16 +26,13 @@
#include "actions.h"
char **
-do_strings_e (char *encoding, char *path)
+do_strings_e (const char *encoding, const char *path)
{
char *buf;
int r;
char *out, *err;
char **lines;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
@@ -64,7 +61,7 @@ do_strings_e (char *encoding, char *path)
}
char **
-do_strings (char *path)
+do_strings (const char *path)
{
return do_strings_e ("s", path);
}
diff --git a/daemon/swap.c b/daemon/swap.c
index 580482f..bcc5f1b 100644
--- a/daemon/swap.c
+++ b/daemon/swap.c
@@ -28,7 +28,7 @@
#include "actions.h"
static int
-mkswap (char *device, const char *flag, const char *value)
+mkswap (const char *device, const char *flag, const char *value)
{
char *err;
int r;
@@ -50,32 +50,29 @@ mkswap (char *device, const char *flag, const char *value)
}
int
-do_mkswap (char *device)
+do_mkswap (const char *device)
{
return mkswap (device, NULL, NULL);
}
int
-do_mkswap_L (char *label, char *device)
+do_mkswap_L (const char *label, const char *device)
{
return mkswap (device, "-L", label);
}
int
-do_mkswap_U (char *uuid, char *device)
+do_mkswap_U (const char *uuid, const char *device)
{
return mkswap (device, "-U", uuid);
}
int
-do_mkswap_file (char *path)
+do_mkswap_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
@@ -110,26 +107,23 @@ swaponoff (const char *cmd, const char *flag, const char *value)
}
int
-do_swapon_device (char *device)
+do_swapon_device (const char *device)
{
return swaponoff ("/sbin/swapon", NULL, device);
}
int
-do_swapoff_device (char *device)
+do_swapoff_device (const char *device)
{
return swaponoff ("/sbin/swapoff", NULL, device);
}
int
-do_swapon_file (char *path)
+do_swapon_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
@@ -142,14 +136,11 @@ do_swapon_file (char *path)
}
int
-do_swapoff_file (char *path)
+do_swapoff_file (const char *path)
{
char *buf;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
buf = sysroot_path (path);
if (!buf) {
reply_with_perror ("malloc");
@@ -162,25 +153,25 @@ do_swapoff_file (char *path)
}
int
-do_swapon_label (char *label)
+do_swapon_label (const char *label)
{
return swaponoff ("/sbin/swapon", "-L", label);
}
int
-do_swapoff_label (char *label)
+do_swapoff_label (const char *label)
{
return swaponoff ("/sbin/swapoff", "-L", label);
}
int
-do_swapon_uuid (char *uuid)
+do_swapon_uuid (const char *uuid)
{
return swaponoff ("/sbin/swapon", "-U", uuid);
}
int
-do_swapoff_uuid (char *uuid)
+do_swapoff_uuid (const char *uuid)
{
return swaponoff ("/sbin/swapoff", "-U", uuid);
}
diff --git a/daemon/tar.c b/daemon/tar.c
index 9d21e79..03dc512 100644
--- a/daemon/tar.c
+++ b/daemon/tar.c
@@ -36,7 +36,7 @@ fwrite_cb (void *fp_ptr, const void *buf, int len)
/* Has one FileIn parameter. */
int
-do_tar_in (char *dir)
+do_tar_in (const char *dir)
{
int err, r;
FILE *fp;
@@ -99,16 +99,13 @@ do_tar_in (char *dir)
/* Has one FileOut parameter. */
int
-do_tar_out (char *dir)
+do_tar_out (const char *dir)
{
int r;
FILE *fp;
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */
if (asprintf_nowarn (&cmd, "tar -C %R -cf - .", dir) == -1) {
reply_with_perror ("asprintf");
@@ -158,7 +155,7 @@ do_tar_out (char *dir)
/* Has one FileIn parameter. */
int
-do_tgz_in (char *dir)
+do_tgz_in (const char *dir)
{
int err, r;
FILE *fp;
@@ -221,16 +218,13 @@ do_tgz_in (char *dir)
/* Has one FileOut parameter. */
int
-do_tgz_out (char *dir)
+do_tgz_out (const char *dir)
{
int r;
FILE *fp;
char *cmd;
char buf[GUESTFS_MAX_CHUNK_SIZE];
- NEED_ROOT (return -1);
- ABS_PATH (dir, return -1);
-
/* "tar -C /sysroot%s -zcf - ." but we have to quote the dir. */
if (asprintf_nowarn (&cmd, "tar -C %R -zcf - .", dir) == -1) {
reply_with_perror ("asprintf");
diff --git a/daemon/upload.c b/daemon/upload.c
index 5c1adaf..aede24a 100644
--- a/daemon/upload.c
+++ b/daemon/upload.c
@@ -36,7 +36,7 @@ write_cb (void *fd_ptr, const void *buf, int len)
/* Has one FileIn parameter. */
int
-do_upload (char *filename)
+do_upload (const char *filename)
{
int err, fd, r, is_dev;
@@ -88,7 +88,7 @@ do_upload (char *filename)
/* Has one FileOut parameter. */
int
-do_download (char *filename)
+do_download (const char *filename)
{
int fd, r, is_dev;
char buf[GUESTFS_MAX_CHUNK_SIZE];
diff --git a/daemon/wc.c b/daemon/wc.c
index 9720443..93d4ebb 100644
--- a/daemon/wc.c
+++ b/daemon/wc.c
@@ -28,15 +28,12 @@
#include "actions.h"
static int
-wc (char *flag, char *path)
+wc (char *flag, const char *path)
{
char *buf;
char *out, *err;
int r;
- NEED_ROOT (return -1);
- ABS_PATH (path, return -1);
-
/* Make the path relative to /sysroot. */
buf = sysroot_path (path);
if (!buf) {
@@ -73,19 +70,19 @@ wc (char *flag, char *path)
}
int
-do_wc_l (char *path)
+do_wc_l (const char *path)
{
return wc ("-l", path);
}
int
-do_wc_w (char *path)
+do_wc_w (const char *path)
{
return wc ("-w", path);
}
int
-do_wc_c (char *path)
+do_wc_c (const char *path)
{
return wc ("-c", path);
}
diff --git a/daemon/xattr.c b/daemon/xattr.c
index d521321..17d9382 100644
--- a/daemon/xattr.c
+++ b/daemon/xattr.c
@@ -35,12 +35,12 @@
#endif
#endif
-static guestfs_int_xattr_list *getxattrs (char *path, ssize_t (*listxattr) (const char
*path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char *name,
void *value, size_t size));
-static int _setxattr (char *xattr, char *val, int vallen, char *path, int (*setxattr)
(const char *path, const char *name, const void *value, size_t size, int flags));
-static int _removexattr (char *xattr, char *path, int (*removexattr) (const char *path,
const char *name));
+static guestfs_int_xattr_list *getxattrs (const char *path, ssize_t (*listxattr) (const
char *path, char *list, size_t size), ssize_t (*getxattr) (const char *path, const char
*name, void *value, size_t size));
+static int _setxattr (const char *xattr, const char *val, int vallen, const char *path,
int (*setxattr) (const char *path, const char *name, const void *value, size_t size, int
flags));
+static int _removexattr (const char *xattr, const char *path, int (*removexattr) (const
char *path, const char *name));
guestfs_int_xattr_list *
-do_getxattrs (char *path)
+do_getxattrs (const char *path)
{
#if defined(HAVE_LISTXATTR) && defined(HAVE_GETXATTR)
return getxattrs (path, listxattr, getxattr);
@@ -51,7 +51,7 @@ do_getxattrs (char *path)
}
guestfs_int_xattr_list *
-do_lgetxattrs (char *path)
+do_lgetxattrs (const char *path)
{
#if defined(HAVE_LLISTXATTR) && defined(HAVE_LGETXATTR)
return getxattrs (path, llistxattr, lgetxattr);
@@ -62,7 +62,7 @@ do_lgetxattrs (char *path)
}
int
-do_setxattr (char *xattr, char *val, int vallen, char *path)
+do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
#if defined(HAVE_SETXATTR)
return _setxattr (xattr, val, vallen, path, setxattr);
@@ -73,7 +73,7 @@ do_setxattr (char *xattr, char *val, int vallen, char *path)
}
int
-do_lsetxattr (char *xattr, char *val, int vallen, char *path)
+do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
#if defined(HAVE_LSETXATTR)
return _setxattr (xattr, val, vallen, path, lsetxattr);
@@ -84,7 +84,7 @@ do_lsetxattr (char *xattr, char *val, int vallen, char *path)
}
int
-do_removexattr (char *xattr, char *path)
+do_removexattr (const char *xattr, const char *path)
{
#if defined(HAVE_REMOVEXATTR)
return _removexattr (xattr, path, removexattr);
@@ -95,7 +95,7 @@ do_removexattr (char *xattr, char *path)
}
int
-do_lremovexattr (char *xattr, char *path)
+do_lremovexattr (const char *xattr, const char *path)
{
#if defined(HAVE_LREMOVEXATTR)
return _removexattr (xattr, path, lremovexattr);
@@ -106,7 +106,7 @@ do_lremovexattr (char *xattr, char *path)
}
static guestfs_int_xattr_list *
-getxattrs (char *path,
+getxattrs (const char *path,
ssize_t (*listxattr) (const char *path, char *list, size_t size),
ssize_t (*getxattr) (const char *path, const char *name,
void *value, size_t size))
@@ -116,9 +116,6 @@ getxattrs (char *path,
int i, j;
guestfs_int_xattr_list *r = NULL;
- NEED_ROOT (return NULL);
- ABS_PATH (path, return NULL);
-
CHROOT_IN;
len = listxattr (path, NULL, 0);
CHROOT_OUT;
@@ -210,7 +207,7 @@ getxattrs (char *path,
}
static int
-_setxattr (char *xattr, char *val, int vallen, char *path,
+_setxattr (const char *xattr, const char *val, int vallen, const char *path,
int (*setxattr) (const char *path, const char *name,
const void *value, size_t size, int flags))
{
@@ -228,7 +225,7 @@ _setxattr (char *xattr, char *val, int vallen, char *path,
}
static int
-_removexattr (char *xattr, char *path,
+_removexattr (const char *xattr, const char *path,
int (*removexattr) (const char *path, const char *name))
{
int r;
@@ -247,42 +244,42 @@ _removexattr (char *xattr, char *path,
#else /* no xattr.h */
guestfs_int_xattr_list *
-do_getxattrs (char *path)
+do_getxattrs (const char *path)
{
reply_with_error ("getxattrs: no support for xattrs");
return NULL;
}
guestfs_int_xattr_list *
-do_lgetxattrs (char *path)
+do_lgetxattrs (const char *path)
{
reply_with_error ("lgetxattrs: no support for xattrs");
return NULL;
}
int
-do_setxattr (char *xattr, char *val, int vallen, char *path)
+do_setxattr (const char *xattr, const char *val, int vallen, const char *path)
{
reply_with_error ("setxattr: no support for xattrs");
return -1;
}
int
-do_lsetxattr (char *xattr, char *val, int vallen, char *path)
+do_lsetxattr (const char *xattr, const char *val, int vallen, const char *path)
{
reply_with_error ("lsetxattr: no support for xattrs");
return -1;
}
int
-do_removexattr (char *xattr, char *path)
+do_removexattr (const char *xattr, const char *path)
{
reply_with_error ("removexattr: no support for xattrs");
return -1;
}
int
-do_lremovexattr (char *xattr, char *path)
+do_lremovexattr (const char *xattr, const char *path)
{
reply_with_error ("lremovexattr: no support for xattrs");
return -1;
diff --git a/daemon/zero.c b/daemon/zero.c
index 864e9a6..ce45ae2 100644
--- a/daemon/zero.c
+++ b/daemon/zero.c
@@ -28,7 +28,7 @@
#include "actions.h"
int
-do_zero (char *device)
+do_zero (const char *device)
{
int fd, i;
char buf[4096];
diff --git a/daemon/zerofree.c b/daemon/zerofree.c
index 457f8db..ffb9b70 100644
--- a/daemon/zerofree.c
+++ b/daemon/zerofree.c
@@ -28,7 +28,7 @@
#include "actions.h"
int
-do_zerofree (char *device)
+do_zerofree (const char *device)
{
char *err;
int r;
diff --git a/src/generator.ml b/src/generator.ml
index 325d3cb..f9032fb 100755
--- a/src/generator.ml
+++ b/src/generator.ml
@@ -981,7 +981,7 @@ Note that this function cannot correctly handle binary files
as end of line). For those you need to use the C<guestfs_read_file>
function which has a more complex interface.");
- ("aug_init", (RErr, [String "root"; Int "flags"]), 16,
[],
+ ("aug_init", (RErr, [Pathname "root"; Int "flags"]), 16,
[],
[], (* XXX Augeas code needs tests. *)
"create a new Augeas handle",
"\
@@ -2130,7 +2130,7 @@ any partition tables, filesystem superblocks and so on.
See also: C<guestfs_scrub_device>.");
- ("grub_install", (RErr, [String "root"; Device
"device"]), 86, [],
+ ("grub_install", (RErr, [Pathname "root"; Device
"device"]), 86, [],
(* Test disabled because grub-install incompatible with virtio-blk driver.
* See also:
https://bugzilla.redhat.com/show_bug.cgi?id=479760
*)
@@ -2226,7 +2226,7 @@ the qemu subprocess. Calling this function checks that the
daemon responds to the ping message, without affecting the daemon
or attached block device(s) in any other way.");
- ("equal", (RBool "equality", [String "file1"; String
"file2"]), 93, [],
+ ("equal", (RBool "equality", [Pathname "file1"; Pathname
"file2"]), 93, [],
[InitBasicFS, Always, TestOutputTrue (
[["write_file"; "/file1"; "contents of a file";
"0"];
["cp"; "/file1"; "/file2"];
@@ -2417,7 +2417,7 @@ C<resize2fs> sometimes gives an error about this and sometimes
not.
In any case, it is always safe to call C<guestfs_e2fsck_f> before
calling this function.");
- ("find", (RStringList "names", [String "directory"]),
107, [],
+ ("find", (RStringList "names", [Pathname "directory"]),
107, [],
[InitBasicFS, Always, TestOutputList (
[["find"; "/"]], ["lost+found"]);
InitBasicFS, Always, TestOutputList (
@@ -2523,7 +2523,11 @@ into a list of lines.
See also: C<guestfs_command_lines>");
- ("glob_expand", (RStringList "paths", [String
"pattern"]), 113, [],
+ ("glob_expand", (RStringList "paths", [Pathname
"pattern"]), 113, [],
+ (* Use Pathname here, and hence ABS_PATH (pattern,... in generated
+ * code in stubs.c, since all valid glob patterns must start with "/".
+ * There is no concept of "cwd" in libguestfs, hence no
"."-relative names.
+ *)
[InitBasicFS, Always, TestOutputList (
[["mkdir_p"; "/a/b/c"];
["touch"; "/a/b/c/d"];
@@ -2590,7 +2594,8 @@ containing C<dir>.
It is an interface to the L<scrub(1)> program. See that
manual page for more details.");
- ("mkdtemp", (RString "dir", [Pathname "template"]), 117,
[],
+(* FIXME: make this a WritableString? *)
+ ("mkdtemp", (RString "dir", [String "template"]), 117,
[],
[InitBasicFS, Always, TestRun (
[["mkdir"; "/tmp"];
["mkdtemp"; "/tmp/tmpXXXXXX"]])],
@@ -2999,7 +3004,12 @@ This call is similar to C<guestfs_mounts>. That call
returns
a list of devices. This one returns a hash table (map) of
device name to directory where the device is mounted.");
- ("mkmountpoint", (RErr, [Pathname "path"]), 148, [],
+ ("mkmountpoint", (RErr, [String "exemptpath"]), 148, [],
+ (* This is a special case: while you would expect a parameter
+ * of type "Pathname", that doesn't work, because it implies
+ * NEED_ROOT in the generated calling code in stubs.c, and
+ * this function cannot use NEED_ROOT.
+ *)
[],
"create a mountpoint",
"\
@@ -3154,7 +3164,7 @@ matching lines.");
Return the canonicalized absolute pathname of C<path>. The
returned path has no C<.>, C<..> or symbolic link path elements.");
- ("ln", (RErr, [String "target"; String "linkname"]), 164,
[],
+ ("ln", (RErr, [String "target"; Pathname "linkname"]),
164, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["ln"; "/a"; "/b"];
@@ -3163,7 +3173,7 @@ returned path has no C<.>, C<..> or symbolic link path
elements.");
"\
This command creates a hard link using the C<ln> command.");
- ("ln_f", (RErr, [String "target"; String "linkname"]),
165, [],
+ ("ln_f", (RErr, [String "target"; Pathname "linkname"]),
165, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["touch"; "/b"];
@@ -3174,7 +3184,7 @@ This command creates a hard link using the C<ln>
command.");
This command creates a hard link using the C<ln -f> command.
The C<-f> option removes the link (C<linkname>) if it exists
already.");
- ("ln_s", (RErr, [String "target"; String "linkname"]),
166, [],
+ ("ln_s", (RErr, [String "target"; Pathname "linkname"]),
166, [],
[InitBasicFS, Always, TestOutputStruct (
[["touch"; "/a"];
["ln_s"; "a"; "/b"];
@@ -3183,7 +3193,7 @@ The C<-f> option removes the link (C<linkname>) if it
exists already.");
"\
This command creates a symbolic link using the C<ln -s> command.");
- ("ln_sf", (RErr, [String "target"; String "linkname"]),
167, [],
+ ("ln_sf", (RErr, [String "target"; Pathname "linkname"]),
167, [],
[InitBasicFS, Always, TestOutput (
[["mkdir_p"; "/a/b"];
["touch"; "/a/b/c"];
@@ -4681,8 +4691,8 @@ and generate_daemon_actions () =
pr " struct guestfs_%s_args args;\n" name;
List.iter (
function
- (* FIXME: eventually, make String "const", too *)
- | Pathname n | Device n -> pr " const char *%s;\n" n
+ | Device n -> pr " const char *%s;\n" n
+ | Pathname n
| String n
| OptString n -> pr " char *%s;\n" n
| StringList n -> pr " char **%s;\n" n
@@ -4705,7 +4715,7 @@ and generate_daemon_actions () =
List.iter (
function
| Pathname n ->
- pr " NEED_ROOT (goto done);\n";
+ pr " %s = args.%s;\n" n n;
pr " ABS_PATH (%s, goto done);\n" n;
| Device n ->
pr " %s = args.%s;\n" n n;
@@ -4728,6 +4738,13 @@ and generate_daemon_actions () =
pr "\n"
);
+ (* this is used at least for do_equal *)
+ if List.exists (function Pathname _ -> true | _ -> false) (snd style) then (
+ (* Emit NEED_ROOT just once, even when there are two or
+ more Pathname args *)
+ pr " NEED_ROOT (goto done);\n";
+ );
+
(* Don't want to call the impl with any FileIn or FileOut
* parameters, since these go "outside" the RPC protocol.
*)
--
1.6.4.337.g5420e