exit(1);
}
-int do_mkfs(const char *path, const char *fstype)
+int do_mkfs_exec_wrapper(void *args)
{
- pid_t pid;
+ int ret;
+ char *mkfs;
+ char **data = args;
+ /* strlen("mkfs.")
+ * +
+ * strlen(data[0])
+ * +
+ * \0
+ */
+ size_t len = 5 + strlen(data[0]) + 1;
- if ((pid = fork()) < 0) {
- ERROR("error forking");
+ mkfs = malloc(len);
+ if (!mkfs)
return -1;
- }
- if (pid > 0)
- return wait_for_pid(pid);
- // If the file is not a block device, we don't want mkfs to ask
- // us about whether to proceed.
- if (null_stdfds() < 0)
- exit(EXIT_FAILURE);
+ ret = snprintf(mkfs, len, "mkfs.%s", data[0]);
+ if (ret < 0 || (size_t)ret >= len)
+ return -1;
- execlp("mkfs", "mkfs", "-t", fstype, path, (char *)NULL);
- exit(EXIT_FAILURE);
+ TRACE("executing \"%s %s\"", mkfs, data[1]);
+ execlp(mkfs, mkfs, data[1], (char *)NULL);
+ SYSERROR("failed to run \"%s %s \"", mkfs, data[1]);
+ return -1;
}
/*
*/
int blk_getsize(struct bdev *bdev, uint64_t *size);
int detect_fs(struct bdev *bdev, char *type, int len);
-int do_mkfs(const char *path, const char *fstype);
+int do_mkfs_exec_wrapper(void *args);
int is_blktype(struct bdev *b);
int mount_unknown_fs(const char *rootfs, const char *target,
const char *options);
src += 5;
loopfd = lxc_prepare_loop_dev(src, loname, LO_FLAGS_AUTOCLEAR);
- if (loopfd < 0)
+ if (loopfd < 0) {
+ ERROR("failed to prepare loop device for loop file \"%s\"", src);
return -1;
+ }
DEBUG("prepared loop device \"%s\"", loname);
ret = mount_unknown_fs(loname, bdev->dest, bdev->mntopts);
static int do_loop_create(const char *path, uint64_t size, const char *fstype)
{
int fd, ret;
+ const char *cmd_args[2] = {fstype, path};
+ char cmd_output[MAXPATHLEN];
+
// create the new loopback file.
fd = creat(path, S_IRUSR|S_IWUSR);
if (fd < 0)
}
// create an fs in the loopback file
- if (do_mkfs(path, fstype) < 0) {
- ERROR("Error creating filesystem type %s on %s", fstype,
- path);
+ ret = run_command(cmd_output, sizeof(cmd_output), do_mkfs_exec_wrapper,
+ (void *)cmd_args);
+ if (ret < 0)
return -1;
- }
return 0;
}
char fstype[100];
uint64_t size = newsize;
int len, ret;
+ const char *cmd_args[2];
+ char cmd_output[MAXPATHLEN];
if (!orig->src || !orig->dest)
return -1;
ERROR("Error creating new lvm blockdev");
return -1;
}
- if (do_mkfs(new->src, fstype) < 0) {
- ERROR("Error creating filesystem type %s on %s", fstype,
- new->src);
+
+ cmd_args[0] = fstype;
+ cmd_args[1] = new->src;
+ // create an fs in the loopback file
+ ret = run_command(cmd_output, sizeof(cmd_output),
+ do_mkfs_exec_wrapper, (void *)cmd_args);
+ if (ret < 0)
return -1;
- }
}
return 0;
const char *vg, *thinpool, *fstype, *lv = n;
uint64_t sz;
int ret, len;
+ const char *cmd_args[2];
+ char cmd_output[MAXPATHLEN];
if (!specs)
return -1;
fstype = specs->fstype;
if (!fstype)
fstype = DEFAULT_FSTYPE;
- if (do_mkfs(bdev->src, fstype) < 0) {
- ERROR("Error creating filesystem type %s on %s", fstype,
- bdev->src);
+
+ cmd_args[0] = fstype;
+ cmd_args[1] = bdev->src;
+ ret = run_command(cmd_output, sizeof(cmd_output), do_mkfs_exec_wrapper,
+ (void *)cmd_args);
+ if (ret < 0)
return -1;
- }
+
if (!(bdev->dest = strdup(dest)))
return -1;
int ret, len;
char sz[24];
pid_t pid;
+ const char *cmd_args[2];
+ char cmd_output[MAXPATHLEN];
if (!specs)
return -1;
if (!fstype)
fstype = DEFAULT_FSTYPE;
- if (do_mkfs(bdev->src, fstype) < 0) {
- ERROR("Error creating filesystem type %s on %s", fstype,
- bdev->src);
+ cmd_args[0] = fstype;
+ cmd_args[1] = bdev->src;
+ ret = run_command(cmd_output, sizeof(cmd_output), do_mkfs_exec_wrapper,
+ (void *)cmd_args);
+ if (ret < 0)
return -1;
- }
+
if (!(bdev->dest = strdup(dest)))
return -1;