chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fstab-generator: make error more helpful in case of duplicates in fstab
[elogind.git]
/
src
/
fstab-generator
/
fstab-generator.c
diff --git
a/src/fstab-generator/fstab-generator.c
b/src/fstab-generator/fstab-generator.c
index f832730b4041ee2bb8e2ce29d1a3e7bd6750f88f..ba55f2c2b73d0ce09bbd59232b4cbbe54c94e998 100644
(file)
--- a/
src/fstab-generator/fstab-generator.c
+++ b/
src/fstab-generator/fstab-generator.c
@@
-47,7
+47,7
@@
static int device_name(const char *path, char **unit) {
p = unit_name_from_path(path, ".device");
if (!p)
p = unit_name_from_path(path, ".device");
if (!p)
- return
-ENOMEM
;
+ return
log_oom()
;
*unit = p;
return 1;
*unit = p;
return 1;
@@
-98,22
+98,23
@@
static int add_swap(const char *what, struct mntent *me) {
name = unit_name_from_path(what, ".swap");
if (!name) {
name = unit_name_from_path(what, ".swap");
if (!name) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
goto finish;
}
- unit = join(arg_dest, "/", name, NULL);
+ unit =
str
join(arg_dest, "/", name, NULL);
if (!unit) {
if (!unit) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
f = fopen(unit, "wxe");
if (!f) {
r = -errno;
goto finish;
}
f = fopen(unit, "wxe");
if (!f) {
r = -errno;
- log_error("Failed to create unit file: %m");
+ if (errno == EEXIST)
+ log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
+ else
+ log_error("Failed to create unit file %s: %m", unit);
goto finish;
}
goto finish;
}
@@
-140,45
+141,40
@@
static int add_swap(const char *what, struct mntent *me) {
fflush(f);
if (ferror(f)) {
fflush(f);
if (ferror(f)) {
- log_error("Failed to write unit file
: %m"
);
+ log_error("Failed to write unit file
%s: %m", unit
);
r = -errno;
goto finish;
}
if (!noauto) {
r = -errno;
goto finish;
}
if (!noauto) {
- lnk = join(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
+ lnk =
str
join(arg_dest, "/" SPECIAL_SWAP_TARGET ".wants/", name, NULL);
if (!lnk) {
if (!lnk) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
- log_error("Failed to create symlink
: %m"
);
+ log_error("Failed to create symlink
%s: %m", lnk
);
r = -errno;
goto finish;
}
r = device_name(what, &device);
r = -errno;
goto finish;
}
r = device_name(what, &device);
- if (r < 0) {
- log_error("Out of memory");
- r = -ENOMEM;
+ if (r < 0)
goto finish;
goto finish;
- }
if (r > 0) {
free(lnk);
if (r > 0) {
free(lnk);
- lnk = join(arg_dest, "/", device, ".wants/", name, NULL);
+ lnk =
str
join(arg_dest, "/", device, ".wants/", name, NULL);
if (!lnk) {
if (!lnk) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
- log_error("Failed to create symlink
: %m"
);
+ log_error("Failed to create symlink
%s: %m", lnk
);
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
@@
-198,14
+194,6
@@
finish:
return r;
}
return r;
}
-static bool mount_is_bind(struct mntent *me) {
- assert(me);
-
- return
- hasmntopt(me, "bind") ||
- streq(me->mnt_opts, "bind");
-}
-
static bool mount_is_network(struct mntent *me) {
assert(me);
static bool mount_is_network(struct mntent *me) {
assert(me);
@@
-238,7
+226,7
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
return 0;
isnetwork = mount_is_network(me);
return 0;
isnetwork = mount_is_network(me);
- isbind =
mount_is_bind(me
);
+ isbind =
!!hasmntopt(me, "bind"
);
noauto = !!hasmntopt(me, "noauto");
nofail = !!hasmntopt(me, "nofail");
noauto = !!hasmntopt(me, "noauto");
nofail = !!hasmntopt(me, "nofail");
@@
-255,23
+243,24
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
}
name = unit_name_from_path(where, ".mount");
}
name = unit_name_from_path(where, ".mount");
- if (!name) {
- log_error("Out of memory");
- r = -ENOMEM;
+ if (!name) {
+ r = log_oom();
goto finish;
}
goto finish;
}
- unit = join(arg_dest, "/", name, NULL);
+ unit =
str
join(arg_dest, "/", name, NULL);
if (!unit) {
if (!unit) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
f = fopen(unit, "wxe");
if (!f) {
r = -errno;
goto finish;
}
f = fopen(unit, "wxe");
if (!f) {
r = -errno;
- log_error("Failed to create unit file: %m");
+ if (errno == EEXIST)
+ log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
+ else
+ log_error("Failed to create unit file %s: %m", unit);
goto finish;
}
goto finish;
}
@@
-315,22
+304,21
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
fflush(f);
if (ferror(f)) {
fflush(f);
if (ferror(f)) {
- log_error("Failed to write unit file
: %m"
);
+ log_error("Failed to write unit file
%s: %m", unit
);
r = -errno;
goto finish;
}
if (!noauto) {
r = -errno;
goto finish;
}
if (!noauto) {
- lnk = join(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
+ lnk =
str
join(arg_dest, "/", post, nofail || automount ? ".wants/" : ".requires/", name, NULL);
if (!lnk) {
if (!lnk) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
- log_error("Failed to create symlink
: %m"
);
+ log_error("Failed to create symlink
%s: %m", lnk
);
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
@@
-339,24
+327,20
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
!path_equal(where, "/")) {
r = device_name(what, &device);
!path_equal(where, "/")) {
r = device_name(what, &device);
- if (r < 0) {
- log_error("Out of memory");
- r = -ENOMEM;
+ if (r < 0)
goto finish;
goto finish;
- }
if (r > 0) {
free(lnk);
if (r > 0) {
free(lnk);
- lnk = join(arg_dest, "/", device, ".wants/", name, NULL);
+ lnk =
str
join(arg_dest, "/", device, ".wants/", name, NULL);
if (!lnk) {
if (!lnk) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(unit, lnk) < 0) {
- log_error("Failed to creat
symlink: %m"
);
+ log_error("Failed to creat
e symlink %s: %m", lnk
);
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
@@
-367,15
+351,13
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
if (automount && !path_equal(where, "/")) {
automount_name = unit_name_from_path(where, ".automount");
if (!name) {
if (automount && !path_equal(where, "/")) {
automount_name = unit_name_from_path(where, ".automount");
if (!name) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
goto finish;
}
- automount_unit = join(arg_dest, "/", automount_name, NULL);
+ automount_unit =
str
join(arg_dest, "/", automount_name, NULL);
if (!automount_unit) {
if (!automount_unit) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
goto finish;
}
@@
-383,7
+365,7
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
f = fopen(automount_unit, "wxe");
if (!f) {
r = -errno;
f = fopen(automount_unit, "wxe");
if (!f) {
r = -errno;
- log_error("Failed to create unit file
: %m"
);
+ log_error("Failed to create unit file
%s: %m", automount_unit
);
goto finish;
}
goto finish;
}
@@
-402,22
+384,21
@@
static int add_mount(const char *what, const char *where, struct mntent *me) {
fflush(f);
if (ferror(f)) {
fflush(f);
if (ferror(f)) {
- log_error("Failed to write unit file
: %m"
);
+ log_error("Failed to write unit file
%s: %m", automount_unit
);
r = -errno;
goto finish;
}
free(lnk);
r = -errno;
goto finish;
}
free(lnk);
- lnk = join(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
+ lnk =
str
join(arg_dest, "/", post, nofail ? ".wants/" : ".requires/", automount_name, NULL);
if (!lnk) {
if (!lnk) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(automount_unit, lnk) < 0) {
goto finish;
}
mkdir_parents_label(lnk, 0755);
if (symlink(automount_unit, lnk) < 0) {
- log_error("Failed to create symlink
: %m"
);
+ log_error("Failed to create symlink
%s: %m", lnk
);
r = -errno;
goto finish;
}
r = -errno;
goto finish;
}
@@
-459,16
+440,14
@@
static int parse_fstab(void) {
what = fstab_node_to_udev_node(me->mnt_fsname);
if (!what) {
what = fstab_node_to_udev_node(me->mnt_fsname);
if (!what) {
- log_error("Out of memory");
- r = -ENOMEM;
+ r = log_oom();
goto finish;
}
where = strdup(me->mnt_dir);
if (!where) {
goto finish;
}
where = strdup(me->mnt_dir);
if (!where) {
-
log_error("Out of memory"
);
+
r = log_oom(
);
free(what);
free(what);
- r = -ENOMEM;
goto finish;
}
goto finish;
}
@@
-513,7
+492,7
@@
static int parse_proc_cmdline(void) {
word = strndup(w, l);
if (!word) {
word = strndup(w, l);
if (!word) {
- r =
-ENOMEM
;
+ r =
log_oom()
;
goto finish;
}
goto finish;
}