public inbox for linux-ia64@vger.kernel.org
 help / color / mirror / Atom feed
From: Andreas Schwab <schwab@suse.de>
To: linux-ia64@vger.kernel.org
Subject: [Linux-ia64] Elilo-3.3: eliloalt broken
Date: Fri, 13 Sep 2002 10:00:16 +0000	[thread overview]
Message-ID: <marc-linux-ia64-105590701906029@msgid-missing> (raw)

Apparently there is no single EFI variable that can be relied upon.  This
fixes eliloalt so that it just uses the first one it finds when it wants
to create the EliloAlt variable.

--- elilo-3.3/tools/eliloalt.c	2002/09/13 09:29:00	1.1
+++ elilo-3.3/tools/eliloalt.c	2002/09/13 09:39:42
@@ -41,6 +41,7 @@
 #include <errno.h>
 #include <stdint.h>
 #include <string.h>
+#include <dirent.h>
 
 
 #define ELILOALT_VERSION	"0.01"
@@ -49,12 +50,6 @@
 #define EFIVAR_DIR	"/proc/efi/vars"
 #define ELILO_ALTVAR	EFIVAR_DIR"/"ELILO_ALT_NAME"-00000000-0000-0000-0000-000000000000"
 
-/*
- * to write/create a variable we need to open for writing ANY existing variable.
- * So here we chose one that does seem to always exist
- */
-#define ELILOALT_WRITE_VICTIM EFIVAR_DIR"/Efi-47c7b226-c42a-11d2-8e57-00a0c969723b";
-
 #define EFI_VARIABLE_NON_VOLATILE 0x0000000000000001
 #define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x0000000000000002
 #define EFI_VARIABLE_RUNTIME_ACCESS 0x0000000000000004
@@ -124,18 +119,35 @@ usage(char **argv)
 	);
 }
 
-static void
-check_proc_efi(void)
+static char *
+check_proc_efi(int find_entry)
 {
-	int fd;
+	DIR *efi_vars;
+	struct dirent *entry;
+	static char name[1024];
 
 	if (getuid() != 0) {
 		fatal_error("This program must be run as root\n");
 	}
-	fd = open(EFIVAR_DIR, O_RDONLY);
-	if (fd = -1) {
+	efi_vars = opendir(EFIVAR_DIR);
+	if (efi_vars = NULL) {
 		fatal_error("Cannot access %s\n", EFIVAR_DIR);
 	}
+	if (!find_entry) {
+		closedir(efi_vars);
+		return NULL;
+	}
+	/* Find one entry we can open */
+	while ((entry = readdir(efi_vars)) != NULL) {
+		if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
+			break;
+	}
+	if (entry = NULL) {
+		fatal_error("Cannot find entry in %s\n", EFIVAR_DIR);
+	}
+	sprintf(name, "%s/%s", EFIVAR_DIR, entry->d_name);
+	closedir(efi_vars);
+	return name;
 }
 
 static void
@@ -144,7 +156,7 @@ delete_var(void)
 	efi_variable_t var;
 	int fd, r, i;
 
-	check_proc_efi();
+	check_proc_efi(0);
 
 	fd = open(ELILO_ALTVAR, O_WRONLY);
 	if (fd = -1) {
@@ -177,7 +189,7 @@ print_var(void)
 	int fd, r, i;
 
 
-	check_proc_efi();
+	check_proc_efi(0);
 
 	fd = open(ELILO_ALTVAR, O_RDONLY);
 	if (fd = -1) {
@@ -203,9 +215,9 @@ set_var(char *cmdline)
 {
 	efi_variable_t var;
 	int fd, r, i, j, l;
-	char *name = ELILOALT_WRITE_VICTIM;
+	char *name;
 
-	check_proc_efi();
+	name = check_proc_efi(1);
 
 	if (cmdline = NULL) {
 		fatal_error("invalid cmdline argument\n");

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


                 reply	other threads:[~2002-09-13 10:00 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-ia64-105590701906029@msgid-missing \
    --to=schwab@suse.de \
    --cc=linux-ia64@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox