diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2015-03-11 17:15:07 +0800 |
---|---|---|
committer | Stewart Smith <stewart@linux.vnet.ibm.com> | 2015-03-17 15:34:37 +1100 |
commit | 4c33ce0ab8999672e8c2ef4088d3524be349e7bc (patch) | |
tree | 54ad315f57b70b52f8b05edb05591bd8e53d590b /external/opal-prd/module.c | |
parent | d6fdddbccfc9a0d991ced7e25c6fdbe067128726 (diff) | |
download | skiboot-4c33ce0ab8999672e8c2ef4088d3524be349e7bc.zip skiboot-4c33ce0ab8999672e8c2ef4088d3524be349e7bc.tar.gz skiboot-4c33ce0ab8999672e8c2ef4088d3524be349e7bc.tar.bz2 |
external/opal-prd: Add a helper for module loading
Rather than calling system("modprobe ...") in different locations, this
change introduces an insert_module() helper function.
We use this for the existing i2c modprobe, and add one for the ipmi
devintf module too.
We won't need the i2c-opal module, as it should be automatically
loaded by the platform device.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'external/opal-prd/module.c')
-rw-r--r-- | external/opal-prd/module.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/external/opal-prd/module.c b/external/opal-prd/module.c new file mode 100644 index 0000000..c483cd4 --- /dev/null +++ b/external/opal-prd/module.c @@ -0,0 +1,55 @@ +/* Copyright 2015 IBM Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. + * See the License for the specific language governing permissions and + * imitations under the License. + */ + +#include <stdlib.h> +#include <unistd.h> +#include <err.h> +#include <sys/types.h> +#include <sys/wait.h> + +#include <module.h> + +int insert_module(const char *module) +{ + int status; + pid_t pid; + + pid = fork(); + if (!pid) { + execlp("modprobe", "modprobe", module, NULL); + err(EXIT_FAILURE, "Failed to run modprobe"); + } + + pid = waitpid(pid, &status, 0); + if (pid < 0) { + warn("waitpid failed for modprobe process"); + return -1; + } + + if (!WIFEXITED(status)) { + warnx("modprobe %s: process didn't exit cleanly", module); + return -1; + } + + if (WEXITSTATUS(status) != 0) { + warnx("modprobe %s failed, status %d", module, + WEXITSTATUS(status)); + return -1; + } + + return 0; +} + |