[PATCH 0/23] factor and const-correctness
This started as a simple warning-elimination change. I'll get back to that series shortly ;-) It turned into a factorization and constification exercise during which I got a taste of ocaml. Thanks to Rich Jones for help with a few snippets in generator.ml. The overall result is that many previously-manually-maintained bits from daemon/*.c functions are now hoisted into the automatically- generated (by generator.ml) file, stubs.c. Now, many of the interfaces in daemon/*.c (with declarations in the autogenerated file, daemon/actions.h) that were not const-correct are. daemon/augeas.c | 25 +-- daemon/blockdev.c | 24 +-- daemon/checksum.c | 5 daemon/cmp.c | 8 - daemon/command.c | 6 daemon/cpmv.c | 12 - daemon/daemon.h | 22 +-- daemon/debug.c | 2 daemon/devsparts.c | 4 daemon/df.c | 4 daemon/dir.c | 50 +------ daemon/du.c | 5 daemon/ext2.c | 28 +--- daemon/fallocate.c | 5 daemon/file.c | 59 +------- daemon/find.c | 5 daemon/fsck.c | 4 daemon/glob.c | 5 daemon/grep.c | 29 +--- daemon/grub.c | 6 daemon/guestfsd.c | 2 daemon/headtail.c | 13 - daemon/hexdump.c | 5 daemon/initrd.c | 5 daemon/inotify.c | 6 daemon/link.c | 17 -- daemon/ls.c | 10 - daemon/lvm.c | 30 +--- daemon/mknod.c | 11 - daemon/mount.c | 54 +++---- daemon/ntfs.c | 4 daemon/readdir.c | 5 daemon/realpath.c | 5 daemon/scrub.c | 14 -- daemon/sfdisk.c | 24 +-- daemon/stat.c | 15 -- daemon/strings.c | 7 - daemon/swap.c | 45 +----- daemon/tar.c | 14 -- daemon/upload.c | 6 daemon/wc.c | 11 - daemon/xattr.c | 39 ++--- daemon/zero.c | 4 daemon/zerofree.c | 4 src/generator.ml | 362 ++++++++++++++++++++++++++++++----------------------- 45 files changed, 430 insertions(+), 590 deletions(-)
From: Jim Meyering <meyering@redhat.com> --- src/generator.ml | 67 +++++++++++++++++++++++++++++++++++------------------ 1 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 8d16945..8159027 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -134,6 +134,7 @@ and args = argt list (* Function parameters, guestfs handle is implicit. *) *) and argt = | String of string (* const char *name, cannot be NULL *) + | Device of string (* /dev device name, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) | Bool of string (* boolean *) @@ -1634,7 +1635,7 @@ C<path> should be a file or directory in the mounted file system This is the same as the C<statvfs(2)> system call."); - ("tune2fs_l", (RHashtable "superblock", [String "device"]), 55, [], + ("tune2fs_l", (RHashtable "superblock", [Device "device"]), 55, [], [], (* XXX test *) "get ext2/ext3/ext4 superblock details", "\ @@ -3726,7 +3727,7 @@ let mapi f xs = loop 0 xs let name_of_argt = function - | String n | OptString n | StringList n | Bool n | Int n + | Device n | String n | OptString n | StringList n | Bool n | Int n | FileIn n | FileOut n -> n let java_name_of_struct typ = @@ -4113,7 +4114,7 @@ and generate_xdr () = pr "struct %s_args {\n" name; List.iter ( function - | String n -> pr " string %s<>;\n" n + | Device n | String n -> pr " string %s<>;\n" n | OptString n -> pr " str *%s;\n" n | StringList n -> pr " str %s<>;\n" n | Bool n -> pr " bool %s;\n" n @@ -4474,7 +4475,8 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | String n -> + (* FIXME *) + | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n @@ -4683,7 +4685,8 @@ and generate_daemon_actions () = * allow device name translation. This is safe because * we can modify the string (passed from RPC). *) - | String n + (* FIXME *) + | Device n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n @@ -4704,7 +4707,7 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | String n -> pr " %s = args.%s;\n" n n + | Device n | String n -> pr " %s = args.%s;\n" n n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; @@ -5608,6 +5611,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString n, "NULL" -> () + | Device n, arg | String n, arg | OptString n, arg -> pr " const char *%s = \"%s\";\n" n (c_quote arg); @@ -5655,6 +5659,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString _, "NULL" -> pr ", NULL" + | Device n, _ | String n, _ | OptString n, _ -> pr ", %s" n @@ -5903,6 +5908,7 @@ and generate_fish_cmds () = ); List.iter ( function + | Device n | String n | OptString n | FileIn n @@ -5923,7 +5929,7 @@ and generate_fish_cmds () = iteri ( fun i -> function - | String name -> pr " %s = argv[%d];\n" name i + | Device name | String name -> pr " %s = argv[%d];\n" name i | OptString name -> pr " %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] : NULL;\n" name i i @@ -6156,7 +6162,7 @@ and generate_fish_actions_pod () = pr " %s" name; List.iter ( function - | String n -> pr " %s" n + | Device n | String n -> pr " %s" n | OptString n -> pr " %s" n | StringList n -> pr " '%s ...'" n | Bool _ -> pr " true|false" @@ -6222,9 +6228,11 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) in List.iter ( function + | Device n | String n | OptString n -> next (); +(* FIXME *) if not in_daemon then pr "const char *%s" n else pr "char *%s" n | StringList n -> @@ -6484,6 +6492,7 @@ copy_table (char * const * argv) List.iter ( function + | Device n | String n | FileIn n | FileOut n -> @@ -6536,7 +6545,8 @@ copy_table (char * const * argv) function | StringList n -> pr " ocaml_guestfs_free_strings (%s);\n" n; - | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () + | Device _ | String _ | OptString _ | Bool _ | Int _ + | FileIn _ | FileOut _ -> () ) (snd style); pr " if (r == %s)\n" error_code; @@ -6619,7 +6629,7 @@ and generate_ocaml_prototype ?(is_external = false) name style = pr "%s : t -> " name; List.iter ( function - | String _ | FileIn _ | FileOut _ -> pr "string -> " + | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " | OptString _ -> pr "string option -> " | StringList _ -> pr "string array -> " | Bool _ -> pr "bool -> " @@ -6764,7 +6774,7 @@ DESTROY (g) iteri ( fun i -> function - | String n | FileIn n | FileOut n -> pr " char *%s;\n" n + | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 * Note that the implicit handle argument means we have @@ -6779,7 +6789,7 @@ DESTROY (g) let do_cleanups () = List.iter ( function - | String _ | OptString _ | Bool _ | Int _ + | Device _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style) @@ -7151,7 +7161,8 @@ and generate_perl_prototype name style = if !comma then pr ", "; comma := true; match arg with - | String n | OptString n | Bool n | Int n | FileIn n | FileOut n -> + | Device n | String n + | OptString n | Bool n | Int n | FileIn n | FileOut n -> pr "$%s" n | StringList n -> pr "\\@%s" n @@ -7398,7 +7409,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | String n | FileIn n | FileOut n -> pr " const char *%s;\n" n + | Device n | String n | FileIn n | FileOut n -> pr " const char *%s;\n" n | OptString n -> pr " const char *%s;\n" n | StringList n -> pr " PyObject *py_%s;\n" n; @@ -7413,7 +7424,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " if (!PyArg_ParseTuple (args, (char *) \"O"; List.iter ( function - | String _ | FileIn _ | FileOut _ -> pr "s" + | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" | OptString _ -> pr "z" | StringList _ -> pr "O" | Bool _ -> pr "i" (* XXX Python has booleans? *) @@ -7423,7 +7434,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " &py_g"; List.iter ( function - | String n | FileIn n | FileOut n -> pr ", &%s" n + | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n | OptString n -> pr ", &%s" n | StringList n -> pr ", &py_%s" n | Bool n -> pr ", &%s" n @@ -7436,7 +7447,8 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " g = get_handle (py_g);\n"; List.iter ( function - | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | Device _ | String _ + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " %s = get_string_list (py_%s);\n" n n; pr " if (!%s) return NULL;\n" n @@ -7450,7 +7462,8 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | Device _ | String _ + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style); @@ -7758,7 +7771,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | String n | FileIn n | FileOut n -> + | Device n | String n | FileIn n | FileOut n -> pr " Check_Type (%sv, T_STRING);\n" n; pr " const char *%s = StringValueCStr (%sv);\n" n n; pr " if (!%s)\n" n; @@ -7810,7 +7823,8 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | Device _ | String _ + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style); @@ -8120,6 +8134,7 @@ and generate_java_prototype ?(public=false) ?(privat=false) ?(native=false) needs_comma := true; match arg with + | Device n | String n | OptString n | FileIn n @@ -8237,6 +8252,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " (JNIEnv *env, jobject obj, jlong jg"; List.iter ( function + | Device n | String n | OptString n | FileIn n @@ -8288,6 +8304,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close "NULL", "NULL" in List.iter ( function + | Device n | String n | OptString n | FileIn n @@ -8316,6 +8333,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Get the parameters. *) List.iter ( function + | Device n | String n | FileIn n | FileOut n -> @@ -8347,6 +8365,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Release the parameters. *) List.iter ( function + | Device n | String n | FileIn n | FileOut n -> @@ -8621,7 +8640,7 @@ last_error h = do function | FileIn n | FileOut n - | String n -> pr "withCString %s $ \\%s -> " n n + | Device n | String n -> pr "withCString %s $ \\%s -> " n n | OptString n -> pr "maybeWith withCString %s $ \\%s -> " n n | StringList n -> pr "withMany withCString %s $ \\%s -> withArray0 nullPtr %s $ \\%s -> " n n n n | Bool _ | Int _ -> () @@ -8632,7 +8651,8 @@ last_error h = do function | Bool n -> sprintf "(fromBool %s)" n | Int n -> sprintf "(fromIntegral %s)" n - | FileIn n | FileOut n | String n | OptString n | StringList n -> n + | FileIn n | FileOut n + | Device n | String n | OptString n | StringList n -> n ) (snd style) in pr "withForeignPtr h (\\p -> c_%s %s)\n" name (String.concat " " ("p" :: args)); @@ -8682,7 +8702,7 @@ and generate_haskell_prototype ~handle ?(hs = false) style = List.iter ( fun arg -> (match arg with - | String _ -> pr "%s" string + | Device _ | String _ -> pr "%s" string | OptString _ -> if hs then pr "Maybe String" else pr "CString" | StringList _ -> if hs then pr "[String]" else pr "Ptr CString" | Bool _ -> pr "%s" bool @@ -8757,6 +8777,7 @@ print_strings (char * const* const argv) pr "{\n"; List.iter ( function + | Device n | String n | FileIn n | FileOut n -> pr " printf (\"%%s\\n\", %s);\n" n -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:37PM +0200, Jim Meyering wrote:
@@ -4474,7 +4475,8 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | String n -> + (* FIXME *) + | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
What was the FIXME here? Looks OK to me.
@@ -4683,7 +4685,8 @@ and generate_daemon_actions () = * allow device name translation. This is safe because * we can modify the string (passed from RPC). *) - | String n + (* FIXME *) + | Device n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n
And here? I guess doing device name translation?
@@ -6222,9 +6228,11 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) in List.iter ( function + | Device n | String n | OptString n -> next (); +(* FIXME *) if not in_daemon then pr "const char *%s" n else pr "char *%s" n | StringList n ->
Also unclear what the FIXME is here? - - - Anyway, the patch looks fine to me. ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:37PM +0200, Jim Meyering wrote:
@@ -4474,7 +4475,8 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | String n -> + (* FIXME *) + | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
What was the FIXME here? Looks OK to me.
Sorry about that. Those were notes to self to revisit. They're gone in the final result. I had already removed a few others from intermediate patches but didn't look back far enough. I can remove those as well, if you wish.
@@ -4683,7 +4685,8 @@ and generate_daemon_actions () = * allow device name translation. This is safe because * we can modify the string (passed from RPC). *) - | String n + (* FIXME *) + | Device n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n
And here? I guess doing device name translation?
@@ -6222,9 +6228,11 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) in List.iter ( function + | Device n | String n | OptString n -> next (); +(* FIXME *) if not in_daemon then pr "const char *%s" n else pr "char *%s" n | StringList n ->
Also unclear what the FIXME is here?
- - -
Anyway, the patch looks fine to me. ACK.
Rich.
On Wed, Aug 12, 2009 at 07:33:44PM +0200, Jim Meyering wrote:
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:37PM +0200, Jim Meyering wrote:
@@ -4474,7 +4475,8 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | String n -> + (* FIXME *) + | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
What was the FIXME here? Looks OK to me.
Sorry about that. Those were notes to self to revisit. They're gone in the final result. I had already removed a few others from intermediate patches but didn't look back far enough. I can remove those as well, if you wish.
No it's fine, don't worry about them. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
From: Jim Meyering <meyering@redhat.com> Change parameter from "errcode" (which would be returned) to "fail_stmt" so that a caller can specify e.g., "goto done" upon failure. --- daemon/daemon.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index a6bbb73..166f3bf 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -151,14 +151,14 @@ extern void reply (xdrproc_t xdrp, char *ret); * * NB. Cannot be used for FileIn functions. */ -#define IS_DEVICE(path,errcode) \ +#define RESOLVE_DEVICE(path,fail_stmt) \ do { \ if (strncmp ((path), "/dev/", 5) != 0) { \ reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \ - return (errcode); \ + fail_stmt; \ } \ if (device_name_translation ((path), __func__) == -1) \ - return (errcode); \ + fail_stmt; \ } while (0) /* Helper for functions which need either an absolute path in the -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:38PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
Change parameter from "errcode" (which would be returned) to "fail_stmt" so that a caller can specify e.g., "goto done" upon failure. --- daemon/daemon.h | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index a6bbb73..166f3bf 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -151,14 +151,14 @@ extern void reply (xdrproc_t xdrp, char *ret); * * NB. Cannot be used for FileIn functions. */ -#define IS_DEVICE(path,errcode) \ +#define RESOLVE_DEVICE(path,fail_stmt) \ do { \ if (strncmp ((path), "/dev/", 5) != 0) { \ reply_with_error ("%s: %s: expecting a device name", __func__, (path)); \ - return (errcode); \ + fail_stmt; \ } \ if (device_name_translation ((path), __func__) == -1) \ - return (errcode); \ + fail_stmt; \ } while (0)
/* Helper for functions which need either an absolute path in the -- 1.6.4.337.g5420e
ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
From: Jim Meyering <meyering@redhat.com> Use this command: git grep -l -w IS_DEVICE|xargs perl -pi -e \ 's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/' --- daemon/blockdev.c | 2 +- daemon/devsparts.c | 2 +- daemon/ext2.c | 14 +++++++------- daemon/file.c | 2 +- daemon/fsck.c | 2 +- daemon/grub.c | 2 +- daemon/lvm.c | 12 ++++++------ daemon/mount.c | 4 ++-- daemon/ntfs.c | 2 +- daemon/scrub.c | 2 +- daemon/sfdisk.c | 4 ++-- daemon/swap.c | 10 +++++----- daemon/upload.c | 2 +- daemon/zero.c | 2 +- daemon/zerofree.c | 2 +- 15 files changed, 32 insertions(+), 32 deletions(-) diff --git a/daemon/blockdev.c b/daemon/blockdev.c index 35d14bf..a5f7691 100644 --- a/daemon/blockdev.c +++ b/daemon/blockdev.c @@ -46,7 +46,7 @@ call_blockdev (char *device, char *switc, int extraarg, int prints) }; char buf[64]; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); if (extraarg > 0) { snprintf (buf, sizeof buf, "%d", extraarg); diff --git a/daemon/devsparts.c b/daemon/devsparts.c index e9c5e8f..c3b9756 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -193,7 +193,7 @@ do_mkfs (char *fstype, char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); if (r == -1) { diff --git a/daemon/ext2.c b/daemon/ext2.c index 0f7a66c..d2304bd 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -36,7 +36,7 @@ do_tune2fs_l (char *device) char **ret = NULL; int size = 0, alloc = 0; - IS_DEVICE (device, NULL); + RESOLVE_DEVICE (device, return NULL); r = command (&out, &err, "/sbin/tune2fs", "-l", device, NULL); if (r == -1) { @@ -122,7 +122,7 @@ do_set_e2label (char *device, char *label) int r; char *err; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/e2label", device, label, NULL); if (r == -1) { @@ -141,7 +141,7 @@ do_get_e2label (char *device) int r, len; char *out, *err; - IS_DEVICE (device, NULL); + RESOLVE_DEVICE (device, return NULL); r = command (&out, &err, "/sbin/e2label", device, NULL); if (r == -1) { @@ -167,7 +167,7 @@ do_set_e2uuid (char *device, char *uuid) int r; char *err; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/tune2fs", "-U", uuid, device, NULL); if (r == -1) { @@ -186,7 +186,7 @@ do_get_e2uuid (char *device) int r; char *out, *err, *p, *q; - IS_DEVICE (device, NULL); + RESOLVE_DEVICE (device, return NULL); /* It's not so straightforward to get the volume UUID. We have * to use tune2fs -l and then look for a particular string in @@ -249,7 +249,7 @@ do_resize2fs (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/resize2fs", device, NULL); if (r == -1) { @@ -268,7 +268,7 @@ do_e2fsck_f (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/e2fsck", "-p", "-f", device, NULL); if (r == -1) { diff --git a/daemon/file.c b/daemon/file.c index cd477e5..d2ada99 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -391,7 +391,7 @@ do_file (char *path) char *buf; int len; - NEED_ROOT_OR_IS_DEVICE (path, NULL); + NEED_ROOT_OR_IS_DEVICE (path, return NULL); if (strncmp (path, "/dev/", 5) == 0) buf = (char *) path; diff --git a/daemon/fsck.c b/daemon/fsck.c index f1a9dc5..907c117 100644 --- a/daemon/fsck.c +++ b/daemon/fsck.c @@ -32,7 +32,7 @@ do_fsck (char *fstype, char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = commandr (NULL, &err, "/sbin/fsck", "-a", "-t", fstype, device, NULL); if (r == -1) { diff --git a/daemon/grub.c b/daemon/grub.c index 86e812e..118771f 100644 --- a/daemon/grub.c +++ b/daemon/grub.c @@ -34,7 +34,7 @@ do_grub_install (char *root, char *device) NEED_ROOT (-1); ABS_PATH (root, -1); - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) { reply_with_perror ("asprintf"); diff --git a/daemon/lvm.c b/daemon/lvm.c index 624dcf3..8f575c4 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -176,7 +176,7 @@ do_pvcreate (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/lvm", "pvcreate", device, NULL); @@ -202,7 +202,7 @@ do_vgcreate (char *volgroup, char **physvols) /* Check they are devices and also do device name translation. */ for (i = 0; physvols[i] != NULL; ++i) - IS_DEVICE (physvols[i], -1); + RESOLVE_DEVICE (physvols[i], return -1); argc = count_strings (physvols) + 3; argv = malloc (sizeof (char *) * (argc + 1)); @@ -262,7 +262,7 @@ do_lvresize (char *logvol, int mbytes) int r; char size[64]; - IS_DEVICE (logvol, -1); + RESOLVE_DEVICE (logvol, return -1); snprintf (size, sizeof size, "%d", mbytes); @@ -352,7 +352,7 @@ do_lvremove (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/lvm", "lvremove", "-f", device, NULL); @@ -396,7 +396,7 @@ do_pvremove (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/lvm", "pvremove", "-ff", device, NULL); @@ -419,7 +419,7 @@ do_pvresize (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/sbin/lvm", "pvresize", device, NULL); diff --git a/daemon/mount.c b/daemon/mount.c index 9754ca9..6c30304 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -48,7 +48,7 @@ do_mount_vfs (char *options, char *vfstype, char *mp; char *error; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); is_root = strcmp (mountpoint, "/") == 0; @@ -113,7 +113,7 @@ do_umount (char *pathordevice) if (strncmp (pathordevice, "/dev/", 5) == 0) { buf = pathordevice; - IS_DEVICE (buf, -1); + RESOLVE_DEVICE (buf, return -1); } else { buf = sysroot_path (pathordevice); if (buf == NULL) { diff --git a/daemon/ntfs.c b/daemon/ntfs.c index 26c8d50..8cb4f6f 100644 --- a/daemon/ntfs.c +++ b/daemon/ntfs.c @@ -33,7 +33,7 @@ do_ntfs_3g_probe (int rw, char *device) int r; const char *rw_flag; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); rw_flag = rw ? "-w" : "-r"; diff --git a/daemon/scrub.c b/daemon/scrub.c index 6e205a0..3c22b66 100644 --- a/daemon/scrub.c +++ b/daemon/scrub.c @@ -33,7 +33,7 @@ do_scrub_device (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "scrub", device, NULL); if (r == -1) { diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index e06d0bf..693e89a 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -38,7 +38,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, char buf[256]; int i; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); strcpy (buf, "/sbin/sfdisk"); @@ -111,7 +111,7 @@ sfdisk_flag (char *device, const char *flag) char *out, *err; int r; - IS_DEVICE (device, NULL); + RESOLVE_DEVICE (device, return NULL); r = command (&out, &err, "/sbin/sfdisk", flag, device, NULL); if (r == -1) { diff --git a/daemon/swap.c b/daemon/swap.c index 3ebdef6..c9104e1 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -52,7 +52,7 @@ mkswap (char *device, const char *flag, const char *value) int do_mkswap (char *device) { - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); return mkswap (device, NULL, NULL); } @@ -60,7 +60,7 @@ do_mkswap (char *device) int do_mkswap_L (char *label, char *device) { - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); return mkswap (device, "-L", label); } @@ -68,7 +68,7 @@ do_mkswap_L (char *label, char *device) int do_mkswap_U (char *uuid, char *device) { - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); return mkswap (device, "-U", uuid); } @@ -118,7 +118,7 @@ swaponoff (const char *cmd, const char *flag, const char *value) int do_swapon_device (char *device) { - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); return swaponoff ("/sbin/swapon", NULL, device); } @@ -126,7 +126,7 @@ do_swapon_device (char *device) int do_swapoff_device (char *device) { - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); return swaponoff ("/sbin/swapoff", NULL, device); } diff --git a/daemon/upload.c b/daemon/upload.c index 6c5f6dc..7815e23 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -93,7 +93,7 @@ do_download (char *filename) int fd, r, is_dev; char buf[GUESTFS_MAX_CHUNK_SIZE]; - NEED_ROOT_OR_IS_DEVICE (filename, -1); + NEED_ROOT_OR_IS_DEVICE (filename, return -1); is_dev = strncmp (filename, "/dev/", 5) == 0; diff --git a/daemon/zero.c b/daemon/zero.c index 9c803d8..ba87e68 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -33,7 +33,7 @@ do_zero (char *device) int fd, i; char buf[4096]; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); fd = open (device, O_WRONLY); if (fd == -1) { diff --git a/daemon/zerofree.c b/daemon/zerofree.c index 8000bb3..27ef692 100644 --- a/daemon/zerofree.c +++ b/daemon/zerofree.c @@ -33,7 +33,7 @@ do_zerofree (char *device) char *err; int r; - IS_DEVICE (device, -1); + RESOLVE_DEVICE (device, return -1); r = command (NULL, &err, "/usr/sbin/zerofree", device, NULL); if (r == -1) { -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:39PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
Use this command: git grep -l -w IS_DEVICE|xargs perl -pi -e \ 's/\b(?:IS_DEVICE)\b( \(.*?,) (.*?)\)/RESOLVE_DEVICE$1 return $2)/'
Yup, ACK this. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
From: Jim Meyering <meyering@redhat.com> --- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag); - /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device); if (verbose) -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:40PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */ sprintf (buf + strlen (buf), " %s", device);
if (verbose) -- 1.6.4.337.g5420e
Looks good, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:40PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */
This stray "S" is a typo I'd started to fix when I realized that the IS_DEVICE (renamed to RESOLVE_DEVICE) is now, in the final patch, gone. I'll rebase -i to fix my typo before committing. I'll also write a separate commit to add a check for buffer overflow.
sprintf (buf + strlen (buf), " %s", device);
Jim Meyering wrote:
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:40PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */
This stray "S" is a typo I'd started to fix when I realized that the IS_DEVICE (renamed to RESOLVE_DEVICE) is now, in the final patch, gone.
I'll rebase -i to fix my typo before committing. I'll also write a separate commit to add a check for buffer overflow.
sprintf (buf + strlen (buf), " %s", device);
Here's the promised patch
From 8aca97fc1e7c0513c2781e3443c51b88876aaa6c Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Wed, 12 Aug 2009 21:16:30 +0200 Subject: [PATCH libguestfs] sfdisk: guard against buffer overflow
* daemon/sfdisk.c (sfdisk): Don't let outrageous "extra_flag" or "device" strings overflow a fixed-size buffer. --- daemon/sfdisk.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-) diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 1ec0c85..8ef46e5 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -48,10 +48,23 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); - if (extra_flag) - sprintf (buf + strlen (buf), " %s", extra_flag); - /* Safe because of RESOLVE_DEVICE above: */ + /* The above are all guaranteed to fit in the fixed-size buffer. + However, extra_flag and device have no restrictions, + so we must check. */ + + if (extra_flag) { + if (strlen (buf) + 1 + strlen (extra_flag) >= sizeof buf) { + reply_with_error ("internal buffer overflow: sfdisk extra_flag too long"); + return -1; + } + snprintf (buf + strlen (buf), " %s", extra_flag); + } + + if (strlen (buf) + 1 + strlen (device) >= sizeof buf) { + reply_with_error ("internal buffer overflow: sfdisk device name too long"); + return -1; + } sprintf (buf + strlen (buf), " %s", device); if (verbose) -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 09:19:37PM +0200, Jim Meyering wrote:
Jim Meyering wrote:
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:40PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */
This stray "S" is a typo I'd started to fix when I realized that the IS_DEVICE (renamed to RESOLVE_DEVICE) is now, in the final patch, gone.
I'll rebase -i to fix my typo before committing. I'll also write a separate commit to add a check for buffer overflow.
sprintf (buf + strlen (buf), " %s", device);
Here's the promised patch
From 8aca97fc1e7c0513c2781e3443c51b88876aaa6c Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Wed, 12 Aug 2009 21:16:30 +0200 Subject: [PATCH libguestfs] sfdisk: guard against buffer overflow
* daemon/sfdisk.c (sfdisk): Don't let outrageous "extra_flag" or "device" strings overflow a fixed-size buffer. --- daemon/sfdisk.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 1ec0c85..8ef46e5 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -48,10 +48,23 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); - if (extra_flag) - sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of RESOLVE_DEVICE above: */ + /* The above are all guaranteed to fit in the fixed-size buffer. + However, extra_flag and device have no restrictions, + so we must check. */ + + if (extra_flag) { + if (strlen (buf) + 1 + strlen (extra_flag) >= sizeof buf) { + reply_with_error ("internal buffer overflow: sfdisk extra_flag too long"); + return -1; + } + snprintf (buf + strlen (buf), " %s", extra_flag); + } + + if (strlen (buf) + 1 + strlen (device) >= sizeof buf) { + reply_with_error ("internal buffer overflow: sfdisk device name too long"); + return -1; + } sprintf (buf + strlen (buf), " %s", device);
if (verbose) -- 1.6.4.337.g5420e
Yes that looks fine to me, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 09:19:37PM +0200, Jim Meyering wrote:
Jim Meyering wrote:
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:40PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/sfdisk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 166f3bf..bebc86f 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -174,7 +174,7 @@ extern void reply (xdrproc_t xdrp, char *ret); #define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - IS_DEVICE ((path),(errcode)); \ + RESOLVE_DEVICE ((path), return errcode); \ else { \ NEED_ROOT ((errcode)); \ ABS_PATH ((path),(errcode)); \ diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 693e89a..cf62f51 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -53,7 +53,7 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, if (extra_flag) sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of IS_DEVICE above: */ + /* Safe because of RESOLVES_DEVICE above: */
This stray "S" is a typo I'd started to fix when I realized that the IS_DEVICE (renamed to RESOLVE_DEVICE) is now, in the final patch, gone.
I'll rebase -i to fix my typo before committing. I'll also write a separate commit to add a check for buffer overflow.
sprintf (buf + strlen (buf), " %s", device);
Here's the promised patch
From 8aca97fc1e7c0513c2781e3443c51b88876aaa6c Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Wed, 12 Aug 2009 21:16:30 +0200 Subject: [PATCH libguestfs] sfdisk: guard against buffer overflow
* daemon/sfdisk.c (sfdisk): Don't let outrageous "extra_flag" or "device" strings overflow a fixed-size buffer. --- daemon/sfdisk.c | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index 1ec0c85..8ef46e5 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -48,10 +48,23 @@ sfdisk (const char *device, int n, int cyls, int heads, int sectors, sprintf (buf + strlen (buf), " -H %d", heads); if (sectors) sprintf (buf + strlen (buf), " -S %d", sectors); - if (extra_flag) - sprintf (buf + strlen (buf), " %s", extra_flag);
- /* Safe because of RESOLVE_DEVICE above: */ + /* The above are all guaranteed to fit in the fixed-size buffer. + However, extra_flag and device have no restrictions, + so we must check. */ + + if (extra_flag) { + if (strlen (buf) + 1 + strlen (extra_flag) >= sizeof buf) { + reply_with_error ("internal buffer overflow: sfdisk extra_flag too long"); + return -1; + } + snprintf (buf + strlen (buf), " %s", extra_flag);
It pains me to admit it, but a typo snuck in there. That should be: sprintf (buf + strlen (buf), " %s", extra_flag); and will be in what I push tomorrow morning. [I missed the warning, but "make check" caught it. It would have better if -Werror could have been used. Coming soon. ]
From: Jim Meyering <meyering@redhat.com> changing IS_DEVICE semantics leads to changing semantics of NEED_ROOT_OR_IS_DEVICE and NEED_ROOT, too. * daemon/daemon.h: Update definitions. --- daemon/daemon.h | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index bebc86f..8bc6344 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -124,11 +124,11 @@ extern void reply (xdrproc_t xdrp, char *ret); /* Helper for functions that need a root filesystem mounted. * NB. Cannot be used for FileIn functions. */ -#define NEED_ROOT(errcode) \ +#define NEED_ROOT(fail_stmt) \ do { \ if (!root_mounted) { \ reply_with_error ("%s: you must call 'mount' first to mount the root filesystem", __func__); \ - return (errcode); \ + fail_stmt; \ } \ } \ while (0) @@ -136,11 +136,11 @@ extern void reply (xdrproc_t xdrp, char *ret); /* Helper for functions that need an argument ("path") that is absolute. * NB. Cannot be used for FileIn functions. */ -#define ABS_PATH(path,errcode) \ +#define ABS_PATH(path,fail_stmt) \ do { \ if ((path)[0] != '/') { \ reply_with_error ("%s: path must start with a / character", __func__); \ - return (errcode); \ + fail_stmt; \ } \ } while (0) @@ -171,13 +171,13 @@ extern void reply (xdrproc_t xdrp, char *ret); * because we intend in future to make device parameters a distinct * type from filenames. */ -#define NEED_ROOT_OR_IS_DEVICE(path,errcode) \ +#define NEED_ROOT_OR_IS_DEVICE(path,fail_stmt) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ - RESOLVE_DEVICE ((path), return errcode); \ + RESOLVE_DEVICE ((path), fail_stmt); \ else { \ - NEED_ROOT ((errcode)); \ - ABS_PATH ((path),(errcode)); \ + NEED_ROOT (fail_stmt); \ + ABS_PATH ((path),fail_stmt); \ } \ } while (0) -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:41PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
changing IS_DEVICE semantics leads to changing semantics of NEED_ROOT_OR_IS_DEVICE and NEED_ROOT, too.
Yes, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones New in Fedora 11: Fedora Windows cross-compiler. Compile Windows programs, test, and build Windows installers. Over 70 libraries supprt'd http://fedoraproject.org/wiki/MinGW http://www.annexia.org/fedora_mingw
From: Jim Meyering <meyering@redhat.com> run this command: git grep -l -w ABS_PATH|xargs perl -pi -e \ 's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/' --- daemon/augeas.c | 4 ++-- daemon/checksum.c | 2 +- daemon/cmp.c | 4 ++-- daemon/cpmv.c | 4 ++-- daemon/dir.c | 12 ++++++------ daemon/du.c | 2 +- daemon/fallocate.c | 2 +- daemon/file.c | 20 ++++++++++---------- daemon/find.c | 2 +- daemon/glob.c | 2 +- daemon/grep.c | 2 +- daemon/grub.c | 2 +- daemon/headtail.c | 2 +- daemon/hexdump.c | 2 +- daemon/initrd.c | 2 +- daemon/inotify.c | 2 +- daemon/link.c | 4 ++-- daemon/ls.c | 2 +- daemon/mknod.c | 2 +- daemon/mount.c | 6 +++--- daemon/readdir.c | 2 +- daemon/realpath.c | 2 +- daemon/scrub.c | 4 ++-- daemon/stat.c | 6 +++--- daemon/strings.c | 2 +- daemon/swap.c | 6 +++--- daemon/tar.c | 4 ++-- daemon/wc.c | 2 +- daemon/xattr.c | 2 +- 29 files changed, 55 insertions(+), 55 deletions(-) diff --git a/daemon/augeas.c b/daemon/augeas.c index 79d41a4..45f86cf 100644 --- a/daemon/augeas.c +++ b/daemon/augeas.c @@ -55,7 +55,7 @@ do_aug_init (char *root, int flags) char *buf; NEED_ROOT (-1); - ABS_PATH (root, -1); + ABS_PATH (root, return -1); if (aug) { aug_close (aug); @@ -350,7 +350,7 @@ do_aug_ls (char *path) NEED_AUG (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); len = strlen (path); diff --git a/daemon/checksum.c b/daemon/checksum.c index bd71182..d12413f 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -37,7 +37,7 @@ do_checksum (char *csumtype, char *path) int len; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); if (strcasecmp (csumtype, "crc") == 0) program = "cksum"; diff --git a/daemon/cmp.c b/daemon/cmp.c index a2d92a3..30574e2 100644 --- a/daemon/cmp.c +++ b/daemon/cmp.c @@ -35,8 +35,8 @@ do_equal (char *file1, char *file2) int r; NEED_ROOT (-1); - ABS_PATH (file1, -1); - ABS_PATH (file2, -1); + ABS_PATH (file1, return -1); + ABS_PATH (file2, return -1); file1buf = sysroot_path (file1); if (file1buf == NULL) { diff --git a/daemon/cpmv.c b/daemon/cpmv.c index 289a2da..37f1219 100644 --- a/daemon/cpmv.c +++ b/daemon/cpmv.c @@ -53,8 +53,8 @@ cpmv_cmd (const char *cmd, const char *flags, const char *src, const char *dest) int r; NEED_ROOT (-1); - ABS_PATH (src, -1); - ABS_PATH (dest, -1); + ABS_PATH (src, return -1); + ABS_PATH (dest, return -1); srcbuf = sysroot_path (src); if (srcbuf == NULL) { diff --git a/daemon/dir.c b/daemon/dir.c index 5945862..20cbd24 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -35,7 +35,7 @@ do_rmdir (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = rmdir (path); @@ -60,7 +60,7 @@ do_rm_rf (char *path) char *buf, *err; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); if (strcmp (path, "/") == 0) { reply_with_error ("rm -rf: cannot remove root directory"); @@ -94,7 +94,7 @@ do_mkdir (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = mkdir (path, 0777); @@ -160,7 +160,7 @@ do_mkdir_p (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = recursive_mkdir (path); @@ -181,7 +181,7 @@ do_is_dir (char *path) struct stat buf; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = lstat (path, &buf); @@ -205,7 +205,7 @@ do_mkdtemp (char *template) char *r; NEED_ROOT (NULL); - ABS_PATH (template, NULL); + ABS_PATH (template, return NULL); CHROOT_IN; r = mkdtemp (template); diff --git a/daemon/du.c b/daemon/du.c index 735132a..7d9c663 100644 --- a/daemon/du.c +++ b/daemon/du.c @@ -37,7 +37,7 @@ do_du (char *path) char *buf; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); /* Make the path relative to /sysroot. */ buf = sysroot_path (path); diff --git a/daemon/fallocate.c b/daemon/fallocate.c index 47e84c6..f61c496 100644 --- a/daemon/fallocate.c +++ b/daemon/fallocate.c @@ -33,7 +33,7 @@ do_fallocate (char *path, int len) int fd, r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; fd = open (path, O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666); diff --git a/daemon/file.c b/daemon/file.c index d2ada99..e185132 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -36,7 +36,7 @@ do_touch (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; fd = open (path, O_WRONLY | O_CREAT | O_NOCTTY, 0666); @@ -148,7 +148,7 @@ do_read_lines (char *path) ssize_t n; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; fp = fopen (path, "r"); @@ -195,7 +195,7 @@ do_rm (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = unlink (path); @@ -215,7 +215,7 @@ do_chmod (int mode, char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = chmod (path, mode); @@ -235,7 +235,7 @@ do_chown (int owner, int group, char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = chown (path, owner, group); @@ -255,7 +255,7 @@ do_exists (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = access (path, F_OK); @@ -271,7 +271,7 @@ do_is_file (char *path) struct stat buf; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = lstat (path, &buf); @@ -295,7 +295,7 @@ do_write_file (char *path, char *content, int size) int fd; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); if (size == 0) size = strlen (content); @@ -331,7 +331,7 @@ do_read_file (char *path, size_t *size_r) char *r; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; fd = open (path, O_RDONLY); @@ -445,7 +445,7 @@ do_zfile (char *method, char *path) char line[256]; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") == 0) zcat = "zcat"; diff --git a/daemon/find.c b/daemon/find.c index 40f1b3b..c514177 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -60,7 +60,7 @@ do_find (char *dir) char str[PATH_MAX]; NEED_ROOT (NULL); - ABS_PATH (dir, NULL); + ABS_PATH (dir, return NULL); sysrootdir = sysroot_path (dir); if (!sysrootdir) { diff --git a/daemon/glob.c b/daemon/glob.c index f15d5e5..1c47ba5 100644 --- a/daemon/glob.c +++ b/daemon/glob.c @@ -32,7 +32,7 @@ do_glob_expand (char *pattern) glob_t buf; NEED_ROOT (NULL); - ABS_PATH (pattern, NULL); /* Required so chroot can be used. */ + 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; diff --git a/daemon/grep.c b/daemon/grep.c index c51dc0b..19e4683 100644 --- a/daemon/grep.c +++ b/daemon/grep.c @@ -36,7 +36,7 @@ grep (const char *prog, const char *flag, char *regex, char *path) char **lines; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); /* Make the path relative to /sysroot. */ buf = sysroot_path (path); diff --git a/daemon/grub.c b/daemon/grub.c index 118771f..8fcd911 100644 --- a/daemon/grub.c +++ b/daemon/grub.c @@ -33,7 +33,7 @@ do_grub_install (char *root, char *device) char *buf; NEED_ROOT (-1); - ABS_PATH (root, -1); + ABS_PATH (root, return -1); RESOLVE_DEVICE (device, return -1); if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) { diff --git a/daemon/headtail.c b/daemon/headtail.c index af2648c..bdd0f49 100644 --- a/daemon/headtail.c +++ b/daemon/headtail.c @@ -36,7 +36,7 @@ headtail (const char *prog, const char *flag, const char *n, char *path) char **lines; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); /* Make the path relative to /sysroot. */ buf = sysroot_path (path); diff --git a/daemon/hexdump.c b/daemon/hexdump.c index e2d8300..27ea108 100644 --- a/daemon/hexdump.c +++ b/daemon/hexdump.c @@ -33,7 +33,7 @@ do_hexdump (char *path) char *out, *err; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); buf = sysroot_path (path); if (!buf) { diff --git a/daemon/initrd.c b/daemon/initrd.c index 59749bb..e703481 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -38,7 +38,7 @@ do_initrd_list (char *path) size_t len; NEED_ROOT (NULL); - ABS_PATH (path, 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) { diff --git a/daemon/inotify.c b/daemon/inotify.c index 8bb8ed2..2f22f52 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -129,7 +129,7 @@ do_inotify_add_watch (char *path, int mask) char *buf; NEED_INOTIFY (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); buf = sysroot_path (path); if (!buf) { diff --git a/daemon/link.c b/daemon/link.c index 29ae679..bf616ed 100644 --- a/daemon/link.c +++ b/daemon/link.c @@ -35,7 +35,7 @@ do_readlink (char *path) char link[PATH_MAX]; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; r = readlink (path, link, sizeof link); @@ -63,7 +63,7 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname) char *buf_target; NEED_ROOT (-1); - ABS_PATH (linkname, -1); + ABS_PATH (linkname, return -1); /* but target does not need to be absolute */ /* Prefix linkname with sysroot. */ diff --git a/daemon/ls.c b/daemon/ls.c index e2ca55f..8ae150b 100644 --- a/daemon/ls.c +++ b/daemon/ls.c @@ -38,7 +38,7 @@ do_ls (char *path) struct dirent *d; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; dir = opendir (path); diff --git a/daemon/mknod.c b/daemon/mknod.c index 315ea7d..ab799cd 100644 --- a/daemon/mknod.c +++ b/daemon/mknod.c @@ -36,7 +36,7 @@ do_mknod (int mode, int devmajor, int devminor, char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = mknod (path, mode, makedev (devmajor, devminor)); diff --git a/daemon/mount.c b/daemon/mount.c index 6c30304..8cf6874 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -320,7 +320,7 @@ do_mount_loop (char *file, char *mountpoint) char *error; NEED_ROOT (-1); - ABS_PATH (file, -1); + ABS_PATH (file, return -1); /* We have to prefix /sysroot on both the filename and the mountpoint. */ mp = sysroot_path (mountpoint); @@ -358,7 +358,7 @@ do_mkmountpoint (char *path) int r; /* NEED_ROOT (-1); - we don't want this test for this call. */ - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = mkdir (path, 0777); @@ -383,7 +383,7 @@ do_rmmountpoint (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); CHROOT_IN; r = rmdir (path); diff --git a/daemon/readdir.c b/daemon/readdir.c index 17fc619..f8f95d2 100644 --- a/daemon/readdir.c +++ b/daemon/readdir.c @@ -37,7 +37,7 @@ do_readdir (char *path) int i; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); ret = malloc (sizeof *ret); if (ret == NULL) { diff --git a/daemon/realpath.c b/daemon/realpath.c index 9ab478d..18adc85 100644 --- a/daemon/realpath.c +++ b/daemon/realpath.c @@ -33,7 +33,7 @@ do_realpath (char *path) char *ret; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; ret = realpath (path, NULL); diff --git a/daemon/scrub.c b/daemon/scrub.c index 3c22b66..f1601f9 100644 --- a/daemon/scrub.c +++ b/daemon/scrub.c @@ -55,7 +55,7 @@ do_scrub_file (char *file) int r; NEED_ROOT (-1); - ABS_PATH (file, -1); + ABS_PATH (file, return -1); /* Make the path relative to /sysroot. */ buf = sysroot_path (file); @@ -85,7 +85,7 @@ do_scrub_freespace (char *dir) int r; NEED_ROOT (-1); - ABS_PATH (dir, -1); + ABS_PATH (dir, return -1); /* Make the path relative to /sysroot. */ buf = sysroot_path (dir); diff --git a/daemon/stat.c b/daemon/stat.c index da360ce..da2d274 100644 --- a/daemon/stat.c +++ b/daemon/stat.c @@ -38,7 +38,7 @@ do_stat (char *path) struct stat statbuf; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; r = stat (path, &statbuf); @@ -80,7 +80,7 @@ do_lstat (char *path) struct stat statbuf; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; r = lstat (path, &statbuf); @@ -122,7 +122,7 @@ do_statvfs (char *path) struct statvfs statbuf; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; r = statvfs (path, &statbuf); diff --git a/daemon/strings.c b/daemon/strings.c index c0e073f..89e04a8 100644 --- a/daemon/strings.c +++ b/daemon/strings.c @@ -34,7 +34,7 @@ do_strings_e (char *encoding, char *path) char **lines; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); buf = sysroot_path (path); if (!buf) { diff --git a/daemon/swap.c b/daemon/swap.c index c9104e1..bb1706f 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -80,7 +80,7 @@ do_mkswap_file (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); buf = sysroot_path (path); if (!buf) { @@ -138,7 +138,7 @@ do_swapon_file (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); buf = sysroot_path (path); if (!buf) { @@ -158,7 +158,7 @@ do_swapoff_file (char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); buf = sysroot_path (path); if (!buf) { diff --git a/daemon/tar.c b/daemon/tar.c index 39b983c..e1ff9b6 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -107,7 +107,7 @@ do_tar_out (char *dir) char buf[GUESTFS_MAX_CHUNK_SIZE]; NEED_ROOT (-1); - ABS_PATH (dir, -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) { @@ -229,7 +229,7 @@ do_tgz_out (char *dir) char buf[GUESTFS_MAX_CHUNK_SIZE]; NEED_ROOT (-1); - ABS_PATH (dir, -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) { diff --git a/daemon/wc.c b/daemon/wc.c index 4878b57..0917eb9 100644 --- a/daemon/wc.c +++ b/daemon/wc.c @@ -35,7 +35,7 @@ wc (char *flag, char *path) int r; NEED_ROOT (-1); - ABS_PATH (path, -1); + ABS_PATH (path, return -1); /* Make the path relative to /sysroot. */ buf = sysroot_path (path); diff --git a/daemon/xattr.c b/daemon/xattr.c index a908a44..88947b2 100644 --- a/daemon/xattr.c +++ b/daemon/xattr.c @@ -117,7 +117,7 @@ getxattrs (char *path, guestfs_int_xattr_list *r = NULL; NEED_ROOT (NULL); - ABS_PATH (path, NULL); + ABS_PATH (path, return NULL); CHROOT_IN; len = listxattr (path, NULL, 0); -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:42PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
run this command: git grep -l -w ABS_PATH|xargs perl -pi -e \ 's/(?:ABS_PATH)( \(.*?,) (.*?)\)/ABS_PATH$1 return $2)/'
Yes, mechanical change. ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
From: Jim Meyering <meyering@redhat.com> * daemon/file.c (do_cat): fix an ABS_PATH use --- daemon/file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/daemon/file.c b/daemon/file.c index e185132..9cc324f 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -74,7 +74,7 @@ do_cat (char *path) char *buf, *buf2; NEED_ROOT (NULL); - ABS_PATH (path,NULL); + ABS_PATH (path, return NULL); CHROOT_IN; fd = open (path, O_RDONLY); -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:43PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* daemon/file.c (do_cat): fix an ABS_PATH use --- daemon/file.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/file.c b/daemon/file.c index e185132..9cc324f 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -74,7 +74,7 @@ do_cat (char *path) char *buf, *buf2;
NEED_ROOT (NULL); - ABS_PATH (path,NULL); + ABS_PATH (path, return NULL);
CHROOT_IN; fd = open (path, O_RDONLY); -- 1.6.4.337.g5420e
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
From: Jim Meyering <meyering@redhat.com> --- daemon/guestfsd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 07a952f..4a14c75 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -775,7 +775,7 @@ print_arginfo (const struct printf_info *info, size_t n, int *argtypes) #endif /* Perform device name translation. Don't call this directly - - * use the IS_DEVICE macro. + * use the RESOLVE_DEVICE macro. * * See guestfs(3) for the algorithm. * -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:44PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/guestfsd.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/guestfsd.c b/daemon/guestfsd.c index 07a952f..4a14c75 100644 --- a/daemon/guestfsd.c +++ b/daemon/guestfsd.c @@ -775,7 +775,7 @@ print_arginfo (const struct printf_info *info, size_t n, int *argtypes) #endif
/* Perform device name translation. Don't call this directly - - * use the IS_DEVICE macro. + * use the RESOLVE_DEVICE macro. * * See guestfs(3) for the algorithm. * -- 1.6.4.337.g5420e
ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
From: Jim Meyering <meyering@redhat.com> --- daemon/daemon.h | 2 +- daemon/file.c | 2 +- daemon/upload.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index 8bc6344..cbcab63 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -171,7 +171,7 @@ extern void reply (xdrproc_t xdrp, char *ret); * because we intend in future to make device parameters a distinct * type from filenames. */ -#define NEED_ROOT_OR_IS_DEVICE(path,fail_stmt) \ +#define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,fail_stmt) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ RESOLVE_DEVICE ((path), fail_stmt); \ diff --git a/daemon/file.c b/daemon/file.c index 9cc324f..2ba2aab 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -391,7 +391,7 @@ do_file (char *path) char *buf; int len; - NEED_ROOT_OR_IS_DEVICE (path, return NULL); + REQUIRE_ROOT_OR_RESOLVE_DEVICE (path, return NULL); if (strncmp (path, "/dev/", 5) == 0) buf = (char *) path; diff --git a/daemon/upload.c b/daemon/upload.c index 7815e23..5c1adaf 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -93,7 +93,7 @@ do_download (char *filename) int fd, r, is_dev; char buf[GUESTFS_MAX_CHUNK_SIZE]; - NEED_ROOT_OR_IS_DEVICE (filename, return -1); + REQUIRE_ROOT_OR_RESOLVE_DEVICE (filename, return -1); is_dev = strncmp (filename, "/dev/", 5) == 0; -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:45PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- daemon/file.c | 2 +- daemon/upload.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index 8bc6344..cbcab63 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -171,7 +171,7 @@ extern void reply (xdrproc_t xdrp, char *ret); * because we intend in future to make device parameters a distinct * type from filenames. */ -#define NEED_ROOT_OR_IS_DEVICE(path,fail_stmt) \ +#define REQUIRE_ROOT_OR_RESOLVE_DEVICE(path,fail_stmt) \ do { \ if (strncmp ((path), "/dev/", 5) == 0) \ RESOLVE_DEVICE ((path), fail_stmt); \ diff --git a/daemon/file.c b/daemon/file.c index 9cc324f..2ba2aab 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -391,7 +391,7 @@ do_file (char *path) char *buf; int len;
- NEED_ROOT_OR_IS_DEVICE (path, return NULL); + REQUIRE_ROOT_OR_RESOLVE_DEVICE (path, return NULL);
if (strncmp (path, "/dev/", 5) == 0) buf = (char *) path; diff --git a/daemon/upload.c b/daemon/upload.c index 7815e23..5c1adaf 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -93,7 +93,7 @@ do_download (char *filename) int fd, r, is_dev; char buf[GUESTFS_MAX_CHUNK_SIZE];
- NEED_ROOT_OR_IS_DEVICE (filename, return -1); + REQUIRE_ROOT_OR_RESOLVE_DEVICE (filename, return -1);
is_dev = strncmp (filename, "/dev/", 5) == 0;
-- 1.6.4.337.g5420e
ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
From: Jim Meyering <meyering@redhat.com> * src/generator.ml: Emit RESOLVE_DEVICE (device, goto done); just before each Device-enabled do_$FUNCTION. --- src/generator.ml | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 8159027..20fe5c1 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4475,7 +4475,6 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - (* FIXME *) | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> @@ -4685,7 +4684,6 @@ and generate_daemon_actions () = * allow device name translation. This is safe because * we can modify the string (passed from RPC). *) - (* FIXME *) | Device n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n @@ -4707,7 +4705,10 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | Device n | String n -> pr " %s = args.%s;\n" n n + | Device n -> + pr " %s = args.%s;\n" n n; + pr " RESOLVE_DEVICE (%s, goto done);" n; + | String n -> pr " %s = args.%s;\n" n n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; @@ -6232,7 +6233,6 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) | String n | OptString n -> next (); -(* FIXME *) if not in_daemon then pr "const char *%s" n else pr "char *%s" n | StringList n -> @@ -7448,7 +7448,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function | Device _ | String _ - | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " %s = get_string_list (py_%s);\n" n n; pr " if (!%s) return NULL;\n" n @@ -7463,7 +7463,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function | Device _ | String _ - | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style); @@ -7824,7 +7824,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function | Device _ | String _ - | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () + | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style); -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:46PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml: Emit RESOLVE_DEVICE (device, goto done); just before each Device-enabled do_$FUNCTION. --- src/generator.ml | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
OK, I understand what the FIXMEs are for now. This patch is fine, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
From: Jim Meyering <meyering@redhat.com> Then update each affected function, removing each uses of RESOLVE_DEVICE, now that it's generated in caller from stub.c. * daemon/blockdev.c (call_blockdev): Remove use of RESOLVE_DEVICE. * daemon/devsparts.c (do_mkfs): Likewise. * daemon/ext2.c (do_e2fsck_f, do_get_e2label, do_get_e2uuid): Likewise. (do_resize2fs, do_set_e2label, do_set_e2uuid, do_tune2fs_l): Likewise. * daemon/fsck.c (do_fsck): Likewise. * daemon/grub.c (do_grub_install): Likewise. * daemon/lvm.c (do_lvremove, do_pvcreate, do_pvremove): Likewise. (do_pvresize): Likewise. * daemon/mount.c (do_mount_vfs): Likewise. * daemon/ntfs.c (do_ntfs_3g_probe): Likewise. * daemon/scrub.c (do_scrub_device): Likewise. * daemon/sfdisk.c (sfdisk, sfdisk_flag): Likewise. * daemon/swap.c (do_mkswap, do_mkswap_L, do_mkswap_U): Likewise. (do_swapoff_device, do_swapon_device): Likewise. * daemon/zero.c (do_zero): Likewise. * daemon/zerofree.c (do_zerofree): Likewise. --- daemon/blockdev.c | 2 - daemon/devsparts.c | 2 - daemon/ext2.c | 14 -------- daemon/fsck.c | 2 - daemon/grub.c | 1 - daemon/lvm.c | 8 ----- daemon/mount.c | 2 - daemon/ntfs.c | 2 - daemon/scrub.c | 2 - daemon/sfdisk.c | 4 -- daemon/swap.c | 10 ------ daemon/zero.c | 2 - daemon/zerofree.c | 2 - src/generator.ml | 86 ++++++++++++++++++++++++++-------------------------- 14 files changed, 43 insertions(+), 96 deletions(-) diff --git a/daemon/blockdev.c b/daemon/blockdev.c index a5f7691..46ee994 100644 --- a/daemon/blockdev.c +++ b/daemon/blockdev.c @@ -46,8 +46,6 @@ call_blockdev (char *device, char *switc, int extraarg, int prints) }; char buf[64]; - RESOLVE_DEVICE (device, return -1); - if (extraarg > 0) { snprintf (buf, sizeof buf, "%d", extraarg); argv[2] = buf; diff --git a/daemon/devsparts.c b/daemon/devsparts.c index c3b9756..04585ed 100644 --- a/daemon/devsparts.c +++ b/daemon/devsparts.c @@ -193,8 +193,6 @@ do_mkfs (char *fstype, char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/mkfs", "-t", fstype, device, NULL); if (r == -1) { reply_with_error ("mkfs: %s", err); diff --git a/daemon/ext2.c b/daemon/ext2.c index d2304bd..04869da 100644 --- a/daemon/ext2.c +++ b/daemon/ext2.c @@ -36,8 +36,6 @@ do_tune2fs_l (char *device) char **ret = NULL; int size = 0, alloc = 0; - RESOLVE_DEVICE (device, return NULL); - r = command (&out, &err, "/sbin/tune2fs", "-l", device, NULL); if (r == -1) { reply_with_error ("tune2fs: %s", err); @@ -122,8 +120,6 @@ do_set_e2label (char *device, char *label) int r; char *err; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/e2label", device, label, NULL); if (r == -1) { reply_with_error ("e2label: %s", err); @@ -141,8 +137,6 @@ do_get_e2label (char *device) int r, len; char *out, *err; - RESOLVE_DEVICE (device, return NULL); - r = command (&out, &err, "/sbin/e2label", device, NULL); if (r == -1) { reply_with_error ("e2label: %s", err); @@ -167,8 +161,6 @@ do_set_e2uuid (char *device, char *uuid) int r; char *err; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/tune2fs", "-U", uuid, device, NULL); if (r == -1) { reply_with_error ("tune2fs -U: %s", err); @@ -186,8 +178,6 @@ do_get_e2uuid (char *device) int r; char *out, *err, *p, *q; - RESOLVE_DEVICE (device, return NULL); - /* It's not so straightforward to get the volume UUID. We have * to use tune2fs -l and then look for a particular string in * the output. @@ -249,8 +239,6 @@ do_resize2fs (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/resize2fs", device, NULL); if (r == -1) { reply_with_error ("resize2fs: %s", err); @@ -268,8 +256,6 @@ do_e2fsck_f (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/e2fsck", "-p", "-f", device, NULL); if (r == -1) { reply_with_error ("e2fsck: %s", err); diff --git a/daemon/fsck.c b/daemon/fsck.c index 907c117..825f97e 100644 --- a/daemon/fsck.c +++ b/daemon/fsck.c @@ -32,8 +32,6 @@ do_fsck (char *fstype, char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = commandr (NULL, &err, "/sbin/fsck", "-a", "-t", fstype, device, NULL); if (r == -1) { reply_with_error ("fsck: %s: %s", device, err); diff --git a/daemon/grub.c b/daemon/grub.c index 8fcd911..0a49c45 100644 --- a/daemon/grub.c +++ b/daemon/grub.c @@ -34,7 +34,6 @@ do_grub_install (char *root, char *device) NEED_ROOT (-1); ABS_PATH (root, return -1); - RESOLVE_DEVICE (device, return -1); if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) { reply_with_perror ("asprintf"); diff --git a/daemon/lvm.c b/daemon/lvm.c index 8f575c4..bee62d4 100644 --- a/daemon/lvm.c +++ b/daemon/lvm.c @@ -176,8 +176,6 @@ do_pvcreate (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/lvm", "pvcreate", device, NULL); if (r == -1) { @@ -352,8 +350,6 @@ do_lvremove (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/lvm", "lvremove", "-f", device, NULL); if (r == -1) { @@ -396,8 +392,6 @@ do_pvremove (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/lvm", "pvremove", "-ff", device, NULL); if (r == -1) { @@ -419,8 +413,6 @@ do_pvresize (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/sbin/lvm", "pvresize", device, NULL); if (r == -1) { diff --git a/daemon/mount.c b/daemon/mount.c index 8cf6874..14e683a 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -48,8 +48,6 @@ do_mount_vfs (char *options, char *vfstype, char *mp; char *error; - RESOLVE_DEVICE (device, return -1); - is_root = strcmp (mountpoint, "/") == 0; if (!root_mounted && !is_root) { diff --git a/daemon/ntfs.c b/daemon/ntfs.c index 8cb4f6f..1d73f2e 100644 --- a/daemon/ntfs.c +++ b/daemon/ntfs.c @@ -33,8 +33,6 @@ do_ntfs_3g_probe (int rw, char *device) int r; const char *rw_flag; - RESOLVE_DEVICE (device, return -1); - rw_flag = rw ? "-w" : "-r"; r = commandr (NULL, &err, "ntfs-3g.probe", rw_flag, device, NULL); diff --git a/daemon/scrub.c b/daemon/scrub.c index f1601f9..2beaea3 100644 --- a/daemon/scrub.c +++ b/daemon/scrub.c @@ -33,8 +33,6 @@ do_scrub_device (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "scrub", device, NULL); if (r == -1) { reply_with_error ("scrub_device: %s: %s", device, err); diff --git a/daemon/sfdisk.c b/daemon/sfdisk.c index cf62f51..fe58d96 100644 --- a/daemon/sfdisk.c +++ b/daemon/sfdisk.c @@ -38,8 +38,6 @@ sfdisk (char *device, int n, int cyls, int heads, int sectors, char buf[256]; int i; - RESOLVE_DEVICE (device, return -1); - strcpy (buf, "/sbin/sfdisk"); if (n > 0) @@ -111,8 +109,6 @@ sfdisk_flag (char *device, const char *flag) char *out, *err; int r; - RESOLVE_DEVICE (device, return NULL); - r = command (&out, &err, "/sbin/sfdisk", flag, device, NULL); if (r == -1) { reply_with_error ("sfdisk: %s: %s", device, err); diff --git a/daemon/swap.c b/daemon/swap.c index bb1706f..f7270f8 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -52,24 +52,18 @@ mkswap (char *device, const char *flag, const char *value) int do_mkswap (char *device) { - RESOLVE_DEVICE (device, return -1); - return mkswap (device, NULL, NULL); } int do_mkswap_L (char *label, char *device) { - RESOLVE_DEVICE (device, return -1); - return mkswap (device, "-L", label); } int do_mkswap_U (char *uuid, char *device) { - RESOLVE_DEVICE (device, return -1); - return mkswap (device, "-U", uuid); } @@ -118,16 +112,12 @@ swaponoff (const char *cmd, const char *flag, const char *value) int do_swapon_device (char *device) { - RESOLVE_DEVICE (device, return -1); - return swaponoff ("/sbin/swapon", NULL, device); } int do_swapoff_device (char *device) { - RESOLVE_DEVICE (device, return -1); - return swaponoff ("/sbin/swapoff", NULL, device); } diff --git a/daemon/zero.c b/daemon/zero.c index ba87e68..864e9a6 100644 --- a/daemon/zero.c +++ b/daemon/zero.c @@ -33,8 +33,6 @@ do_zero (char *device) int fd, i; char buf[4096]; - RESOLVE_DEVICE (device, return -1); - fd = open (device, O_WRONLY); if (fd == -1) { reply_with_perror ("%s", device); diff --git a/daemon/zerofree.c b/daemon/zerofree.c index 27ef692..457f8db 100644 --- a/daemon/zerofree.c +++ b/daemon/zerofree.c @@ -33,8 +33,6 @@ do_zerofree (char *device) char *err; int r; - RESOLVE_DEVICE (device, return -1); - r = command (NULL, &err, "/usr/sbin/zerofree", device, NULL); if (r == -1) { reply_with_error ("zerofree: %s: %s", device, err); diff --git a/src/generator.ml b/src/generator.ml index 20fe5c1..0c9cf36 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -769,7 +769,7 @@ of features. Distro backports makes this unreliable."); *) let daemon_functions = [ - ("mount", (RErr, [String "device"; String "mountpoint"]), 1, [], + ("mount", (RErr, [Device "device"; String "mountpoint"]), 1, [], [InitEmpty, Always, TestOutput ( [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; @@ -1265,7 +1265,7 @@ other objects like files. See also C<guestfs_stat>."); - ("pvcreate", (RErr, [String "device"]), 39, [], + ("pvcreate", (RErr, [Device "device"]), 39, [], [InitEmpty, Always, TestOutputListOfDevices ( [["sfdiskM"; "/dev/sda"; ",100 ,200 ,"]; ["pvcreate"; "/dev/sda1"]; @@ -1313,7 +1313,7 @@ from the non-empty list of physical volumes C<physvols>."); This creates an LVM volume group called C<logvol> on the volume group C<volgroup>, with C<size> megabytes."); - ("mkfs", (RErr, [String "fstype"; String "device"]), 42, [], + ("mkfs", (RErr, [String "fstype"; Device "device"]), 42, [], [InitEmpty, Always, TestOutput ( [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext2"; "/dev/sda1"]; @@ -1326,7 +1326,7 @@ This creates a filesystem on C<device> (usually a partition or LVM logical volume). The filesystem type is C<fstype>, for example C<ext3>."); - ("sfdisk", (RErr, [String "device"; + ("sfdisk", (RErr, [Device "device"; Int "cyls"; Int "heads"; Int "sectors"; StringList "lines"]), 43, [DangerWillRobinson], [], @@ -1647,7 +1647,7 @@ manpage for more details. The list of fields returned isn't clearly defined, and depends on both the version of C<tune2fs> that libguestfs was built against, and the filesystem itself."); - ("blockdev_setro", (RErr, [String "device"]), 56, [], + ("blockdev_setro", (RErr, [Device "device"]), 56, [], [InitEmpty, Always, TestOutputTrue ( [["blockdev_setro"; "/dev/sda"]; ["blockdev_getro"; "/dev/sda"]])], @@ -1657,7 +1657,7 @@ Sets the block device named C<device> to read-only. This uses the L<blockdev(8)> command."); - ("blockdev_setrw", (RErr, [String "device"]), 57, [], + ("blockdev_setrw", (RErr, [Device "device"]), 57, [], [InitEmpty, Always, TestOutputFalse ( [["blockdev_setrw"; "/dev/sda"]; ["blockdev_getro"; "/dev/sda"]])], @@ -1667,7 +1667,7 @@ Sets the block device named C<device> to read-write. This uses the L<blockdev(8)> command."); - ("blockdev_getro", (RBool "ro", [String "device"]), 58, [], + ("blockdev_getro", (RBool "ro", [Device "device"]), 58, [], [InitEmpty, Always, TestOutputTrue ( [["blockdev_setro"; "/dev/sda"]; ["blockdev_getro"; "/dev/sda"]])], @@ -1678,7 +1678,7 @@ Returns a boolean indicating if the block device is read-only This uses the L<blockdev(8)> command."); - ("blockdev_getss", (RInt "sectorsize", [String "device"]), 59, [], + ("blockdev_getss", (RInt "sectorsize", [Device "device"]), 59, [], [InitEmpty, Always, TestOutputInt ( [["blockdev_getss"; "/dev/sda"]], 512)], "get sectorsize of block device", @@ -1691,7 +1691,7 @@ for that). This uses the L<blockdev(8)> command."); - ("blockdev_getbsz", (RInt "blocksize", [String "device"]), 60, [], + ("blockdev_getbsz", (RInt "blocksize", [Device "device"]), 60, [], [InitEmpty, Always, TestOutputInt ( [["blockdev_getbsz"; "/dev/sda"]], 4096)], "get blocksize of block device", @@ -1703,7 +1703,7 @@ I<filesystem block size>). This uses the L<blockdev(8)> command."); - ("blockdev_setbsz", (RErr, [String "device"; Int "blocksize"]), 61, [], + ("blockdev_setbsz", (RErr, [Device "device"; Int "blocksize"]), 61, [], [], (* XXX test *) "set blocksize of block device", "\ @@ -1714,7 +1714,7 @@ I<filesystem block size>). This uses the L<blockdev(8)> command."); - ("blockdev_getsz", (RInt64 "sizeinsectors", [String "device"]), 62, [], + ("blockdev_getsz", (RInt64 "sizeinsectors", [Device "device"]), 62, [], [InitEmpty, Always, TestOutputInt ( [["blockdev_getsz"; "/dev/sda"]], 1024000)], "get total size of device in 512-byte sectors", @@ -1728,7 +1728,7 @@ useful I<size in bytes>. This uses the L<blockdev(8)> command."); - ("blockdev_getsize64", (RInt64 "sizeinbytes", [String "device"]), 63, [], + ("blockdev_getsize64", (RInt64 "sizeinbytes", [Device "device"]), 63, [], [InitEmpty, Always, TestOutputInt ( [["blockdev_getsize64"; "/dev/sda"]], 524288000)], "get total size of device in bytes", @@ -1739,7 +1739,7 @@ See also C<guestfs_blockdev_getsz>. This uses the L<blockdev(8)> command."); - ("blockdev_flushbufs", (RErr, [String "device"]), 64, [], + ("blockdev_flushbufs", (RErr, [Device "device"]), 64, [], [InitEmpty, Always, TestRun [["blockdev_flushbufs"; "/dev/sda"]]], "flush device buffers", @@ -1749,7 +1749,7 @@ with C<device>. This uses the L<blockdev(8)> command."); - ("blockdev_rereadpt", (RErr, [String "device"]), 65, [], + ("blockdev_rereadpt", (RErr, [Device "device"]), 65, [], [InitEmpty, Always, TestRun [["blockdev_rereadpt"; "/dev/sda"]]], "reread partition table", @@ -1890,7 +1890,7 @@ it to local file C<tarball>. To download an uncompressed tarball, use C<guestfs_tar_out>."); - ("mount_ro", (RErr, [String "device"; String "mountpoint"]), 73, [], + ("mount_ro", (RErr, [Device "device"; String "mountpoint"]), 73, [], [InitBasicFS, Always, TestLastFail ( [["umount"; "/"]; ["mount_ro"; "/dev/sda1"; "/"]; @@ -1905,7 +1905,7 @@ To download an uncompressed tarball, use C<guestfs_tar_out>."); This is the same as the C<guestfs_mount> command, but it mounts the filesystem with the read-only (I<-o ro>) flag."); - ("mount_options", (RErr, [String "options"; String "device"; String "mountpoint"]), 74, [], + ("mount_options", (RErr, [String "options"; Device "device"; String "mountpoint"]), 74, [], [], "mount a guest disk with mount options", "\ @@ -1913,7 +1913,7 @@ This is the same as the C<guestfs_mount> command, but it allows you to set the mount options as for the L<mount(8)> I<-o> flag."); - ("mount_vfs", (RErr, [String "options"; String "vfstype"; String "device"; String "mountpoint"]), 75, [], + ("mount_vfs", (RErr, [String "options"; String "vfstype"; Device "device"; String "mountpoint"]), 75, [], [], "mount a guest disk with mount options and vfstype", "\ @@ -1933,7 +1933,7 @@ There is no comprehensive help for this command. You have to look at the file C<daemon/debug.c> in the libguestfs source to find out what you can do."); - ("lvremove", (RErr, [String "device"]), 77, [], + ("lvremove", (RErr, [Device "device"]), 77, [], [InitEmpty, Always, TestOutputList ( [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; @@ -1990,7 +1990,7 @@ Remove an LVM volume group C<vgname>, (for example C<VG>). This also forcibly removes all logical volumes in the volume group (if any)."); - ("pvremove", (RErr, [String "device"]), 79, [], + ("pvremove", (RErr, [Device "device"]), 79, [], [InitEmpty, Always, TestOutputListOfDevices ( [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; @@ -2027,7 +2027,7 @@ The implementation uses the C<pvremove> command which refuses to wipe physical volumes that contain any volume groups, so you have to remove those first."); - ("set_e2label", (RErr, [String "device"; String "label"]), 80, [], + ("set_e2label", (RErr, [Device "device"; String "label"]), 80, [], [InitBasicFS, Always, TestOutput ( [["set_e2label"; "/dev/sda1"; "testlabel"]; ["get_e2label"; "/dev/sda1"]], "testlabel")], @@ -2040,14 +2040,14 @@ C<device> to C<label>. Filesystem labels are limited to You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2label> to return the existing label on a filesystem."); - ("get_e2label", (RString "label", [String "device"]), 81, [], + ("get_e2label", (RString "label", [Device "device"]), 81, [], [], "get the ext2/3/4 filesystem label", "\ This returns the ext2/3/4 filesystem label of the filesystem on C<device>."); - ("set_e2uuid", (RErr, [String "device"; String "uuid"]), 82, [], + ("set_e2uuid", (RErr, [Device "device"; String "uuid"]), 82, [], [InitBasicFS, Always, TestOutput ( [["set_e2uuid"; "/dev/sda1"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"]; ["get_e2uuid"; "/dev/sda1"]], "a3a61220-882b-4f61-89f4-cf24dcc7297d"); @@ -2069,14 +2069,14 @@ L<tune2fs(8)> manpage. You can use either C<guestfs_tune2fs_l> or C<guestfs_get_e2uuid> to return the existing UUID of a filesystem."); - ("get_e2uuid", (RString "uuid", [String "device"]), 83, [], + ("get_e2uuid", (RString "uuid", [Device "device"]), 83, [], [], "get the ext2/3/4 filesystem UUID", "\ This returns the ext2/3/4 filesystem UUID of the filesystem on C<device>."); - ("fsck", (RInt "status", [String "fstype"; String "device"]), 84, [], + ("fsck", (RInt "status", [String "fstype"; Device "device"]), 84, [], [InitBasicFS, Always, TestOutputInt ( [["umount"; "/dev/sda1"]; ["fsck"; "ext2"; "/dev/sda1"]], 0); @@ -2114,7 +2114,7 @@ Checking or repairing NTFS volumes is not supported This command is entirely equivalent to running C<fsck -a -t fstype device>."); - ("zero", (RErr, [String "device"]), 85, [], + ("zero", (RErr, [Device "device"]), 85, [], [InitBasicFS, Always, TestOutput ( [["umount"; "/dev/sda1"]; ["zero"; "/dev/sda1"]; @@ -2129,7 +2129,7 @@ any partition tables, filesystem superblocks and so on. See also: C<guestfs_scrub_device>."); - ("grub_install", (RErr, [String "root"; String "device"]), 86, [], + ("grub_install", (RErr, [String "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 *) @@ -2284,7 +2284,7 @@ The returned strings are transcoded to UTF-8."); This runs C<hexdump -C> on the given C<path>. The result is the human-readable, canonical hex dump of the file."); - ("zerofree", (RErr, [String "device"]), 97, [], + ("zerofree", (RErr, [Device "device"]), 97, [], [InitNone, Always, TestOutput ( [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ext3"; "/dev/sda1"]; @@ -2307,14 +2307,14 @@ mounted. It is possible that using this program can damage the filesystem or data on the filesystem."); - ("pvresize", (RErr, [String "device"]), 98, [], + ("pvresize", (RErr, [Device "device"]), 98, [], [], "resize an LVM physical volume", "\ This resizes (expands or shrinks) an existing LVM physical volume to match the new size of the underlying device."); - ("sfdisk_N", (RErr, [String "device"; Int "partnum"; + ("sfdisk_N", (RErr, [Device "device"; Int "partnum"; Int "cyls"; Int "heads"; Int "sectors"; String "line"]), 99, [DangerWillRobinson], [], @@ -2326,7 +2326,7 @@ partition C<n> (note: C<n> counts from 1). For other parameters, see C<guestfs_sfdisk>. You should usually pass C<0> for the cyls/heads/sectors parameters."); - ("sfdisk_l", (RString "partitions", [String "device"]), 100, [], + ("sfdisk_l", (RString "partitions", [Device "device"]), 100, [], [], "display the partition table", "\ @@ -2334,7 +2334,7 @@ This displays the partition table on C<device>, in the human-readable output of the L<sfdisk(8)> command. It is not intended to be parsed."); - ("sfdisk_kernel_geometry", (RString "partitions", [String "device"]), 101, [], + ("sfdisk_kernel_geometry", (RString "partitions", [Device "device"]), 101, [], [], "display the kernel geometry", "\ @@ -2343,7 +2343,7 @@ This displays the kernel's idea of the geometry of C<device>. The result is in human-readable format, and not designed to be parsed."); - ("sfdisk_disk_geometry", (RString "partitions", [String "device"]), 102, [], + ("sfdisk_disk_geometry", (RString "partitions", [Device "device"]), 102, [], [], "display the disk geometry from the partition table", "\ @@ -2382,7 +2382,7 @@ This command is the same as running C<vgchange -a y|n volgroups...> Note that if C<volgroups> is an empty list then B<all> volume groups are activated or deactivated."); - ("lvresize", (RErr, [String "device"; Int "mbytes"]), 105, [], + ("lvresize", (RErr, [Device "device"; Int "mbytes"]), 105, [], [InitNone, Always, TestOutput ( [["sfdiskM"; "/dev/sda"; ","]; ["pvcreate"; "/dev/sda1"]; @@ -2403,7 +2403,7 @@ This resizes (expands or shrinks) an existing LVM logical volume to C<mbytes>. When reducing, data in the reduced part is lost."); - ("resize2fs", (RErr, [String "device"]), 106, [], + ("resize2fs", (RErr, [Device "device"]), 106, [], [], (* lvresize tests this *) "resize an ext2/ext3 filesystem", "\ @@ -2455,7 +2455,7 @@ an error. The returned list is sorted."); - ("e2fsck_f", (RErr, [String "device"]), 108, [], + ("e2fsck_f", (RErr, [Device "device"]), 108, [], [], (* lvresize tests this *) "check an ext2/ext3 filesystem", "\ @@ -2473,7 +2473,7 @@ This command is only needed because of C<guestfs_resize2fs> "\ Sleep for C<secs> seconds."); - ("ntfs_3g_probe", (RInt "status", [Bool "rw"; String "device"]), 110, [], + ("ntfs_3g_probe", (RInt "status", [Bool "rw"; Device "device"]), 110, [], [InitNone, Always, TestOutputInt ( [["sfdiskM"; "/dev/sda"; ","]; ["mkfs"; "ntfs"; "/dev/sda1"]; @@ -2551,7 +2551,7 @@ It is just a wrapper around the C L<glob(3)> function with flags C<GLOB_MARK|GLOB_BRACE>. See that manual page for more details."); - ("scrub_device", (RErr, [String "device"]), 114, [DangerWillRobinson], + ("scrub_device", (RErr, [Device "device"]), 114, [DangerWillRobinson], [InitNone, Always, TestRun ( (* use /dev/sdc because it's smaller *) [["scrub_device"; "/dev/sdc"]])], "scrub (securely wipe) a device", @@ -2751,7 +2751,7 @@ This command lets you mount C<file> (a filesystem image in a file) on a mount point. It is entirely equivalent to the command C<mount -o loop file mountpoint>."); - ("mkswap", (RErr, [String "device"]), 130, [], + ("mkswap", (RErr, [Device "device"]), 130, [], [InitEmpty, Always, TestRun ( [["sfdiskM"; "/dev/sda"; ","]; ["mkswap"; "/dev/sda1"]])], @@ -2759,7 +2759,7 @@ the command C<mount -o loop file mountpoint>."); "\ Create a swap partition on C<device>."); - ("mkswap_L", (RErr, [String "label"; String "device"]), 131, [], + ("mkswap_L", (RErr, [String "label"; Device "device"]), 131, [], [InitEmpty, Always, TestRun ( [["sfdiskM"; "/dev/sda"; ","]; ["mkswap_L"; "hello"; "/dev/sda1"]])], @@ -2771,7 +2771,7 @@ Note that you cannot attach a swap label to a block device (eg. C</dev/sda>), just to a partition. This appears to be a limitation of the kernel or swap tools."); - ("mkswap_U", (RErr, [String "uuid"; String "device"]), 132, [], + ("mkswap_U", (RErr, [String "uuid"; Device "device"]), 132, [], [InitEmpty, Always, TestRun ( [["sfdiskM"; "/dev/sda"; ","]; ["mkswap_U"; "a3a61220-882b-4f61-89f4-cf24dcc7297d"; "/dev/sda1"]])], @@ -2907,7 +2907,7 @@ This function is primarily intended for use by programs. To get a simple list of names, use C<guestfs_ls>. To get a printable directory for human consumption, use C<guestfs_ll>."); - ("sfdiskM", (RErr, [String "device"; StringList "lines"]), 139, [DangerWillRobinson], + ("sfdiskM", (RErr, [Device "device"; StringList "lines"]), 139, [DangerWillRobinson], [], "create partitions on a block device", "\ @@ -3213,7 +3213,7 @@ Do not confuse this with the guestfish-specific C<alloc> command which allocates a file in the host and attaches it as a device."); - ("swapon_device", (RErr, [String "device"]), 170, [], + ("swapon_device", (RErr, [Device "device"]), 170, [], [InitPartition, Always, TestRun ( [["mkswap"; "/dev/sda1"]; ["swapon_device"; "/dev/sda1"]; @@ -3232,7 +3232,7 @@ the guest doesn't want you to trash. You also risk leaking information about the host to the guest this way. Instead, attach a new host device to the guest and swap on that."); - ("swapoff_device", (RErr, [String "device"]), 171, [], + ("swapoff_device", (RErr, [Device "device"]), 171, [], [], (* XXX tested by swapon_device *) "disable swap on device", "\ -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:47PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
Then update each affected function, removing each uses of RESOLVE_DEVICE, now that it's generated in caller from stub.c. * daemon/blockdev.c (call_blockdev): Remove use of RESOLVE_DEVICE. * daemon/devsparts.c (do_mkfs): Likewise. * daemon/ext2.c (do_e2fsck_f, do_get_e2label, do_get_e2uuid): Likewise. (do_resize2fs, do_set_e2label, do_set_e2uuid, do_tune2fs_l): Likewise. * daemon/fsck.c (do_fsck): Likewise. * daemon/grub.c (do_grub_install): Likewise. * daemon/lvm.c (do_lvremove, do_pvcreate, do_pvremove): Likewise. (do_pvresize): Likewise. * daemon/mount.c (do_mount_vfs): Likewise. * daemon/ntfs.c (do_ntfs_3g_probe): Likewise. * daemon/scrub.c (do_scrub_device): Likewise. * daemon/sfdisk.c (sfdisk, sfdisk_flag): Likewise. * daemon/swap.c (do_mkswap, do_mkswap_L, do_mkswap_U): Likewise. (do_swapoff_device, do_swapon_device): Likewise. * daemon/zero.c (do_zero): Likewise. * daemon/zerofree.c (do_zerofree): Likewise. --- daemon/blockdev.c | 2 - daemon/devsparts.c | 2 - daemon/ext2.c | 14 -------- daemon/fsck.c | 2 - daemon/grub.c | 1 - daemon/lvm.c | 8 ----- daemon/mount.c | 2 - daemon/ntfs.c | 2 - daemon/scrub.c | 2 - daemon/sfdisk.c | 4 -- daemon/swap.c | 10 ------ daemon/zero.c | 2 - daemon/zerofree.c | 2 - src/generator.ml | 86 ++++++++++++++++++++++++++-------------------------- 14 files changed, 43 insertions(+), 96 deletions(-)
Yes, this is all good. ACK. At the end of this patch series, someone needs to go through the list of calls in the generator and make sure all the parameters are correct. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
From: Jim Meyering <meyering@redhat.com> run this command: git grep -l -w NEED_ROOT|xargs perl -pi -e \ 's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/' --- daemon/augeas.c | 2 +- daemon/checksum.c | 2 +- daemon/cmp.c | 2 +- daemon/command.c | 2 +- daemon/cpmv.c | 2 +- daemon/daemon.h | 2 +- daemon/df.c | 4 ++-- daemon/dir.c | 12 ++++++------ daemon/du.c | 2 +- daemon/fallocate.c | 2 +- daemon/file.c | 22 +++++++++++----------- daemon/find.c | 2 +- daemon/glob.c | 2 +- daemon/grep.c | 2 +- daemon/grub.c | 2 +- daemon/headtail.c | 2 +- daemon/hexdump.c | 2 +- daemon/initrd.c | 2 +- daemon/inotify.c | 2 +- daemon/link.c | 4 ++-- daemon/ls.c | 2 +- daemon/mknod.c | 2 +- daemon/mount.c | 6 +++--- daemon/readdir.c | 2 +- daemon/realpath.c | 2 +- daemon/scrub.c | 4 ++-- daemon/stat.c | 6 +++--- daemon/strings.c | 2 +- daemon/swap.c | 6 +++--- daemon/tar.c | 4 ++-- daemon/wc.c | 2 +- daemon/xattr.c | 2 +- 32 files changed, 57 insertions(+), 57 deletions(-) diff --git a/daemon/augeas.c b/daemon/augeas.c index 45f86cf..b6cc8f0 100644 --- a/daemon/augeas.c +++ b/daemon/augeas.c @@ -54,7 +54,7 @@ do_aug_init (char *root, int flags) #ifdef HAVE_AUGEAS char *buf; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (root, return -1); if (aug) { diff --git a/daemon/checksum.c b/daemon/checksum.c index d12413f..c06a697 100644 --- a/daemon/checksum.c +++ b/daemon/checksum.c @@ -36,7 +36,7 @@ do_checksum (char *csumtype, char *path) int r; int len; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); if (strcasecmp (csumtype, "crc") == 0) diff --git a/daemon/cmp.c b/daemon/cmp.c index 30574e2..a48e924 100644 --- a/daemon/cmp.c +++ b/daemon/cmp.c @@ -34,7 +34,7 @@ do_equal (char *file1, char *file2) char *err; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (file1, return -1); ABS_PATH (file2, return -1); diff --git a/daemon/command.c b/daemon/command.c index 0399255..7f5fc95 100644 --- a/daemon/command.c +++ b/daemon/command.c @@ -35,7 +35,7 @@ do_command (char **argv) int proc_ok, dev_ok, dev_pts_ok, sys_ok; /* We need a root filesystem mounted to do this. */ - NEED_ROOT (NULL); + NEED_ROOT (return NULL); /* Conveniently, argv is already a NULL-terminated argv-style array * of parameters, so we can pass it straight in to our internal diff --git a/daemon/cpmv.c b/daemon/cpmv.c index 37f1219..4fdee6b 100644 --- a/daemon/cpmv.c +++ b/daemon/cpmv.c @@ -52,7 +52,7 @@ cpmv_cmd (const char *cmd, const char *flags, const char *src, const char *dest) char *err; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (src, return -1); ABS_PATH (dest, return -1); diff --git a/daemon/daemon.h b/daemon/daemon.h index cbcab63..ee71fb6 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -176,7 +176,7 @@ extern void reply (xdrproc_t xdrp, char *ret); if (strncmp ((path), "/dev/", 5) == 0) \ RESOLVE_DEVICE ((path), fail_stmt); \ else { \ - NEED_ROOT (fail_stmt); \ + NEED_ROOT (return fail_stmt); \ ABS_PATH ((path),fail_stmt); \ } \ } while (0) diff --git a/daemon/df.c b/daemon/df.c index 73604b4..ad662fa 100644 --- a/daemon/df.c +++ b/daemon/df.c @@ -33,7 +33,7 @@ do_df () int r; char *out, *err; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); r = command (&out, &err, "df", NULL); if (r == -1) { @@ -54,7 +54,7 @@ do_df_h () int r; char *out, *err; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); r = command (&out, &err, "df", "-h", NULL); if (r == -1) { diff --git a/daemon/dir.c b/daemon/dir.c index 20cbd24..ec072dd 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -34,7 +34,7 @@ do_rmdir (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -59,7 +59,7 @@ do_rm_rf (char *path) int r; char *buf, *err; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); if (strcmp (path, "/") == 0) { @@ -93,7 +93,7 @@ do_mkdir (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -159,7 +159,7 @@ do_mkdir_p (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -180,7 +180,7 @@ do_is_dir (char *path) int r; struct stat buf; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -204,7 +204,7 @@ do_mkdtemp (char *template) { char *r; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (template, return NULL); CHROOT_IN; diff --git a/daemon/du.c b/daemon/du.c index 7d9c663..f5f083d 100644 --- a/daemon/du.c +++ b/daemon/du.c @@ -36,7 +36,7 @@ do_du (char *path) char *out, *err; char *buf; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); /* Make the path relative to /sysroot. */ diff --git a/daemon/fallocate.c b/daemon/fallocate.c index f61c496..9c5a3dd 100644 --- a/daemon/fallocate.c +++ b/daemon/fallocate.c @@ -32,7 +32,7 @@ do_fallocate (char *path, int len) { int fd, r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; diff --git a/daemon/file.c b/daemon/file.c index 2ba2aab..d8425e9 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -35,7 +35,7 @@ do_touch (char *path) int fd; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -73,7 +73,7 @@ do_cat (char *path) int alloc, size, r, max; char *buf, *buf2; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -147,7 +147,7 @@ do_read_lines (char *path) size_t len = 0; ssize_t n; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -194,7 +194,7 @@ do_rm (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -214,7 +214,7 @@ do_chmod (int mode, char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -234,7 +234,7 @@ do_chown (int owner, int group, char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -254,7 +254,7 @@ do_exists (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -270,7 +270,7 @@ do_is_file (char *path) int r; struct stat buf; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; @@ -294,7 +294,7 @@ do_write_file (char *path, char *content, int size) { int fd; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); if (size == 0) @@ -330,7 +330,7 @@ do_read_file (char *path, size_t *size_r) struct stat statbuf; char *r; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -444,7 +444,7 @@ do_zfile (char *method, char *path) FILE *fp; char line[256]; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); if (strcmp (method, "gzip") == 0 || strcmp (method, "compress") == 0) diff --git a/daemon/find.c b/daemon/find.c index c514177..950a0fc 100644 --- a/daemon/find.c +++ b/daemon/find.c @@ -59,7 +59,7 @@ do_find (char *dir) char *sysrootdir; char str[PATH_MAX]; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (dir, return NULL); sysrootdir = sysroot_path (dir); diff --git a/daemon/glob.c b/daemon/glob.c index 1c47ba5..40b7c50 100644 --- a/daemon/glob.c +++ b/daemon/glob.c @@ -31,7 +31,7 @@ do_glob_expand (char *pattern) int r; glob_t buf; - NEED_ROOT (NULL); + 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: */ diff --git a/daemon/grep.c b/daemon/grep.c index 19e4683..f0dbefd 100644 --- a/daemon/grep.c +++ b/daemon/grep.c @@ -35,7 +35,7 @@ grep (const char *prog, const char *flag, char *regex, char *path) int r; char **lines; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); /* Make the path relative to /sysroot. */ diff --git a/daemon/grub.c b/daemon/grub.c index 0a49c45..8476619 100644 --- a/daemon/grub.c +++ b/daemon/grub.c @@ -32,7 +32,7 @@ do_grub_install (char *root, char *device) char *err; char *buf; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (root, return -1); if (asprintf_nowarn (&buf, "--root-directory=%R", root) == -1) { diff --git a/daemon/headtail.c b/daemon/headtail.c index bdd0f49..79dcfbb 100644 --- a/daemon/headtail.c +++ b/daemon/headtail.c @@ -35,7 +35,7 @@ headtail (const char *prog, const char *flag, const char *n, char *path) int r; char **lines; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); /* Make the path relative to /sysroot. */ diff --git a/daemon/hexdump.c b/daemon/hexdump.c index 27ea108..faf3dc5 100644 --- a/daemon/hexdump.c +++ b/daemon/hexdump.c @@ -32,7 +32,7 @@ do_hexdump (char *path) int r; char *out, *err; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); buf = sysroot_path (path); diff --git a/daemon/initrd.c b/daemon/initrd.c index e703481..c1c7ce0 100644 --- a/daemon/initrd.c +++ b/daemon/initrd.c @@ -37,7 +37,7 @@ do_initrd_list (char *path) int size = 0, alloc = 0; size_t len; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); /* "zcat /sysroot/<path> | cpio --quiet -it", but path must be quoted. */ diff --git a/daemon/inotify.c b/daemon/inotify.c index 2f22f52..96b9681 100644 --- a/daemon/inotify.c +++ b/daemon/inotify.c @@ -51,7 +51,7 @@ do_inotify_init (int max_events) { FILE *fp; - NEED_ROOT (-1); + NEED_ROOT (return -1); if (max_events < 0) { reply_with_error ("inotify_init: max_events < 0"); diff --git a/daemon/link.c b/daemon/link.c index bf616ed..9129b5c 100644 --- a/daemon/link.c +++ b/daemon/link.c @@ -34,7 +34,7 @@ do_readlink (char *path) char *ret; char link[PATH_MAX]; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -62,7 +62,7 @@ _link (const char *flag, int symbolic, const char *target, const char *linkname) char *buf_linkname; char *buf_target; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (linkname, return -1); /* but target does not need to be absolute */ diff --git a/daemon/ls.c b/daemon/ls.c index 8ae150b..8dba1bf 100644 --- a/daemon/ls.c +++ b/daemon/ls.c @@ -37,7 +37,7 @@ do_ls (char *path) DIR *dir; struct dirent *d; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; diff --git a/daemon/mknod.c b/daemon/mknod.c index ab799cd..a6e6eca 100644 --- a/daemon/mknod.c +++ b/daemon/mknod.c @@ -35,7 +35,7 @@ do_mknod (int mode, int devmajor, int devminor, char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; diff --git a/daemon/mount.c b/daemon/mount.c index 14e683a..4f60682 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -317,7 +317,7 @@ do_mount_loop (char *file, char *mountpoint) char *buf, *mp; char *error; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (file, return -1); /* We have to prefix /sysroot on both the filename and the mountpoint. */ @@ -355,7 +355,7 @@ do_mkmountpoint (char *path) { int r; - /* NEED_ROOT (-1); - we don't want this test for this call. */ + /* NEED_ROOT (return -1); - we don't want this test for this call. */ ABS_PATH (path, return -1); CHROOT_IN; @@ -380,7 +380,7 @@ do_rmmountpoint (char *path) { int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); CHROOT_IN; diff --git a/daemon/readdir.c b/daemon/readdir.c index f8f95d2..45256b2 100644 --- a/daemon/readdir.c +++ b/daemon/readdir.c @@ -36,7 +36,7 @@ do_readdir (char *path) struct dirent *d; int i; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); ret = malloc (sizeof *ret); diff --git a/daemon/realpath.c b/daemon/realpath.c index 18adc85..c081a45 100644 --- a/daemon/realpath.c +++ b/daemon/realpath.c @@ -32,7 +32,7 @@ do_realpath (char *path) { char *ret; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; diff --git a/daemon/scrub.c b/daemon/scrub.c index 2beaea3..5530c69 100644 --- a/daemon/scrub.c +++ b/daemon/scrub.c @@ -52,7 +52,7 @@ do_scrub_file (char *file) char *err; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (file, return -1); /* Make the path relative to /sysroot. */ @@ -82,7 +82,7 @@ do_scrub_freespace (char *dir) char *err; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (dir, return -1); /* Make the path relative to /sysroot. */ diff --git a/daemon/stat.c b/daemon/stat.c index da2d274..4845851 100644 --- a/daemon/stat.c +++ b/daemon/stat.c @@ -37,7 +37,7 @@ do_stat (char *path) guestfs_int_stat *ret; struct stat statbuf; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -79,7 +79,7 @@ do_lstat (char *path) guestfs_int_stat *ret; struct stat statbuf; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; @@ -121,7 +121,7 @@ do_statvfs (char *path) guestfs_int_statvfs *ret; struct statvfs statbuf; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; diff --git a/daemon/strings.c b/daemon/strings.c index 89e04a8..e5aefca 100644 --- a/daemon/strings.c +++ b/daemon/strings.c @@ -33,7 +33,7 @@ do_strings_e (char *encoding, char *path) char *out, *err; char **lines; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); buf = sysroot_path (path); diff --git a/daemon/swap.c b/daemon/swap.c index f7270f8..580482f 100644 --- a/daemon/swap.c +++ b/daemon/swap.c @@ -73,7 +73,7 @@ do_mkswap_file (char *path) char *buf; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); buf = sysroot_path (path); @@ -127,7 +127,7 @@ do_swapon_file (char *path) char *buf; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); buf = sysroot_path (path); @@ -147,7 +147,7 @@ do_swapoff_file (char *path) char *buf; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); buf = sysroot_path (path); diff --git a/daemon/tar.c b/daemon/tar.c index e1ff9b6..9d21e79 100644 --- a/daemon/tar.c +++ b/daemon/tar.c @@ -106,7 +106,7 @@ do_tar_out (char *dir) char *cmd; char buf[GUESTFS_MAX_CHUNK_SIZE]; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (dir, return -1); /* "tar -C /sysroot%s -cf - ." but we have to quote the dir. */ @@ -228,7 +228,7 @@ do_tgz_out (char *dir) char *cmd; char buf[GUESTFS_MAX_CHUNK_SIZE]; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (dir, return -1); /* "tar -C /sysroot%s -zcf - ." but we have to quote the dir. */ diff --git a/daemon/wc.c b/daemon/wc.c index 0917eb9..9720443 100644 --- a/daemon/wc.c +++ b/daemon/wc.c @@ -34,7 +34,7 @@ wc (char *flag, char *path) char *out, *err; int r; - NEED_ROOT (-1); + NEED_ROOT (return -1); ABS_PATH (path, return -1); /* Make the path relative to /sysroot. */ diff --git a/daemon/xattr.c b/daemon/xattr.c index 88947b2..d521321 100644 --- a/daemon/xattr.c +++ b/daemon/xattr.c @@ -116,7 +116,7 @@ getxattrs (char *path, int i, j; guestfs_int_xattr_list *r = NULL; - NEED_ROOT (NULL); + NEED_ROOT (return NULL); ABS_PATH (path, return NULL); CHROOT_IN; -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:48PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
run this command: git grep -l -w NEED_ROOT|xargs perl -pi -e \ 's/(NEED_ROOT) \((.*?)\)/$1 (return $2)/'
Mechanical change, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones Read my programming blog: http://rwmj.wordpress.com Fedora now supports 75 OCaml packages (the OPEN alternative to F#) http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora
From: Jim Meyering <meyering@redhat.com> --- daemon/daemon.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/daemon/daemon.h b/daemon/daemon.h index ee71fb6..cbcab63 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -176,7 +176,7 @@ extern void reply (xdrproc_t xdrp, char *ret); if (strncmp ((path), "/dev/", 5) == 0) \ RESOLVE_DEVICE ((path), fail_stmt); \ else { \ - NEED_ROOT (return fail_stmt); \ + NEED_ROOT (fail_stmt); \ ABS_PATH ((path),fail_stmt); \ } \ } while (0) -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:49PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/daemon.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/daemon.h b/daemon/daemon.h index ee71fb6..cbcab63 100644 --- a/daemon/daemon.h +++ b/daemon/daemon.h @@ -176,7 +176,7 @@ extern void reply (xdrproc_t xdrp, char *ret); if (strncmp ((path), "/dev/", 5) == 0) \ RESOLVE_DEVICE ((path), fail_stmt); \ else { \ - NEED_ROOT (return fail_stmt); \ + NEED_ROOT (fail_stmt); \ ABS_PATH ((path),fail_stmt); \ } \ } while (0) -- 1.6.4.337.g5420e
Yes, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v
From: Jim Meyering <meyering@redhat.com> * src/generator.ml: Emit "const char *", not "char *" for Device and String params, now that the non-const code is hoisted into the calling code in stubs.c. --- src/generator.ml | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 0c9cf36..30fe41c 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4680,11 +4680,9 @@ and generate_daemon_actions () = pr " struct guestfs_%s_args args;\n" name; List.iter ( function - (* Note we allow the string to be writable, in order to - * allow device name translation. This is safe because - * we can modify the string (passed from RPC). - *) - | Device n | String n + (* FIXME: eventually, make String "const", too *) + | Device n -> pr " const char *%s;\n" n + | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n @@ -6233,8 +6231,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) | String n | OptString n -> next (); - if not in_daemon then pr "const char *%s" n - else pr "char *%s" n + pr "const char *%s" n | StringList n -> next (); if not in_daemon then pr "char * const* const %s" n @@ -6774,6 +6771,7 @@ DESTROY (g) iteri ( fun i -> function + (* FIXME: ? *) | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:50PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml: Emit "const char *", not "char *" for Device and String params, now that the non-const code is hoisted into the calling code in stubs.c. --- src/generator.ml | 12 +++++------- 1 files changed, 5 insertions(+), 7 deletions(-) [..]
@@ -6774,6 +6771,7 @@ DESTROY (g) iteri ( fun i -> function + (* FIXME: ? *) | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 -- 1.6.4.337.g5420e
Whether this is correct depends on the global typemap. Anyway, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://et.redhat.com/~rjones/libguestfs/ See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html
From: Jim Meyering <meyering@redhat.com> * src/generator.ml: Emit NEED_ROOT and ABS_PATH into generated stubs.c, rather than requiring they be added manually at the start of each and every do_* function that operates on a "path" parameter. Update grammar: Pathname is just a String, with the above exception. --- src/generator.ml | 200 +++++++++++++++++++++++++++++------------------------ 1 files changed, 109 insertions(+), 91 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 30fe41c..325d3cb 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -135,6 +135,7 @@ and args = argt list (* Function parameters, guestfs handle is implicit. *) and argt = | String of string (* const char *name, cannot be NULL *) | Device of string (* /dev device name, cannot be NULL *) + | Pathname of string (* file name, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) | Bool of string (* boolean *) @@ -532,7 +533,7 @@ Return the current qemu binary. This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name."); - ("set_path", (RErr, [String "path"]), -1, [FishAlias "path"], + ("set_path", (RErr, [Pathname "path"]), -1, [FishAlias "path"], [], "set the search path", "\ @@ -805,7 +806,7 @@ underlying disk image. You should always call this if you have modified a disk image, before closing the handle."); - ("touch", (RErr, [String "path"]), 3, [], + ("touch", (RErr, [Pathname "path"]), 3, [], [InitBasicFS, Always, TestOutputTrue ( [["touch"; "/new"]; ["exists"; "/new"]])], @@ -815,7 +816,7 @@ Touch acts like the L<touch(1)> command. It can be used to update the timestamps on a file, or, if the file does not exist, to create a new zero-length file."); - ("cat", (RString "content", [String "path"]), 4, [ProtocolLimitWarning], + ("cat", (RString "content", [Pathname "path"]), 4, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutput ( [["cat"; "/known-2"]], "abcdef\n")], "list the contents of a file", @@ -963,7 +964,7 @@ of the L<vgs(8)> command. The \"full\" version includes all fields."); List all the logical volumes detected. This is the equivalent of the L<lvs(8)> command. The \"full\" version includes all fields."); - ("read_lines", (RStringList "lines", [String "path"]), 15, [], + ("read_lines", (RStringList "lines", [Pathname "path"]), 15, [], [InitSquashFS, Always, TestOutputList ( [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]); InitSquashFS, Always, TestOutputList ( @@ -1066,20 +1067,20 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created."); - ("aug_get", (RString "val", [String "path"]), 19, [], + ("aug_get", (RString "val", [Pathname "path"]), 19, [], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C<path>. If C<path> matches exactly one node, the C<value> is returned."); - ("aug_set", (RErr, [String "path"; String "val"]), 20, [], + ("aug_set", (RErr, [Pathname "path"; String "val"]), 20, [], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ Set the value associated with C<path> to C<value>."); - ("aug_insert", (RErr, [String "path"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [Pathname "path"; String "label"; Bool "before"]), 21, [], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1091,7 +1092,7 @@ C<path> must match exactly one existing node in the tree, and C<label> must be a label, ie. not contain C</>, C<*> or end with a bracketed index C<[N]>."); - ("aug_rm", (RInt "nrnodes", [String "path"]), 22, [], + ("aug_rm", (RInt "nrnodes", [Pathname "path"]), 22, [], [], (* XXX Augeas code needs tests. *) "remove an Augeas path", "\ @@ -1106,7 +1107,7 @@ On success this returns the number of entries which were removed."); Move the node C<src> to C<dest>. C<src> must match exactly one node. C<dest> is overwritten if it exists."); - ("aug_match", (RStringList "matches", [String "path"]), 24, [], + ("aug_match", (RStringList "matches", [Pathname "path"]), 24, [], [], (* XXX Augeas code needs tests. *) "return Augeas nodes which match path", "\ @@ -1132,14 +1133,14 @@ Load files into the tree. See C<aug_load> in the Augeas documentation for the full gory details."); - ("aug_ls", (RStringList "matches", [String "path"]), 28, [], + ("aug_ls", (RStringList "matches", [Pathname "path"]), 28, [], [], (* XXX Augeas code needs tests. *) "list Augeas nodes under a path", "\ This is just a shortcut for listing C<guestfs_aug_match> C<path/*> and sorting the resulting nodes into alphabetical order."); - ("rm", (RErr, [String "path"]), 29, [], + ("rm", (RErr, [Pathname "path"]), 29, [], [InitBasicFS, Always, TestRun [["touch"; "/new"]; ["rm"; "/new"]]; @@ -1152,7 +1153,7 @@ C<path/*> and sorting the resulting nodes into alphabetical order."); "\ Remove the single file C<path>."); - ("rmdir", (RErr, [String "path"]), 30, [], + ("rmdir", (RErr, [Pathname "path"]), 30, [], [InitBasicFS, Always, TestRun [["mkdir"; "/new"]; ["rmdir"; "/new"]]; @@ -1165,7 +1166,7 @@ Remove the single file C<path>."); "\ Remove the single directory C<path>."); - ("rm_rf", (RErr, [String "path"]), 31, [], + ("rm_rf", (RErr, [Pathname "path"]), 31, [], [InitBasicFS, Always, TestOutputFalse [["mkdir"; "/new"]; ["mkdir"; "/new/foo"]; @@ -1178,7 +1179,7 @@ Remove the file or directory C<path>, recursively removing the contents if its a directory. This is like the C<rm -rf> shell command."); - ("mkdir", (RErr, [String "path"]), 32, [], + ("mkdir", (RErr, [Pathname "path"]), 32, [], [InitBasicFS, Always, TestOutputTrue [["mkdir"; "/new"]; ["is_dir"; "/new"]]; @@ -1188,7 +1189,7 @@ command."); "\ Create a directory named C<path>."); - ("mkdir_p", (RErr, [String "path"]), 33, [], + ("mkdir_p", (RErr, [Pathname "path"]), 33, [], [InitBasicFS, Always, TestOutputTrue [["mkdir_p"; "/new/foo/bar"]; ["is_dir"; "/new/foo/bar"]]; @@ -1210,14 +1211,14 @@ Create a directory named C<path>."); Create a directory named C<path>, creating any parent directories as necessary. This is like the C<mkdir -p> shell command."); - ("chmod", (RErr, [Int "mode"; String "path"]), 34, [], + ("chmod", (RErr, [Int "mode"; Pathname "path"]), 34, [], [], (* XXX Need stat command to test *) "change file mode", "\ Change the mode (permissions) of C<path> to C<mode>. Only numeric modes are supported."); - ("chown", (RErr, [Int "owner"; Int "group"; String "path"]), 35, [], + ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 35, [], [], (* XXX Need stat command to test *) "change file owner and group", "\ @@ -1227,7 +1228,7 @@ Only numeric uid and gid are supported. If you want to use names, you will need to locate and parse the password file yourself (Augeas support makes this relatively easy)."); - ("exists", (RBool "existsflag", [String "path"]), 36, [], + ("exists", (RBool "existsflag", [Pathname "path"]), 36, [], [InitSquashFS, Always, TestOutputTrue ( [["exists"; "/empty"]]); InitSquashFS, Always, TestOutputTrue ( @@ -1239,7 +1240,7 @@ This returns C<true> if and only if there is a file, directory See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>."); - ("is_file", (RBool "fileflag", [String "path"]), 37, [], + ("is_file", (RBool "fileflag", [Pathname "path"]), 37, [], [InitSquashFS, Always, TestOutputTrue ( [["is_file"; "/known-1"]]); InitSquashFS, Always, TestOutputFalse ( @@ -1252,7 +1253,7 @@ other objects like directories. See also C<guestfs_stat>."); - ("is_dir", (RBool "dirflag", [String "path"]), 38, [], + ("is_dir", (RBool "dirflag", [Pathname "path"]), 38, [], [InitSquashFS, Always, TestOutputFalse ( [["is_dir"; "/known-3"]]); InitSquashFS, Always, TestOutputTrue ( @@ -1354,7 +1355,7 @@ the string C<,> (comma). See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>"); - ("write_file", (RErr, [String "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning], + ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning], [InitBasicFS, Always, TestOutput ( [["write_file"; "/new"; "new file contents"; "0"]; ["cat"; "/new"]], "new file contents"); @@ -1449,7 +1450,7 @@ Some internal mounts are not unmounted by this call."); This command removes all LVM logical volumes, volume groups and physical volumes."); - ("file", (RString "description", [String "path"]), 49, [], + ("file", (RString "description", [Pathname "path"]), 49, [], [InitSquashFS, Always, TestOutput ( [["file"; "/empty"]], "empty"); InitSquashFS, Always, TestOutput ( @@ -1602,7 +1603,7 @@ result into a list of lines. See also: C<guestfs_sh_lines>"); - ("stat", (RStruct ("statbuf", "stat"), [String "path"]), 52, [], + ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 52, [], [InitSquashFS, Always, TestOutputStruct ( [["stat"; "/empty"]], [CompareWithInt ("size", 0)])], "get file information", @@ -1611,7 +1612,7 @@ Returns file information for the given C<path>. This is the same as the C<stat(2)> system call."); - ("lstat", (RStruct ("statbuf", "stat"), [String "path"]), 53, [], + ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 53, [], [InitSquashFS, Always, TestOutputStruct ( [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])], "get file information for a symbolic link", @@ -1624,7 +1625,7 @@ refers to. This is the same as the C<lstat(2)> system call."); - ("statvfs", (RStruct ("statbuf", "statvfs"), [String "path"]), 54, [], + ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"]), 54, [], [InitSquashFS, Always, TestOutputStruct ( [["statvfs"; "/"]], [CompareWithInt ("namemax", 256)])], "get file system statistics", @@ -1790,7 +1791,7 @@ C<filename> can also be a named pipe. See also C<guestfs_upload>, C<guestfs_cat>."); - ("checksum", (RString "checksum", [String "csumtype"; String "path"]), 68, [], + ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"]), 68, [], [InitSquashFS, Always, TestOutput ( [["checksum"; "crc"; "/known-3"]], "2891671662"); InitSquashFS, Always, TestLastFail ( @@ -2243,7 +2244,7 @@ true if their content is exactly equal, or false otherwise. The external L<cmp(1)> program is used for the comparison."); - ("strings", (RStringList "stringsout", [String "path"]), 94, [ProtocolLimitWarning], + ("strings", (RStringList "stringsout", [Pathname "path"]), 94, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]); InitSquashFS, Always, TestOutputList ( @@ -2253,7 +2254,7 @@ The external L<cmp(1)> program is used for the comparison."); This runs the L<strings(1)> command on a file and returns the list of printable strings found."); - ("strings_e", (RStringList "stringsout", [String "encoding"; String "path"]), 95, [ProtocolLimitWarning], + ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"]), 95, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["strings_e"; "b"; "/known-5"]], []); InitBasicFS, Disabled, TestOutputList ( @@ -2271,7 +2272,7 @@ show strings inside Windows/x86 files. The returned strings are transcoded to UTF-8."); - ("hexdump", (RString "dump", [String "path"]), 96, [ProtocolLimitWarning], + ("hexdump", (RString "dump", [Pathname "path"]), 96, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutput ( [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n"); (* Test for RHBZ#501888c2 regression which caused large hexdump @@ -2589,7 +2590,7 @@ containing C<dir>. It is an interface to the L<scrub(1)> program. See that manual page for more details."); - ("mkdtemp", (RString "dir", [String "template"]), 117, [], + ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [], [InitBasicFS, Always, TestRun ( [["mkdir"; "/tmp"]; ["mkdtemp"; "/tmp/tmpXXXXXX"]])], @@ -2614,7 +2615,7 @@ directory and its contents after use. See also: L<mkdtemp(3)>"); - ("wc_l", (RInt "lines", [String "path"]), 118, [], + ("wc_l", (RInt "lines", [Pathname "path"]), 118, [], [InitSquashFS, Always, TestOutputInt ( [["wc_l"; "/10klines"]], 10000)], "count lines in a file", @@ -2622,7 +2623,7 @@ See also: L<mkdtemp(3)>"); This command counts the lines in a file, using the C<wc -l> external command."); - ("wc_w", (RInt "words", [String "path"]), 119, [], + ("wc_w", (RInt "words", [Pathname "path"]), 119, [], [InitSquashFS, Always, TestOutputInt ( [["wc_w"; "/10klines"]], 10000)], "count words in a file", @@ -2630,7 +2631,7 @@ C<wc -l> external command."); This command counts the words in a file, using the C<wc -w> external command."); - ("wc_c", (RInt "chars", [String "path"]), 120, [], + ("wc_c", (RInt "chars", [Pathname "path"]), 120, [], [InitSquashFS, Always, TestOutputInt ( [["wc_c"; "/100kallspaces"]], 102400)], "count characters in a file", @@ -2638,7 +2639,7 @@ C<wc -w> external command."); This command counts the characters in a file, using the C<wc -c> external command."); - ("head", (RStringList "lines", [String "path"]), 121, [ProtocolLimitWarning], + ("head", (RStringList "lines", [Pathname "path"]), 121, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])], "return first 10 lines of a file", @@ -2646,7 +2647,7 @@ C<wc -c> external command."); This command returns up to the first 10 lines of a file as a list of strings."); - ("head_n", (RStringList "lines", [Int "nrlines"; String "path"]), 122, [ProtocolLimitWarning], + ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 122, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]); InitSquashFS, Always, TestOutputList ( @@ -2663,7 +2664,7 @@ from the file C<path>, excluding the last C<nrlines> lines. If the parameter C<nrlines> is zero, this returns an empty list."); - ("tail", (RStringList "lines", [String "path"]), 123, [ProtocolLimitWarning], + ("tail", (RStringList "lines", [Pathname "path"]), 123, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])], "return last 10 lines of a file", @@ -2671,7 +2672,7 @@ If the parameter C<nrlines> is zero, this returns an empty list."); This command returns up to the last 10 lines of a file as a list of strings."); - ("tail_n", (RStringList "lines", [Int "nrlines"; String "path"]), 124, [ProtocolLimitWarning], + ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 124, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]); InitSquashFS, Always, TestOutputList ( @@ -2713,7 +2714,7 @@ This command is mostly useful for interactive sessions. It is I<not> intended that you try to parse the output string. Use C<statvfs> from programs."); - ("du", (RInt64 "sizekb", [String "path"]), 127, [], + ("du", (RInt64 "sizekb", [Pathname "path"]), 127, [], [InitSquashFS, Always, TestOutputInt ( [["du"; "/directory"]], 0 (* squashfs doesn't have blocks *))], "estimate file space usage", @@ -2728,7 +2729,7 @@ subdirectories (recursively). The result is the estimated size in I<kilobytes> (ie. units of 1024 bytes)."); - ("initrd_list", (RStringList "filenames", [String "path"]), 128, [], + ("initrd_list", (RStringList "filenames", [Pathname "path"]), 128, [], [InitSquashFS, Always, TestOutputList ( [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])], "list files in an initrd", @@ -2779,7 +2780,7 @@ a limitation of the kernel or swap tools."); "\ Create a swap partition on C<device> with UUID C<uuid>."); - ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 133, [], + ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 133, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod"; "0o10777"; "0"; "0"; "/node"]; (* NB: default umask 022 means 0777 -> 0755 in these tests *) @@ -2797,7 +2798,7 @@ constants. C<devmajor> and C<devminor> are the device major and minor numbers, only used when creating block and character special devices."); - ("mkfifo", (RErr, [Int "mode"; String "path"]), 134, [], + ("mkfifo", (RErr, [Int "mode"; Pathname "path"]), 134, [], [InitBasicFS, Always, TestOutputStruct ( [["mkfifo"; "0o777"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])], @@ -2807,7 +2808,7 @@ This call creates a FIFO (named pipe) called C<path> with mode C<mode>. It is just a convenient wrapper around C<guestfs_mknod>."); - ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 135, [], + ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 135, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod_b"; "0o777"; "99"; "66"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])], @@ -2817,7 +2818,7 @@ This call creates a block device node called C<path> with mode C<mode> and device major/minor C<devmajor> and C<devminor>. It is just a convenient wrapper around C<guestfs_mknod>."); - ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 136, [], + ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 136, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod_c"; "0o777"; "99"; "66"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])], @@ -2919,7 +2920,7 @@ were rarely if ever used anyway. See also C<guestfs_sfdisk> and the L<sfdisk(8)> manpage."); - ("zfile", (RString "description", [String "method"; String "path"]), 140, [DeprecatedBy "file"], + ("zfile", (RString "description", [String "method"; Pathname "path"]), 140, [DeprecatedBy "file"], [], "determine file type inside a compressed file", "\ @@ -2931,7 +2932,7 @@ C<method> must be one of C<gzip>, C<compress> or C<bzip2>. Since 1.0.63, use C<guestfs_file> instead which can now process compressed files."); - ("getxattrs", (RStructList ("xattrs", "xattr"), [String "path"]), 141, [], + ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 141, [], [], "list extended attributes of a file or directory", "\ @@ -2943,7 +2944,7 @@ L<listxattr(2)> and L<getxattr(2)> calls. See also: C<guestfs_lgetxattrs>, L<attr(5)>."); - ("lgetxattrs", (RStructList ("xattrs", "xattr"), [String "path"]), 142, [], + ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 142, [], [], "list extended attributes of a file or directory", "\ @@ -2953,7 +2954,7 @@ of the link itself."); ("setxattr", (RErr, [String "xattr"; String "val"; Int "vallen"; (* will be BufferIn *) - String "path"]), 143, [], + Pathname "path"]), 143, [], [], "set extended attribute of a file or directory", "\ @@ -2965,7 +2966,7 @@ See also: C<guestfs_lsetxattr>, L<attr(5)>."); ("lsetxattr", (RErr, [String "xattr"; String "val"; Int "vallen"; (* will be BufferIn *) - String "path"]), 144, [], + Pathname "path"]), 144, [], [], "set extended attribute of a file or directory", "\ @@ -2973,7 +2974,7 @@ This is the same as C<guestfs_setxattr>, but if C<path> is a symbolic link, then it sets an extended attribute of the link itself."); - ("removexattr", (RErr, [String "xattr"; String "path"]), 145, [], + ("removexattr", (RErr, [String "xattr"; Pathname "path"]), 145, [], [], "remove extended attribute of a file or directory", "\ @@ -2982,7 +2983,7 @@ of the file C<path>. See also: C<guestfs_lremovexattr>, L<attr(5)>."); - ("lremovexattr", (RErr, [String "xattr"; String "path"]), 146, [], + ("lremovexattr", (RErr, [String "xattr"; Pathname "path"]), 146, [], [], "remove extended attribute of a file or directory", "\ @@ -2998,7 +2999,7 @@ 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, [String "path"]), 148, [], + ("mkmountpoint", (RErr, [Pathname "path"]), 148, [], [], "create a mountpoint", "\ @@ -3026,7 +3027,7 @@ in guestfish: The inner filesystem is now unpacked under the /ext3 mountpoint."); - ("rmmountpoint", (RErr, [String "path"]), 149, [], + ("rmmountpoint", (RErr, [Pathname "path"]), 149, [], [], "remove a mountpoint", "\ @@ -3034,7 +3035,7 @@ This calls removes a mountpoint that was previously created with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint> for full details."); - ("read_file", (RBufferOut "content", [String "path"]), 150, [ProtocolLimitWarning], + ("read_file", (RBufferOut "content", [Pathname "path"]), 150, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputBuffer ( [["read_file"; "/known-4"]], "abc\ndef\nghi")], "read a file", @@ -3047,7 +3048,7 @@ handle files that contain embedded ASCII NUL characters. However unlike C<guestfs_download>, this function is limited in the total size of file that can be handled."); - ("grep", (RStringList "lines", [String "regex"; String "path"]), 151, [ProtocolLimitWarning], + ("grep", (RStringList "lines", [String "regex"; Pathname "path"]), 151, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]); InitSquashFS, Always, TestOutputList ( @@ -3057,7 +3058,7 @@ in the total size of file that can be handled."); This calls the external C<grep> program and returns the matching lines."); - ("egrep", (RStringList "lines", [String "regex"; String "path"]), 152, [ProtocolLimitWarning], + ("egrep", (RStringList "lines", [String "regex"; Pathname "path"]), 152, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3065,7 +3066,7 @@ matching lines."); This calls the external C<egrep> program and returns the matching lines."); - ("fgrep", (RStringList "lines", [String "pattern"; String "path"]), 153, [ProtocolLimitWarning], + ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 153, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3073,7 +3074,7 @@ matching lines."); This calls the external C<fgrep> program and returns the matching lines."); - ("grepi", (RStringList "lines", [String "regex"; String "path"]), 154, [ProtocolLimitWarning], + ("grepi", (RStringList "lines", [String "regex"; Pathname "path"]), 154, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3081,7 +3082,7 @@ matching lines."); This calls the external C<grep -i> program and returns the matching lines."); - ("egrepi", (RStringList "lines", [String "regex"; String "path"]), 155, [ProtocolLimitWarning], + ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 155, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3089,7 +3090,7 @@ matching lines."); This calls the external C<egrep -i> program and returns the matching lines."); - ("fgrepi", (RStringList "lines", [String "pattern"; String "path"]), 156, [ProtocolLimitWarning], + ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 156, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3097,7 +3098,7 @@ matching lines."); This calls the external C<fgrep -i> program and returns the matching lines."); - ("zgrep", (RStringList "lines", [String "regex"; String "path"]), 157, [ProtocolLimitWarning], + ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"]), 157, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3105,7 +3106,7 @@ matching lines."); This calls the external C<zgrep> program and returns the matching lines."); - ("zegrep", (RStringList "lines", [String "regex"; String "path"]), 158, [ProtocolLimitWarning], + ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"]), 158, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3113,7 +3114,7 @@ matching lines."); This calls the external C<zegrep> program and returns the matching lines."); - ("zfgrep", (RStringList "lines", [String "pattern"; String "path"]), 159, [ProtocolLimitWarning], + ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 159, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3121,7 +3122,7 @@ matching lines."); This calls the external C<zfgrep> program and returns the matching lines."); - ("zgrepi", (RStringList "lines", [String "regex"; String "path"]), 160, [ProtocolLimitWarning], + ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 160, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3129,7 +3130,7 @@ matching lines."); This calls the external C<zgrep -i> program and returns the matching lines."); - ("zegrepi", (RStringList "lines", [String "regex"; String "path"]), 161, [ProtocolLimitWarning], + ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 161, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3137,7 +3138,7 @@ matching lines."); This calls the external C<zegrep -i> program and returns the matching lines."); - ("zfgrepi", (RStringList "lines", [String "pattern"; String "path"]), 162, [ProtocolLimitWarning], + ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 162, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3145,7 +3146,7 @@ matching lines."); This calls the external C<zfgrep -i> program and returns the matching lines."); - ("realpath", (RString "rpath", [String "path"]), 163, [], + ("realpath", (RString "rpath", [Pathname "path"]), 163, [], [InitSquashFS, Always, TestOutput ( [["realpath"; "/../directory"]], "/directory")], "canonicalized absolute pathname", @@ -3193,13 +3194,13 @@ This command creates a symbolic link using the C<ln -s> command."); This command creates a symbolic link using the C<ln -sf> command, The C<-f> option removes the link (C<linkname>) if it exists already."); - ("readlink", (RString "link", [String "path"]), 168, [], + ("readlink", (RString "link", [Pathname "path"]), 168, [], [] (* XXX tested above *), "read the target of a symbolic link", "\ This command reads the target of a symbolic link."); - ("fallocate", (RErr, [String "path"; Int "len"]), 169, [], + ("fallocate", (RErr, [Pathname "path"; Int "len"]), 169, [], [InitBasicFS, Always, TestOutputStruct ( [["fallocate"; "/a"; "1000000"]; ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])], @@ -3294,7 +3295,7 @@ See C<guestfs_swapon_device> for other notes."); This command disables the libguestfs appliance swap partition with the given UUID."); - ("mkswap_file", (RErr, [String "path"]), 178, [], + ("mkswap_file", (RErr, [Pathname "path"]), 178, [], [InitBasicFS, Always, TestRun ( [["fallocate"; "/swap"; "8388608"]; ["mkswap_file"; "/swap"]])], @@ -3346,7 +3347,7 @@ as exposed by the Linux kernel, which is roughly what we expose via libguestfs. Note that there is one global inotify handle per libguestfs instance."); - ("inotify_add_watch", (RInt64 "wd", [String "path"; Int "mask"]), 180, [], + ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"]), 180, [], [InitBasicFS, Always, TestOutputList ( [["inotify_init"; "0"]; ["inotify_add_watch"; "/"; "1073741823"]; @@ -3727,7 +3728,7 @@ let mapi f xs = loop 0 xs let name_of_argt = function - | Device n | String n | OptString n | StringList n | Bool n | Int n + | Pathname n | Device n | String n | OptString n | StringList n | Bool n | Int n | FileIn n | FileOut n -> n let java_name_of_struct typ = @@ -4114,7 +4115,7 @@ and generate_xdr () = pr "struct %s_args {\n" name; List.iter ( function - | Device n | String n -> pr " string %s<>;\n" n + | Pathname n | Device n | String n -> pr " string %s<>;\n" n | OptString n -> pr " str *%s;\n" n | StringList n -> pr " str %s<>;\n" n | Bool n -> pr " bool %s;\n" n @@ -4475,7 +4476,7 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | Device n | String n -> + | Pathname n | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n @@ -4681,7 +4682,7 @@ and generate_daemon_actions () = List.iter ( function (* FIXME: eventually, make String "const", too *) - | Device n -> pr " const char *%s;\n" n + | Pathname n | Device n -> pr " const char *%s;\n" n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n @@ -4703,7 +4704,10 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | Device n -> + | Pathname n -> + pr " NEED_ROOT (goto done);\n"; + pr " ABS_PATH (%s, goto done);\n" n; + | Device n -> pr " %s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " %s = args.%s;\n" n n @@ -5610,6 +5614,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString n, "NULL" -> () + | Pathname n, arg | Device n, arg | String n, arg | OptString n, arg -> @@ -5658,6 +5663,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString _, "NULL" -> pr ", NULL" + | Pathname n, _ | Device n, _ | String n, _ | OptString n, _ -> @@ -5907,6 +5913,7 @@ and generate_fish_cmds () = ); List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -5928,6 +5935,7 @@ and generate_fish_cmds () = iteri ( fun i -> function + | Pathname name | Device name | String name -> pr " %s = argv[%d];\n" name i | OptString name -> pr " %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] : NULL;\n" @@ -6161,7 +6169,7 @@ and generate_fish_actions_pod () = pr " %s" name; List.iter ( function - | Device n | String n -> pr " %s" n + | Pathname n | Device n | String n -> pr " %s" n | OptString n -> pr " %s" n | StringList n -> pr " '%s ...'" n | Bool _ -> pr " true|false" @@ -6227,6 +6235,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) in List.iter ( function + | Pathname n | Device n | String n | OptString n -> @@ -6489,6 +6498,7 @@ copy_table (char * const * argv) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -6542,7 +6552,7 @@ copy_table (char * const * argv) function | StringList n -> pr " ocaml_guestfs_free_strings (%s);\n" n; - | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () ) (snd style); @@ -6626,7 +6636,7 @@ and generate_ocaml_prototype ?(is_external = false) name style = pr "%s : t -> " name; List.iter ( function - | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " | OptString _ -> pr "string option -> " | StringList _ -> pr "string array -> " | Bool _ -> pr "bool -> " @@ -6772,7 +6782,8 @@ DESTROY (g) fun i -> function (* FIXME: ? *) - | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> + pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 * Note that the implicit handle argument means we have @@ -6787,7 +6798,7 @@ DESTROY (g) let do_cleanups () = List.iter ( function - | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style) @@ -7159,7 +7170,7 @@ and generate_perl_prototype name style = if !comma then pr ", "; comma := true; match arg with - | Device n | String n + | Pathname n | Device n | String n | OptString n | Bool n | Int n | FileIn n | FileOut n -> pr "$%s" n | StringList n -> @@ -7407,7 +7418,8 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Device n | String n | FileIn n | FileOut n -> pr " const char *%s;\n" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> + pr " const char *%s;\n" n | OptString n -> pr " const char *%s;\n" n | StringList n -> pr " PyObject *py_%s;\n" n; @@ -7422,7 +7434,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " if (!PyArg_ParseTuple (args, (char *) \"O"; List.iter ( function - | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" | OptString _ -> pr "z" | StringList _ -> pr "O" | Bool _ -> pr "i" (* XXX Python has booleans? *) @@ -7432,7 +7444,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " &py_g"; List.iter ( function - | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n | OptString n -> pr ", &%s" n | StringList n -> pr ", &py_%s" n | Bool n -> pr ", &%s" n @@ -7445,7 +7457,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " g = get_handle (py_g);\n"; List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " %s = get_string_list (py_%s);\n" n n; @@ -7460,7 +7472,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -7769,7 +7781,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Device n | String n | FileIn n | FileOut n -> + | Pathname n | Device n | String n | FileIn n | FileOut n -> pr " Check_Type (%sv, T_STRING);\n" n; pr " const char *%s = StringValueCStr (%sv);\n" n n; pr " if (!%s)\n" n; @@ -7821,7 +7833,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -8132,6 +8144,7 @@ and generate_java_prototype ?(public=false) ?(privat=false) ?(native=false) needs_comma := true; match arg with + | Pathname n | Device n | String n | OptString n @@ -8250,6 +8263,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " (JNIEnv *env, jobject obj, jlong jg"; List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -8302,6 +8316,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close "NULL", "NULL" in List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -8331,6 +8346,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Get the parameters. *) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -8363,6 +8379,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Release the parameters. *) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -8638,7 +8655,7 @@ last_error h = do function | FileIn n | FileOut n - | Device n | String n -> pr "withCString %s $ \\%s -> " n n + | Pathname n | Device n | String n -> pr "withCString %s $ \\%s -> " n n | OptString n -> pr "maybeWith withCString %s $ \\%s -> " n n | StringList n -> pr "withMany withCString %s $ \\%s -> withArray0 nullPtr %s $ \\%s -> " n n n n | Bool _ | Int _ -> () @@ -8650,7 +8667,7 @@ last_error h = do | Bool n -> sprintf "(fromBool %s)" n | Int n -> sprintf "(fromIntegral %s)" n | FileIn n | FileOut n - | Device n | String n | OptString n | StringList n -> n + | Pathname n | Device n | String n | OptString n | StringList n -> n ) (snd style) in pr "withForeignPtr h (\\p -> c_%s %s)\n" name (String.concat " " ("p" :: args)); @@ -8700,7 +8717,7 @@ and generate_haskell_prototype ~handle ?(hs = false) style = List.iter ( fun arg -> (match arg with - | Device _ | String _ -> pr "%s" string + | Pathname _ | Device _ | String _ -> pr "%s" string | OptString _ -> if hs then pr "Maybe String" else pr "CString" | StringList _ -> if hs then pr "[String]" else pr "Ptr CString" | Bool _ -> pr "%s" bool @@ -8775,6 +8792,7 @@ print_strings (char * const* const argv) pr "{\n"; List.iter ( function + | Pathname n | Device n | String n | FileIn n -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:51PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml: Emit NEED_ROOT and ABS_PATH into generated stubs.c, rather than requiring they be added manually at the start of each and every do_* function that operates on a "path" parameter. Update grammar: Pathname is just a String, with the above exception.
@@ -532,7 +533,7 @@ Return the current qemu binary. This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name.");
- ("set_path", (RErr, [String "path"]), -1, [FishAlias "path"], + ("set_path", (RErr, [Pathname "path"]), -1, [FishAlias "path"], [], "set the search path", "\
This is wrong. The path here is the :-separated path for finding the appliance: http://libguestfs.org/guestfs.3.html#path None of the non-daemon functions should be touched by your patches, because they are handled on the library side and don't go through to the daemon.
@@ -1066,20 +1067,20 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created.");
- ("aug_get", (RString "val", [String "path"]), 19, [], + ("aug_get", (RString "val", [Pathname "path"]), 19, [], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C<path>. If C<path> matches exactly one node, the C<value> is returned.");
- ("aug_set", (RErr, [String "path"; String "val"]), 20, [], + ("aug_set", (RErr, [Pathname "path"; String "val"]), 20, [], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ Set the value associated with C<path> to C<value>.");
- ("aug_insert", (RErr, [String "path"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [Pathname "path"; String "label"; Bool "before"]), 21, [], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1091,7 +1092,7 @@ C<path> must match exactly one existing node in the tree, and C<label> must be a label, ie. not contain C</>, C<*> or end with a bracketed index C<[N]>.");
- ("aug_rm", (RInt "nrnodes", [String "path"]), 22, [], + ("aug_rm", (RInt "nrnodes", [Pathname "path"]), 22, [], [], (* XXX Augeas code needs tests. *) "remove an Augeas path", "\ @@ -1106,7 +1107,7 @@ On success this returns the number of entries which were removed."); Move the node C<src> to C<dest>. C<src> must match exactly one node. C<dest> is overwritten if it exists.");
- ("aug_match", (RStringList "matches", [String "path"]), 24, [], + ("aug_match", (RStringList "matches", [Pathname "path"]), 24, [], [], (* XXX Augeas code needs tests. *) "return Augeas nodes which match path", "\ @@ -1132,14 +1133,14 @@ Load files into the tree. See C<aug_load> in the Augeas documentation for the full gory details.");
- ("aug_ls", (RStringList "matches", [String "path"]), 28, [], + ("aug_ls", (RStringList "matches", [Pathname "path"]), 28, [], [], (* XXX Augeas code needs tests. *) "list Augeas nodes under a path", "\ This is just a shortcut for listing C<guestfs_aug_match> C<path/*> and sorting the resulting nodes into alphabetical order.");
These Augeas changes are dubious. Augeas paths != real paths: http://augeas.net/docs/tree.html
- ("mkmountpoint", (RErr, [String "path"]), 148, [], + ("mkmountpoint", (RErr, [Pathname "path"]), 148, [], [], "create a mountpoint", "\ @@ -3026,7 +3027,7 @@ in guestfish:
The inner filesystem is now unpacked under the /ext3 mountpoint.");
- ("rmmountpoint", (RErr, [String "path"]), 149, [], + ("rmmountpoint", (RErr, [Pathname "path"]), 149, [], [], "remove a mountpoint", "\
I guess as discussed on IRC a future patch will change these. Nevertheless checking for root mounted in these two calls is wrong.
@@ -4703,7 +4704,10 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | Device n -> + | Pathname n -> + pr " NEED_ROOT (goto done);\n"; + pr " ABS_PATH (%s, goto done);\n" n; + | Device n -> pr " %s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " %s = args.%s;\n" n n
NEED_ROOT once - future patch? Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Richard W.M. Jones wrote:
On Wed, Aug 12, 2009 at 06:52:51PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml: Emit NEED_ROOT and ABS_PATH into generated stubs.c, rather than requiring they be added manually at the start of each and every do_* function that operates on a "path" parameter. Update grammar: Pathname is just a String, with the above exception.
@@ -532,7 +533,7 @@ Return the current qemu binary. This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name.");
- ("set_path", (RErr, [String "path"]), -1, [FishAlias "path"], + ("set_path", (RErr, [Pathname "path"]), -1, [FishAlias "path"], [], "set the search path", "\
Thanks for the quick feedback!
This is wrong. The path here is the :-separated path for finding the appliance:
http://libguestfs.org/guestfs.3.html#path
None of the non-daemon functions should be touched by your patches, because they are handled on the library side and don't go through to the daemon.
@@ -1066,20 +1067,20 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created.");
- ("aug_get", (RString "val", [String "path"]), 19, [], + ("aug_get", (RString "val", [Pathname "path"]), 19, [], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C<path>. If C<path> matches exactly one node, the C<value> is returned.");
- ("aug_set", (RErr, [String "path"; String "val"]), 20, [], + ("aug_set", (RErr, [Pathname "path"; String "val"]), 20, [], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ Set the value associated with C<path> to C<value>.");
- ("aug_insert", (RErr, [String "path"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [Pathname "path"; String "label"; Bool "before"]), 21, [], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1091,7 +1092,7 @@ C<path> must match exactly one existing node in the tree, and C<label> must be a label, ie. not contain C</>, C<*> or end with a bracketed index C<[N]>.");
- ("aug_rm", (RInt "nrnodes", [String "path"]), 22, [], + ("aug_rm", (RInt "nrnodes", [Pathname "path"]), 22, [], [], (* XXX Augeas code needs tests. *) "remove an Augeas path", "\ @@ -1106,7 +1107,7 @@ On success this returns the number of entries which were removed."); Move the node C<src> to C<dest>. C<src> must match exactly one node. C<dest> is overwritten if it exists.");
- ("aug_match", (RStringList "matches", [String "path"]), 24, [], + ("aug_match", (RStringList "matches", [Pathname "path"]), 24, [], [], (* XXX Augeas code needs tests. *) "return Augeas nodes which match path", "\ @@ -1132,14 +1133,14 @@ Load files into the tree. See C<aug_load> in the Augeas documentation for the full gory details.");
- ("aug_ls", (RStringList "matches", [String "path"]), 28, [], + ("aug_ls", (RStringList "matches", [Pathname "path"]), 28, [], [], (* XXX Augeas code needs tests. *) "list Augeas nodes under a path", "\ This is just a shortcut for listing C<guestfs_aug_match> C<path/*> and sorting the resulting nodes into alphabetical order.");
These Augeas changes are dubious. Augeas paths != real paths:
s/dubious/wrong/ ;-) Thanks.
http://augeas.net/docs/tree.html
- ("mkmountpoint", (RErr, [String "path"]), 148, [], + ("mkmountpoint", (RErr, [Pathname "path"]), 148, [], [], "create a mountpoint", "\ @@ -3026,7 +3027,7 @@ in guestfish:
The inner filesystem is now unpacked under the /ext3 mountpoint.");
- ("rmmountpoint", (RErr, [String "path"]), 149, [], + ("rmmountpoint", (RErr, [Pathname "path"]), 149, [], [], "remove a mountpoint", "\
I guess as discussed on IRC a future patch will change these. Nevertheless checking for root mounted in these two calls is wrong.
Good catch. I'd corrected mkmountpoint, but not rmmountpoint.
@@ -4703,7 +4704,10 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | Device n -> + | Pathname n -> + pr " NEED_ROOT (goto done);\n"; + pr " ABS_PATH (%s, goto done);\n" n; + | Device n -> pr " %s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " %s = args.%s;\n" n n
NEED_ROOT once - future patch?
Yes. Here's an incremental (vs head), followed by the merged result. I've reverted all "aug..." String-to-Pathname changes except the one for aug_init. In addition, in an attempt to show that augeas paths are different, I've renamed the parameters from "path" to "augpath". Similarly for rmmountpoint, I changed the param name to exemptpath, to match that of mkmountpoint. Easy to adjust if you'd prefer some other names. --------------------------------------------- diff --git a/src/generator.ml b/src/generator.ml index b6e4522..43e3164 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -1093,20 +1093,20 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created."); - ("aug_get", (RString "val", [Pathname "path"]), 19, [], + ("aug_get", (RString "val", [String "augpath"]), 19, [], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C<path>. If C<path> matches exactly one node, the C<value> is returned."); - ("aug_set", (RErr, [Pathname "path"; String "val"]), 20, [], + ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ Set the value associated with C<path> to C<value>."); - ("aug_insert", (RErr, [Pathname "path"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1118,7 +1118,7 @@ C<path> must match exactly one existing node in the tree, and C<label> must be a label, ie. not contain C</>, C<*> or end with a bracketed index C<[N]>."); - ("aug_rm", (RInt "nrnodes", [Pathname "path"]), 22, [], + ("aug_rm", (RInt "nrnodes", [String "augpath"]), 22, [], [], (* XXX Augeas code needs tests. *) "remove an Augeas path", "\ @@ -1133,9 +1133,9 @@ On success this returns the number of entries which were removed."); Move the node C<src> to C<dest>. C<src> must match exactly one node. C<dest> is overwritten if it exists."); - ("aug_match", (RStringList "matches", [Pathname "path"]), 24, [], + ("aug_match", (RStringList "matches", [String "augpath"]), 24, [], [], (* XXX Augeas code needs tests. *) - "return Augeas nodes which match path", + "return Augeas nodes which match augpath", "\ Returns a list of paths which match the path expression C<path>. The returned paths are sufficiently qualified so that they match @@ -1159,9 +1159,9 @@ Load files into the tree. See C<aug_load> in the Augeas documentation for the full gory details."); - ("aug_ls", (RStringList "matches", [Pathname "path"]), 28, [], + ("aug_ls", (RStringList "matches", [String "augpath"]), 28, [], [], (* XXX Augeas code needs tests. *) - "list Augeas nodes under a path", + "list Augeas nodes under augpath", "\ This is just a shortcut for listing C<guestfs_aug_match> C<path/*> and sorting the resulting nodes into alphabetical order."); @@ -3062,7 +3062,7 @@ in guestfish: The inner filesystem is now unpacked under the /ext3 mountpoint."); - ("rmmountpoint", (RErr, [Pathname "path"]), 149, [], + ("rmmountpoint", (RErr, [String "exemptpath"]), 149, [], [], "remove a mountpoint", "\ -----------------------------------------------------------
From 0f59191e5d6e2d8422406e96412e567b19f2a270 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyering@redhat.com> Date: Tue, 11 Aug 2009 12:16:51 +0200 Subject: [PATCH libguestfs 15/23] generator.ml: new type, "Pathname"
* src/generator.ml: Emit NEED_ROOT and ABS_PATH into generated stubs.c, rather than requiring they be added manually at the start of each and every do_* function that operates on a "path" parameter. Update grammar: Pathname is just a String, with the above exception. Do not update augeas "path" parameters, since they are not file names, but rather ":"-separated search paths. Except aug_init, for which "path" *is* a file name. --- src/generator.ml | 204 +++++++++++++++++++++++++++++------------------------- 1 files changed, 111 insertions(+), 93 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index dc574fd..b96088b 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -135,6 +135,7 @@ and args = argt list (* Function parameters, guestfs handle is implicit. *) and argt = | String of string (* const char *name, cannot be NULL *) | Device of string (* /dev device name, cannot be NULL *) + | Pathname of string (* file name, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) | Bool of string (* boolean *) @@ -532,7 +533,7 @@ Return the current qemu binary. This is always non-NULL. If it wasn't set already, then this will return the default qemu binary name."); - ("set_path", (RErr, [String "path"]), -1, [FishAlias "path"], + ("set_path", (RErr, [Pathname "path"]), -1, [FishAlias "path"], [], "set the search path", "\ @@ -830,7 +831,7 @@ underlying disk image. You should always call this if you have modified a disk image, before closing the handle."); - ("touch", (RErr, [String "path"]), 3, [], + ("touch", (RErr, [Pathname "path"]), 3, [], [InitBasicFS, Always, TestOutputTrue ( [["touch"; "/new"]; ["exists"; "/new"]])], @@ -840,7 +841,7 @@ Touch acts like the L<touch(1)> command. It can be used to update the timestamps on a file, or, if the file does not exist, to create a new zero-length file."); - ("cat", (RString "content", [String "path"]), 4, [ProtocolLimitWarning], + ("cat", (RString "content", [Pathname "path"]), 4, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutput ( [["cat"; "/known-2"]], "abcdef\n")], "list the contents of a file", @@ -988,7 +989,7 @@ of the L<vgs(8)> command. The \"full\" version includes all fields."); List all the logical volumes detected. This is the equivalent of the L<lvs(8)> command. The \"full\" version includes all fields."); - ("read_lines", (RStringList "lines", [String "path"]), 15, [], + ("read_lines", (RStringList "lines", [Pathname "path"]), 15, [], [InitSquashFS, Always, TestOutputList ( [["read_lines"; "/known-4"]], ["abc"; "def"; "ghi"]); InitSquashFS, Always, TestOutputList ( @@ -1091,20 +1092,20 @@ On success this returns a pair containing the number of nodes in the nodeset, and a boolean flag if a node was created."); - ("aug_get", (RString "val", [String "path"]), 19, [], + ("aug_get", (RString "val", [String "augpath"]), 19, [], [], (* XXX Augeas code needs tests. *) "look up the value of an Augeas path", "\ Look up the value associated with C<path>. If C<path> matches exactly one node, the C<value> is returned."); - ("aug_set", (RErr, [String "path"; String "val"]), 20, [], + ("aug_set", (RErr, [String "augpath"; String "val"]), 20, [], [], (* XXX Augeas code needs tests. *) "set Augeas path to value", "\ Set the value associated with C<path> to C<value>."); - ("aug_insert", (RErr, [String "path"; String "label"; Bool "before"]), 21, [], + ("aug_insert", (RErr, [String "augpath"; String "label"; Bool "before"]), 21, [], [], (* XXX Augeas code needs tests. *) "insert a sibling Augeas node", "\ @@ -1116,7 +1117,7 @@ C<path> must match exactly one existing node in the tree, and C<label> must be a label, ie. not contain C</>, C<*> or end with a bracketed index C<[N]>."); - ("aug_rm", (RInt "nrnodes", [String "path"]), 22, [], + ("aug_rm", (RInt "nrnodes", [String "augpath"]), 22, [], [], (* XXX Augeas code needs tests. *) "remove an Augeas path", "\ @@ -1131,9 +1132,9 @@ On success this returns the number of entries which were removed."); Move the node C<src> to C<dest>. C<src> must match exactly one node. C<dest> is overwritten if it exists."); - ("aug_match", (RStringList "matches", [String "path"]), 24, [], + ("aug_match", (RStringList "matches", [String "augpath"]), 24, [], [], (* XXX Augeas code needs tests. *) - "return Augeas nodes which match path", + "return Augeas nodes which match augpath", "\ Returns a list of paths which match the path expression C<path>. The returned paths are sufficiently qualified so that they match @@ -1157,14 +1158,14 @@ Load files into the tree. See C<aug_load> in the Augeas documentation for the full gory details."); - ("aug_ls", (RStringList "matches", [String "path"]), 28, [], + ("aug_ls", (RStringList "matches", [String "augpath"]), 28, [], [], (* XXX Augeas code needs tests. *) - "list Augeas nodes under a path", + "list Augeas nodes under augpath", "\ This is just a shortcut for listing C<guestfs_aug_match> C<path/*> and sorting the resulting nodes into alphabetical order."); - ("rm", (RErr, [String "path"]), 29, [], + ("rm", (RErr, [Pathname "path"]), 29, [], [InitBasicFS, Always, TestRun [["touch"; "/new"]; ["rm"; "/new"]]; @@ -1177,7 +1178,7 @@ C<path/*> and sorting the resulting nodes into alphabetical order."); "\ Remove the single file C<path>."); - ("rmdir", (RErr, [String "path"]), 30, [], + ("rmdir", (RErr, [Pathname "path"]), 30, [], [InitBasicFS, Always, TestRun [["mkdir"; "/new"]; ["rmdir"; "/new"]]; @@ -1190,7 +1191,7 @@ Remove the single file C<path>."); "\ Remove the single directory C<path>."); - ("rm_rf", (RErr, [String "path"]), 31, [], + ("rm_rf", (RErr, [Pathname "path"]), 31, [], [InitBasicFS, Always, TestOutputFalse [["mkdir"; "/new"]; ["mkdir"; "/new/foo"]; @@ -1203,7 +1204,7 @@ Remove the file or directory C<path>, recursively removing the contents if its a directory. This is like the C<rm -rf> shell command."); - ("mkdir", (RErr, [String "path"]), 32, [], + ("mkdir", (RErr, [Pathname "path"]), 32, [], [InitBasicFS, Always, TestOutputTrue [["mkdir"; "/new"]; ["is_dir"; "/new"]]; @@ -1213,7 +1214,7 @@ command."); "\ Create a directory named C<path>."); - ("mkdir_p", (RErr, [String "path"]), 33, [], + ("mkdir_p", (RErr, [Pathname "path"]), 33, [], [InitBasicFS, Always, TestOutputTrue [["mkdir_p"; "/new/foo/bar"]; ["is_dir"; "/new/foo/bar"]]; @@ -1235,14 +1236,14 @@ Create a directory named C<path>."); Create a directory named C<path>, creating any parent directories as necessary. This is like the C<mkdir -p> shell command."); - ("chmod", (RErr, [Int "mode"; String "path"]), 34, [], + ("chmod", (RErr, [Int "mode"; Pathname "path"]), 34, [], [], (* XXX Need stat command to test *) "change file mode", "\ Change the mode (permissions) of C<path> to C<mode>. Only numeric modes are supported."); - ("chown", (RErr, [Int "owner"; Int "group"; String "path"]), 35, [], + ("chown", (RErr, [Int "owner"; Int "group"; Pathname "path"]), 35, [], [], (* XXX Need stat command to test *) "change file owner and group", "\ @@ -1252,7 +1253,7 @@ Only numeric uid and gid are supported. If you want to use names, you will need to locate and parse the password file yourself (Augeas support makes this relatively easy)."); - ("exists", (RBool "existsflag", [String "path"]), 36, [], + ("exists", (RBool "existsflag", [Pathname "path"]), 36, [], [InitSquashFS, Always, TestOutputTrue ( [["exists"; "/empty"]]); InitSquashFS, Always, TestOutputTrue ( @@ -1264,7 +1265,7 @@ This returns C<true> if and only if there is a file, directory See also C<guestfs_is_file>, C<guestfs_is_dir>, C<guestfs_stat>."); - ("is_file", (RBool "fileflag", [String "path"]), 37, [], + ("is_file", (RBool "fileflag", [Pathname "path"]), 37, [], [InitSquashFS, Always, TestOutputTrue ( [["is_file"; "/known-1"]]); InitSquashFS, Always, TestOutputFalse ( @@ -1277,7 +1278,7 @@ other objects like directories. See also C<guestfs_stat>."); - ("is_dir", (RBool "dirflag", [String "path"]), 38, [], + ("is_dir", (RBool "dirflag", [Pathname "path"]), 38, [], [InitSquashFS, Always, TestOutputFalse ( [["is_dir"; "/known-3"]]); InitSquashFS, Always, TestOutputTrue ( @@ -1379,7 +1380,7 @@ the string C<,> (comma). See also: C<guestfs_sfdisk_l>, C<guestfs_sfdisk_N>"); - ("write_file", (RErr, [String "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning], + ("write_file", (RErr, [Pathname "path"; String "content"; Int "size"]), 44, [ProtocolLimitWarning], [InitBasicFS, Always, TestOutput ( [["write_file"; "/new"; "new file contents"; "0"]; ["cat"; "/new"]], "new file contents"); @@ -1474,7 +1475,7 @@ Some internal mounts are not unmounted by this call."); This command removes all LVM logical volumes, volume groups and physical volumes."); - ("file", (RString "description", [String "path"]), 49, [], + ("file", (RString "description", [Pathname "path"]), 49, [], [InitSquashFS, Always, TestOutput ( [["file"; "/empty"]], "empty"); InitSquashFS, Always, TestOutput ( @@ -1627,7 +1628,7 @@ result into a list of lines. See also: C<guestfs_sh_lines>"); - ("stat", (RStruct ("statbuf", "stat"), [String "path"]), 52, [], + ("stat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 52, [], [InitSquashFS, Always, TestOutputStruct ( [["stat"; "/empty"]], [CompareWithInt ("size", 0)])], "get file information", @@ -1636,7 +1637,7 @@ Returns file information for the given C<path>. This is the same as the C<stat(2)> system call."); - ("lstat", (RStruct ("statbuf", "stat"), [String "path"]), 53, [], + ("lstat", (RStruct ("statbuf", "stat"), [Pathname "path"]), 53, [], [InitSquashFS, Always, TestOutputStruct ( [["lstat"; "/empty"]], [CompareWithInt ("size", 0)])], "get file information for a symbolic link", @@ -1649,7 +1650,7 @@ refers to. This is the same as the C<lstat(2)> system call."); - ("statvfs", (RStruct ("statbuf", "statvfs"), [String "path"]), 54, [], + ("statvfs", (RStruct ("statbuf", "statvfs"), [Pathname "path"]), 54, [], [InitSquashFS, Always, TestOutputStruct ( [["statvfs"; "/"]], [CompareWithInt ("namemax", 256)])], "get file system statistics", @@ -1815,7 +1816,7 @@ C<filename> can also be a named pipe. See also C<guestfs_upload>, C<guestfs_cat>."); - ("checksum", (RString "checksum", [String "csumtype"; String "path"]), 68, [], + ("checksum", (RString "checksum", [String "csumtype"; Pathname "path"]), 68, [], [InitSquashFS, Always, TestOutput ( [["checksum"; "crc"; "/known-3"]], "2891671662"); InitSquashFS, Always, TestLastFail ( @@ -2268,7 +2269,7 @@ true if their content is exactly equal, or false otherwise. The external L<cmp(1)> program is used for the comparison."); - ("strings", (RStringList "stringsout", [String "path"]), 94, [ProtocolLimitWarning], + ("strings", (RStringList "stringsout", [Pathname "path"]), 94, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["strings"; "/known-5"]], ["abcdefghi"; "jklmnopqr"]); InitSquashFS, Always, TestOutputList ( @@ -2278,7 +2279,7 @@ The external L<cmp(1)> program is used for the comparison."); This runs the L<strings(1)> command on a file and returns the list of printable strings found."); - ("strings_e", (RStringList "stringsout", [String "encoding"; String "path"]), 95, [ProtocolLimitWarning], + ("strings_e", (RStringList "stringsout", [String "encoding"; Pathname "path"]), 95, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["strings_e"; "b"; "/known-5"]], []); InitBasicFS, Disabled, TestOutputList ( @@ -2296,7 +2297,7 @@ show strings inside Windows/x86 files. The returned strings are transcoded to UTF-8."); - ("hexdump", (RString "dump", [String "path"]), 96, [ProtocolLimitWarning], + ("hexdump", (RString "dump", [Pathname "path"]), 96, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutput ( [["hexdump"; "/known-4"]], "00000000 61 62 63 0a 64 65 66 0a 67 68 69 |abc.def.ghi|\n0000000b\n"); (* Test for RHBZ#501888c2 regression which caused large hexdump @@ -2614,7 +2615,7 @@ containing C<dir>. It is an interface to the L<scrub(1)> program. See that manual page for more details."); - ("mkdtemp", (RString "dir", [String "template"]), 117, [], + ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [], [InitBasicFS, Always, TestRun ( [["mkdir"; "/tmp"]; ["mkdtemp"; "/tmp/tmpXXXXXX"]])], @@ -2639,7 +2640,7 @@ directory and its contents after use. See also: L<mkdtemp(3)>"); - ("wc_l", (RInt "lines", [String "path"]), 118, [], + ("wc_l", (RInt "lines", [Pathname "path"]), 118, [], [InitSquashFS, Always, TestOutputInt ( [["wc_l"; "/10klines"]], 10000)], "count lines in a file", @@ -2647,7 +2648,7 @@ See also: L<mkdtemp(3)>"); This command counts the lines in a file, using the C<wc -l> external command."); - ("wc_w", (RInt "words", [String "path"]), 119, [], + ("wc_w", (RInt "words", [Pathname "path"]), 119, [], [InitSquashFS, Always, TestOutputInt ( [["wc_w"; "/10klines"]], 10000)], "count words in a file", @@ -2655,7 +2656,7 @@ C<wc -l> external command."); This command counts the words in a file, using the C<wc -w> external command."); - ("wc_c", (RInt "chars", [String "path"]), 120, [], + ("wc_c", (RInt "chars", [Pathname "path"]), 120, [], [InitSquashFS, Always, TestOutputInt ( [["wc_c"; "/100kallspaces"]], 102400)], "count characters in a file", @@ -2663,7 +2664,7 @@ C<wc -w> external command."); This command counts the characters in a file, using the C<wc -c> external command."); - ("head", (RStringList "lines", [String "path"]), 121, [ProtocolLimitWarning], + ("head", (RStringList "lines", [Pathname "path"]), 121, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["head"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz";"3abcdefghijklmnopqrstuvwxyz";"4abcdefghijklmnopqrstuvwxyz";"5abcdefghijklmnopqrstuvwxyz";"6abcdefghijklmnopqrstuvwxyz";"7abcdefghijklmnopqrstuvwxyz";"8abcdefghijklmnopqrstuvwxyz";"9abcdefghijklmnopqrstuvwxyz"])], "return first 10 lines of a file", @@ -2671,7 +2672,7 @@ C<wc -c> external command."); This command returns up to the first 10 lines of a file as a list of strings."); - ("head_n", (RStringList "lines", [Int "nrlines"; String "path"]), 122, [ProtocolLimitWarning], + ("head_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 122, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["head_n"; "3"; "/10klines"]], ["0abcdefghijklmnopqrstuvwxyz";"1abcdefghijklmnopqrstuvwxyz";"2abcdefghijklmnopqrstuvwxyz"]); InitSquashFS, Always, TestOutputList ( @@ -2688,7 +2689,7 @@ from the file C<path>, excluding the last C<nrlines> lines. If the parameter C<nrlines> is zero, this returns an empty list."); - ("tail", (RStringList "lines", [String "path"]), 123, [ProtocolLimitWarning], + ("tail", (RStringList "lines", [Pathname "path"]), 123, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["tail"; "/10klines"]], ["9990abcdefghijklmnopqrstuvwxyz";"9991abcdefghijklmnopqrstuvwxyz";"9992abcdefghijklmnopqrstuvwxyz";"9993abcdefghijklmnopqrstuvwxyz";"9994abcdefghijklmnopqrstuvwxyz";"9995abcdefghijklmnopqrstuvwxyz";"9996abcdefghijklmnopqrstuvwxyz";"9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"])], "return last 10 lines of a file", @@ -2696,7 +2697,7 @@ If the parameter C<nrlines> is zero, this returns an empty list."); This command returns up to the last 10 lines of a file as a list of strings."); - ("tail_n", (RStringList "lines", [Int "nrlines"; String "path"]), 124, [ProtocolLimitWarning], + ("tail_n", (RStringList "lines", [Int "nrlines"; Pathname "path"]), 124, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["tail_n"; "3"; "/10klines"]], ["9997abcdefghijklmnopqrstuvwxyz";"9998abcdefghijklmnopqrstuvwxyz";"9999abcdefghijklmnopqrstuvwxyz"]); InitSquashFS, Always, TestOutputList ( @@ -2738,7 +2739,7 @@ This command is mostly useful for interactive sessions. It is I<not> intended that you try to parse the output string. Use C<statvfs> from programs."); - ("du", (RInt64 "sizekb", [String "path"]), 127, [], + ("du", (RInt64 "sizekb", [Pathname "path"]), 127, [], [InitSquashFS, Always, TestOutputInt ( [["du"; "/directory"]], 0 (* squashfs doesn't have blocks *))], "estimate file space usage", @@ -2753,7 +2754,7 @@ subdirectories (recursively). The result is the estimated size in I<kilobytes> (ie. units of 1024 bytes)."); - ("initrd_list", (RStringList "filenames", [String "path"]), 128, [], + ("initrd_list", (RStringList "filenames", [Pathname "path"]), 128, [], [InitSquashFS, Always, TestOutputList ( [["initrd_list"; "/initrd"]], ["empty";"known-1";"known-2";"known-3";"known-4"; "known-5"])], "list files in an initrd", @@ -2804,7 +2805,7 @@ a limitation of the kernel or swap tools."); "\ Create a swap partition on C<device> with UUID C<uuid>."); - ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 133, [], + ("mknod", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 133, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod"; "0o10777"; "0"; "0"; "/node"]; (* NB: default umask 022 means 0777 -> 0755 in these tests *) @@ -2822,7 +2823,7 @@ constants. C<devmajor> and C<devminor> are the device major and minor numbers, only used when creating block and character special devices."); - ("mkfifo", (RErr, [Int "mode"; String "path"]), 134, [], + ("mkfifo", (RErr, [Int "mode"; Pathname "path"]), 134, [], [InitBasicFS, Always, TestOutputStruct ( [["mkfifo"; "0o777"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o10755)])], @@ -2832,7 +2833,7 @@ This call creates a FIFO (named pipe) called C<path> with mode C<mode>. It is just a convenient wrapper around C<guestfs_mknod>."); - ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 135, [], + ("mknod_b", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 135, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod_b"; "0o777"; "99"; "66"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o60755)])], @@ -2842,7 +2843,7 @@ This call creates a block device node called C<path> with mode C<mode> and device major/minor C<devmajor> and C<devminor>. It is just a convenient wrapper around C<guestfs_mknod>."); - ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; String "path"]), 136, [], + ("mknod_c", (RErr, [Int "mode"; Int "devmajor"; Int "devminor"; Pathname "path"]), 136, [], [InitBasicFS, Always, TestOutputStruct ( [["mknod_c"; "0o777"; "99"; "66"; "/node"]; ["stat"; "/node"]], [CompareWithInt ("mode", 0o20755)])], @@ -2944,7 +2945,7 @@ were rarely if ever used anyway. See also C<guestfs_sfdisk> and the L<sfdisk(8)> manpage."); - ("zfile", (RString "description", [String "method"; String "path"]), 140, [DeprecatedBy "file"], + ("zfile", (RString "description", [String "method"; Pathname "path"]), 140, [DeprecatedBy "file"], [], "determine file type inside a compressed file", "\ @@ -2956,7 +2957,7 @@ C<method> must be one of C<gzip>, C<compress> or C<bzip2>. Since 1.0.63, use C<guestfs_file> instead which can now process compressed files."); - ("getxattrs", (RStructList ("xattrs", "xattr"), [String "path"]), 141, [], + ("getxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 141, [], [], "list extended attributes of a file or directory", "\ @@ -2968,7 +2969,7 @@ L<listxattr(2)> and L<getxattr(2)> calls. See also: C<guestfs_lgetxattrs>, L<attr(5)>."); - ("lgetxattrs", (RStructList ("xattrs", "xattr"), [String "path"]), 142, [], + ("lgetxattrs", (RStructList ("xattrs", "xattr"), [Pathname "path"]), 142, [], [], "list extended attributes of a file or directory", "\ @@ -2978,7 +2979,7 @@ of the link itself."); ("setxattr", (RErr, [String "xattr"; String "val"; Int "vallen"; (* will be BufferIn *) - String "path"]), 143, [], + Pathname "path"]), 143, [], [], "set extended attribute of a file or directory", "\ @@ -2990,7 +2991,7 @@ See also: C<guestfs_lsetxattr>, L<attr(5)>."); ("lsetxattr", (RErr, [String "xattr"; String "val"; Int "vallen"; (* will be BufferIn *) - String "path"]), 144, [], + Pathname "path"]), 144, [], [], "set extended attribute of a file or directory", "\ @@ -2998,7 +2999,7 @@ This is the same as C<guestfs_setxattr>, but if C<path> is a symbolic link, then it sets an extended attribute of the link itself."); - ("removexattr", (RErr, [String "xattr"; String "path"]), 145, [], + ("removexattr", (RErr, [String "xattr"; Pathname "path"]), 145, [], [], "remove extended attribute of a file or directory", "\ @@ -3007,7 +3008,7 @@ of the file C<path>. See also: C<guestfs_lremovexattr>, L<attr(5)>."); - ("lremovexattr", (RErr, [String "xattr"; String "path"]), 146, [], + ("lremovexattr", (RErr, [String "xattr"; Pathname "path"]), 146, [], [], "remove extended attribute of a file or directory", "\ @@ -3023,7 +3024,7 @@ 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, [String "path"]), 148, [], + ("mkmountpoint", (RErr, [Pathname "path"]), 148, [], [], "create a mountpoint", "\ @@ -3051,7 +3052,7 @@ in guestfish: The inner filesystem is now unpacked under the /ext3 mountpoint."); - ("rmmountpoint", (RErr, [String "path"]), 149, [], + ("rmmountpoint", (RErr, [String "exemptpath"]), 149, [], [], "remove a mountpoint", "\ @@ -3059,7 +3060,7 @@ This calls removes a mountpoint that was previously created with C<guestfs_mkmountpoint>. See C<guestfs_mkmountpoint> for full details."); - ("read_file", (RBufferOut "content", [String "path"]), 150, [ProtocolLimitWarning], + ("read_file", (RBufferOut "content", [Pathname "path"]), 150, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputBuffer ( [["read_file"; "/known-4"]], "abc\ndef\nghi")], "read a file", @@ -3072,7 +3073,7 @@ handle files that contain embedded ASCII NUL characters. However unlike C<guestfs_download>, this function is limited in the total size of file that can be handled."); - ("grep", (RStringList "lines", [String "regex"; String "path"]), 151, [ProtocolLimitWarning], + ("grep", (RStringList "lines", [String "regex"; Pathname "path"]), 151, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["grep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"]); InitSquashFS, Always, TestOutputList ( @@ -3082,7 +3083,7 @@ in the total size of file that can be handled."); This calls the external C<grep> program and returns the matching lines."); - ("egrep", (RStringList "lines", [String "regex"; String "path"]), 152, [ProtocolLimitWarning], + ("egrep", (RStringList "lines", [String "regex"; Pathname "path"]), 152, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["egrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3090,7 +3091,7 @@ matching lines."); This calls the external C<egrep> program and returns the matching lines."); - ("fgrep", (RStringList "lines", [String "pattern"; String "path"]), 153, [ProtocolLimitWarning], + ("fgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 153, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["fgrep"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3098,7 +3099,7 @@ matching lines."); This calls the external C<fgrep> program and returns the matching lines."); - ("grepi", (RStringList "lines", [String "regex"; String "path"]), 154, [ProtocolLimitWarning], + ("grepi", (RStringList "lines", [String "regex"; Pathname "path"]), 154, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["grepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3106,7 +3107,7 @@ matching lines."); This calls the external C<grep -i> program and returns the matching lines."); - ("egrepi", (RStringList "lines", [String "regex"; String "path"]), 155, [ProtocolLimitWarning], + ("egrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 155, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["egrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3114,7 +3115,7 @@ matching lines."); This calls the external C<egrep -i> program and returns the matching lines."); - ("fgrepi", (RStringList "lines", [String "pattern"; String "path"]), 156, [ProtocolLimitWarning], + ("fgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 156, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["fgrepi"; "abc"; "/test-grep.txt"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3122,7 +3123,7 @@ matching lines."); This calls the external C<fgrep -i> program and returns the matching lines."); - ("zgrep", (RStringList "lines", [String "regex"; String "path"]), 157, [ProtocolLimitWarning], + ("zgrep", (RStringList "lines", [String "regex"; Pathname "path"]), 157, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3130,7 +3131,7 @@ matching lines."); This calls the external C<zgrep> program and returns the matching lines."); - ("zegrep", (RStringList "lines", [String "regex"; String "path"]), 158, [ProtocolLimitWarning], + ("zegrep", (RStringList "lines", [String "regex"; Pathname "path"]), 158, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zegrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3138,7 +3139,7 @@ matching lines."); This calls the external C<zegrep> program and returns the matching lines."); - ("zfgrep", (RStringList "lines", [String "pattern"; String "path"]), 159, [ProtocolLimitWarning], + ("zfgrep", (RStringList "lines", [String "pattern"; Pathname "path"]), 159, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zfgrep"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"])], "return lines matching a pattern", @@ -3146,7 +3147,7 @@ matching lines."); This calls the external C<zfgrep> program and returns the matching lines."); - ("zgrepi", (RStringList "lines", [String "regex"; String "path"]), 160, [ProtocolLimitWarning], + ("zgrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 160, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3154,7 +3155,7 @@ matching lines."); This calls the external C<zgrep -i> program and returns the matching lines."); - ("zegrepi", (RStringList "lines", [String "regex"; String "path"]), 161, [ProtocolLimitWarning], + ("zegrepi", (RStringList "lines", [String "regex"; Pathname "path"]), 161, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zegrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3162,7 +3163,7 @@ matching lines."); This calls the external C<zegrep -i> program and returns the matching lines."); - ("zfgrepi", (RStringList "lines", [String "pattern"; String "path"]), 162, [ProtocolLimitWarning], + ("zfgrepi", (RStringList "lines", [String "pattern"; Pathname "path"]), 162, [ProtocolLimitWarning], [InitSquashFS, Always, TestOutputList ( [["zfgrepi"; "abc"; "/test-grep.txt.gz"]], ["abc"; "abc123"; "ABC"])], "return lines matching a pattern", @@ -3170,7 +3171,7 @@ matching lines."); This calls the external C<zfgrep -i> program and returns the matching lines."); - ("realpath", (RString "rpath", [String "path"]), 163, [], + ("realpath", (RString "rpath", [Pathname "path"]), 163, [], [InitSquashFS, Always, TestOutput ( [["realpath"; "/../directory"]], "/directory")], "canonicalized absolute pathname", @@ -3218,13 +3219,13 @@ This command creates a symbolic link using the C<ln -s> command."); This command creates a symbolic link using the C<ln -sf> command, The C<-f> option removes the link (C<linkname>) if it exists already."); - ("readlink", (RString "link", [String "path"]), 168, [], + ("readlink", (RString "link", [Pathname "path"]), 168, [], [] (* XXX tested above *), "read the target of a symbolic link", "\ This command reads the target of a symbolic link."); - ("fallocate", (RErr, [String "path"; Int "len"]), 169, [], + ("fallocate", (RErr, [Pathname "path"; Int "len"]), 169, [], [InitBasicFS, Always, TestOutputStruct ( [["fallocate"; "/a"; "1000000"]; ["stat"; "/a"]], [CompareWithInt ("size", 1_000_000)])], @@ -3319,7 +3320,7 @@ See C<guestfs_swapon_device> for other notes."); This command disables the libguestfs appliance swap partition with the given UUID."); - ("mkswap_file", (RErr, [String "path"]), 178, [], + ("mkswap_file", (RErr, [Pathname "path"]), 178, [], [InitBasicFS, Always, TestRun ( [["fallocate"; "/swap"; "8388608"]; ["mkswap_file"; "/swap"]])], @@ -3371,7 +3372,7 @@ as exposed by the Linux kernel, which is roughly what we expose via libguestfs. Note that there is one global inotify handle per libguestfs instance."); - ("inotify_add_watch", (RInt64 "wd", [String "path"; Int "mask"]), 180, [], + ("inotify_add_watch", (RInt64 "wd", [Pathname "path"; Int "mask"]), 180, [], [InitBasicFS, Always, TestOutputList ( [["inotify_init"; "0"]; ["inotify_add_watch"; "/"; "1073741823"]; @@ -3752,7 +3753,7 @@ let mapi f xs = loop 0 xs let name_of_argt = function - | Device n | String n | OptString n | StringList n | Bool n | Int n + | Pathname n | Device n | String n | OptString n | StringList n | Bool n | Int n | FileIn n | FileOut n -> n let java_name_of_struct typ = @@ -4139,7 +4140,7 @@ and generate_xdr () = pr "struct %s_args {\n" name; List.iter ( function - | Device n | String n -> pr " string %s<>;\n" n + | Pathname n | Device n | String n -> pr " string %s<>;\n" n | OptString n -> pr " str *%s;\n" n | StringList n -> pr " str %s<>;\n" n | Bool n -> pr " bool %s;\n" n @@ -4500,7 +4501,7 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | Device n | String n -> + | Pathname n | Device n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n @@ -4706,7 +4707,7 @@ and generate_daemon_actions () = List.iter ( function (* FIXME: eventually, make String "const", too *) - | Device n -> pr " const char *%s;\n" n + | Pathname n | Device n -> pr " const char *%s;\n" n | String n | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n @@ -4728,7 +4729,10 @@ and generate_daemon_actions () = pr " }\n"; List.iter ( function - | Device n -> + | Pathname n -> + pr " NEED_ROOT (goto done);\n"; + pr " ABS_PATH (%s, goto done);\n" n; + | Device n -> pr " %s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " %s = args.%s;\n" n n @@ -5635,6 +5639,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString n, "NULL" -> () + | Pathname n, arg | Device n, arg | String n, arg | OptString n, arg -> @@ -5683,6 +5688,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = List.iter ( function | OptString _, "NULL" -> pr ", NULL" + | Pathname n, _ | Device n, _ | String n, _ | OptString n, _ -> @@ -5932,6 +5938,7 @@ and generate_fish_cmds () = ); List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -5953,6 +5960,7 @@ and generate_fish_cmds () = iteri ( fun i -> function + | Pathname name | Device name | String name -> pr " %s = argv[%d];\n" name i | OptString name -> pr " %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] : NULL;\n" @@ -6186,7 +6194,7 @@ and generate_fish_actions_pod () = pr " %s" name; List.iter ( function - | Device n | String n -> pr " %s" n + | Pathname n | Device n | String n -> pr " %s" n | OptString n -> pr " %s" n | StringList n -> pr " '%s ...'" n | Bool _ -> pr " true|false" @@ -6252,6 +6260,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) in List.iter ( function + | Pathname n | Device n | String n | OptString n -> @@ -6514,6 +6523,7 @@ copy_table (char * const * argv) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -6567,7 +6577,7 @@ copy_table (char * const * argv) function | StringList n -> pr " ocaml_guestfs_free_strings (%s);\n" n; - | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () ) (snd style); @@ -6651,7 +6661,7 @@ and generate_ocaml_prototype ?(is_external = false) name style = pr "%s : t -> " name; List.iter ( function - | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " | OptString _ -> pr "string option -> " | StringList _ -> pr "string array -> " | Bool _ -> pr "bool -> " @@ -6797,7 +6807,8 @@ DESTROY (g) fun i -> function (* FIXME: ? *) - | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> + pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 * Note that the implicit handle argument means we have @@ -6812,7 +6823,7 @@ DESTROY (g) let do_cleanups () = List.iter ( function - | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style) @@ -7184,7 +7195,7 @@ and generate_perl_prototype name style = if !comma then pr ", "; comma := true; match arg with - | Device n | String n + | Pathname n | Device n | String n | OptString n | Bool n | Int n | FileIn n | FileOut n -> pr "$%s" n | StringList n -> @@ -7432,7 +7443,8 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Device n | String n | FileIn n | FileOut n -> pr " const char *%s;\n" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> + pr " const char *%s;\n" n | OptString n -> pr " const char *%s;\n" n | StringList n -> pr " PyObject *py_%s;\n" n; @@ -7447,7 +7459,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " if (!PyArg_ParseTuple (args, (char *) \"O"; List.iter ( function - | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" | OptString _ -> pr "z" | StringList _ -> pr "O" | Bool _ -> pr "i" (* XXX Python has booleans? *) @@ -7457,7 +7469,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " &py_g"; List.iter ( function - | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n + | Pathname n | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n | OptString n -> pr ", &%s" n | StringList n -> pr ", &py_%s" n | Bool n -> pr ", &%s" n @@ -7470,7 +7482,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " g = get_handle (py_g);\n"; List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " %s = get_string_list (py_%s);\n" n n; @@ -7485,7 +7497,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -7794,7 +7806,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Device n | String n | FileIn n | FileOut n -> + | Pathname n | Device n | String n | FileIn n | FileOut n -> pr " Check_Type (%sv, T_STRING);\n" n; pr " const char *%s = StringValueCStr (%sv);\n" n n; pr " if (!%s)\n" n; @@ -7846,7 +7858,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Device _ | String _ + | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -8157,6 +8169,7 @@ and generate_java_prototype ?(public=false) ?(privat=false) ?(native=false) needs_comma := true; match arg with + | Pathname n | Device n | String n | OptString n @@ -8275,6 +8288,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close pr " (JNIEnv *env, jobject obj, jlong jg"; List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -8327,6 +8341,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close "NULL", "NULL" in List.iter ( function + | Pathname n | Device n | String n | OptString n @@ -8356,6 +8371,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Get the parameters. *) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -8388,6 +8404,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close (* Release the parameters. *) List.iter ( function + | Pathname n | Device n | String n | FileIn n @@ -8663,7 +8680,7 @@ last_error h = do function | FileIn n | FileOut n - | Device n | String n -> pr "withCString %s $ \\%s -> " n n + | Pathname n | Device n | String n -> pr "withCString %s $ \\%s -> " n n | OptString n -> pr "maybeWith withCString %s $ \\%s -> " n n | StringList n -> pr "withMany withCString %s $ \\%s -> withArray0 nullPtr %s $ \\%s -> " n n n n | Bool _ | Int _ -> () @@ -8675,7 +8692,7 @@ last_error h = do | Bool n -> sprintf "(fromBool %s)" n | Int n -> sprintf "(fromIntegral %s)" n | FileIn n | FileOut n - | Device n | String n | OptString n | StringList n -> n + | Pathname n | Device n | String n | OptString n | StringList n -> n ) (snd style) in pr "withForeignPtr h (\\p -> c_%s %s)\n" name (String.concat " " ("p" :: args)); @@ -8725,7 +8742,7 @@ and generate_haskell_prototype ~handle ?(hs = false) style = List.iter ( fun arg -> (match arg with - | Device _ | String _ -> pr "%s" string + | Pathname _ | Device _ | String _ -> pr "%s" string | OptString _ -> if hs then pr "Maybe String" else pr "CString" | StringList _ -> if hs then pr "[String]" else pr "Ptr CString" | Bool _ -> pr "%s" bool @@ -8800,6 +8817,7 @@ print_strings (char * const* const argv) pr "{\n"; List.iter ( function + | Pathname n | Device n | String n | FileIn n -- 1.6.4.337.g5420e
From: Jim Meyering <meyering@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
On Wed, Aug 12, 2009 at 06:52:52PM +0200, Jim Meyering wrote:
/* 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) [etc.]
As discussed in the previous patch, the augeas change to path is dubious. However hopefully this will become a const char * in the end.
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", "\
This change is actually OK however. Here the "root" really is a path.
@@ -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"];
Agreed.
@@ -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"]])],
Hope this is fixed in a future patch.
@@ -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", "\
Agreed. ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
From: Jim Meyering <meyering@redhat.com> --- src/generator.ml | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index f9032fb..8aa36bd 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4691,9 +4691,9 @@ and generate_daemon_actions () = pr " struct guestfs_%s_args args;\n" name; List.iter ( function - | Device n -> pr " const char *%s;\n" n + | Device n | Pathname n - | String n + | String n -> () | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n @@ -4715,12 +4715,12 @@ and generate_daemon_actions () = List.iter ( function | Pathname n -> - pr " %s = args.%s;\n" n n; + pr " char *%s = args.%s;\n" n n; pr " ABS_PATH (%s, goto done);\n" n; | Device n -> - pr " %s = args.%s;\n" n n; + pr " char *%s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; - | String n -> pr " %s = args.%s;\n" n n + | String n -> pr " char *%s = args.%s;\n" n n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:53PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- src/generator.ml | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml index f9032fb..8aa36bd 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4691,9 +4691,9 @@ and generate_daemon_actions () = pr " struct guestfs_%s_args args;\n" name; List.iter ( function - | Device n -> pr " const char *%s;\n" n + | Device n | Pathname n - | String n + | String n -> () | OptString n -> pr " char *%s;\n" n | StringList n -> pr " char **%s;\n" n | Bool n -> pr " int %s;\n" n @@ -4715,12 +4715,12 @@ and generate_daemon_actions () = List.iter ( function | Pathname n -> - pr " %s = args.%s;\n" n n; + pr " char *%s = args.%s;\n" n n; pr " ABS_PATH (%s, goto done);\n" n; | Device n -> - pr " %s = args.%s;\n" n n; + pr " char *%s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; - | String n -> pr " %s = args.%s;\n" n n + | String n -> pr " char *%s = args.%s;\n" n n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; -- 1.6.4.337.g5420e
This patch is a bit unusual (although not wrong). It sort of redistributes the C variable declarations between two sections of code. Device|Pathname|String use an inline declaration: char *foo = args.foo; whereas OptString|StringList|Bool use: type foo; ... foo = args.foo; ACK-ish. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
From: Jim Meyering <meyering@redhat.com> * daemon/dir.c (do_mkdtemp): Rewrite for a "const" parameter. * src/generator.ml (mkdtemp): Declare parameter to be of type Pathname. --- daemon/dir.c | 25 ++++++++----------------- src/generator.ml | 6 ++---- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/daemon/dir.c b/daemon/dir.c index ad1c7c9..1ca6286 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -185,31 +185,22 @@ do_is_dir (const char *path) } char * -do_mkdtemp (char *template) +do_mkdtemp (const char *template) { - char *r; - - NEED_ROOT (return NULL); - ABS_PATH (template, return NULL); + char *writable = strdup (template); + if (writable == NULL) { + reply_with_perror ("strdup"); + return NULL; + } CHROOT_IN; - r = mkdtemp (template); + char *r = mkdtemp (writable); CHROOT_OUT; if (r == NULL) { reply_with_perror ("mkdtemp: %s", template); - return NULL; + free (writable); } - /* The caller will free template AND try to free the return value, - * so we must make a copy here. - */ - if (r == template) { - r = strdup (template); - if (r == NULL) { - reply_with_perror ("strdup"); - return NULL; - } - } return r; } diff --git a/src/generator.ml b/src/generator.ml index 8aa36bd..ddeeb25 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2594,8 +2594,7 @@ containing C<dir>. It is an interface to the L<scrub(1)> program. See that manual page for more details."); -(* FIXME: make this a WritableString? *) - ("mkdtemp", (RString "dir", [String "template"]), 117, [], + ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [], [InitBasicFS, Always, TestRun ( [["mkdir"; "/tmp"]; ["mkdtemp"; "/tmp/tmpXXXXXX"]])], @@ -4717,7 +4716,7 @@ and generate_daemon_actions () = | Pathname n -> pr " char *%s = args.%s;\n" n n; pr " ABS_PATH (%s, goto done);\n" n; - | Device n -> + | Device n -> pr " char *%s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " char *%s = args.%s;\n" n n @@ -6798,7 +6797,6 @@ DESTROY (g) iteri ( fun i -> function - (* FIXME: ? *) | Pathname n | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:54PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* daemon/dir.c (do_mkdtemp): Rewrite for a "const" parameter. * src/generator.ml (mkdtemp): Declare parameter to be of type Pathname. --- daemon/dir.c | 25 ++++++++----------------- src/generator.ml | 6 ++---- 2 files changed, 10 insertions(+), 21 deletions(-)
diff --git a/daemon/dir.c b/daemon/dir.c index ad1c7c9..1ca6286 100644 --- a/daemon/dir.c +++ b/daemon/dir.c @@ -185,31 +185,22 @@ do_is_dir (const char *path) }
char * -do_mkdtemp (char *template) +do_mkdtemp (const char *template) { - char *r; - - NEED_ROOT (return NULL); - ABS_PATH (template, return NULL); + char *writable = strdup (template); + if (writable == NULL) { + reply_with_perror ("strdup"); + return NULL; + }
CHROOT_IN; - r = mkdtemp (template); + char *r = mkdtemp (writable); CHROOT_OUT;
if (r == NULL) { reply_with_perror ("mkdtemp: %s", template); - return NULL; + free (writable); }
- /* The caller will free template AND try to free the return value, - * so we must make a copy here. - */ - if (r == template) { - r = strdup (template); - if (r == NULL) { - reply_with_perror ("strdup"); - return NULL; - } - } return r; } diff --git a/src/generator.ml b/src/generator.ml index 8aa36bd..ddeeb25 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -2594,8 +2594,7 @@ containing C<dir>. It is an interface to the L<scrub(1)> program. See that manual page for more details.");
-(* FIXME: make this a WritableString? *) - ("mkdtemp", (RString "dir", [String "template"]), 117, [], + ("mkdtemp", (RString "dir", [Pathname "template"]), 117, [], [InitBasicFS, Always, TestRun ( [["mkdir"; "/tmp"]; ["mkdtemp"; "/tmp/tmpXXXXXX"]])], @@ -4717,7 +4716,7 @@ and generate_daemon_actions () = | Pathname n -> pr " char *%s = args.%s;\n" n n; pr " ABS_PATH (%s, goto done);\n" n; - | Device n -> + | Device n -> pr " char *%s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " char *%s = args.%s;\n" n n @@ -6798,7 +6797,6 @@ DESTROY (g) iteri ( fun i -> function - (* FIXME: ? *) | Pathname n | Device n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> -- 1.6.4.337.g5420e
Discussed on IRC already, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
From: Jim Meyering <meyering@redhat.com> * src/generator.ml (file, download): Use it. --- src/generator.ml | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index ddeeb25..072b9f4 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -136,6 +136,7 @@ and argt = | String of string (* const char *name, cannot be NULL *) | Device of string (* /dev device name, cannot be NULL *) | Pathname of string (* file name, cannot be NULL *) + | Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) | Bool of string (* boolean *) @@ -1450,7 +1451,7 @@ Some internal mounts are not unmounted by this call."); This command removes all LVM logical volumes, volume groups and physical volumes."); - ("file", (RString "description", [Pathname "path"]), 49, [], + ("file", (RString "description", [Dev_or_Path "path"]), 49, [], [InitSquashFS, Always, TestOutput ( [["file"; "/empty"]], "empty"); InitSquashFS, Always, TestOutput ( @@ -1774,7 +1775,7 @@ C<filename> can also be a named pipe. See also C<guestfs_download>."); - ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [], + ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"]), 67, [], [InitBasicFS, Always, TestOutput ( (* Pick a file from cwd which isn't likely to change. *) [["upload"; "../COPYING.LIB"; "/COPYING.LIB"]; -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:55PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml (file, download): Use it. --- src/generator.ml | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml index ddeeb25..072b9f4 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -136,6 +136,7 @@ and argt = | String of string (* const char *name, cannot be NULL *) | Device of string (* /dev device name, cannot be NULL *) | Pathname of string (* file name, cannot be NULL *) + | Dev_or_Path of string (* /dev device name or Pathname, cannot be NULL *) | OptString of string (* const char *name, may be NULL *) | StringList of string(* list of strings (each string cannot be NULL) *) | Bool of string (* boolean *) @@ -1450,7 +1451,7 @@ Some internal mounts are not unmounted by this call."); This command removes all LVM logical volumes, volume groups and physical volumes.");
- ("file", (RString "description", [Pathname "path"]), 49, [], + ("file", (RString "description", [Dev_or_Path "path"]), 49, [], [InitSquashFS, Always, TestOutput ( [["file"; "/empty"]], "empty"); InitSquashFS, Always, TestOutput ( @@ -1774,7 +1775,7 @@ C<filename> can also be a named pipe.
See also C<guestfs_download>.");
- ("download", (RErr, [String "remotefilename"; FileOut "filename"]), 67, [], + ("download", (RErr, [Dev_or_Path "remotefilename"; FileOut "filename"]), 67, [], [InitBasicFS, Always, TestOutput ( (* Pick a file from cwd which isn't likely to change. *) [["upload"; "../COPYING.LIB"; "/COPYING.LIB"]; -- 1.6.4.337.g5420e
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
Always fun to have exceptions ... ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
From: Jim Meyering <meyering@redhat.com> --- daemon/mount.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/daemon/mount.c b/daemon/mount.c index 89bef34..9ccb37b 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -106,7 +106,7 @@ int do_umount (const char *pathordevice) { int freeit = 0, r; - char *buf; + const char *buf; char *err; if (strncmp (pathordevice, "/dev/", 5) == 0) { -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:56PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/mount.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/mount.c b/daemon/mount.c index 89bef34..9ccb37b 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -106,7 +106,7 @@ int do_umount (const char *pathordevice) { int freeit = 0, r; - char *buf; + const char *buf; char *err;
if (strncmp (pathordevice, "/dev/", 5) == 0) { -- 1.6.4.337.g5420e
_______________________________________________ Libguestfs mailing list Libguestfs@redhat.com https://www.redhat.com/mailman/listinfo/libguestfs
Seems OK, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- daemon/mount.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/daemon/mount.c b/daemon/mount.c index 89bef34..9ccb37b 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -106,7 +106,7 @@ int do_umount (const char *pathordevice) { int freeit = 0, r; - char *buf; + const char *buf; char *err;
I've just noticed that is bogus, and should be merged with the later, do_umount: don't use RESOLVE_DEVICE anymore change that rewrites the function. Also, I got the function name wrong in the subject: should be s/mount/umount/.
From: Jim Meyering <meyering@redhat.com> * src/generator.ml: Update all rules to handle Dev_or_Path. (the above changes to generator.ml are mostly mechanical) Emit a use of REQUIRE_ROOT_OR_RESOLVE_DEVICE. * daemon/upload.c (do_download): Remove use of REQUIRE_ROOT_OR_RESOLVE_DEVICE, now that it's automatically done in calling code. * daemon/file.c (do_file): Likewise. --- daemon/file.c | 2 - daemon/upload.c | 2 - src/generator.ml | 66 ++++++++++++++++++++++++++++------------------------- 3 files changed, 35 insertions(+), 35 deletions(-) diff --git a/daemon/file.c b/daemon/file.c index ed3221d..212aff2 100644 --- a/daemon/file.c +++ b/daemon/file.c @@ -361,8 +361,6 @@ do_file (const char *path) char *buf; int len; - REQUIRE_ROOT_OR_RESOLVE_DEVICE (path, return NULL); - if (strncmp (path, "/dev/", 5) == 0) buf = (char *) path; else { diff --git a/daemon/upload.c b/daemon/upload.c index aede24a..143fa82 100644 --- a/daemon/upload.c +++ b/daemon/upload.c @@ -93,8 +93,6 @@ do_download (const char *filename) int fd, r, is_dev; char buf[GUESTFS_MAX_CHUNK_SIZE]; - REQUIRE_ROOT_OR_RESOLVE_DEVICE (filename, return -1); - is_dev = strncmp (filename, "/dev/", 5) == 0; if (!is_dev) CHROOT_IN; diff --git a/src/generator.ml b/src/generator.ml index 072b9f4..70ccbef 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -3738,7 +3738,7 @@ let mapi f xs = loop 0 xs let name_of_argt = function - | Pathname n | Device n | String n | OptString n | StringList n | Bool n | Int n + | Pathname n | Device n | Dev_or_Path n | String n | OptString n | StringList n | Bool n | Int n | FileIn n | FileOut n -> n let java_name_of_struct typ = @@ -4125,7 +4125,7 @@ and generate_xdr () = pr "struct %s_args {\n" name; List.iter ( function - | Pathname n | Device n | String n -> pr " string %s<>;\n" n + | Pathname n | Device n | Dev_or_Path n | String n -> pr " string %s<>;\n" n | OptString n -> pr " str *%s;\n" n | StringList n -> pr " str %s<>;\n" n | Bool n -> pr " bool %s;\n" n @@ -4486,7 +4486,7 @@ check_state (guestfs_h *g, const char *caller) | args -> List.iter ( function - | Pathname n | Device n | String n -> + | Pathname n | Device n | Dev_or_Path n | String n -> pr " args.%s = (char *) %s;\n" n n | OptString n -> pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n @@ -4691,7 +4691,7 @@ and generate_daemon_actions () = pr " struct guestfs_%s_args args;\n" name; List.iter ( function - | Device n + | Device n | Dev_or_Path n | Pathname n | String n -> () | OptString n -> pr " char *%s;\n" n @@ -4720,6 +4720,9 @@ and generate_daemon_actions () = | Device n -> pr " char *%s = args.%s;\n" n n; pr " RESOLVE_DEVICE (%s, goto done);" n; + | Dev_or_Path n -> + pr " char *%s = args.%s;\n" n n; + pr " REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, goto done);" n; | String n -> pr " char *%s = args.%s;\n" n n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> @@ -5633,6 +5636,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = | OptString n, "NULL" -> () | Pathname n, arg | Device n, arg + | Dev_or_Path n, arg | String n, arg | OptString n, arg -> pr " const char *%s = \"%s\";\n" n (c_quote arg); @@ -5681,7 +5685,7 @@ and generate_test_command_call ?(expect_error = false) ?test test_name cmd = function | OptString _, "NULL" -> pr ", NULL" | Pathname n, _ - | Device n, _ + | Device n, _ | Dev_or_Path n, _ | String n, _ | OptString n, _ -> pr ", %s" n @@ -5931,7 +5935,7 @@ and generate_fish_cmds () = List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | OptString n | FileIn n @@ -5953,7 +5957,7 @@ and generate_fish_cmds () = fun i -> function | Pathname name - | Device name | String name -> pr " %s = argv[%d];\n" name i + | Device name | Dev_or_Path name | String name -> pr " %s = argv[%d];\n" name i | OptString name -> pr " %s = strcmp (argv[%d], \"\") != 0 ? argv[%d] : NULL;\n" name i i @@ -6186,7 +6190,7 @@ and generate_fish_actions_pod () = pr " %s" name; List.iter ( function - | Pathname n | Device n | String n -> pr " %s" n + | Pathname n | Device n | Dev_or_Path n | String n -> pr " %s" n | OptString n -> pr " %s" n | StringList n -> pr " '%s ...'" n | Bool _ -> pr " true|false" @@ -6253,7 +6257,7 @@ and generate_prototype ?(extern = true) ?(static = false) ?(semicolon = true) List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | OptString n -> next (); @@ -6516,7 +6520,7 @@ copy_table (char * const * argv) List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> @@ -6569,7 +6573,7 @@ copy_table (char * const * argv) function | StringList n -> pr " ocaml_guestfs_free_strings (%s);\n" n; - | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | Dev_or_Path _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () ) (snd style); @@ -6653,7 +6657,7 @@ and generate_ocaml_prototype ?(is_external = false) name style = pr "%s : t -> " name; List.iter ( function - | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "string -> " + | Pathname _ | Device _ | Dev_or_Path _ | String _ | FileIn _ | FileOut _ -> pr "string -> " | OptString _ -> pr "string option -> " | StringList _ -> pr "string array -> " | Bool _ -> pr "bool -> " @@ -6798,7 +6802,7 @@ DESTROY (g) iteri ( fun i -> function - | Pathname n | Device n | String n | FileIn n | FileOut n -> + | Pathname n | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> pr " char *%s;\n" n | OptString n -> (* http://www.perlmonks.org/?node_id=554277 @@ -6814,7 +6818,7 @@ DESTROY (g) let do_cleanups () = List.iter ( function - | Pathname _ | Device _ | String _ | OptString _ | Bool _ | Int _ + | Pathname _ | Device _ | Dev_or_Path _ | String _ | OptString _ | Bool _ | Int _ | FileIn _ | FileOut _ -> () | StringList n -> pr " free (%s);\n" n ) (snd style) @@ -7186,7 +7190,7 @@ and generate_perl_prototype name style = if !comma then pr ", "; comma := true; match arg with - | Pathname n | Device n | String n + | Pathname n | Device n | Dev_or_Path n | String n | OptString n | Bool n | Int n | FileIn n | FileOut n -> pr "$%s" n | StringList n -> @@ -7434,7 +7438,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Pathname n | Device n | String n | FileIn n | FileOut n -> + | Pathname n | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> pr " const char *%s;\n" n | OptString n -> pr " const char *%s;\n" n | StringList n -> @@ -7450,7 +7454,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " if (!PyArg_ParseTuple (args, (char *) \"O"; List.iter ( function - | Pathname _ | Device _ | String _ | FileIn _ | FileOut _ -> pr "s" + | Pathname _ | Device _ | Dev_or_Path _ | String _ | FileIn _ | FileOut _ -> pr "s" | OptString _ -> pr "z" | StringList _ -> pr "O" | Bool _ -> pr "i" (* XXX Python has booleans? *) @@ -7460,7 +7464,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " &py_g"; List.iter ( function - | Pathname n | Device n | String n | FileIn n | FileOut n -> pr ", &%s" n + | Pathname n | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> pr ", &%s" n | OptString n -> pr ", &%s" n | StringList n -> pr ", &py_%s" n | Bool n -> pr ", &%s" n @@ -7473,7 +7477,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " g = get_handle (py_g);\n"; List.iter ( function - | Pathname _ | Device _ | String _ + | Pathname _ | Device _ | Dev_or_Path _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " %s = get_string_list (py_%s);\n" n n; @@ -7488,7 +7492,7 @@ py_guestfs_close (PyObject *self, PyObject *args) List.iter ( function - | Pathname _ | Device _ | String _ + | Pathname _ | Device _ | Dev_or_Path _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -7797,7 +7801,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Pathname n | Device n | String n | FileIn n | FileOut n -> + | Pathname n | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> pr " Check_Type (%sv, T_STRING);\n" n; pr " const char *%s = StringValueCStr (%sv);\n" n n; pr " if (!%s)\n" n; @@ -7849,7 +7853,7 @@ static VALUE ruby_guestfs_close (VALUE gv) List.iter ( function - | Pathname _ | Device _ | String _ + | Pathname _ | Device _ | Dev_or_Path _ | String _ | FileIn _ | FileOut _ | OptString _ | Bool _ | Int _ -> () | StringList n -> pr " free (%s);\n" n @@ -8161,7 +8165,7 @@ and generate_java_prototype ?(public=false) ?(privat=false) ?(native=false) match arg with | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | OptString n | FileIn n @@ -8280,7 +8284,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | OptString n | FileIn n @@ -8333,7 +8337,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | OptString n | FileIn n @@ -8363,7 +8367,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> @@ -8396,7 +8400,7 @@ Java_com_redhat_et_libguestfs_GuestFS__1close List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> @@ -8671,7 +8675,7 @@ last_error h = do function | FileIn n | FileOut n - | Pathname n | Device n | String n -> pr "withCString %s $ \\%s -> " n n + | Pathname n | Device n | Dev_or_Path n | String n -> pr "withCString %s $ \\%s -> " n n | OptString n -> pr "maybeWith withCString %s $ \\%s -> " n n | StringList n -> pr "withMany withCString %s $ \\%s -> withArray0 nullPtr %s $ \\%s -> " n n n n | Bool _ | Int _ -> () @@ -8683,7 +8687,7 @@ last_error h = do | Bool n -> sprintf "(fromBool %s)" n | Int n -> sprintf "(fromIntegral %s)" n | FileIn n | FileOut n - | Pathname n | Device n | String n | OptString n | StringList n -> n + | Pathname n | Device n | Dev_or_Path n | String n | OptString n | StringList n -> n ) (snd style) in pr "withForeignPtr h (\\p -> c_%s %s)\n" name (String.concat " " ("p" :: args)); @@ -8733,7 +8737,7 @@ and generate_haskell_prototype ~handle ?(hs = false) style = List.iter ( fun arg -> (match arg with - | Pathname _ | Device _ | String _ -> pr "%s" string + | Pathname _ | Device _ | Dev_or_Path _ | String _ -> pr "%s" string | OptString _ -> if hs then pr "Maybe String" else pr "CString" | StringList _ -> if hs then pr "[String]" else pr "Ptr CString" | Bool _ -> pr "%s" bool @@ -8809,7 +8813,7 @@ print_strings (char * const* const argv) List.iter ( function | Pathname n - | Device n + | Device n | Dev_or_Path n | String n | FileIn n | FileOut n -> pr " printf (\"%%s\\n\", %s);\n" n -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:57PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* src/generator.ml: Update all rules to handle Dev_or_Path. (the above changes to generator.ml are mostly mechanical) Emit a use of REQUIRE_ROOT_OR_RESOLVE_DEVICE. * daemon/upload.c (do_download): Remove use of REQUIRE_ROOT_OR_RESOLVE_DEVICE, now that it's automatically done in calling code. * daemon/file.c (do_file): Likewise.
ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
From: Jim Meyering <meyering@redhat.com> --- src/generator.ml | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index 70ccbef..256283f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4712,18 +4712,21 @@ and generate_daemon_actions () = pr " reply_with_error (\"%%s: daemon failed to decode procedure arguments\", \"%s\");\n" name; pr " return;\n"; pr " }\n"; + let pr_args n = + pr " char *%s = args.%s;\n" n n + in List.iter ( function | Pathname n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " ABS_PATH (%s, goto done);\n" n; | Device n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " RESOLVE_DEVICE (%s, goto done);" n; | Dev_or_Path n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, goto done);" n; - | String n -> pr " char *%s = args.%s;\n" n n + | String n -> pr_args n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:58PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
--- src/generator.ml | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/src/generator.ml b/src/generator.ml index 70ccbef..256283f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -4712,18 +4712,21 @@ and generate_daemon_actions () = pr " reply_with_error (\"%%s: daemon failed to decode procedure arguments\", \"%s\");\n" name; pr " return;\n"; pr " }\n"; + let pr_args n = + pr " char *%s = args.%s;\n" n n + in List.iter ( function | Pathname n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " ABS_PATH (%s, goto done);\n" n; | Device n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " RESOLVE_DEVICE (%s, goto done);" n; | Dev_or_Path n -> - pr " char *%s = args.%s;\n" n n; + pr_args n; pr " REQUIRE_ROOT_OR_RESOLVE_DEVICE (%s, goto done);" n; - | String n -> pr " char *%s = args.%s;\n" n n + | String n -> pr_args n | OptString n -> pr " %s = args.%s ? *args.%s : NULL;\n" n n n | StringList n -> pr " %s = realloc (args.%s.%s_val,\n" n n n; -- 1.6.4.337.g5420e
As discussed before, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://et.redhat.com/~rjones/virt-df/
From: Jim Meyering <meyering@redhat.com> * daemon/mount.c (do_umount): Don't use RESOLVE_DEVICE here, now that the caller always invokes REQUIRE_ROOT_OR_RESOLVE_DEVICE. --- daemon/mount.c | 22 +++++++++------------- 1 files changed, 9 insertions(+), 13 deletions(-) diff --git a/daemon/mount.c b/daemon/mount.c index 9ccb37b..4f74c02 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -105,24 +105,20 @@ do_mount_options (const char *options, const char *device, int do_umount (const char *pathordevice) { - int freeit = 0, r; - const char *buf; + int r; char *err; - if (strncmp (pathordevice, "/dev/", 5) == 0) { - buf = pathordevice; - RESOLVE_DEVICE (buf, return -1); - } else { - buf = sysroot_path (pathordevice); - if (buf == NULL) { - reply_with_perror ("malloc"); - return -1; - } - freeit = 1; + char *buf = (strncmp (pathordevice, "/dev/", 5) == 0 + ? strdup (pathordevice) + : sysroot_path (pathordevice)); + if (buf == NULL) { + reply_with_perror ("malloc"); + return -1; } r = command (NULL, &err, "umount", buf, NULL); - if (freeit) free (buf); + free (buf); + if (r == -1) { reply_with_error ("umount: %s: %s", pathordevice, err); free (err); -- 1.6.4.337.g5420e
On Wed, Aug 12, 2009 at 06:52:59PM +0200, Jim Meyering wrote:
From: Jim Meyering <meyering@redhat.com>
* daemon/mount.c (do_umount): Don't use RESOLVE_DEVICE here, now that the caller always invokes REQUIRE_ROOT_OR_RESOLVE_DEVICE. --- daemon/mount.c | 22 +++++++++------------- 1 files changed, 9 insertions(+), 13 deletions(-)
diff --git a/daemon/mount.c b/daemon/mount.c index 9ccb37b..4f74c02 100644 --- a/daemon/mount.c +++ b/daemon/mount.c @@ -105,24 +105,20 @@ do_mount_options (const char *options, const char *device, int do_umount (const char *pathordevice) { - int freeit = 0, r; - const char *buf; + int r; char *err;
- if (strncmp (pathordevice, "/dev/", 5) == 0) { - buf = pathordevice; - RESOLVE_DEVICE (buf, return -1); - } else { - buf = sysroot_path (pathordevice); - if (buf == NULL) { - reply_with_perror ("malloc"); - return -1; - } - freeit = 1; + char *buf = (strncmp (pathordevice, "/dev/", 5) == 0 + ? strdup (pathordevice) + : sysroot_path (pathordevice)); + if (buf == NULL) { + reply_with_perror ("malloc"); + return -1; }
r = command (NULL, &err, "umount", buf, NULL); - if (freeit) free (buf); + free (buf); + if (r == -1) { reply_with_error ("umount: %s: %s", pathordevice, err); free (err); -- 1.6.4.337.g5420e
As discussed before, ACK. Rich. -- Richard Jones, Emerging Technologies, Red Hat http://et.redhat.com/~rjones virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://et.redhat.com/~rjones/virt-top
participants (2)
-
Jim Meyering -
Richard W.M. Jones