summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2002-07-03 09:14:33 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2002-07-03 09:14:33 +0000
commit8f71ad0e632704ce7a5b0480efbb87299c85b079 (patch)
treefd82f364ec6c438a9a77e0c843f62454878ffbff
parent7949691d9a6fff4831d7ab8ea11883a9deb79e9f (diff)
downloadldetect-8f71ad0e632704ce7a5b0480efbb87299c85b079.tar
ldetect-8f71ad0e632704ce7a5b0480efbb87299c85b079.tar.gz
ldetect-8f71ad0e632704ce7a5b0480efbb87299c85b079.tar.bz2
ldetect-8f71ad0e632704ce7a5b0480efbb87299c85b079.tar.xz
ldetect-8f71ad0e632704ce7a5b0480efbb87299c85b079.zip
- no need to allocate fname_gz in fast path
- reduce cmd size - use zcat rather than gzip
-rw-r--r--pciusb.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/pciusb.c b/pciusb.c
index 44f9d8b..0c66c1d 100644
--- a/pciusb.c
+++ b/pciusb.c
@@ -21,40 +21,43 @@ typedef struct {
static fh fh_open(char *fname) {
fh ret;
int length = strlen(fname);
- char *fname_gz = alloca(length + sizeof(".gz"));
- sprintf(fname_gz, "%s.gz", fname);
if (access(fname, R_OK) == 0) {
ret.f = fopen(fname, "r");
ret.pid = 0;
- } else if (access(fname_gz, R_OK) == 0) {
- int fdno[2];
- if (pipe(fdno)) { perror("pciusb"); exit(1); }
- if ((ret.pid = fork()) != 0) {
- ret.f = fdopen(fdno[0], "r");
- close(fdno[1]);
+ } else {
+ char *fname_gz = alloca(length + sizeof(".gz"));
+ sprintf(fname_gz, "%s.gz", fname);
+ if (access(fname_gz, R_OK) == 0) {
+ int fdno[2];
+ if (pipe(fdno)) {
+ perror("pciusb"); exit(1);
+ }
+ if ((ret.pid = fork()) != 0) {
+ ret.f = fdopen(fdno[0], "r");
+ close(fdno[1]);
+ } else {
+ char* cmd[4];
+ int ip = 0;
+ char *ld_loader = getenv("LD_LOADER");
+
+ if (ld_loader && *ld_loader)
+ cmd[ip++] = ld_loader;
+
+ cmd[ip++] = "zcat";
+ cmd[ip++] = fname_gz;
+ cmd[ip++] = NULL;
+
+ dup2(fdno[1], STDOUT_FILENO);
+ close(fdno[0]);
+ close(fdno[1]);
+ execvp(cmd[0], cmd);
+ perror("pciusb"); exit(2);
+ }
} else {
- char *cmd[8];
- int ip = 0;
- char *ld_loader = getenv("LD_LOADER");
-
- if (ld_loader && *ld_loader)
- cmd[ip++] = ld_loader;
-
- cmd[ip++] = "gzip";
- cmd[ip++] = "-dc";
- cmd[ip++] = fname_gz;
- cmd[ip++] = NULL;
-
- dup2(fdno[1], STDOUT_FILENO);
- close(fdno[0]);
- close(fdno[1]);
- execvp(cmd[0], cmd);
- perror("pciusb"); exit(2);
+ fprintf(stderr, "Missing pciusbtable (should be %s)\n", fname);
+ exit(1);
}
- } else {
- fprintf(stderr, "Missing pciusbtable (should be %s)\n", fname);
- exit(1);
}
return ret;
}