mirror of
https://github.com/troglobit/finit.git
synced 2026-11-13 17:00:16 +00:00
Added debug support and a lot of Mandriva quirks
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
1 parent
3b9f459f73
commit
d76ac231b9
1 file changed
+78
-10
@@ -20,11 +20,36 @@
|
|||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
|
|
||||||
|
#define DEBUG
|
||||||
|
|
||||||
#ifdef DIST_MDV
|
#ifdef DEBUG
|
||||||
#define RANDOMSEED "/var/lib/random-seed"
|
#define debug(x...) do { \
|
||||||
|
printf("finit: %d: ", __LINE__); printf(x); printf("\n"); \
|
||||||
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define RANDOMSEED "/var/lib/urandom/random-seed"
|
#define debug(x...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Distribution configuration */
|
||||||
|
|
||||||
|
#ifdef DIST_MDV /* Mandriva */
|
||||||
|
#define RANDOMSEED "/var/lib/random-seed"
|
||||||
|
#define SYSROOT "/sysroot"
|
||||||
|
#define GETTY "/sbin/mingetty tty3"
|
||||||
|
#define RUNPARTS "/usr/bin/run-parts --arg=-i"
|
||||||
|
#define DEFUSER "u"
|
||||||
|
#define STARTX "/usr/bin/startx"
|
||||||
|
#define HOMEDEV "/dev/sda3"
|
||||||
|
#define AGPDRV "intel-agp"
|
||||||
|
#define REMOUNT_ROOTFS_RW
|
||||||
|
#define MAKE_DEVICES
|
||||||
|
#else /* original Eeepc distribution */
|
||||||
|
#define RANDOMSEED "/var/lib/urandom/random-seed"
|
||||||
|
#define SYSROOT "/mnt"
|
||||||
|
#define GETTY "/sbin/getty 38400 tty3"
|
||||||
|
#define RUNPARTS "/bin/run-parts --arg=-i"
|
||||||
|
#define DEFUSER "user"
|
||||||
|
#define STARTX "startx"
|
||||||
#define TOUCH_ETC_NETWORK_RUN_IFSTATE
|
#define TOUCH_ETC_NETWORK_RUN_IFSTATE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -37,9 +62,11 @@
|
|||||||
sa.sa_flags = flags; \
|
sa.sa_flags = flags; \
|
||||||
sigemptyset(&sa.sa_mask); \
|
sigemptyset(&sa.sa_mask); \
|
||||||
sigaction(sig, &sa, NULL); \
|
sigaction(sig, &sa, NULL); \
|
||||||
} while(0)
|
} while (0)
|
||||||
|
|
||||||
#define touch(x) close(open((x), O_CREAT|O_WRONLY|O_TRUNC, 0644))
|
//#define touch(x) close(open((x), O_CREAT|O_WRONLY|O_TRUNC, 0644))
|
||||||
|
#define touch(x) mknod((x), S_IFREG|0644, 0)
|
||||||
|
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
|
||||||
|
|
||||||
|
|
||||||
int makepath(char *p)
|
int makepath(char *p)
|
||||||
@@ -78,6 +105,8 @@ int main()
|
|||||||
char *x;
|
char *x;
|
||||||
sigset_t nmask, nmask2;
|
sigset_t nmask, nmask2;
|
||||||
|
|
||||||
|
debug("start");
|
||||||
|
|
||||||
chdir("/");
|
chdir("/");
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
@@ -124,12 +153,36 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* Mount filesystems
|
* Mount filesystems
|
||||||
*/
|
*/
|
||||||
|
debug("mount filesystems");
|
||||||
|
|
||||||
|
#ifdef REMOUNT_ROOTFS_RW
|
||||||
|
system("/bin/mount -n -o remount,rw /");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
mkdir("/dev/pts", 0644);
|
||||||
|
mkdir("/dev/shm", 0644);
|
||||||
|
|
||||||
mount("proc", "/proc", "proc", 0, NULL);
|
mount("proc", "/proc", "proc", 0, NULL);
|
||||||
mount("sysfs", "/sys", "sysfs", 0, NULL);
|
mount("sysfs", "/sys", "sysfs", 0, NULL);
|
||||||
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620");
|
mount("devpts", "/dev/pts", "devpts", 0, "gid=5,mode=620");
|
||||||
mount("tmpfs", "/dev/shm", "tmpfs", 0, NULL);
|
mount("tmpfs", "/dev/shm", "tmpfs", 0, NULL);
|
||||||
mount("tmpfs", "/tmp", "tmpfs", 0, "mode=1777,size=128m");
|
mount("tmpfs", "/tmp", "tmpfs", 0, "mode=1777,size=128m");
|
||||||
mount("/mnt", "/", NULL, MS_MOVE, NULL);
|
#ifdef HOMEDEV
|
||||||
|
mount(HOMEDEV, "/home", "ext3", 0, NULL);
|
||||||
|
#endif
|
||||||
|
mount(SYSROOT, "/", NULL, MS_MOVE, NULL);
|
||||||
|
|
||||||
|
#ifdef MAKE_DEVICES
|
||||||
|
debug("make devices");
|
||||||
|
umask(0777);
|
||||||
|
mkdir("/dev/input", 0644);
|
||||||
|
chardev("/dev/null", 0666, 1, 3);
|
||||||
|
chardev("/dev/mem", 0640, 1, 1);
|
||||||
|
chardev("/dev/tty", 0666, 5, 0);
|
||||||
|
chardev("/dev/input/mice", 0660, 13, 63);
|
||||||
|
chardev("/dev/agpgart", 0660, 10, 175);
|
||||||
|
umask(0022);
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Time adjustments
|
* Time adjustments
|
||||||
@@ -162,7 +215,7 @@ int main()
|
|||||||
touch("/etc/resolvconf/run/enable-updates");
|
touch("/etc/resolvconf/run/enable-updates");
|
||||||
|
|
||||||
chdir("/etc/resolvconf/run/interface");
|
chdir("/etc/resolvconf/run/interface");
|
||||||
system("/bin/run-parts --arg=-i /etc/resolvconf/update.d");
|
system(RUNPARTS "/etc/resolvconf/update.d");
|
||||||
chdir("/");
|
chdir("/");
|
||||||
|
|
||||||
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
|
#ifdef TOUCH_ETC_NETWORK_RUN_IFSTATE
|
||||||
@@ -202,6 +255,8 @@ int main()
|
|||||||
mkdir("/tmp/.ICE-unix", 01777);
|
mkdir("/tmp/.ICE-unix", 01777);
|
||||||
umask(022);
|
umask(022);
|
||||||
|
|
||||||
|
debug("forking");
|
||||||
|
|
||||||
if (!fork()) {
|
if (!fork()) {
|
||||||
/* child process */
|
/* child process */
|
||||||
|
|
||||||
@@ -230,15 +285,27 @@ int main()
|
|||||||
|
|
||||||
touch("/tmp/nologin");
|
touch("/tmp/nologin");
|
||||||
|
|
||||||
while (access("/tmp/shutdown", F_OK) < 0)
|
#ifdef AGPDRV
|
||||||
system("su -c startx -l user &> /dev/null");
|
system("/sbin/modprobe agpgart");
|
||||||
|
system("/sbin/modprobe " AGPDRV);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while (access("/tmp/shutdown", F_OK) < 0) {
|
||||||
|
debug("run " STARTX " as " DEFUSER);
|
||||||
|
#ifdef DEBUG
|
||||||
|
system("su -c " STARTX " -l " DEFUSER);
|
||||||
|
system("/bin/sh");
|
||||||
|
#else
|
||||||
|
system("su -c " STARTX " -l " DEFUSER " &> /dev/null");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parent process */
|
/* parent process */
|
||||||
|
|
||||||
system("/sbin/getty 38400 tty3 &");
|
system(GETTY " &");
|
||||||
sleep(1);
|
sleep(1);
|
||||||
system("/usr/sbin/services.sh &> /dev/null &");
|
system("/usr/sbin/services.sh &> /dev/null &");
|
||||||
|
|
||||||
@@ -256,6 +323,7 @@ void shutdown(int sig)
|
|||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
debug("shutdown");
|
||||||
touch("/tmp/shutdown");
|
touch("/tmp/shutdown");
|
||||||
|
|
||||||
kill(-1, SIGTERM);
|
kill(-1, SIGTERM);
|
||||||
|
|||||||
Reference in new issue
Block a user