blob: f8984382e97701cfde11f12c0e2a5a73e17e306d [file] [log] [blame]
Lucas De Marchi586fc302011-11-21 14:35:35 -02001/*
2 * libkmod - interface to kernel module operations
3 *
Lucas De Marchia66a6a92012-01-09 00:40:50 -02004 * Copyright (C) 2011-2012 ProFUSION embedded systems
Lucas De Marchi586fc302011-11-21 14:35:35 -02005 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
Lucas De Marchicb451f32011-12-12 18:24:35 -02008 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
Lucas De Marchi586fc302011-11-21 14:35:35 -020010 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
Lucas De Marchiee1d1882012-02-27 18:48:02 -030021#include <assert.h>
Lucas De Marchi586fc302011-11-21 14:35:35 -020022#include <stdio.h>
23#include <stdlib.h>
24#include <stddef.h>
25#include <stdarg.h>
Lucas De Marchi1eb2ef62011-12-05 19:58:39 -020026#include <limits.h>
Lucas De Marchi586fc302011-11-21 14:35:35 -020027#include <unistd.h>
28#include <errno.h>
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -020029#include <fnmatch.h>
Lucas De Marchi586fc302011-11-21 14:35:35 -020030#include <string.h>
31#include <ctype.h>
Lucas De Marchi221631d2011-11-24 16:41:01 -020032#include <sys/utsname.h>
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -020033#include <sys/stat.h>
Lucas De Marchi586fc302011-11-21 14:35:35 -020034
35#include "libkmod.h"
36#include "libkmod-private.h"
Lucas De Marchi9ba6f572011-11-30 20:31:45 -020037#include "libkmod-index.h"
Lucas De Marchi586fc302011-11-21 14:35:35 -020038
Lucas De Marchifd186ae2011-12-06 03:38:37 -020039#define KMOD_HASH_SIZE (256)
40#define KMOD_LRU_MAX (128)
Lucas De Marchi38052742012-02-16 20:43:16 -020041#define _KMOD_INDEX_MODULES_SIZE KMOD_INDEX_MODULES_BUILTIN + 1
Lucas De Marchifd186ae2011-12-06 03:38:37 -020042
Lucas De Marchi586fc302011-11-21 14:35:35 -020043/**
44 * SECTION:libkmod
45 * @short_description: libkmod context
46 *
47 * The context contains the default values for the library user,
48 * and is passed to all library operations.
49 */
50
Lucas De Marchi63be91c2012-01-16 10:43:34 -020051static struct _index_files {
52 const char *fn;
53 const char *prefix;
54} index_files[] = {
Lucas De Marchib08314f2012-01-16 12:01:48 -020055 [KMOD_INDEX_MODULES_DEP] = { .fn = "modules.dep", .prefix = "" },
56 [KMOD_INDEX_MODULES_ALIAS] = { .fn = "modules.alias", .prefix = "alias " },
57 [KMOD_INDEX_MODULES_SYMBOL] = { .fn = "modules.symbols", .prefix = "alias "},
Lucas De Marchi38052742012-02-16 20:43:16 -020058 [KMOD_INDEX_MODULES_BUILTIN] = { .fn = "modules.builtin", .prefix = ""},
Lucas De Marchia4a75022011-12-08 14:56:48 -020059};
60
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -020061static const char *default_config_paths[] = {
Kay Sieversa308abe2011-12-20 17:58:05 +010062 SYSCONFDIR "/modprobe.d",
Lucas De Marchi436da1e2012-03-15 09:19:34 -030063 "/run/modprobe.d",
Dave Reisnerc5b37db2012-09-27 11:00:42 -040064 "/lib/modprobe.d",
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -020065 NULL
66};
67
Lucas De Marchi586fc302011-11-21 14:35:35 -020068/**
69 * kmod_ctx:
70 *
71 * Opaque object representing the library context.
72 */
73struct kmod_ctx {
74 int refcount;
Gustavo Sverzut Barbieri8d3f3ef2011-12-02 21:10:24 -020075 int log_priority;
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -020076 void (*log_fn)(void *data,
Lucas De Marchie4351b02011-11-21 14:59:23 -020077 int priority, const char *file, int line,
78 const char *fn, const char *format, va_list args);
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -020079 void *log_data;
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -020080 const void *userdata;
81 char *dirname;
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -020082 struct kmod_config *config;
Lucas De Marchi822913d2011-12-27 12:13:54 -020083 struct hash *modules_by_name;
Lucas De Marchib08314f2012-01-16 12:01:48 -020084 struct index_mm *indexes[_KMOD_INDEX_MODULES_SIZE];
85 unsigned long long indexes_stamp[_KMOD_INDEX_MODULES_SIZE];
Lucas De Marchi586fc302011-11-21 14:35:35 -020086};
87
Lucas De Marchi71928282012-05-10 20:58:46 -030088void kmod_log(const struct kmod_ctx *ctx,
89 int priority, const char *file, int line, const char *fn,
90 const char *format, ...)
Lucas De Marchi586fc302011-11-21 14:35:35 -020091{
92 va_list args;
93
Gustavo Sverzut Barbierie5c60f12011-12-08 13:58:46 -020094 if (ctx->log_fn == NULL)
95 return;
96
Lucas De Marchi586fc302011-11-21 14:35:35 -020097 va_start(args, format);
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -020098 ctx->log_fn(ctx->log_data, priority, file, line, fn, format, args);
Lucas De Marchi586fc302011-11-21 14:35:35 -020099 va_end(args);
100}
101
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200102static void log_filep(void *data,
Lucas De Marchie4351b02011-11-21 14:59:23 -0200103 int priority, const char *file, int line,
104 const char *fn, const char *format, va_list args)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200105{
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200106 FILE *fp = data;
Gustavo Sverzut Barbierie3cb0902012-01-07 19:25:03 -0200107#ifdef ENABLE_DEBUG
108 char buf[16];
109 const char *priname;
110 switch (priority) {
111 case LOG_EMERG:
112 priname = "EMERGENCY";
113 break;
114 case LOG_ALERT:
115 priname = "ALERT";
116 break;
117 case LOG_CRIT:
118 priname = "CRITICAL";
119 break;
120 case LOG_ERR:
121 priname = "ERROR";
122 break;
123 case LOG_WARNING:
124 priname = "WARNING";
125 break;
126 case LOG_NOTICE:
127 priname = "NOTICE";
128 break;
129 case LOG_INFO:
130 priname = "INFO";
131 break;
132 case LOG_DEBUG:
133 priname = "DEBUG";
134 break;
135 default:
136 snprintf(buf, sizeof(buf), "L:%d", priority);
137 priname = buf;
138 }
139 fprintf(fp, "libkmod: %s %s:%d %s: ", priname, file, line, fn);
140#else
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200141 fprintf(fp, "libkmod: %s: ", fn);
Gustavo Sverzut Barbierie3cb0902012-01-07 19:25:03 -0200142#endif
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200143 vfprintf(fp, format, args);
Lucas De Marchi586fc302011-11-21 14:35:35 -0200144}
145
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -0200146const char *kmod_get_dirname(const struct kmod_ctx *ctx)
Lucas De Marchi221631d2011-11-24 16:41:01 -0200147{
148 return ctx->dirname;
149}
150
Lucas De Marchi586fc302011-11-21 14:35:35 -0200151/**
152 * kmod_get_userdata:
153 * @ctx: kmod library context
154 *
155 * Retrieve stored data pointer from library context. This might be useful
Lucas De Marchibe5a6de2011-12-14 03:44:38 -0200156 * to access from callbacks.
Lucas De Marchi586fc302011-11-21 14:35:35 -0200157 *
158 * Returns: stored userdata
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200159 */
Lucas De Marchi6d177552011-11-23 11:52:30 -0200160KMOD_EXPORT void *kmod_get_userdata(const struct kmod_ctx *ctx)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200161{
162 if (ctx == NULL)
163 return NULL;
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -0200164 return (void *)ctx->userdata;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200165}
166
167/**
168 * kmod_set_userdata:
169 * @ctx: kmod library context
170 * @userdata: data pointer
171 *
172 * Store custom @userdata in the library context.
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200173 */
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -0200174KMOD_EXPORT void kmod_set_userdata(struct kmod_ctx *ctx, const void *userdata)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200175{
176 if (ctx == NULL)
177 return;
178 ctx->userdata = userdata;
179}
180
181static int log_priority(const char *priority)
182{
183 char *endptr;
184 int prio;
185
186 prio = strtol(priority, &endptr, 10);
187 if (endptr[0] == '\0' || isspace(endptr[0]))
188 return prio;
189 if (strncmp(priority, "err", 3) == 0)
190 return LOG_ERR;
191 if (strncmp(priority, "info", 4) == 0)
192 return LOG_INFO;
193 if (strncmp(priority, "debug", 5) == 0)
194 return LOG_DEBUG;
195 return 0;
196}
197
Dave Reisnerc5b37db2012-09-27 11:00:42 -0400198static const char *dirname_default_prefix = "/lib/modules";
Lucas De Marchi904c63a2011-11-30 20:27:50 -0200199
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -0200200static char *get_kernel_release(const char *dirname)
Lucas De Marchi221631d2011-11-24 16:41:01 -0200201{
202 struct utsname u;
Lucas De Marchi904c63a2011-11-30 20:27:50 -0200203 char *p;
204
205 if (dirname != NULL)
Lucas De Marchi2e092e12012-01-14 02:31:51 -0200206 return path_make_absolute_cwd(dirname);
Lucas De Marchi221631d2011-11-24 16:41:01 -0200207
208 if (uname(&u) < 0)
209 return NULL;
210
Lucas De Marchi904c63a2011-11-30 20:27:50 -0200211 if (asprintf(&p, "%s/%s", dirname_default_prefix, u.release) < 0)
212 return NULL;
213
214 return p;
Lucas De Marchi221631d2011-11-24 16:41:01 -0200215}
216
Lucas De Marchi586fc302011-11-21 14:35:35 -0200217/**
218 * kmod_new:
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200219 * @dirname: what to consider as linux module's directory, if NULL
Dave Reisnerc5b37db2012-09-27 11:00:42 -0400220 * defaults to /lib/modules/`uname -r`. If it's relative,
Lucas De Marchi2f47c7f2012-01-14 12:09:34 -0200221 * it's treated as relative to current the current working
222 * directory. Otherwise, give an absolute dirname.
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200223 * @config_paths: ordered array of paths (directories or files) where
Lucas De Marchibe5a6de2011-12-14 03:44:38 -0200224 * to load from user-defined configuration parameters such as
225 * alias, blacklists, commands (install, remove). If
226 * NULL defaults to /run/modprobe.d, /etc/modprobe.d and
Dave Reisnerc5b37db2012-09-27 11:00:42 -0400227 * /lib/modprobe.d. Give an empty vector if configuration should
228 * not be read. This array must be null terminated.
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200229 *
Lucas De Marchie1daa4f2012-01-09 03:09:49 -0200230 * Create kmod library context. This reads the kmod configuration
231 * and fills in the default values.
232 *
233 * The initial refcount is 1, and needs to be decremented to
234 * release the resources of the kmod library context.
235 *
Lucas De Marchi586fc302011-11-21 14:35:35 -0200236 * Returns: a new kmod library context
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200237 */
Lucas De Marchic35347f2011-12-12 10:48:02 -0200238KMOD_EXPORT struct kmod_ctx *kmod_new(const char *dirname,
239 const char * const *config_paths)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200240{
241 const char *env;
Lucas De Marchi52a77042011-11-21 15:07:27 -0200242 struct kmod_ctx *ctx;
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -0200243 int err;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200244
Lucas De Marchi52a77042011-11-21 15:07:27 -0200245 ctx = calloc(1, sizeof(struct kmod_ctx));
246 if (!ctx)
247 return NULL;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200248
Lucas De Marchi52a77042011-11-21 15:07:27 -0200249 ctx->refcount = 1;
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200250 ctx->log_fn = log_filep;
251 ctx->log_data = stderr;
Lucas De Marchi52a77042011-11-21 15:07:27 -0200252 ctx->log_priority = LOG_ERR;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200253
Lucas De Marchi904c63a2011-11-30 20:27:50 -0200254 ctx->dirname = get_kernel_release(dirname);
Lucas De Marchi221631d2011-11-24 16:41:01 -0200255
Lucas De Marchi586fc302011-11-21 14:35:35 -0200256 /* environment overwrites config */
257 env = getenv("KMOD_LOG");
258 if (env != NULL)
Lucas De Marchi52a77042011-11-21 15:07:27 -0200259 kmod_set_log_priority(ctx, log_priority(env));
Lucas De Marchi586fc302011-11-21 14:35:35 -0200260
Gustavo Sverzut Barbiericb8d4d32011-12-11 20:37:01 -0200261 if (config_paths == NULL)
262 config_paths = default_config_paths;
263 err = kmod_config_new(ctx, &ctx->config, config_paths);
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -0200264 if (err < 0) {
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200265 ERR(ctx, "could not create config\n");
266 goto fail;
267 }
268
Lucas De Marchi822913d2011-12-27 12:13:54 -0200269 ctx->modules_by_name = hash_new(KMOD_HASH_SIZE, NULL);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200270 if (ctx->modules_by_name == NULL) {
271 ERR(ctx, "could not create by-name hash\n");
272 goto fail;
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -0200273 }
Lucas De Marchi7c2ab352011-11-29 18:07:43 -0200274
Lucas De Marchiae6df842011-11-25 01:05:30 -0200275 INFO(ctx, "ctx %p created\n", ctx);
276 DBG(ctx, "log_priority=%d\n", ctx->log_priority);
Lucas De Marchi52a77042011-11-21 15:07:27 -0200277
278 return ctx;
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200279
280fail:
281 free(ctx->modules_by_name);
282 free(ctx->dirname);
283 free(ctx);
284 return NULL;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200285}
286
287/**
288 * kmod_ref:
289 * @ctx: kmod library context
290 *
291 * Take a reference of the kmod library context.
292 *
293 * Returns: the passed kmod library context
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200294 */
Lucas De Marchi586fc302011-11-21 14:35:35 -0200295KMOD_EXPORT struct kmod_ctx *kmod_ref(struct kmod_ctx *ctx)
296{
297 if (ctx == NULL)
298 return NULL;
299 ctx->refcount++;
300 return ctx;
301}
302
303/**
304 * kmod_unref:
305 * @ctx: kmod library context
306 *
307 * Drop a reference of the kmod library context. If the refcount
308 * reaches zero, the resources of the context will be released.
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200309 */
Lucas De Marchi586fc302011-11-21 14:35:35 -0200310KMOD_EXPORT struct kmod_ctx *kmod_unref(struct kmod_ctx *ctx)
311{
312 if (ctx == NULL)
313 return NULL;
Lucas De Marchi4d1e6892011-11-24 15:41:48 -0200314
315 if (--ctx->refcount > 0)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200316 return ctx;
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200317
Lucas De Marchiae6df842011-11-25 01:05:30 -0200318 INFO(ctx, "context %p released\n", ctx);
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200319
320 kmod_unload_resources(ctx);
Lucas De Marchi822913d2011-12-27 12:13:54 -0200321 hash_free(ctx->modules_by_name);
Gustavo Sverzut Barbieri1ce08a52011-12-02 20:24:07 -0200322 free(ctx->dirname);
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -0200323 if (ctx->config)
324 kmod_config_free(ctx->config);
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200325
Lucas De Marchi586fc302011-11-21 14:35:35 -0200326 free(ctx);
327 return NULL;
328}
329
330/**
331 * kmod_set_log_fn:
332 * @ctx: kmod library context
333 * @log_fn: function to be called for logging messages
Lucas De Marchib5b4d8e2012-01-04 21:07:59 -0200334 * @data: data to pass to log function
Lucas De Marchi586fc302011-11-21 14:35:35 -0200335 *
336 * The built-in logging writes to stderr. It can be
337 * overridden by a custom function, to plug log messages
338 * into the user's logging functionality.
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200339 */
Lucas De Marchi586fc302011-11-21 14:35:35 -0200340KMOD_EXPORT void kmod_set_log_fn(struct kmod_ctx *ctx,
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200341 void (*log_fn)(void *data,
Lucas De Marchie4351b02011-11-21 14:59:23 -0200342 int priority, const char *file,
343 int line, const char *fn,
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200344 const char *format, va_list args),
345 const void *data)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200346{
Gustavo Sverzut Barbierie5c60f12011-12-08 13:58:46 -0200347 if (ctx == NULL)
348 return;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200349 ctx->log_fn = log_fn;
Gustavo Sverzut Barbieri1bdd9512011-12-08 13:47:55 -0200350 ctx->log_data = (void *)data;
Lucas De Marchiae6df842011-11-25 01:05:30 -0200351 INFO(ctx, "custom logging function %p registered\n", log_fn);
Lucas De Marchi586fc302011-11-21 14:35:35 -0200352}
353
354/**
355 * kmod_get_log_priority:
356 * @ctx: kmod library context
357 *
358 * Returns: the current logging priority
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200359 */
Lucas De Marchi6d177552011-11-23 11:52:30 -0200360KMOD_EXPORT int kmod_get_log_priority(const struct kmod_ctx *ctx)
Lucas De Marchi586fc302011-11-21 14:35:35 -0200361{
Gustavo Sverzut Barbierie5c60f12011-12-08 13:58:46 -0200362 if (ctx == NULL)
363 return -1;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200364 return ctx->log_priority;
365}
366
367/**
368 * kmod_set_log_priority:
369 * @ctx: kmod library context
370 * @priority: the new logging priority
371 *
372 * Set the current logging priority. The value controls which messages
373 * are logged.
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200374 */
Lucas De Marchi586fc302011-11-21 14:35:35 -0200375KMOD_EXPORT void kmod_set_log_priority(struct kmod_ctx *ctx, int priority)
376{
Gustavo Sverzut Barbierie5c60f12011-12-08 13:58:46 -0200377 if (ctx == NULL)
378 return;
Lucas De Marchi586fc302011-11-21 14:35:35 -0200379 ctx->log_priority = priority;
380}
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200381
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200382struct kmod_module *kmod_pool_get_module(struct kmod_ctx *ctx,
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200383 const char *key)
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200384{
385 struct kmod_module *mod;
386
Lucas De Marchi822913d2011-12-27 12:13:54 -0200387 mod = hash_find(ctx->modules_by_name, key);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200388
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200389 DBG(ctx, "get module name='%s' found=%p\n", key, mod);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200390
391 return mod;
392}
393
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200394void kmod_pool_add_module(struct kmod_ctx *ctx, struct kmod_module *mod,
395 const char *key)
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200396{
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200397 DBG(ctx, "add %p key='%s'\n", mod, key);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200398
Lucas De Marchi822913d2011-12-27 12:13:54 -0200399 hash_add(ctx->modules_by_name, key, mod);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200400}
401
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200402void kmod_pool_del_module(struct kmod_ctx *ctx, struct kmod_module *mod,
403 const char *key)
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200404{
Lucas De Marchi8bdeca12011-12-15 13:11:51 -0200405 DBG(ctx, "del %p key='%s'\n", mod, key);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200406
Lucas De Marchi822913d2011-12-27 12:13:54 -0200407 hash_del(ctx->modules_by_name, key);
Lucas De Marchifd186ae2011-12-06 03:38:37 -0200408}
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200409
Lucas De Marchia0094822011-12-02 09:53:31 -0200410static int kmod_lookup_alias_from_alias_bin(struct kmod_ctx *ctx,
Lucas De Marchi810803d2011-12-09 16:06:04 -0200411 enum kmod_index index_number,
Lucas De Marchi7b30f4f2011-12-01 16:25:37 -0200412 const char *name,
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200413 struct kmod_list **list)
414{
Lucas De Marchi6f1bc6e2011-12-02 10:02:05 -0200415 int err, nmatch = 0;
Lucas De Marchi0fbdfef2011-12-02 09:56:22 -0200416 struct index_file *idx;
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200417 struct index_value *realnames, *realname;
418
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200419 if (ctx->indexes[index_number] != NULL) {
Gustavo Sverzut Barbieri3e245be2011-12-10 09:28:42 -0200420 DBG(ctx, "use mmaped index '%s' for name=%s\n",
Lucas De Marchi63be91c2012-01-16 10:43:34 -0200421 index_files[index_number].fn, name);
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200422 realnames = index_mm_searchwild(ctx->indexes[index_number],
423 name);
Lucas De Marchi9fd58f32011-12-31 18:53:24 -0200424 } else {
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200425 char fn[PATH_MAX];
426
Gustavo Sverzut Barbieri3b209952011-12-10 09:21:03 -0200427 snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
Lucas De Marchi63be91c2012-01-16 10:43:34 -0200428 index_files[index_number].fn);
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200429
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200430 DBG(ctx, "file=%s name=%s\n", fn, name);
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200431
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200432 idx = index_file_open(fn);
433 if (idx == NULL)
434 return -ENOSYS;
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200435
Lucas De Marchi65a84f52011-12-09 16:11:42 -0200436 realnames = index_searchwild(idx, name);
437 index_file_close(idx);
438 }
Lucas De Marchi4272d082011-12-09 15:33:37 -0200439
Ulisses Furquima955f712011-12-15 19:17:49 -0200440 for (realname = realnames; realname; realname = realname->next) {
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200441 struct kmod_module *mod;
442
Lucas De Marchiee3b3ff2011-12-13 14:20:48 -0200443 err = kmod_module_new_from_alias(ctx, name, realname->value, &mod);
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200444 if (err < 0) {
Gustavo Sverzut Barbieridfa96f12012-01-07 19:37:37 -0200445 ERR(ctx, "Could not create module for alias=%s realname=%s: %s\n",
446 name, realname->value, strerror(-err));
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200447 goto fail;
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200448 }
449
450 *list = kmod_list_append(*list, mod);
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200451 nmatch++;
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200452 }
453
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200454 index_values_free(realnames);
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200455 return nmatch;
456
457fail:
458 *list = kmod_list_remove_n_latest(*list, nmatch);
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200459 return err;
Lucas De Marchi7b30f4f2011-12-01 16:25:37 -0200460
461}
462
Lucas De Marchi7b30f4f2011-12-01 16:25:37 -0200463int kmod_lookup_alias_from_symbols_file(struct kmod_ctx *ctx, const char *name,
464 struct kmod_list **list)
465{
Lucas De Marchi0c010fa2011-12-28 13:33:26 -0200466 if (!strstartswith(name, "symbol:"))
Lucas De Marchi7b30f4f2011-12-01 16:25:37 -0200467 return 0;
468
Lucas De Marchib08314f2012-01-16 12:01:48 -0200469 return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_SYMBOL,
470 name, list);
Lucas De Marchi9ba6f572011-11-30 20:31:45 -0200471}
472
Lucas De Marchi49e61ca2011-12-01 16:27:04 -0200473int kmod_lookup_alias_from_aliases_file(struct kmod_ctx *ctx, const char *name,
474 struct kmod_list **list)
475{
Lucas De Marchib08314f2012-01-16 12:01:48 -0200476 return kmod_lookup_alias_from_alias_bin(ctx, KMOD_INDEX_MODULES_ALIAS,
477 name, list);
Lucas De Marchi49e61ca2011-12-01 16:27:04 -0200478}
479
Lucas De Marchi38052742012-02-16 20:43:16 -0200480int kmod_lookup_alias_from_builtin_file(struct kmod_ctx *ctx, const char *name,
481 struct kmod_list **list)
482{
Lucas De Marchiee1d1882012-02-27 18:48:02 -0300483 char *line = NULL;
484 int err = 0;
Lucas De Marchi38052742012-02-16 20:43:16 -0200485
Lucas De Marchiee1d1882012-02-27 18:48:02 -0300486 assert(*list == NULL);
Lucas De Marchi38052742012-02-16 20:43:16 -0200487
Lucas De Marchiee1d1882012-02-27 18:48:02 -0300488 if (ctx->indexes[KMOD_INDEX_MODULES_BUILTIN]) {
489 DBG(ctx, "use mmaped index '%s' modname=%s\n",
490 index_files[KMOD_INDEX_MODULES_BUILTIN].fn,
491 name);
492 line = index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_BUILTIN],
493 name);
494 } else {
495 struct index_file *idx;
496 char fn[PATH_MAX];
497
498 snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
499 index_files[KMOD_INDEX_MODULES_BUILTIN].fn);
500 DBG(ctx, "file=%s modname=%s\n", fn, name);
501
502 idx = index_file_open(fn);
503 if (idx == NULL) {
504 DBG(ctx, "could not open builtin file '%s'\n", fn);
505 goto finish;
506 }
507
508 line = index_search(idx, name);
509 index_file_close(idx);
Lucas De Marchi38052742012-02-16 20:43:16 -0200510 }
511
Lucas De Marchiee1d1882012-02-27 18:48:02 -0300512 if (line != NULL) {
513 struct kmod_module *mod;
514
515 err = kmod_module_new_from_name(ctx, name, &mod);
516 if (err < 0) {
517 ERR(ctx, "Could not create module from name %s: %s\n",
518 name, strerror(-err));
519 goto finish;
520 }
521
522 kmod_module_set_builtin(mod, true);
523 *list = kmod_list_append(*list, mod);
524 if (*list == NULL)
525 err = -ENOMEM;
526 }
527
528finish:
529 free(line);
Lucas De Marchi38052742012-02-16 20:43:16 -0200530 return err;
531}
532
Lucas De Marchi671d4892011-12-05 20:23:05 -0200533char *kmod_search_moddep(struct kmod_ctx *ctx, const char *name)
Lucas De Marchi1eb2ef62011-12-05 19:58:39 -0200534{
535 struct index_file *idx;
536 char fn[PATH_MAX];
537 char *line;
538
Lucas De Marchib08314f2012-01-16 12:01:48 -0200539 if (ctx->indexes[KMOD_INDEX_MODULES_DEP]) {
Gustavo Sverzut Barbieri85132102011-12-10 09:26:27 -0200540 DBG(ctx, "use mmaped index '%s' modname=%s\n",
Lucas De Marchib08314f2012-01-16 12:01:48 -0200541 index_files[KMOD_INDEX_MODULES_DEP].fn, name);
542 return index_mm_search(ctx->indexes[KMOD_INDEX_MODULES_DEP],
543 name);
Gustavo Sverzut Barbieri85132102011-12-10 09:26:27 -0200544 }
545
Lucas De Marchia4a75022011-12-08 14:56:48 -0200546 snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
Lucas De Marchib08314f2012-01-16 12:01:48 -0200547 index_files[KMOD_INDEX_MODULES_DEP].fn);
Lucas De Marchi1eb2ef62011-12-05 19:58:39 -0200548
549 DBG(ctx, "file=%s modname=%s\n", fn, name);
550
551 idx = index_file_open(fn);
552 if (idx == NULL) {
Lucas De Marchiadca3cd2012-02-17 05:00:09 -0200553 DBG(ctx, "could not open moddep file '%s'\n", fn);
Lucas De Marchi1eb2ef62011-12-05 19:58:39 -0200554 return NULL;
555 }
556
557 line = index_search(idx, name);
558 index_file_close(idx);
559
560 return line;
561}
562
Lucas De Marchi64700e42011-12-01 15:57:53 -0200563int kmod_lookup_alias_from_moddep_file(struct kmod_ctx *ctx, const char *name,
564 struct kmod_list **list)
565{
Lucas De Marchi1eb2ef62011-12-05 19:58:39 -0200566 char *line;
Lucas De Marchi64700e42011-12-01 15:57:53 -0200567 int n = 0;
568
569 /*
570 * Module names do not contain ':'. Return early if we know it will
571 * not be found.
572 */
573 if (strchr(name, ':'))
574 return 0;
575
Lucas De Marchi671d4892011-12-05 20:23:05 -0200576 line = kmod_search_moddep(ctx, name);
Lucas De Marchi64700e42011-12-01 15:57:53 -0200577 if (line != NULL) {
578 struct kmod_module *mod;
579
580 n = kmod_module_new_from_name(ctx, name, &mod);
581 if (n < 0) {
Gustavo Sverzut Barbieridfa96f12012-01-07 19:37:37 -0200582 ERR(ctx, "Could not create module from name %s: %s\n",
583 name, strerror(-n));
Lucas De Marchi64700e42011-12-01 15:57:53 -0200584 goto finish;
585 }
586
587 *list = kmod_list_append(*list, mod);
Lucas De Marchi671d4892011-12-05 20:23:05 -0200588 kmod_module_parse_depline(mod, line);
Lucas De Marchi64700e42011-12-01 15:57:53 -0200589 }
590
591finish:
592 free(line);
Lucas De Marchi64700e42011-12-01 15:57:53 -0200593
594 return n;
595}
596
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200597int kmod_lookup_alias_from_config(struct kmod_ctx *ctx, const char *name,
598 struct kmod_list **list)
599{
Gustavo Sverzut Barbierid13e6062011-12-02 21:40:22 -0200600 struct kmod_config *config = ctx->config;
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200601 struct kmod_list *l;
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200602 int err, nmatch = 0;
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200603
604 kmod_list_foreach(l, config->aliases) {
605 const char *aliasname = kmod_alias_get_name(l);
606 const char *modname = kmod_alias_get_modname(l);
607
608 if (fnmatch(aliasname, name, 0) == 0) {
609 struct kmod_module *mod;
610
Lucas De Marchiee3b3ff2011-12-13 14:20:48 -0200611 err = kmod_module_new_from_alias(ctx, aliasname,
612 modname, &mod);
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200613 if (err < 0) {
Gustavo Sverzut Barbieridfa96f12012-01-07 19:37:37 -0200614 ERR(ctx, "Could not create module for alias=%s modname=%s: %s\n",
615 name, modname, strerror(-err));
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200616 goto fail;
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200617 }
618
619 *list = kmod_list_append(*list, mod);
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200620 nmatch++;
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200621 }
622 }
623
Lucas De Marchi23fc91c2011-12-01 15:35:31 -0200624 return nmatch;
625
626fail:
627 *list = kmod_list_remove_n_latest(*list, nmatch);
628 return err;
Lucas De Marchi7f3eb0c2011-11-30 19:03:41 -0200629}
Gustavo Sverzut Barbieri1487a642011-12-08 05:17:43 -0200630
Lucas De Marchif4fc5522011-12-16 03:57:12 -0200631int kmod_lookup_alias_from_commands(struct kmod_ctx *ctx, const char *name,
632 struct kmod_list **list)
633{
634 struct kmod_config *config = ctx->config;
635 struct kmod_list *l, *node;
636 int err, nmatch = 0;
637
638 kmod_list_foreach(l, config->install_commands) {
639 const char *modname = kmod_command_get_modname(l);
640
641 if (streq(modname, name)) {
642 const char *cmd = kmod_command_get_command(l);
643 struct kmod_module *mod;
644
645 err = kmod_module_new_from_name(ctx, modname, &mod);
646 if (err < 0) {
Gustavo Sverzut Barbieridfa96f12012-01-07 19:37:37 -0200647 ERR(ctx, "Could not create module from name %s: %s\n",
648 modname, strerror(-err));
Lucas De Marchif4fc5522011-12-16 03:57:12 -0200649 return err;
650 }
651
652 node = kmod_list_append(*list, mod);
653 if (node == NULL) {
654 ERR(ctx, "out of memory\n");
655 return -ENOMEM;
656 }
657
658 *list = node;
659 nmatch = 1;
660
661 kmod_module_set_install_commands(mod, cmd);
662
663 /*
664 * match only the first one, like modprobe from
665 * module-init-tools does
666 */
667 break;
668 }
669 }
670
671 if (nmatch)
672 return nmatch;
673
674 kmod_list_foreach(l, config->remove_commands) {
675 const char *modname = kmod_command_get_modname(l);
676
677 if (streq(modname, name)) {
678 const char *cmd = kmod_command_get_command(l);
679 struct kmod_module *mod;
680
681 err = kmod_module_new_from_name(ctx, modname, &mod);
682 if (err < 0) {
Gustavo Sverzut Barbieridfa96f12012-01-07 19:37:37 -0200683 ERR(ctx, "Could not create module from name %s: %s\n",
684 modname, strerror(-err));
Lucas De Marchif4fc5522011-12-16 03:57:12 -0200685 return err;
686 }
687
688 node = kmod_list_append(*list, mod);
689 if (node == NULL) {
690 ERR(ctx, "out of memory\n");
691 return -ENOMEM;
692 }
693
694 *list = node;
695 nmatch = 1;
696
697 kmod_module_set_remove_commands(mod, cmd);
698
699 /*
700 * match only the first one, like modprobe from
701 * module-init-tools does
702 */
703 break;
704 }
705 }
706
707 return nmatch;
708}
709
Lucas De Marchiece09aa2012-01-18 01:26:44 -0200710void kmod_set_modules_visited(struct kmod_ctx *ctx, bool visited)
711{
712 struct hash_iter iter;
713 const void *v;
714
715 hash_iter_init(ctx->modules_by_name, &iter);
716 while (hash_iter_next(&iter, NULL, &v))
717 kmod_module_set_visited((struct kmod_module *)v, visited);
718}
719
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -0200720static bool is_cache_invalid(const char *path, unsigned long long stamp)
721{
722 struct stat st;
723
724 if (stat(path, &st) < 0)
725 return true;
726
Lucas De Marchi6068aaa2012-01-17 12:10:42 -0200727 if (stamp != stat_mstamp(&st))
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -0200728 return true;
729
730 return false;
731}
732
733/**
734 * kmod_validate_resources:
735 * @ctx: kmod library context
736 *
737 * Check if indexes and configuration files changed on disk and the current
738 * context is not valid anymore.
739 *
Lucas De Marchif4cc6ea2012-01-09 02:35:41 -0200740 * Returns: KMOD_RESOURCES_OK if resources are still valid,
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -0200741 * KMOD_RESOURCES_MUST_RELOAD if it's sufficient to call
742 * kmod_unload_resources() and kmod_load_resources() or
743 * KMOD_RESOURCES_MUST_RECREATE if @ctx must be re-created.
744 */
745KMOD_EXPORT int kmod_validate_resources(struct kmod_ctx *ctx)
746{
747 struct kmod_list *l;
748 size_t i;
749
750 if (ctx == NULL || ctx->config == NULL)
751 return KMOD_RESOURCES_MUST_RECREATE;
752
753 kmod_list_foreach(l, ctx->config->paths) {
754 struct kmod_config_path *cf = l->data;
755
756 if (is_cache_invalid(cf->path, cf->stamp))
757 return KMOD_RESOURCES_MUST_RECREATE;
758 }
759
Lucas De Marchib08314f2012-01-16 12:01:48 -0200760 for (i = 0; i < _KMOD_INDEX_MODULES_SIZE; i++) {
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -0200761 char path[PATH_MAX];
762
763 if (ctx->indexes[i] == NULL)
764 continue;
765
766 snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
Lucas De Marchi63be91c2012-01-16 10:43:34 -0200767 index_files[i].fn);
Lucas De Marchic4dc3ca2011-12-31 19:28:31 -0200768
769 if (is_cache_invalid(path, ctx->indexes_stamp[i]))
770 return KMOD_RESOURCES_MUST_RELOAD;
771 }
772
773 return KMOD_RESOURCES_OK;
774}
775
Lucas De Marchi54ba8b32011-12-09 16:42:14 -0200776/**
Lucas De Marchibe5a6de2011-12-14 03:44:38 -0200777 * kmod_load_resources:
778 * @ctx: kmod library context
779 *
780 * Load indexes and keep them open in @ctx. This way it's faster to lookup
781 * information within the indexes. If this function is not called before a
782 * search, the necessary index is always opened and closed.
783 *
784 * If user will do more than one or two lookups, insertions, deletions, most
785 * likely it's good to call this function first. Particularly in a daemon like
786 * udev that on bootup issues hundreds of calls to lookup the index, calling
787 * this function will speedup the searches.
788 *
789 * Returns: 0 on success or < 0 otherwise.
790 */
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200791KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
792{
793 size_t i;
794
795 if (ctx == NULL)
796 return -ENOENT;
797
Lucas De Marchib08314f2012-01-16 12:01:48 -0200798 for (i = 0; i < _KMOD_INDEX_MODULES_SIZE; i++) {
Lucas De Marchi6de8f6e2011-12-14 03:58:31 -0200799 char path[PATH_MAX];
Lucas De Marchi3e676762011-12-14 03:53:43 -0200800
Lucas De Marchi16ca3662011-12-20 12:29:13 -0200801 if (ctx->indexes[i] != NULL) {
Lucas De Marchi63be91c2012-01-16 10:43:34 -0200802 INFO(ctx, "Index %s already loaded\n",
803 index_files[i].fn);
Lucas De Marchi3e676762011-12-14 03:53:43 -0200804 continue;
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200805 }
Lucas De Marchi3e676762011-12-14 03:53:43 -0200806
Lucas De Marchi6de8f6e2011-12-14 03:58:31 -0200807 snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
Lucas De Marchi63be91c2012-01-16 10:43:34 -0200808 index_files[i].fn);
Lucas De Marchi2e2e2522012-03-02 20:33:26 -0300809 ctx->indexes[i] = index_mm_open(ctx, path,
Lucas De Marchi9fd58f32011-12-31 18:53:24 -0200810 &ctx->indexes_stamp[i]);
Lucas De Marchi3e676762011-12-14 03:53:43 -0200811 if (ctx->indexes[i] == NULL)
812 goto fail;
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200813 }
814
815 return 0;
816
817fail:
818 kmod_unload_resources(ctx);
819 return -ENOMEM;
820}
821
Lucas De Marchibe5a6de2011-12-14 03:44:38 -0200822/**
823 * kmod_unload_resources:
824 * @ctx: kmod library context
825 *
826 * Unload all the indexes. This will free the resources to maintain the index
827 * open and all subsequent searches will need to open and close the index.
828 *
829 * User is free to call kmod_load_resources() and kmod_unload_resources() as
830 * many times as wanted during the lifecycle of @ctx. For example, if a daemon
831 * knows that when starting up it will lookup a lot of modules, it could call
832 * kmod_load_resources() and after the first burst of searches is gone, it
833 * could free the resources by calling kmod_unload_resources().
834 *
835 * Returns: 0 on success or < 0 otherwise.
836 */
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200837KMOD_EXPORT void kmod_unload_resources(struct kmod_ctx *ctx)
838{
839 size_t i;
840
841 if (ctx == NULL)
842 return;
843
Lucas De Marchib08314f2012-01-16 12:01:48 -0200844 for (i = 0; i < _KMOD_INDEX_MODULES_SIZE; i++) {
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200845 if (ctx->indexes[i] != NULL) {
846 index_mm_close(ctx->indexes[i]);
847 ctx->indexes[i] = NULL;
Lucas De Marchi9fd58f32011-12-31 18:53:24 -0200848 ctx->indexes_stamp[i] = 0;
Lucas De Marchi33bb69b2011-12-08 14:59:51 -0200849 }
850 }
851}
Gustavo Sverzut Barbieribd3f5532011-12-10 20:47:01 -0200852
Lucas De Marchi02244822012-01-16 16:43:47 -0200853/**
854 * kmod_dump_index:
855 * @ctx: kmod library context
856 * @type: index to dump
857 * @fd: file descriptor to dump index to
858 *
Lucas De Marchi09e9ae52012-01-17 10:05:02 -0200859 * Dump index to file descriptor. Note that this function doesn't use stdio.h
860 * so call fflush() before calling this function to be sure data is written in
861 * order.
Lucas De Marchi02244822012-01-16 16:43:47 -0200862 *
863 * Returns: 0 on success or < 0 otherwise.
864 */
Lucas De Marchi758428a2012-01-16 15:56:17 -0200865KMOD_EXPORT int kmod_dump_index(struct kmod_ctx *ctx, enum kmod_index type,
866 int fd)
867{
868 if (ctx == NULL)
869 return -ENOSYS;
870
871 if (type < 0 || type >= _KMOD_INDEX_MODULES_SIZE)
872 return -ENOENT;
873
874 if (ctx->indexes[type] != NULL) {
875 DBG(ctx, "use mmaped index '%s'\n", index_files[type].fn);
876 index_mm_dump(ctx->indexes[type], fd,
877 index_files[type].prefix);
878 } else {
879 char fn[PATH_MAX];
880 struct index_file *idx;
881
882 snprintf(fn, sizeof(fn), "%s/%s.bin", ctx->dirname,
883 index_files[type].fn);
884
885 DBG(ctx, "file=%s\n", fn);
886
887 idx = index_file_open(fn);
888 if (idx == NULL)
889 return -ENOSYS;
890
891 index_dump(idx, fd, index_files[type].prefix);
892 index_file_close(idx);
893 }
894
895 return 0;
896}
897
Lucas De Marchie7fc2c82012-06-12 01:43:46 -0300898const struct kmod_config *kmod_get_config(const struct kmod_ctx *ctx)
Lucas De Marchic1c9c442011-12-24 10:50:47 -0200899{
Lucas De Marchie7fc2c82012-06-12 01:43:46 -0300900 return ctx->config;
Lucas De Marchi8b5ee612012-01-13 01:14:46 -0200901}