Use macro for line size, reuse line buffer for hostname and filename

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
Claudio Matsuoka committed 2008-03-16 17:07:14 -03:00
1 parent b5e2af21a6
commit 5ad9ff48c5
2 files changed
+18 -20

No files matched your search

+9 -10
View File
@@ -90,6 +90,7 @@ 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)))
#define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min))) #define blkdev(x,m,maj,min) mknod((x), S_IFBLK|(m), makedev((maj),(min)))
#define LINE_SIZE 1024
void shutdown(int); void shutdown(int);
void signal_handler(int); void signal_handler(int);
@@ -100,13 +101,11 @@ int main()
{ {
int i; int i;
FILE *f; FILE *f;
char line[2096]; char line[LINE_SIZE];
int fd; int fd;
DIR *dir; DIR *dir;
struct dirent *d; struct dirent *d;
char filename[1024];
struct sigaction sa, act; struct sigaction sa, act;
char hline[1024];
char *x; char *x;
sigset_t nmask, nmask2; sigset_t nmask, nmask2;
@@ -144,7 +143,7 @@ int main()
* Parse kernel parameters * Parse kernel parameters
*/ */
if ((f = fopen("/proc/cmdline", "r")) != NULL) { if ((f = fopen("/proc/cmdline", "r")) != NULL) {
fgets(line, 2095, f); fgets(line, LINE_SIZE, f);
if (strstr(line, "quiet")) { if (strstr(line, "quiet")) {
close(0); close(0);
close(1); close(1);
@@ -222,9 +221,9 @@ int main()
while ((d = readdir(dir)) != NULL) { while ((d = readdir(dir)) != NULL) {
if (isalnum(d->d_name[0])) if (isalnum(d->d_name[0]))
continue; continue;
sprintf(filename, "/etc/resolvconf/run/interface/%s", snprintf(line, LINE_SIZE,
d->d_name); "/etc/resolvconf/run/interface/%s", d->d_name);
unlink(filename); unlink(line);
} }
closedir(dir); closedir(dir);
@@ -246,11 +245,11 @@ int main()
#endif #endif
if ((f = fopen("/etc/hostname", "r")) != NULL) { if ((f = fopen("/etc/hostname", "r")) != NULL) {
fgets(hline, 1023, f); fgets(line, LINE_SIZE, f);
if ((x = strchr(hline, 0x0a)) != NULL) if ((x = strchr(line, 0x0a)) != NULL)
*x = 0; *x = 0;
sethostname(hline, strlen(hline)); sethostname(line, strlen(line));
fclose(f); fclose(f);
} }
+9 -10
View File
@@ -81,6 +81,7 @@ Changelog from the original Eeepc fastinit:
#define touch(x) mknod((x), S_IFREG|0644, 0) #define touch(x) mknod((x), S_IFREG|0644, 0)
#define LINE_SIZE 1024
void shutdown(int); void shutdown(int);
void signal_handler(int); void signal_handler(int);
@@ -91,13 +92,11 @@ int main()
{ {
int i; int i;
FILE *f; FILE *f;
char line[2096]; char line[LINE_SIZE];
int fd; int fd;
DIR *dir; DIR *dir;
struct dirent *d; struct dirent *d;
char filename[1024];
struct sigaction sa, act; struct sigaction sa, act;
char hline[1024];
char *x; char *x;
sigset_t nmask, nmask2; sigset_t nmask, nmask2;
@@ -133,7 +132,7 @@ int main()
* Parse kernel parameters * Parse kernel parameters
*/ */
if ((f = fopen("/proc/cmdline", "r")) != NULL) { if ((f = fopen("/proc/cmdline", "r")) != NULL) {
fgets(line, 2095, f); fgets(line, LINE_SIZE, f);
if (strstr(line, "quiet")) { if (strstr(line, "quiet")) {
close(0); close(0);
close(1); close(1);
@@ -177,9 +176,9 @@ int main()
while ((d = readdir(dir)) != NULL) { while ((d = readdir(dir)) != NULL) {
if (isalnum(d->d_name[0])) if (isalnum(d->d_name[0]))
continue; continue;
sprintf(filename, "/etc/resolvconf/run/interface/%s", snprintf(line, LINE_SIZE,
d->d_name); "/etc/resolvconf/run/interface/%s", d->d_name);
unlink(filename); unlink(line);
} }
closedir(dir); closedir(dir);
@@ -199,11 +198,11 @@ int main()
touch("/etc/network/run/ifstate"); touch("/etc/network/run/ifstate");
if ((f = fopen("/etc/hostname", "r")) != NULL) { if ((f = fopen("/etc/hostname", "r")) != NULL) {
fgets(hline, 1023, f); fgets(line, LINE_SIZE, f);
if ((x = strchr(hline, 0x0a)) != NULL) if ((x = strchr(line, 0x0a)) != NULL)
*x = 0; *x = 0;
sethostname(hline, strlen(hline)); sethostname(line, strlen(line));
fclose(f); fclose(f);
} }