2 #ifdef HAVE_XORG_CONFIG_H
3 #include <xorg-config.h>
11 #include "xf86_OSlib.h"
14 #define MODPROBE_PATH_FILE "/proc/sys/kernel/modprobe"
18 /* XFree86 #defines execl to be the xf86execl() function which does
19 * a fork AND exec. We don't want that. We want the regular,
28 * Load a Linux kernel module.
29 * This is used by the DRI/DRM to load a DRM kernel module when
30 * the X server starts. It could be used for other purposes in the future.
32 * modName - name of the kernel module (Ex: "tdfx")
34 * 0 for failure, 1 for success
37 xf86LoadKernelModule(const char *modName
)
39 char mpPath
[MAX_PATH
] = "";
40 int fd
= -1, status
, n
;
43 /* get the path to the modprobe program */
44 fd
= open(MODPROBE_PATH_FILE
, O_RDONLY
);
46 int count
= read(fd
, mpPath
, MAX_PATH
- 1);
51 else if (mpPath
[count
- 1] == '\n') {
52 mpPath
[count
- 1] = 0; /* replaces \n with \0 */
55 /* if this worked, mpPath will be "/sbin/modprobe" or similar. */
59 /* we failed to get the path from the system, use a default */
60 strcpy(mpPath
, "/sbin/modprobe");
63 /* now fork/exec the modprobe command */
65 * It would be good to capture stdout/stderr so that it can be directed
66 * to the log file. modprobe errors currently are missing from the log
69 switch (pid
= fork()) {
71 /* change real/effective user ID to 0/0 as we need to
72 * preinstall agpgart module for some DRM modules
75 xf86Msg(X_WARNING
, "LoadKernelModule: "
76 "Setting of real/effective user Id to 0/0 failed");
78 setenv("PATH", "/sbin", 1);
79 n
= execl(mpPath
, "modprobe", modName
, NULL
);
80 xf86Msg(X_WARNING
, "LoadKernelModule %s\n", strerror(errno
));
81 exit(EXIT_FAILURE
); /* if we get here the child's exec failed */
83 case -1: /* fork failed */
85 default: /* fork worked */
87 /* XXX we loop over waitpid() because it sometimes fails on
88 * the first attempt. Don't know why!
93 p
= waitpid(pid
, &status
, 0);
94 } while (p
== -1 && count
++ < 4);
100 if (WIFEXITED(status
) && WEXITSTATUS(status
) == 0) {
101 return 1; /* success! */