2 * Ceph - scalable distributed file system
4 * Copyright (C) 2014 Inktank Storage, Inc.
6 * This is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License version 2.1, as published by the Free Software
9 * Foundation. See file COPYING.
18 #if defined(__FreeBSD__)
23 * TODO: Switch to libkmod when we abandon older platforms. The APIs
26 * - kmod_module_new_from_name() for obtaining handles;
27 * - kmod_module_probe_insert_module() for module_load();
28 * - kmod_module_get_info(), kmod_module_info_get_{key,value}() for
33 * Return command's exit status or -1 on error.
35 static int run_command(const char *command)
39 status = system(command);
40 if (status >= 0 && WIFEXITED(status))
41 return WEXITSTATUS(status);
45 #ifdef STRERROR_R_CHAR_P
46 char* dummy = strerror_r(errno, error_buf, sizeof(error_buf));
49 strerror_r(errno, error_buf, sizeof(error_buf));
51 fprintf(stderr, "couldn't run '%s': %s\n", command,
53 } else if (WIFSIGNALED(status)) {
54 fprintf(stderr, "'%s' killed by signal %d\n", command,
57 fprintf(stderr, "weird status from '%s': %d\n", command,
64 int module_has_param(const char *module, const char *param)
68 snprintf(command, sizeof(command),
69 "/sbin/modinfo -F parm %s | /bin/grep -q ^%s:",
72 return run_command(command) == 0;
75 int module_load(const char *module, const char *options)
79 snprintf(command, sizeof(command), "/sbin/modprobe %s %s",
80 module, (options ? options : ""));
82 return run_command(command);