aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2004-12-22 23:14:54 +0000
committerBill Nottingham <notting@redhat.com>2004-12-22 23:14:54 +0000
commit8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81 (patch)
tree08f01224f6b9e0949b1e1dfdafc7440dceb38c20
parent301385f8dc2d7fd0c11ea1305991dd2e64f063a3 (diff)
downloadinitscripts-8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81.tar
initscripts-8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81.tar.gz
initscripts-8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81.tar.bz2
initscripts-8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81.tar.xz
initscripts-8aefbbdc8f4f3739a467c6ecbedfda27dd71fb81.zip
simplify
-rw-r--r--src/kmodule.c51
1 files changed, 10 insertions, 41 deletions
diff --git a/src/kmodule.c b/src/kmodule.c
index 8d1ea042..d344eca6 100644
--- a/src/kmodule.c
+++ b/src/kmodule.c
@@ -64,45 +64,11 @@ int isAvailable(char *modulename)
return 0;
}
-char *dumpDevices(struct device **devlist)
+void waitForConnection(struct device **devlist)
{
- int fds[2],x;
- FILE *tmp;
- char *buf = NULL;
-
- pipe(fds);
- tmp = fdopen(fds[1],"w");
-
- buf = NULL;
- for (x = 0; devlist[x]; x++) {
- char b[4096];
-
- devlist[x]->writeDevice(tmp,devlist[x]);
- fflush(tmp);
- memset(b,'\0',4096);
- while (read(fds[0],b,4096)) {
- if (!buf) {
- buf = calloc(strlen(b)+1,sizeof(char));
- strcpy(buf,b);
- buf[strlen(b)] = '\0';
- } else {
- buf = realloc(buf, strlen(buf)+strlen(b)+1);
- sprintf(buf,"%s%s",buf,b);
- buf[strlen(buf)+strlen(b)] = '\0';
- }
- if (strlen(b) != 4096)
- break;
- }
- }
- close(fds[0]);
- close(fds[1]);
- return buf;
-}
-
-void waitForConnection(char *buf)
-{
- int sock, fd, socklen;
+ int sock, fd, socklen, x;
struct sockaddr_un addr;
+ FILE *tmp;
sock = socket(PF_UNIX, SOCK_STREAM, 0);
if (sock == -1) return;
@@ -117,8 +83,12 @@ void waitForConnection(char *buf)
fd = accept(sock, &addr, &socklen);
if (fd == -1)
return;
- write(fd,buf,strlen(buf));
- close(fd);
+ tmp = fdopen(fd,"w");
+ for (x = 0; devlist[x]; x++) {
+ devlist[x]->writeDevice(tmp,devlist[x]);
+ fflush(tmp);
+ }
+ fclose(tmp);
close(sock);
}
@@ -187,9 +157,8 @@ int main(int argc, char **argv)
}
}
if (isdaemon) {
- buf = dumpDevices(devs);
daemon(0,0);
- waitForConnection(buf);
+ waitForConnection(devs);
}
return 0;
}