mirror of
https://github.com/troglobit/finit.git
synced 2026-11-08 16:11:10 +00:00
Replace system("cat") and system("dd") with C implementation
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
1 parent
57d982699b
commit
a31bd547d6
4 files changed
+46
-10
No files matched your search
@@ -5,7 +5,8 @@
|
|||||||
- 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
|
- use direct calls to set loopback instead of system("ifconfig")
|
||||||
|
- replace system("cat") and system("dd") with C implementation
|
||||||
|
|
||||||
0.1 (20081214)
|
0.1 (20081214)
|
||||||
- initial release
|
- initial release
|
||||||
@@ -70,3 +70,4 @@ problems related to udev and pam.
|
|||||||
/etc/init.d/nfs-common start
|
/etc/init.d/nfs-common start
|
||||||
|
|
||||||
3 - Create /etc/hostname if you don't have it already
|
3 - Create /etc/hostname if you don't have it already
|
||||||
|
|
||||||
+21
-4
@@ -93,6 +93,10 @@ THE SOFTWARE.
|
|||||||
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
|
#define chardev(x,m,maj,min) mknod((x), S_IFCHR|(m), makedev((maj),(min)))
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helpers to replace system() calls
|
||||||
|
*/
|
||||||
|
|
||||||
int makepath(char *p)
|
int makepath(char *p)
|
||||||
{
|
{
|
||||||
char *x, path[PATH_MAX];
|
char *x, path[PATH_MAX];
|
||||||
@@ -130,6 +134,21 @@ void ifconfig(char *name, char *inet, char *mask, int flags)
|
|||||||
close(sock);
|
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);
|
void do_shutdown(int);
|
||||||
@@ -289,12 +308,10 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* Set random seed
|
* Set random seed
|
||||||
*/
|
*/
|
||||||
system("/bin/cat " RANDOMSEED " >/dev/urandom 2> /dev/null");
|
copy4k(RANDOMSEED, "/dev/urandom");
|
||||||
unlink(RANDOMSEED);
|
unlink(RANDOMSEED);
|
||||||
|
|
||||||
umask(077);
|
umask(077);
|
||||||
system("/bin/dd if=/dev/urandom of=" RANDOMSEED "bs=4096 count=1 "
|
copy4k("/dev/urandom", RANDOMSEED);
|
||||||
">/dev/null 2>&1");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Misc setup
|
* Misc setup
|
||||||
|
|||||||
+22
-5
@@ -36,6 +36,7 @@ Changelog from the original Eeepc fastinit:
|
|||||||
- 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")
|
- 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)
|
#define touch(x) mknod((x), S_IFREG|0644, 0)
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helpers to replace system() calls
|
||||||
|
*/
|
||||||
|
|
||||||
int makepath(char *p)
|
int makepath(char *p)
|
||||||
{
|
{
|
||||||
char *x, path[PATH_MAX];
|
char *x, path[PATH_MAX];
|
||||||
@@ -116,6 +121,21 @@ void ifconfig(char *name, char *inet, char *mask, int flags)
|
|||||||
close(sock);
|
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);
|
void do_shutdown(int);
|
||||||
@@ -243,13 +263,10 @@ int main()
|
|||||||
/*
|
/*
|
||||||
* Set random seed
|
* Set random seed
|
||||||
*/
|
*/
|
||||||
system("/bin/cat /var/lib/urandom/random-seed >/dev/urandom "
|
copy4k("/var/lib/urandom/random-seed", "/dev/urandom");
|
||||||
"2> /dev/null");
|
|
||||||
unlink("/var/lib/urandom/random-seed");
|
unlink("/var/lib/urandom/random-seed");
|
||||||
|
|
||||||
umask(077);
|
umask(077);
|
||||||
system("/bin/dd if=/dev/urandom of=/var/lib/urandom/random-seed "
|
copy4k("/dev/urandom", "/var/lib/urandom/random-seed");
|
||||||
"bs=4096 count=1 >/dev/null 2>&1");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Misc setup
|
* Misc setup
|
||||||
|
|||||||
Reference in new issue
Block a user