소스 검색

Rewrote initramfs hotplug script in C

This prevents ~10 segfaults at early kernel loading stage when the
hotplug program is not statically linked.
Maxim Kammerer 11 년 전
부모
커밋
9c816d3523
4개의 변경된 파일33개의 추가작업 그리고 14개의 파일을 삭제
  1. 0 9
      src/root/initrd/hotplug
  2. 4 4
      src/root/initrd/initramfs
  3. 2 1
      src/root/setup
  4. 27 0
      src/usr/local/src/hotplug.c

+ 0 - 9
src/root/initrd/hotplug

@@ -1,9 +0,0 @@
-#!/bin/busybox sh
-
-# Redirect input/output to console
-exec </dev/null 1>/dev/console 2>&1
-
-
-if [ "${ACTION}" = add  -a  -n "${MODALIAS}" ]; then
-    exec /sbin/modprobe -qb "${MODALIAS}"
-fi

+ 4 - 4
src/root/initrd/initramfs

@@ -7,10 +7,10 @@ nod   dev/console    0600 0 0  c 5 1
 dir   etc            0755 0 0
 dir   sbin           0755 0 0
 dir   etc/modprobe.d 0755 0 0
-file  init              /root/initrd/init         0755 0 0
-file  etc/init.scripts  /root/initrd/init.scripts 0644 0 0
-file  etc/modules.fs    /root/initrd/modules.fs   0644 0 0
-file  sbin/hotplug      /root/initrd/hotplug      0755 0 0
+file  init              /root/initrd/init                0755 0 0
+file  etc/init.scripts  /root/initrd/init.scripts        0644 0 0
+file  etc/modules.fs    /root/initrd/modules.fs          0644 0 0
+file  sbin/hotplug      /usr/local/addons/initrd/hotplug 0755 0 0
 
 # Init scripts support
 dir   stage          0755 0 0

+ 2 - 1
src/root/setup

@@ -247,10 +247,11 @@ gcc  ${cflags} -o /usr/local/bin/log-limit           /usr/local/src/log-limit.c
 
 cflags="-std=c99 -Wall `portageq envvar CFLAGS`"
 mkdir -p /usr/local/addons/initrd
+klcc ${cflags} -o /usr/local/addons/initrd/hotplug    /usr/local/src/hotplug.c
 klcc ${cflags} -o /usr/local/addons/initrd/init-kexec /usr/local/src/init-kexec.c
 
 strip -s /usr/local/{sbin/{udev-watchdog,slay,privsh},bin/log-limit} \
-         /usr/local/addons/initrd/init-kexec
+         /usr/local/addons/initrd/{hotplug,init-kexec}
 
 
 sinfo "Generating localization, timezone and keyboard layout menus"

+ 27 - 0
src/usr/local/src/hotplug.c

@@ -0,0 +1,27 @@
+/*
+   initramfs module hotplugging script.
+
+   Written in C to be statically compiled in order to prevent
+   segfaults in ld-linux.so.2 at early kernel initialization stages
+   (empirically, when /dev/null is available, but /dev/tty0 is not
+   yet, during device addition events).
+*/
+
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+#define MODPROBE "/sbin/modprobe"
+
+int main() {
+    char *value;
+
+    if (((value = getenv("ACTION"))) && !strcmp("add", value)) {
+        if ((value = getenv("MODALIAS"))) {
+            execl(MODPROBE, MODPROBE, "-qb", value, (char *) NULL);
+            return EXIT_FAILURE;
+        }
+    }
+
+    return EXIT_SUCCESS;
+}