Skip to content

Commit

Permalink
generator.ml: use new "Pathname" designation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Jim Meyering committed Aug 13, 2009
1 parent 79b5084 commit 84fc760
Show file tree
Hide file tree
Showing 43 changed files with 206 additions and 339 deletions.
23 changes: 10 additions & 13 deletions daemon/augeas.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 11 additions & 11 deletions daemon/blockdev.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
5 changes: 1 addition & 4 deletions daemon/checksum.c
Expand Up @@ -28,17 +28,14 @@
#include "actions.h"

char *
do_checksum (char *csumtype, char *path)
do_checksum (const char *csumtype, const char *path)
{
const char *program;
char *buf;
char *out, *err;
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)
Expand Down
2 changes: 1 addition & 1 deletion daemon/cmp.c
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions daemon/command.c
Expand Up @@ -132,15 +132,15 @@ do_command_lines (char **argv)
}

char *
do_sh (char *command)
do_sh (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };

return do_command (argv);
}

char **
do_sh_lines (char *command)
do_sh_lines (const char *command)
{
char *argv[] = { "/bin/sh", "-c", command, NULL };

Expand Down
6 changes: 3 additions & 3 deletions daemon/cpmv.c
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion daemon/debug.c
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion daemon/devsparts.c
Expand Up @@ -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;
Expand Down
25 changes: 5 additions & 20 deletions daemon/dir.c
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions daemon/du.c
Expand Up @@ -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) {
Expand Down

0 comments on commit 84fc760

Please sign in to comment.