]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/module.c
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.
14 #include "include/compat.h"
19 #if defined(__FreeBSD__)
24 * TODO: Switch to libkmod when we abandon older platforms. The APIs
27 * - kmod_module_new_from_name() for obtaining handles;
28 * - kmod_module_probe_insert_module() for module_load();
29 * - kmod_module_get_info(), kmod_module_info_get_{key,value}() for
34 * Return command's exit status or -1 on error.
36 static int run_command(const char *command
)
40 status
= system(command
);
41 if (status
>= 0 && WIFEXITED(status
))
42 return WEXITSTATUS(status
);
46 char* errp
= ceph_strerror_r(errno
, error_buf
, sizeof(error_buf
));
47 fprintf(stderr
, "couldn't run '%s': %s\n", command
,
49 } else if (WIFSIGNALED(status
)) {
50 fprintf(stderr
, "'%s' killed by signal %d\n", command
,
53 fprintf(stderr
, "weird status from '%s': %d\n", command
,
60 int module_has_param(const char *module
, const char *param
)
64 snprintf(command
, sizeof(command
),
65 "/sbin/modinfo -F parm %s | /bin/grep -q ^%s:",
68 return run_command(command
) == 0;
71 int module_load(const char *module
, const char *options
)
75 snprintf(command
, sizeof(command
), "/sbin/modprobe %s %s",
76 module
, (options
? options
: ""));
78 return run_command(command
);