From 0f1110bb5f14e288cf8a3dac5a36547bb9456929 Mon Sep 17 00:00:00 2001 From: Mark Newton Date: Thu, 4 Feb 1999 12:43:17 +0000 Subject: [PATCH] svr4 emulator will refuse to unload itself if it is currently in use. --- sys/compat/svr4/svr4_sysvec.c | 16 ++++++++-------- sys/svr4/svr4_sysvec.c | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/sys/compat/svr4/svr4_sysvec.c b/sys/compat/svr4/svr4_sysvec.c index 8b0997d340a..7823ef07b10 100644 --- a/sys/compat/svr4/svr4_sysvec.c +++ b/sys/compat/svr4/svr4_sysvec.c @@ -356,16 +356,16 @@ svr4_elf_modevent(module_t mod, int type, void *data) printf("svr4 ELF exec handler installed\n"); break; case MOD_UNLOAD: - /* XXX There needs to be a generic function that any - * emulator can call to say, "Are any currently-running - * executables using me?" so we can fail to unload the - * module if it's in use. Locking up because you forgot - * to shut down a program prior to a kldunload isn't fun. - */ - if (elf_remove_brand_entry(&svr4_brand) < 0) + /* Only allow the emulator to be removed if it isn't in use. */ + if (elf_brand_inuse(&svr4_brand) != 0) { + error = EBUSY; + } else if (elf_remove_brand_entry(&svr4_brand) < 0) { error = EINVAL; + } + if (error) - printf("Could not deinstall ELF interpreter entry\n"); + printf("Could not deinstall ELF interpreter entry (error %d)\n", + error); else if (bootverbose) printf("svr4 ELF exec handler removed\n"); break; diff --git a/sys/svr4/svr4_sysvec.c b/sys/svr4/svr4_sysvec.c index 8b0997d340a..7823ef07b10 100644 --- a/sys/svr4/svr4_sysvec.c +++ b/sys/svr4/svr4_sysvec.c @@ -356,16 +356,16 @@ svr4_elf_modevent(module_t mod, int type, void *data) printf("svr4 ELF exec handler installed\n"); break; case MOD_UNLOAD: - /* XXX There needs to be a generic function that any - * emulator can call to say, "Are any currently-running - * executables using me?" so we can fail to unload the - * module if it's in use. Locking up because you forgot - * to shut down a program prior to a kldunload isn't fun. - */ - if (elf_remove_brand_entry(&svr4_brand) < 0) + /* Only allow the emulator to be removed if it isn't in use. */ + if (elf_brand_inuse(&svr4_brand) != 0) { + error = EBUSY; + } else if (elf_remove_brand_entry(&svr4_brand) < 0) { error = EINVAL; + } + if (error) - printf("Could not deinstall ELF interpreter entry\n"); + printf("Could not deinstall ELF interpreter entry (error %d)\n", + error); else if (bootverbose) printf("svr4 ELF exec handler removed\n"); break;