echo Starting /init script ...
-PATH=/sbin:/usr/sbin:$PATH
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+export PATH
mount -t proc /proc /proc
mount -t sysfs /sys /sys
int r;
r = command (&out, &err,
- "/sbin/blkid", "-o", "value", "-s", "TYPE", device, NULL);
+ "blkid", "-o", "value", "-s", "TYPE", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (out);
int64_t rv;
char *out, *err;
const char *argv[] = {
- "/sbin/blockdev",
+ "blockdev",
switc,
NULL,
NULL,
extern int device_name_translation (char *device, const char *func);
+extern int prog_exists (const char *prog);
+
extern void udev_settle (void);
/* This just stops gcc from giving a warning about our custom
p++;
*p = '4';
- if (access (name, X_OK) == 0)
+ if (prog_exists (name))
return 0;
*p = '2';
- if (access (name, X_OK) == 0)
+ if (prog_exists (name))
return 0;
reply_with_error ("cannot find required program %s", name);
char **ret = NULL;
int size = 0, alloc = 0;
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return NULL;
int r;
char *err;
- char prog[] = "/sbin/e2label";
+ char prog[] = "e2label";
if (e2prog (prog) == -1)
return -1;
int r, len;
char *out, *err;
- char prog[] = "/sbin/e2label";
+ char prog[] = "e2label";
if (e2prog (prog) == -1)
return NULL;
int r;
char *err;
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return -1;
* to use tune2fs -l and then look for a particular string in
* the output.
*/
- char prog[] = "/sbin/tune2fs";
+ char prog[] = "tune2fs";
if (e2prog (prog) == -1)
return NULL;
char *err;
int r;
- char prog[] = "/sbin/resize2fs";
+ char prog[] = "resize2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/e2fsck";
+ char prog[] = "e2fsck";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- char prog[] = "/sbin/mke2fs";
+ char prog[] = "mke2fs";
if (e2prog (prog) == -1)
return -1;
char *err;
int r;
- r = commandr (NULL, &err, "/sbin/fsck", "-a", "-t", fstype, device, NULL);
+ r = commandr (NULL, &err, "fsck", "-a", "-t", fstype, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
return -1;
}
- r = command (NULL, &err, "/sbin/grub-install", buf, device, NULL);
+ r = command (NULL, &err, "grub-install", buf, device, NULL);
free (buf);
if (r == -1) {
/* Set up a basic environment. After we are called by /init the
* environment is essentially empty.
* https://bugzilla.redhat.com/show_bug.cgi?id=502074#c5
+ *
+ * NOTE: if you change $PATH, you must also change 'prog_exists'
+ * function below.
*/
- setenv ("PATH", "/usr/bin:/bin", 1);
+ setenv ("PATH", "/sbin:/usr/sbin:/bin:/usr/bin", 1);
setenv ("SHELL", "/bin/sh", 1);
setenv ("LC_ALL", "C", 1);
goto error;
}
+/* Check program exists and is executable on $PATH. Actually, we
+ * just assume PATH contains the default entries (see main() above).
+ */
+int
+prog_exists (const char *prog)
+{
+ static const char *dirs[] =
+ { "/sbin", "/usr/sbin", "/bin", "/usr/bin" };
+ size_t i;
+ char buf[1024];
+
+ for (i = 0; i < sizeof dirs / sizeof dirs[0]; ++i) {
+ snprintf (buf, sizeof buf, "%s/%s", dirs[i], prog);
+ if (access (buf, X_OK) == 0)
+ return 1;
+ }
+ return 0;
+}
+
/* LVM and other commands aren't synchronous, especially when udev is
* involved. eg. You can create or remove some device, but the /dev
* device node won't appear until some time later. This means that
void
udev_settle (void)
{
- (void) command (NULL, NULL, "/sbin/udevadm", "settle", NULL);
- (void) command (NULL, NULL, "/sbin/udevsettle", NULL);
+ (void) command (NULL, NULL, "udevadm", "settle", NULL);
+ (void) command (NULL, NULL, "udevsettle", NULL);
}
int
optgroup_lvm2_available (void)
{
- int r = access ("/sbin/lvm", X_OK);
- return r == 0;
+ return prog_exists ("lvm");
}
/* LVM actions. Keep an eye on liblvm, although at the time
int r;
r = command (&out, &err,
- "/sbin/lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
+ "lvm", "pvs", "-o", "pv_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
int r;
r = command (&out, &err,
- "/sbin/lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
+ "lvm", "vgs", "-o", "vg_name", "--noheadings", NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (out);
int r;
r = command (&out, &err,
- "/sbin/lvm", "lvs",
+ "lvm", "lvs",
"-o", "vg_name,lv_name", "--noheadings",
"--separator", "/", NULL);
if (r == -1) {
int r;
r = command (NULL, &err,
- "/sbin/lvm", "pvcreate", device, NULL);
+ "lvm", "pvcreate", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
reply_with_perror ("malloc");
return -1;
}
- argv[0] = "/sbin/lvm";
+ argv[0] = "lvm";
argv[1] = "vgcreate";
argv[2] = volgroup;
for (i = 3; i <= argc; ++i)
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "/sbin/lvm", "lvcreate",
+ "lvm", "lvcreate",
"-L", size, "-n", logvol, volgroup, NULL);
if (r == -1) {
reply_with_error ("%s", err);
snprintf (size, sizeof size, "%d", mbytes);
r = command (NULL, &err,
- "/sbin/lvm", "lvresize",
+ "lvm", "lvresize",
"-L", size, logvol, NULL);
if (r == -1) {
reply_with_error ("%s", err);
return -1;
for (i = 0; xs[i] != NULL; ++i) {
- r = command (NULL, &err, "/sbin/lvm", "lvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, "lvm", "lvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("lvremove: %s: %s", xs[i], err);
free (err);
return -1;
for (i = 0; xs[i] != NULL; ++i) {
- r = command (NULL, &err, "/sbin/lvm", "vgremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, "lvm", "vgremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("vgremove: %s: %s", xs[i], err);
free (err);
return -1;
for (i = 0; xs[i] != NULL; ++i) {
- r = command (NULL, &err, "/sbin/lvm", "pvremove", "-f", xs[i], NULL);
+ r = command (NULL, &err, "lvm", "pvremove", "-f", xs[i], NULL);
if (r == -1) {
reply_with_error ("pvremove: %s: %s", xs[i], err);
free (err);
int r;
r = command (NULL, &err,
- "/sbin/lvm", "lvremove", "-f", device, NULL);
+ "lvm", "lvremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
int r;
r = command (NULL, &err,
- "/sbin/lvm", "vgremove", "-f", device, NULL);
+ "lvm", "vgremove", "-f", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
int r;
r = command (NULL, &err,
- "/sbin/lvm", "pvremove", "-ff", device, NULL);
+ "lvm", "pvremove", "-ff", device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
free (err);
int r;
r = command (NULL, &err,
- "/sbin/lvm", "pvresize", device, NULL);
+ "lvm", "pvresize", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
return -1;
}
- argv[0] = "/sbin/lvm";
+ argv[0] = "lvm";
argv[1] = "vgchange";
argv[2] = "-a";
argv[3] = activate ? "y" : "n";
int r;
r = command (NULL, &err,
- "/sbin/lvm", "lvrename",
+ "lvm", "lvrename",
logvol, newlogvol, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", logvol, newlogvol, err);
int r;
r = command (NULL, &err,
- "/sbin/lvm", "vgrename",
+ "lvm", "vgrename",
volgroup, newvolgroup, NULL);
if (r == -1) {
reply_with_error ("%s -> %s: %s", volgroup, newvolgroup, err);
char *out;
char *err;
int r = command (&out, &err,
- "/sbin/lvm", cmd,
+ "lvm", cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
char *out;
char *err;
int r = command (&out, &err,
- "/sbin/lvm", cmd,
+ "lvm", cmd,
"--unbuffered", "--noheadings", "-o", field,
device, NULL);
if (r == -1) {
int r;
char *err;
- argv[i++] = "/sbin/mkfs";
+ argv[i++] = "mkfs";
argv[i++] = "-t";
argv[i++] = fstype;
int
optgroup_linuxmodules_available (void)
{
- int r = access ("/sbin/modprobe", X_OK);
- return r == 0;
+ return prog_exists ("modprobe");
}
int
do_modprobe (const char *module)
{
char *err;
- int r = command (NULL, &err, "/sbin/modprobe", module, NULL);
+ int r = command (NULL, &err, "modprobe", module, NULL);
if (r == -1) {
reply_with_error ("%s", err);
"Error informing the kernel about modifications to partition"))
return -1;
- r = command (NULL, NULL, "/sbin/blockdev", "--rereadpt", device, NULL);
+ r = command (NULL, NULL, "blockdev", "--rereadpt", device, NULL);
if (r == -1)
return -1;
char *err; \
\
r = commandf (NULL, &err, COMMAND_FLAG_FOLD_STDOUT_ON_STDERR, \
- "/sbin/parted", "-s", "--", (device), __VA_ARGS__); \
+ "parted", "-s", "--", (device), __VA_ARGS__); \
if (r == -1) { \
if (recover_blkrrpart ((device), err) == -1) { \
reply_with_error ("%s: parted: %s: %s", __func__, (device), err); \
int r;
char **lines;
- r = command (&out, &err, "/sbin/parted", "-m", "--", device,
+ r = command (&out, &err, "parted", "-m", "--", device,
"unit", "b",
"print", NULL);
if (r == -1) {
int
optgroup_scrub_available (void)
{
- int r = access ("/usr/bin/scrub", X_OK);
- return r == 0;
+ return prog_exists ("scrub");
}
int
char buf[256];
int i;
- strcpy (buf, "/sbin/sfdisk");
+ strcpy (buf, "sfdisk");
if (n > 0)
sprintf (buf + strlen (buf), " -N %d", n);
char *out, *err;
int r;
- r = command (&out, &err, "/sbin/sfdisk", flag, device, NULL);
+ r = command (&out, &err, "sfdisk", flag, device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (out);
int av;
/* Ignore return code - mkswap --help *will* fail. */
- command (NULL, &err, "/sbin/mkswap", "--help", NULL);
+ command (NULL, &err, "mkswap", "--help", NULL);
av = strstr (err, "-U") != NULL;
free (err);
int r;
if (!flag)
- r = command (NULL, &err, "/sbin/mkswap", "-f", device, NULL);
+ r = command (NULL, &err, "mkswap", "-f", device, NULL);
else
- r = command (NULL, &err, "/sbin/mkswap", "-f", flag, value, device, NULL);
+ r = command (NULL, &err, "mkswap", "-f", flag, value, device, NULL);
if (r == -1) {
reply_with_error ("%s", err);
int
do_swapon_device (const char *device)
{
- return swaponoff ("/sbin/swapon", NULL, device);
+ return swaponoff ("swapon", NULL, device);
}
int
do_swapoff_device (const char *device)
{
- return swaponoff ("/sbin/swapoff", NULL, device);
+ return swaponoff ("swapoff", NULL, device);
}
int
return -1;
}
- r = swaponoff ("/sbin/swapon", NULL, buf);
+ r = swaponoff ("swapon", NULL, buf);
free (buf);
return r;
}
return -1;
}
- r = swaponoff ("/sbin/swapoff", NULL, buf);
+ r = swaponoff ("swapoff", NULL, buf);
free (buf);
return r;
}
int
do_swapon_label (const char *label)
{
- return swaponoff ("/sbin/swapon", "-L", label);
+ return swaponoff ("swapon", "-L", label);
}
int
do_swapoff_label (const char *label)
{
- return swaponoff ("/sbin/swapoff", "-L", label);
+ return swaponoff ("swapoff", "-L", label);
}
int
do_swapon_uuid (const char *uuid)
{
- return swaponoff ("/sbin/swapon", "-U", uuid);
+ return swaponoff ("swapon", "-U", uuid);
}
int
do_swapoff_uuid (const char *uuid)
{
- return swaponoff ("/sbin/swapoff", "-U", uuid);
+ return swaponoff ("swapoff", "-U", uuid);
}
int
optgroup_zerofree_available (void)
{
- int r = access ("/usr/sbin/zerofree", X_OK);
- return r == 0;
+ return prog_exists ("zerofree");
}
int
char *err;
int r;
- r = command (NULL, &err, "/usr/sbin/zerofree", device, NULL);
+ r = command (NULL, &err, "zerofree", device, NULL);
if (r == -1) {
reply_with_error ("%s: %s", device, err);
free (err);
pr " ret->guestfs_int_lvm_%s_list_val = NULL;\n" typ;
pr "\n";
pr " r = command (&out, &err,\n";
- pr " \"/sbin/lvm\", \"%ss\",\n" typ;
+ pr " \"lvm\", \"%ss\",\n" typ;
pr " \"-o\", lvm_%s_cols, \"--unbuffered\", \"--noheadings\",\n" typ;
pr " \"--nosuffix\", \"--separator\", \",\", \"--units\", \"b\", NULL);\n";
pr " if (r == -1) {\n";