summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Lledó <jlledom@member.fsf.org>2022-03-12 19:28:04 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2022-03-14 00:46:20 +0100
commit21aa2bf6edda711cc4a883e89fd4d3c337c76d6b (patch)
treea1f291661894d8968d6750bc36d200f8a2be878e
parent4ef1660667425c0f171949aacae9d07b10a40d7f (diff)
Hurd: Fix initialization order
This allows non-root programs to to rely on /servers/bus/pci Message-Id: <20220312182804.9318-2-jlledom@mailfence.com> Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
-rw-r--r--src/hurd_pci.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/hurd_pci.c b/src/hurd_pci.c
index 5492513..2d10c5c 100644
--- a/src/hurd_pci.c
+++ b/src/hurd_pci.c
@@ -621,7 +621,8 @@ pci_system_hurd_create(void)
{
int err;
struct pci_system_hurd *pci_sys_hurd;
- mach_port_t device_master, pci_port;
+ mach_port_t device_master;
+ mach_port_t pci_port = MACH_PORT_NULL;
mach_port_t root = MACH_PORT_NULL;
if (&netfs_server_name && netfs_server_name
@@ -648,23 +649,24 @@ pci_system_hurd_create(void)
pci_sys->num_devices = 0;
- if ((err = get_privileged_ports (NULL, &device_master)) || (device_master == MACH_PORT_NULL)) {
- pci_system_cleanup();
- return err;
+ err = get_privileged_ports (NULL, &device_master);
+
+ if(!err && device_master != MACH_PORT_NULL) {
+ err = device_open (device_master, D_READ, "pci", &pci_port);
+ mach_port_deallocate (mach_task_self (), device_master);
}
- err = device_open (device_master, D_READ|D_WRITE, "pci", &pci_port);
- if (!err) {
- root = file_name_lookup_under (pci_port, ".", O_DIRECTORY | O_RDWR | O_EXEC, 0);
+ if (!err && pci_port != MACH_PORT_NULL) {
+ root = file_name_lookup_under (pci_port, ".", O_DIRECTORY | O_RDONLY | O_EXEC, 0);
device_close (pci_port);
mach_port_deallocate (mach_task_self (), pci_port);
}
- if (!root) {
- root = file_name_lookup (_SERVERS_BUS_PCI, O_RDWR, 0);
+ if (root == MACH_PORT_NULL) {
+ root = file_name_lookup (_SERVERS_BUS_PCI, O_RDONLY, 0);
}
- if (!root) {
+ if (root == MACH_PORT_NULL) {
pci_system_cleanup();
return errno;
}