Replace system("cat") and system("dd") with C implementation

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
Claudio Matsuoka
2008-02-16 21:26:33 -02:00
parent 57d982699b
commit a31bd547d6
4 changed files with 46 additions and 10 deletions
+2 -1
View File
@@ -5,7 +5,8 @@
- 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 fork ifconfig
- use direct calls to set loopback instead of system("ifconfig")
- replace system("cat") and system("dd") with C implementation
0.1 (20081214)
- initial release
+1
View File
@@ -70,3 +70,4 @@ problems related to udev and pam.
/etc/init.d/nfs-common start
3 - Create /etc/hostname if you don't have it already
+21 -4
View File
@@ -93,6 +93,10 @@ THE SOFTWARE.
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
/*
* Helpers to replace system() calls
*/
int makepath(char *p)
{
char *x, path[PATH_MAX];
@@ -130,6 +134,21 @@ void ifconfig(char *name, char *inet, char *mask, int flags)
close(sock);
}
void copy4k(char *src, char *dst)
{
char buffer[4096];
int s, d, n;
if ((s = open(src, O_RDONLY)) >= 0) {
if ((d = open(dst, O_WRONLY | O_CREAT, 0644)) >= 0) {
if ((n = read(s, buffer, 4096)) > 0)
write(d, buffer, n);
close(d);
}
close(s);
}
}
void do_shutdown(int);
@@ -289,12 +308,10 @@ int main()
/*
* Set random seed
*/
system("/bin/cat " RANDOMSEED " >/dev/urandom 2> /dev/null");
copy4k(RANDOMSEED, "/dev/urandom");
unlink(RANDOMSEED);
umask(077);
system("/bin/dd if=/dev/urandom of=" RANDOMSEED "bs=4096 count=1 "
">/dev/null 2>&1");
copy4k("/dev/urandom", RANDOMSEED);
/*
* Misc setup
+22 -5
View File
@@ -36,6 +36,7 @@ Changelog from the original Eeepc fastinit:
- 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")
*/
@@ -79,6 +80,10 @@ Changelog from the original Eeepc fastinit:
#define touch(x) mknod((x), S_IFREG|0644, 0)
/*
* Helpers to replace system() calls
*/
int makepath(char *p)
{
char *x, path[PATH_MAX];
@@ -116,6 +121,21 @@ void ifconfig(char *name, char *inet, char *mask, int flags)
close(sock);
}
void copy4k(char *src, char *dst)
{
char buffer[4096];
int s, d, n;
if ((s = open(src, O_RDONLY)) >= 0) {
if ((d = open(dst, O_WRONLY | O_CREAT, 0644)) >= 0) {
if ((n = read(s, buffer, 4096)) > 0)
write(d, buffer, n);
close(d);
}
close(s);
}
}
void do_shutdown(int);
@@ -243,13 +263,10 @@ int main()
/*
* Set random seed
*/
system("/bin/cat /var/lib/urandom/random-seed >/dev/urandom "
"2> /dev/null");
copy4k("/var/lib/urandom/random-seed", "/dev/urandom");
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");
copy4k("/dev/urandom", "/var/lib/urandom/random-seed");
/*
* Misc setup