--- Makefile +++ Makefile 2006-05-16 17:16:01.000000000 +0200 @@ -21,7 +21,7 @@ install: startpar $(INSTALL) -d $(DESTDIR)$(sbindir) $(DESTDIR)$(man8dir) - $(INSTALL) -s startpar $(DESTDIR)$(sbindir)/. + $(INSTALL) startpar $(DESTDIR)$(sbindir)/. $(INSTALL_DATA) startpar.8 $(DESTDIR)$(man8dir)/. clean: --- proc.c +++ proc.c 2006-05-16 18:10:47.000000000 +0200 @@ -45,30 +45,29 @@ int read_proc(unsigned long int * const prcs_run, unsigned long int * const prcs_blked) { - static char StatBuf[32*1024]; + char StatBuf[2048], *ptr = &StatBuf[0]; unsigned long int running, blocked; - ssize_t n; - int fd; + ssize_t len; + size_t skip; + FILE *stat; *prcs_run = 0; *prcs_blked = 0; - if ((fd = open( "/proc/stat", O_RDONLY )) < 0) { + if ((stat = fopen("/proc/stat", "r")) == (FILE*)0) { fprintf(stderr, "ERROR: could not open /proc/stat: %s\n", strerror(errno)); return 1; } - n = read( fd, StatBuf, (sizeof(StatBuf) - 1)); - close(fd); - if (n < 40) { - if (n < 0) { - fprintf(stderr, "ERROR: could not read /proc/stat: %s\n", strerror(errno)); - return 1; - } - fprintf(stderr, "ERROR: no enough data in /proc/stat?\n"); - return 1; + len = sizeof(StatBuf); + while ((len > 0) && (fgets(ptr, len, stat))) { + if (ptr[0] != 'p') + continue; + skip = strlen(ptr); + len -= skip; + ptr += skip; } - StatBuf[n] = 0; + fclose(stat); running = scan_one(StatBuf, "procs_running"); blocked = scan_one(StatBuf, "procs_blocked"); --- startpar.c +++ startpar.c 2006-05-16 17:16:01.000000000 +0200 @@ -127,6 +127,19 @@ splashpid = 0; } +void closeall(void) +{ + int s; + + if (!prgs) + return; + for (s = 0; s < par; s++) + if (prgs[s].fd) + close(prgs[s].fd); + close(pidpipe[0]); + close(pidpipe[1]); +} + void callsplash(int n, char *path, char *action) { char *p; @@ -169,24 +182,11 @@ } close(1); dup(2); + closeall(); execl("/sbin/splash", "splash", "-p", sbuf, "-t", tbuf, splashcfg, (char *)0); _exit(1); } - -void closeall(void) -{ - int s; - - if (!prgs) - return; - for (s = 0; s < par; s++) - if (prgs[s].fd) - close(prgs[s].fd); - close(pidpipe[0]); - close(pidpipe[1]); -} - void writebuf(struct prg *p) { char *b = p->buf; @@ -360,6 +360,7 @@ close(1); dup(2); + closeall(); if (run_mode) { char path[128];