@@ -1382,6 +1382,39 @@ static void print_yes_no_line(bool first, bool good, const char *name) {
13821382 name );
13831383}
13841384
1385+ static int are_we_installed (void ) {
1386+ int r ;
1387+
1388+ r = acquire_esp (/* privileged_mode= */ false, /* graceful= */ false, NULL , NULL , NULL , NULL );
1389+ if (r < 0 )
1390+ return r ;
1391+
1392+ /* Tests whether systemd-boot is installed. It's not obvious what to use as check here: we could
1393+ * check EFI variables, we could check what binary /EFI/BOOT/BOOT*.EFI points to, or whether the
1394+ * loader entries directory exists. Here we opted to check whether /EFI/systemd/ is non-empty, which
1395+ * should be a suitable and very minimal check for a number of reasons:
1396+ *
1397+ * → The check is architecture independent (i.e. we check if any systemd-boot loader is installed,
1398+ * not a specific one.)
1399+ *
1400+ * → It doesn't assume we are the only boot loader (i.e doesn't check if we own the main
1401+ * /EFI/BOOT/BOOT*.EFI fallback binary.
1402+ *
1403+ * → It specifically checks for systemd-boot, not for other boot loaders (which a check for
1404+ * /boot/loader/entries would do). */
1405+
1406+ _cleanup_free_ char * p = path_join (arg_esp_path , "/EFI/systemd/" );
1407+ if (!p )
1408+ return log_oom ();
1409+
1410+ log_debug ("Checking whether %s contains any files…" , p );
1411+ r = dir_is_empty (p );
1412+ if (r < 0 && r != - ENOENT )
1413+ return log_error_errno (r , "Failed to check whether %s contains any files: %m" , p );
1414+
1415+ return r == 0 ;
1416+ }
1417+
13851418static int verb_status (int argc , char * argv [], void * userdata ) {
13861419 sd_id128_t esp_uuid = SD_ID128_NULL , xbootldr_uuid = SD_ID128_NULL ;
13871420 int r , k ;
@@ -1880,41 +1913,19 @@ static int verb_remove(int argc, char *argv[], void *userdata) {
18801913}
18811914
18821915static int verb_is_installed (int argc , char * argv [], void * userdata ) {
1883- _cleanup_free_ char * p = NULL ;
18841916 int r ;
18851917
1886- r = acquire_esp ( /* privileged_mode= */ false, /* graceful= */ false, NULL , NULL , NULL , NULL );
1918+ r = are_we_installed ( );
18871919 if (r < 0 )
18881920 return r ;
18891921
1890- /* Tests whether systemd-boot is installed. It's not obvious what to use as check here: we could
1891- * check EFI variables, we could check what binary /EFI/BOOT/BOOT*.EFI points to, or whether the
1892- * loader entries directory exists. Here we opted to check whether /EFI/systemd/ is non-empty, which
1893- * should be a suitable and very minimal check for a number of reasons:
1894- *
1895- * → The check is architecture independent (i.e. we check if any systemd-boot loader is installed, not a
1896- * specific one.)
1897- *
1898- * → It doesn't assume we are the only boot loader (i.e doesn't check if we own the main
1899- * /EFI/BOOT/BOOT*.EFI fallback binary.
1900- *
1901- * → It specifically checks for systemd-boot, not for other boot loaders (which a check for
1902- * /boot/loader/entries would do). */
1903-
1904- p = path_join (arg_esp_path , "/EFI/systemd/" );
1905- if (!p )
1906- return log_oom ();
1907-
1908- r = dir_is_empty (p );
1909- if (r > 0 || r == - ENOENT ) {
1922+ if (r > 0 ) {
1923+ puts ("yes" );
1924+ return EXIT_SUCCESS ;
1925+ } else {
19101926 puts ("no" );
19111927 return EXIT_FAILURE ;
19121928 }
1913- if (r < 0 )
1914- return log_error_errno (r , "Failed to detect whether systemd-boot is installed: %m" );
1915-
1916- puts ("yes" );
1917- return EXIT_SUCCESS ;
19181929}
19191930
19201931static int parse_timeout (const char * arg1 , char16_t * * ret_timeout , size_t * ret_timeout_size ) {
0 commit comments