From 88664bd5879b5973cbb8ef43aac5ec4f04af78d8 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 31 May 2011 14:49:16 -0700 Subject: [PATCH] staprun: Discriminate errors before retrying module insertion * runtime/staprun/staprun_funcs.c(insert_module): Copy the saved_errno back into errno when insertion fails. * runtime/staprun/staprun.c(init_staprun): When the first insertion attempt fails, check for EEXIST and then successful module removal before trying module insertion again. --- runtime/staprun/staprun.c | 18 ++++++++++++------ runtime/staprun/staprun_funcs.c | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/runtime/staprun/staprun.c b/runtime/staprun/staprun.c index 458180a9f..4d8310b64 100644 --- a/runtime/staprun/staprun.c +++ b/runtime/staprun/staprun.c @@ -226,12 +226,18 @@ int init_staprun(void) if (need_uprobes && enable_uprobes() != 0) return -1; if (insert_stap_module() < 0) { - /* staprun or stapio might have crashed or been SIGKILL'd, - without first removing the kernel module. This would block - a subsequent rerun attempt. So here we gingerly try to - unload it first. */ - int ret = remove_module (modname, 0); - err("Retrying, after attempted removal of module %s (rc %d)\n", modname, ret); + if (errno != EEXIST) + return -1; + + /* staprun or stapio might have crashed or been SIGKILL'd, + without first removing the kernel module. This would block + a subsequent rerun attempt. So here we gingerly try to + unload it first. */ + int ret = remove_module (modname, 0); + if (ret != 0) + return ret; + + err("Retrying, after attempted removal of module %s\n", modname); /* Then we try an insert a second time. */ if (insert_stap_module() < 0) return -1; diff --git a/runtime/staprun/staprun_funcs.c b/runtime/staprun/staprun_funcs.c index 74eef9cec..688726b0d 100644 --- a/runtime/staprun/staprun_funcs.c +++ b/runtime/staprun/staprun_funcs.c @@ -136,6 +136,7 @@ int insert_module( if (ret != 0) { err("Error inserting module '%s': %s\n", module_realpath, moderror(saved_errno)); + errno = saved_errno; return -1; } return 0; -- 2.43.5