Compare commits

..
19 Commits
Author SHA1 Message Date
Claudio Matsuoka 3e29872db7 Cosmetic fix
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-19 20:22:31 -03:00
Claudio Matsuoka 944ba857e6 No need to rename shutdown(), socket functions moved to helpers
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-17 19:51:34 -03:00
Claudio Matsuoka 0c72f960f1 Fixed shutdown splash copyfile() call
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-17 08:55:31 -03:00
Claudio Matsuoka 1fc2d9596a Draw shutdown splash screen using C calls instead of system("echo;cat")
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-17 08:54:34 -03:00
Claudio Matsuoka cdbc2c536d Helper code cleanup
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-17 08:42:57 -03:00
Claudio Matsuoka d17c3160bd Size 0 in copyfile copies entire file (semantics of <0 reserved)
Also updated documentation

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-17 08:11:51 -03:00
Claudio Matsuoka dbb31994a0 Moved helpers to a separate file
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 22:03:16 -02:00
Claudio Matsuoka a31bd547d6 Replace system("cat") and system("dd") with C implementation
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 21:26:33 -02:00
Claudio Matsuoka 57d982699b Minor comment fix
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 21:03:37 -02:00
Claudio Matsuoka e1f57e78c9 Fix typo in variable name
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 20:57:30 -02:00
Claudio Matsuoka 3657d539c1 Use direct calls to set loopback instead of fork ifconfig
Also renamed shutdown() to do_shutdown() because socket.h redefines it

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 20:52:02 -02:00
Claudio Matsuoka 9a2b6890e5 Write ACPI sleep state to /sys/power/state instead of /proc/acpi/sleep
From http://acpi.sourceforge.net/documentation/sleep.html:

/proc/acpi is being replaced by interfaces in /sys and new software
should not look in /proc. Users of 2.6 are advised to use the new file
in sysfs: /sys/power/state.

Metalshark says:
February 15th, 2008 at 6:15 am

