]>
git.ipfire.org Git - thirdparty/kmod.git/blob - libkmod/libkmod-loaded.c
6914e57a7719ae7e08d5924dfd29bf5156ef81b7
2 * libkmod - interface to kernel module operations
4 * Copyright (C) 2011 ProFUSION embedded systems
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation version 2.1.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 #include "libkmod-private.h"
34 * SECTION:libkmod-loaded
35 * @short_description: currently loaded modules
37 * Information about currently loaded modules, as reported by Linux kernel
39 KMOD_EXPORT
int kmod_loaded_get_list(struct kmod_ctx
*ctx
,
40 struct kmod_list
**list
)
42 struct kmod_list
*l
= NULL
;
46 if (ctx
== NULL
|| list
== NULL
)
49 fp
= fopen("/proc/modules", "r");
52 ERR(ctx
, "could not open /proc/modules: %s\n", strerror(errno
));
56 while (fgets(line
, sizeof(line
), fp
)) {
57 struct kmod_module
*m
;
58 struct kmod_list
*node
;
60 char *saveptr
, *name
= strtok_r(line
, " \t", &saveptr
);
62 err
= kmod_module_new_from_name(ctx
, name
, &m
);
64 ERR(ctx
, "could not get module from name '%s': %s\n",
65 name
, strerror(-err
));
69 node
= kmod_list_append(l
, m
);
73 ERR(ctx
, "out of memory\n");