mirror of
https://github.com/troglobit/finit.git
synced 2026-11-03 13:28:27 +00:00
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>
This commit is contained in:
1 parent
9a2b6890e5
commit
3657d539c1
3 files changed
+66
-13
No files matched your search
@@ -5,6 +5,7 @@
|
|||||||
- drop system("rm -f") to clean /tmp, its a fresh mounted tmpfs
|
- drop system("rm -f") to clean /tmp, its a fresh mounted tmpfs
|
||||||
- write ACPI sleep state to /sys/power/state instead of
|
- write ACPI sleep state to /sys/power/state instead of
|
||||||
/proc/acpi/sleep (Metalshark)
|
/proc/acpi/sleep (Metalshark)
|
||||||
|
- use direct calls to set loopback instead of fork ifconfig
|
||||||
|
|
||||||
0.1 (20081214)
|
0.1 (20081214)
|
||||||
- initial release
|
- initial release
|
||||||
+32
-7
@@ -37,7 +37,10 @@ THE SOFTWARE.
|
|||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
#include <linux/limits.h>
|
#include <sys/socket.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
@@ -105,9 +108,31 @@ int makepath(char *p)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ifconfig(char *name, char *inet, char *broadcast, int flags)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
inet_aton(inet, &a->sin_addr);
|
||||||
|
ioctl(sock, SIOCSIFADDR, &ifr);
|
||||||
|
inet_aton(broadcast, &a->sin_addr);
|
||||||
|
ioctl(sock, SIOCSIFNETMASK, &ifr);
|
||||||
|
ioctl(sock, SIOCGIFFLAGS, &ifr);
|
||||||
|
ifr.ifr_flags |= flags;
|
||||||
|
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
||||||
|
close(sock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void shutdown(int);
|
|
||||||
|
void do_shutdown(int);
|
||||||
void signal_handler(int);
|
void signal_handler(int);
|
||||||
void chld_handler(int);
|
void chld_handler(int);
|
||||||
|
|
||||||
@@ -137,10 +162,10 @@ int main()
|
|||||||
for (i = 1; i < NSIG; i++)
|
for (i = 1; i < NSIG; i++)
|
||||||
SETSIG(sa, i, SIG_IGN, SA_RESTART);
|
SETSIG(sa, i, SIG_IGN, SA_RESTART);
|
||||||
|
|
||||||
SETSIG(sa, SIGINT, shutdown, 0);
|
SETSIG(sa, SIGINT, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGPWR, signal_handler, 0);
|
SETSIG(sa, SIGPWR, signal_handler, 0);
|
||||||
SETSIG(sa, SIGUSR1, shutdown, 0);
|
SETSIG(sa, SIGUSR1, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGUSR2, shutdown, 0);
|
SETSIG(sa, SIGUSR2, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGTERM, signal_handler, 0);
|
SETSIG(sa, SIGTERM, signal_handler, 0);
|
||||||
SETSIG(sa, SIGALRM, signal_handler, 0);
|
SETSIG(sa, SIGALRM, signal_handler, 0);
|
||||||
SETSIG(sa, SIGHUP, signal_handler, 0);
|
SETSIG(sa, SIGHUP, signal_handler, 0);
|
||||||
@@ -259,7 +284,7 @@ int main()
|
|||||||
fclose(f);
|
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", IFF_UP);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set random seed
|
* Set random seed
|
||||||
@@ -345,7 +370,7 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* Shut down on INT USR1 USR2
|
* Shut down on INT USR1 USR2
|
||||||
*/
|
*/
|
||||||
void shutdown(int sig)
|
void do_shutdown(int sig)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
|||||||
+33
-6
@@ -35,6 +35,7 @@ Changelog from the original Eeepc fastinit:
|
|||||||
CONFIG_RTC but not CONFIG_HPET_TIMER and CONFIG_HPET_RTC_IRQ (by Metalshark)
|
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
|
- Drop system() call to clean /tmp, it's a fresh mounted tmpfs
|
||||||
- Change /proc/acpi/sleep to /sys/power/state (by Metalshark)
|
- Change /proc/acpi/sleep to /sys/power/state (by Metalshark)
|
||||||
|
- Set loopback interface using direct calls instead of system("ifconfig")
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -53,6 +54,10 @@ Changelog from the original Eeepc fastinit:
|
|||||||
#include <sys/reboot.h>
|
#include <sys/reboot.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <linux/fs.h>
|
#include <linux/fs.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <net/if.h>
|
||||||
|
#include <netinet/in.h>
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
|
||||||
#ifdef DIRECTISA
|
#ifdef DIRECTISA
|
||||||
#define HWCLOCK_DIRECTISA " --directisa"
|
#define HWCLOCK_DIRECTISA " --directisa"
|
||||||
@@ -89,9 +94,31 @@ int makepath(char *p)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ifconfig(char *name, char *inet, char *broadcast, int flags)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
inet_aton(inet, &a->sin_addr);
|
||||||
|
ioctl(sock, SIOCSIFADDR, &ifr);
|
||||||
|
inet_aton(broadcast, &a->sin_addr);
|
||||||
|
ioctl(sock, SIOCSIFNETMASK, &ifr);
|
||||||
|
ioctl(sock, SIOCGIFFLAGS, &ifr);
|
||||||
|
ifr.ifr_flags |= flags;
|
||||||
|
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
||||||
|
close(sock);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void shutdown(int);
|
|
||||||
|
void do_shutdown(int);
|
||||||
void signal_handler(int);
|
void signal_handler(int);
|
||||||
void chld_handler(int);
|
void chld_handler(int);
|
||||||
|
|
||||||
@@ -121,10 +148,10 @@ int main()
|
|||||||
for (i = 1; i < NSIG; i++)
|
for (i = 1; i < NSIG; i++)
|
||||||
SETSIG(sa, i, SIG_IGN, SA_RESTART);
|
SETSIG(sa, i, SIG_IGN, SA_RESTART);
|
||||||
|
|
||||||
SETSIG(sa, SIGINT, shutdown, 0);
|
SETSIG(sa, SIGINT, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGPWR, signal_handler, 0);
|
SETSIG(sa, SIGPWR, signal_handler, 0);
|
||||||
SETSIG(sa, SIGUSR1, shutdown, 0);
|
SETSIG(sa, SIGUSR1, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGUSR2, shutdown, 0);
|
SETSIG(sa, SIGUSR2, do_shutdown, 0);
|
||||||
SETSIG(sa, SIGTERM, signal_handler, 0);
|
SETSIG(sa, SIGTERM, signal_handler, 0);
|
||||||
SETSIG(sa, SIGALRM, signal_handler, 0);
|
SETSIG(sa, SIGALRM, signal_handler, 0);
|
||||||
SETSIG(sa, SIGHUP, signal_handler, 0);
|
SETSIG(sa, SIGHUP, signal_handler, 0);
|
||||||
@@ -211,7 +238,7 @@ 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", IFF_UP);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set random seed
|
* Set random seed
|
||||||
@@ -284,7 +311,7 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* Shut down on INT USR1 USR2
|
* Shut down on INT USR1 USR2
|
||||||
*/
|
*/
|
||||||
void shutdown(int sig)
|
void do_shutdown(int sig)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user