[systemd-devel] [PATCH] efi-boot-generator: Continue if /boot does not exist

Lennart Poettering lennart at poettering.net
Fri Apr 3 07:50:02 PDT 2015


On Wed, 01.04.15 22:53, Tobias Hunger (tobias.hunger at gmail.com) wrote:

> /boot does not exist on a stateless system, so do not get
> confused by that.
> ---
>  src/efi-boot-generator/efi-boot-generator.c | 23 +++++++++++++++++++----
>  1 file changed, 19 insertions(+), 4 deletions(-)
> 
> diff --git a/src/efi-boot-generator/efi-boot-generator.c b/src/efi-boot-generator/efi-boot-generator.c
> index 58c4cc2..938bbe2 100644
> --- a/src/efi-boot-generator/efi-boot-generator.c
> +++ b/src/efi-boot-generator/efi-boot-generator.c
> @@ -35,6 +35,7 @@ static const char *arg_dest = "/tmp";
>  int main(int argc, char *argv[]) {
>          _cleanup_free_ char *what = NULL;
>          _cleanup_fclose_ FILE *f = NULL;
> +        struct stat boot_stat;
>          int r = EXIT_SUCCESS;
>          sd_id128_t id;
>          char *name;
> @@ -68,10 +69,24 @@ int main(int argc, char *argv[]) {
>                  return EXIT_SUCCESS;
>          }
>  
> -        if (path_is_mount_point("/boot", true) <= 0 &&
> -            dir_is_empty("/boot") <= 0) {
> -                log_debug("/boot already populated, exiting.");
> -                return EXIT_SUCCESS;
> +        r = stat("/boot", &boot_stat);
> +        if (r < 0) {
> +                if (errno == ENOENT)
> +                        log_debug("/boot does not exist, continuing.");
> +                else {
> +                        log_debug("Failed to stat /boot, exiting.");
> +                        return EXIT_FAILURE;
> +                }
> +        } else {
> +                if (!S_ISDIR(boot_stat.st_mode) && !S_ISLNK(boot_stat.st_mode)) {
> +                        log_debug("/boot is not a directory or link, exiting.");
> +                        return EXIT_FAILURE;
> +                }
> +                if (path_is_mount_point("/boot", true) <= 0 &&
> +                    dir_is_empty("/boot") <= 0) {
> +                        log_debug("/boot already populated, exiting.");
> +                        return EXIT_SUCCESS;
> +                }

Hmm, path_is_mount_point() internally does the equivalent of stat()
anyway, and returns its error code as return value. Can't we simplify
this with that? Something like:

r = path_is_mount_point("/boot", true");
if (r != -ENOENT && r <= 0 && dir_isempty("/boot") <= 0)
   ....

or so?

Lennart

-- 
Lennart Poettering, Red Hat


More information about the systemd-devel mailing list