In shutdown you use “/proc/acpi/sleep”, would it be advisable to use the
new sysfs method and use that if available and if not use proc (at runtime)
with compile time options to disable proc/sysfs methods?

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 19:37:21 -02:00
Claudio Matsuoka bbe281db55 Drop system("rm -f") to clean /tmp, its a fresh mounted tmpfs
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-16 18:07:57 -02:00
Claudio Matsuoka ef3071b957 Disable NO_HCTOSYS by default to match stock Eeepc kernel
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-15 16:56:05 -02:00
Claudio Matsuoka 1d4d7df3cc Replace remaining system("touch") with touch() (by Metalshark)
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-15 14:14:34 -02:00
Claudio Matsuoka 16ef455fb1 Added Mandriva 2008 notes
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-15 14:10:59 -02:00
Claudio Matsuoka 8c3580d352 Add Changelog file
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-15 09:08:04 -02:00
Claudio Matsuoka 412de97ad8 Fixed changelog message
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-15 00:04:34 -02:00
Claudio Matsuoka 7af37f1fb7 Update version number after release
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
2008-02-14 22:21:27 -02:00
8 changed files with 190 additions and 75 deletions
+14
View File
@@ -0,0 +1,14 @@
0.2 ()
- replace system("touch") with touch() in finit-mod (Metalshark)
- disable NO_HCTOSYS by default to match stock Eeepc kernel
- drop system("rm -f") to clean /tmp, its a fresh mounted tmpfs
- write ACPI sleep state to /sys/power/state instead of
/proc/acpi/sleep (Metalshark)
- use direct calls to set loopback instead of system("ifconfig")
- replace system("cat") and system("dd") with C implementation
- moved finit-mod and finit-alt helpers to helpers.c
- replace system("echo;cat") to draw shutdown splash with C calls
0.1 (20081214)
- initial release
+14 -4
View File
@@ -3,8 +3,10 @@ CFLAGS = -Os -Wall -DVERSION=\"$(VERSION)\" -DWHOAMI=\"`whoami`@`hostname`\"
LD = gcc
LDFLAGS =
LIBS =
VERSION = 0.1
VERSION = 0.2
PKG = finit-$(VERSION)
DFILES = Makefile README finit.c finit-mod.c finit-alt.c helpers.c helpers.h
#### Configurable parameters
@@ -17,7 +19,7 @@ PKG = finit-$(VERSION)
CFLAGS += -march=pentium-m
# Omit the first /sbin/hwclock if CONFIG_RTC_HCTOSYS is enabled in the kernel
CFLAGS += -DNO_HCTOSYS
#CFLAGS += -DNO_HCTOSYS
# Append –directisa to /sbin/hwclock lines if the user has disabled
# CONFIG_GENRTC and enabled CONFIG_RTC but not enabled CONFIG_HPET_TIMER
@@ -31,7 +33,15 @@ CFLAGS += -DNO_HCTOSYS
all: finit finit-mod finit-mdv
%: %.o
finit: finit.o
$(LD) $(LDFLAGS) -o $@ $+ $(LIBS)
strip $@
finit-mod: finit-mod.o helpers.o
$(LD) $(LDFLAGS) -o $@ $+ $(LIBS)
strip $@
finit-mdv: finit-mdv.o helpers.o
$(LD) $(LDFLAGS) -o $@ $+ $(LIBS)
strip $@
@@ -48,7 +58,7 @@ finit-mod.o: finit-mod.c Makefile
dist:
rm -Rf $(PKG)
mkdir $(PKG)
cp Makefile README finit.c finit-mod.c finit-alt.c $(PKG)
cp Makefile $(DFILES) $(PKG)
tar cf - $(PKG) | gzip -c > $(PKG).tar.gz
rm -Rf $(PKG)
ls -l $(PKG).tar.gz
+25
View File
@@ -48,3 +48,28 @@ umount vi
console fb null ram0 sda1 sda2 sda3 sr0 tty0
Using finit with alternative systems
------------------------------------
Currently tested only with Mandriva 2008. Proceed with caution, there are
problems related to udev and pam.
1 - Add init=/sbin/finit-mdv to the kernel boot line
2 - Provide a suitable /usr/sbin/services.sh, this is the one I use in my
test system:
mkdir /var/lock/subsys
chmod 1777 /var/lock/subsys
/etc/init.d/network start
dhclient eth0
/sbin/start_udev&
/etc/init.d/portmap start
/etc/init.d/nfs-common start
3 - Provide /etc/hostname if you don't have it already
4 - Set the pointer device in the X server configuration to /dev/input/mice
+14 -34
View File
@@ -37,8 +37,8 @@ THE SOFTWARE.
#include <sys/reboot.h>
#include <sys/wait.h>
#include <linux/fs.h>
#include <linux/limits.h>
#include "helpers.h"
#ifdef DEBUG
#define debug(x...) do { \
@@ -90,23 +90,6 @@ THE SOFTWARE.
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
int makepath(char *p)
{
char *x, path[PATH_MAX];
int ret;
x = path;
do {
do { *x++ = *p++; } while (*p && *p != '/');
ret = mkdir(path, 0777);
} while (*p && (*p != '/' || *(p + 1))); /* ignore trailing slash */
return ret;
}
void shutdown(int);
void signal_handler(int);
void chld_handler(int);
@@ -137,10 +120,10 @@ int main()
for (i = 1; i < NSIG; i++)
SETSIG(sa, i, SIG_IGN, SA_RESTART);
SETSIG(sa, SIGINT, shutdown, 0);
SETSIG(sa, SIGINT, shutdown, 0);
SETSIG(sa, SIGPWR, signal_handler, 0);
SETSIG(sa, SIGUSR1, shutdown, 0);
SETSIG(sa, SIGUSR2, shutdown, 0);
SETSIG(sa, SIGUSR1, shutdown, 0);
SETSIG(sa, SIGUSR2, shutdown, 0);
SETSIG(sa, SIGTERM, signal_handler, 0);
SETSIG(sa, SIGALRM, signal_handler, 0);
SETSIG(sa, SIGHUP, signal_handler, 0);
@@ -259,22 +242,19 @@ int main()
fclose(f);
}
system("/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 up > /dev/null");
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
/*
* Set random seed
*/
system("/bin/cat " RANDOMSEED " >/dev/urandom 2> /dev/null");
copyfile(RANDOMSEED, "/dev/urandom", 0);
unlink(RANDOMSEED);
umask(077);
system("/bin/dd if=/dev/urandom of=" RANDOMSEED "bs=4096 count=1 "
">/dev/null 2>&1");
copyfile("/dev/urandom", RANDOMSEED, 4096);
/*
* Misc setup
*/
system("/bin/rm -rf /tmp/* /tmp/.* 2>/dev/null");
unlink("/var/run/.clean");
unlink("/var/lock/.clean");
umask(0);
@@ -332,9 +312,9 @@ int main()
/* parent process */
system(GETTY " &");
system(GETTY "&");
sleep(1);
system("/usr/sbin/services.sh &> /dev/null &");
system("/usr/sbin/services.sh &>/dev/null&");
while (1) {
sigemptyset(&nmask);
@@ -355,9 +335,9 @@ void shutdown(int sig)
kill(-1, SIGTERM);
system("/bin/echo -e \"\033[?25l\033[30;40m\"; "
"/bin/cp /boot/shutdown.fb /dev/fb/0");
sleep(1);
write(1, "\033[?25l\033[30;40m", 14);
copyfile("/boot/shutdown.fb", "/dev/fb/0", 0);
sleep(2);
system("/usr/sbin/alsactl store > /dev/null 2>&1");
system("/sbin/hwclock --systohc --localtime" HWCLOCK_DIRECTISA);
@@ -374,7 +354,7 @@ void shutdown(int sig)
if (sig == SIGINT || sig == SIGUSR1)
reboot(RB_AUTOBOOT);
if ((fd = open("/proc/acpi/sleep", O_WRONLY)) >= 0) {
if ((fd = open("/sys/power/state", O_WRONLY)) >= 0) {
write(fd, "5", 1);
close(fd);
}
@@ -396,7 +376,7 @@ void chld_handler(int sig)
/*
* We got a signal (PWR TERM ALRM HUP STOP CONT)
* We got a signal (PWR TERM ALRM HUP CONT)
*/
void signal_handler(int sig)
{
+22 -37
View File
@@ -26,13 +26,18 @@ THE SOFTWARE.
Changelog from the original Eeepc fastinit:
- Use mknod() instead of close(creat()) call to create empty file
- Use mknod() instead of close(open()) call to create empty file
- Fix random seed initialization
- Don't try to handle signal 0, SIGKILL or SIGSTOP
- Implement makepath() to avoid system("mkdir -p")
- Omit first hwclock if user has CONFIG_RTC_HCTOSYS in kernel (by Metalshark)
- Add –directisa to hwclock if user has disabled CONFIG_GENRTC and enabled
CONFIG_RTC but not CONFIG_HPET_TIMER and CONFIG_HPET_RTC_IRQ (by Metalshark)
- Drop system() call to clean /tmp, it's a fresh mounted tmpfs
- Change /proc/acpi/sleep to /sys/power/state (by Metalshark)
- Set loopback interface using direct calls instead of system("ifconfig")
- Copy 4096 data block in C instead of system("cat") or system("dd")
- Draw shutdown splash screen using C calls instead of system("echo;cat")
*/
@@ -52,6 +57,8 @@ Changelog from the original Eeepc fastinit:
#include <sys/wait.h>
#include <linux/fs.h>
#include "helpers.h"
#ifdef DIRECTISA
#define HWCLOCK_DIRECTISA " --directisa"
#else
@@ -72,23 +79,6 @@ Changelog from the original Eeepc fastinit:
#define touch(x) mknod((x), S_IFREG|0644, 0)
int makepath(char *p)
{
char *x, path[PATH_MAX];
int ret;
x = path;
do {
do { *x++ = *p++; } while (*p && *p != '/');
ret = mkdir(path, 0777);
} while (*p && (*p != '/' || *(p + 1))); /* ignore trailing slash */
return ret;
}
void shutdown(int);
void signal_handler(int);
void chld_handler(int);
@@ -119,10 +109,10 @@ int main()
for (i = 1; i < NSIG; i++)
SETSIG(sa, i, SIG_IGN, SA_RESTART);
SETSIG(sa, SIGINT, shutdown, 0);
SETSIG(sa, SIGINT, shutdown, 0);
SETSIG(sa, SIGPWR, signal_handler, 0);
SETSIG(sa, SIGUSR1, shutdown, 0);
SETSIG(sa, SIGUSR2, shutdown, 0);
SETSIG(sa, SIGUSR1, shutdown, 0);
SETSIG(sa, SIGUSR2, shutdown, 0);
SETSIG(sa, SIGTERM, signal_handler, 0);
SETSIG(sa, SIGALRM, signal_handler, 0);
SETSIG(sa, SIGHUP, signal_handler, 0);
@@ -209,23 +199,19 @@ int main()
}
system("/sbin/ifconfig lo 127.0.0.1 netmask 255.0.0.0 up > /dev/null");
ifconfig("lo", "127.0.0.1", "255.0.0.0", 1);
/*
* Set random seed
*/
system("/bin/cat /var/lib/urandom/random-seed >/dev/urandom "
"2> /dev/null");
copyfile("/var/lib/urandom/random-seed", "/dev/urandom", 0);
unlink("/var/lib/urandom/random-seed");
umask(077);
system("/bin/dd if=/dev/urandom of=/var/lib/urandom/random-seed "
"bs=4096 count=1 >/dev/null 2>&1");
copyfile("/dev/urandom", "/var/lib/urandom/random-seed", 4096);
/*
* Misc setup
*/
system("/bin/rm -rf /tmp/* /tmp/.* 2>/dev/null");
unlink("/var/run/.clean");
unlink("/var/lock/.clean");
umask(0);
@@ -269,9 +255,9 @@ int main()
/* parent process */
system("/sbin/getty 38400 tty3 &");
system("/sbin/getty 38400 tty3&");
sleep(1);
system("/usr/sbin/services.sh &> /dev/null &");
system("/usr/sbin/services.sh &>/dev/null&");
while (1) {
sigemptyset(&nmask);
@@ -287,14 +273,13 @@ void shutdown(int sig)
{
int fd;
system("/usr/bin/touch /tmp/shutdown");
touch("/tmp/shutdown");
kill(-1, SIGTERM);
system("/bin/echo -e \"\033[?25l\033[30;40m\"; "
"/bin/cp /boot/shutdown.fb /dev/fb/0");
sleep(1);
sleep(1);
write(1, "\033[?25l\033[30;40m", 14);
copyfile("/boot/shutdown.fb", "/dev/fb/0", 0);
sleep(2);
system("/usr/sbin/alsactl store > /dev/null 2>&1");
system("/sbin/hwclock --systohc --localtime" HWCLOCK_DIRECTISA);
@@ -311,7 +296,7 @@ void shutdown(int sig)
if (sig == SIGINT || sig == SIGUSR1)
reboot(RB_AUTOBOOT);
if ((fd = open("/proc/acpi/sleep", O_WRONLY)) >= 0) {
if ((fd = open("/sys/power/state", O_WRONLY)) >= 0) {
write(fd, "5", 1);
close(fd);
}
@@ -333,7 +318,7 @@ void chld_handler(int sig)
/*
* We got a signal (PWR TERM ALRM HUP STOP CONT)
* We got a signal (PWR TERM ALRM HUP CONT)
*/
void signal_handler(int sig)
{
+2
View File
@@ -164,7 +164,9 @@ int main()
/*
* Misc setup
*/
/* not really needed, /tmp is a fresh mounted tmpfs */
system("/bin/rm -rf /tmp/* /tmp/.* 2>/dev/null");
unlink("/var/run/.clean");
unlink("/var/lock/.clean");
umask(0);
+91
View File
@@ -0,0 +1,91 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "helpers.h"
/*
* Helpers to replace system() calls
*/
int makepath(char *p)
{
char *x, path[PATH_MAX];
int ret;
x = path;
do {
do { *x++ = *p++; } while (*p && *p != '/');
ret = mkdir(path, 0777);
} while (*p && (*p != '/' || *(p + 1))); /* ignore trailing slash */
return ret;
}
void ifconfig(char *name, char *inet, char *mask, int up)
{
struct ifreq ifr;
struct sockaddr_in *a = (struct sockaddr_in *)&ifr.ifr_addr;
int sock;
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
return;
memset(&ifr, 0, sizeof (ifr));
strncpy(ifr.ifr_name, name, IFNAMSIZ);
a->sin_family = AF_INET;
if (up) {
inet_aton(inet, &a->sin_addr);
ioctl(sock, SIOCSIFADDR, &ifr);
inet_aton(mask, &a->sin_addr);
ioctl(sock, SIOCSIFNETMASK, &ifr);
}
ioctl(sock, SIOCGIFFLAGS, &ifr);
if (up)
ifr.ifr_flags |= IFF_UP;
else
ifr.ifr_flags &= ~IFF_UP;
ioctl(sock, SIOCSIFFLAGS, &ifr);
close(sock);
}
#define BUF_SIZE 4096
void copyfile(char *src, char *dst, int size)
{
char buffer[BUF_SIZE];
int s, d, n;
/* Size == 0 means copy entire file */
if (size == 0)
size = INT_MAX;
if ((s = open(src, O_RDONLY)) >= 0) {
if ((d = open(dst, O_WRONLY | O_CREAT, 0644)) >= 0) {
do {
int csize = size > BUF_SIZE ? BUF_SIZE : size;
if ((n = read(s, buffer, csize)) > 0)
write(d, buffer, n);
size -= csize;
} while (size > 0 && n == BUF_SIZE);
close(d);
}
close(s);
}
}
+8
View File
@@ -0,0 +1,8 @@
#ifndef __FINIT_HELPERS_H
#define __FINIT_HELPERS_H
int makepath (char *);
void ifconfig (char *, char *, char *, int);
void copyfile (char *, char *, int);
#endif