~ubuntu-branches/debian/jessie/systemd/jessie

« back to all changes in this revision

Viewing changes to src/kmod-setup.c

  • Committer: Package Import Robot
  • Author(s): Tollef Fog Heen, Tollef Fog Heen, Michael Biebl
  • Date: 2012-04-03 19:59:17 UTC
  • mfrom: (1.1.10) (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20120403195917-l532urrbg4pkreas
Tags: 44-1
[ Tollef Fog Heen ]
* New upstream version.
  - Backport 3492207: journal: PAGE_SIZE is not known on ppc and other
    archs
  - Backport 5a2a2a1: journal: react with immediate rotation to a couple
    of more errors
  - Backport 693ce21: util: never follow symlinks in rm_rf_children()
    Fixes CVE-2012-1174, closes: #664364
* Drop output message from init-functions hook, it's pointless.
* Only rmdir /lib/init/rw if it exists.
* Explicitly order debian-fixup before sysinit.target to prevent a
  possible race condition with the creation of sockets.  Thanks to
  Michael Biebl for debugging this.
* Always restart the initctl socket on upgrades, to mask sysvinit
  removing it.

[ Michael Biebl ]
* Remove workaround for non-interactive sessions from pam config again.
* Create compat /dev/initctl symlink in case we are upgrading from a system
  running a newer version of sysvinit (using /run/initctl) and sysvinit is
  replaced with systemd-sysv during the upgrade. Closes: #663219
* Install new man pages.
* Build-Depend on valac (>= 0.12) instead of valac-0.12. Closes: #663323

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#include <unistd.h>
24
24
#include <string.h>
25
25
#include <errno.h>
 
26
#include <libkmod.h>
26
27
 
27
28
#include "macro.h"
28
29
#include "execute.h"
35
36
        "unix",    "/proc/net/unix"
36
37
};
37
38
 
 
39
#pragma GCC diagnostic push
 
40
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
 
41
static void systemd_kmod_log(void *data, int priority, const char *file, int line,
 
42
                             const char *fn, const char *format, va_list args)
 
43
{
 
44
        log_meta(priority, file, line, fn, format, args);
 
45
}
 
46
#pragma GCC diagnostic pop
 
47
 
38
48
int kmod_setup(void) {
39
 
        unsigned i, n = 0;
40
 
        const char * cmdline[3 + ELEMENTSOF(kmod_table) + 1];
41
 
        ExecCommand command;
42
 
        ExecContext context;
43
 
        pid_t pid;
44
 
        int r;
 
49
        unsigned i;
 
50
        struct kmod_ctx *ctx = NULL;
 
51
        struct kmod_module *mod;
 
52
        int err;
45
53
 
46
54
        for (i = 0; i < ELEMENTSOF(kmod_table); i += 2) {
47
55
 
49
57
                        continue;
50
58
 
51
59
                log_debug("Your kernel apparently lacks built-in %s support. Might be a good idea to compile it in. "
52
 
                          "We'll now try to work around this by calling '/sbin/modprobe %s'...",
53
 
                          kmod_table[i], kmod_table[i]);
54
 
 
55
 
                cmdline[3 + n++] = kmod_table[i];
56
 
        }
57
 
 
58
 
        if (n <= 0)
59
 
                return 0;
60
 
 
61
 
        cmdline[0] = "/sbin/modprobe";
62
 
        cmdline[1] = "-qab";
63
 
        cmdline[2] = "--";
64
 
        cmdline[3 + n] = NULL;
65
 
 
66
 
        zero(command);
67
 
        zero(context);
68
 
 
69
 
        command.path = (char*) cmdline[0];
70
 
        command.argv = (char**) cmdline;
71
 
 
72
 
        exec_context_init(&context);
73
 
        r = exec_spawn(&command, NULL, &context, NULL, 0, NULL, false, false, false, false, NULL, NULL, &pid);
74
 
        exec_context_done(&context);
75
 
 
76
 
        if (r < 0) {
77
 
                log_error("Failed to spawn %s: %s", cmdline[0], strerror(-r));
78
 
                return r;
79
 
        }
80
 
 
81
 
        return wait_for_terminate_and_warn(cmdline[0], pid);
 
60
                          "We'll now try to work around this by loading the module...",
 
61
                          kmod_table[i]);
 
62
 
 
63
                if (!ctx) {
 
64
                        ctx = kmod_new(NULL, NULL);
 
65
                        if (!ctx) {
 
66
                                log_error("Failed to allocate memory for kmod");
 
67
                                return -ENOMEM;
 
68
                        }
 
69
 
 
70
                        kmod_set_log_fn(ctx, systemd_kmod_log, NULL);
 
71
 
 
72
                        kmod_load_resources(ctx);
 
73
                }
 
74
 
 
75
                err = kmod_module_new_from_name(ctx, kmod_table[i], &mod);
 
76
                if (err < 0) {
 
77
                        log_error("Failed to load module '%s'", kmod_table[i]);
 
78
                        continue;
 
79
                }
 
80
 
 
81
                err = kmod_module_probe_insert_module(mod, KMOD_PROBE_APPLY_BLACKLIST, NULL, NULL, NULL, NULL);
 
82
                if (err == 0)
 
83
                        log_info("Inserted module '%s'", kmod_module_get_name(mod));
 
84
                else if (err == KMOD_PROBE_APPLY_BLACKLIST)
 
85
                        log_info("Module '%s' is blacklisted", kmod_module_get_name(mod));
 
86
                else
 
87
                        log_error("Failed to insert '%s'", kmod_module_get_name(mod));
 
88
 
 
89
                kmod_module_unref(mod);
 
90
        }
 
91
 
 
92
        if (ctx)
 
93
                kmod_unref(ctx);
 
94
 
 
95
        return 0;
82
96
}