--- /usr/src/usr.sbin/kldxref/kldxref.c Mon Apr 22 15:44:44 2002 +++ kldxref.new.c Sun Jan 4 14:00:07 2004 @@ -2,6 +2,9 @@ * Copyright (c) 2000, Boris Popov * All rights reserved. * + * Modified by Stacy Olivas (olivas@digiflux.org) + * -Added the option "-p [path]" to allow creation of hints file at an alternate location + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -50,9 +53,12 @@ #include #include #include +#include #include "ef.h" +#define DEBUG 1 /* Set to 1 for debugging output */ + #define MAXRECSIZE 1024 #define check(val) if ((error = (val)) != 0) break @@ -81,6 +87,8 @@ FILE *fxref; static const char *xref_file = "linker.hints"; +static const char *xref_path = ""; /* path for creating hints file */ +static int xref_flag = 0; /* 1 = filename specified */ static char recbuf[MAXRECSIZE]; static int recpos, reccnt; @@ -261,6 +269,9 @@ strcpy(p, "lhint.XXXXXX"); if (mkstemp(dest) == -1) err(1, "%s", dest); +#if DEBUG + printf("--> Temp file: %s\n", dest); +#endif } static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN]; @@ -275,7 +286,7 @@ fts_options = FTS_PHYSICAL; /* SLIST_INIT(&kldlist);*/ - while ((opt = getopt(argc, argv, "Rdf:v")) != -1) { + while ((opt = getopt(argc, argv, "Rdf:p:v")) != -1) { switch (opt) { case 'd': dflag = 1; @@ -283,6 +294,10 @@ case 'f': xref_file = optarg; break; + case 'p': /* alternate path specified */ + xref_path = optarg; + xref_flag = 1; + break; case 'v': verbose++; break; @@ -299,13 +314,19 @@ argc -= optind; argv += optind; +#if DEBUG +/* print out variable info set from command line args */ + printf("--> xref_file: %s\n" + "--> xref_path: %s\n" + "--> xref_flag: %d\n", xref_file, xref_path, xref_flag); +#endif ftsp = fts_open(argv, fts_options, 0); if (ftsp == NULL) exit(1); for (;;) { p = fts_read(ftsp); - if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref) { + if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref && !xref_flag) { fclose(fxref); if (reccnt) { rename(tempname, xrefname); @@ -314,19 +335,49 @@ unlink(xrefname); } } + +/* if xref_flag is set, only cleanup after everything is finished. */ + if (p == NULL && !dflag && xref_flag) + { + fclose(fxref); + if (reccnt) { + rename(tempname, xrefname); + } else { + unlink(tempname); + unlink(xrefname); + } + } if (p == NULL) break; - if (p && p->fts_info == FTS_D && !dflag) { + +/* if xref_flag is set, create temp file in path specified */ + if (p && p->fts_info == FTS_D && !dflag && xref_flag == 1) { + snprintf(xrefname, sizeof(xrefname), "%s/%s", xref_path, xref_file); +#if DEBUG + printf("--> xrefname: %s\n", xrefname); +#endif + maketempfile(tempname, xref_path); + xref_flag++; + fxref = fopen(tempname, "w+t"); + if (fxref == NULL) + err(1, "can't create %s", tempname); + ival = 1; + fwrite(&ival, sizeof(ival), 1, fxref); + reccnt = 0; + } + + if (p && p->fts_info == FTS_D && !dflag && !xref_flag) { snprintf(xrefname, sizeof(xrefname), "%s/%s", - ftsp->fts_path, xref_file); + ftsp->fts_path, xref_file); maketempfile(tempname, ftsp->fts_path); - fxref = fopen(tempname, "w+t"); - if (fxref == NULL) - err(1, "can't create %s", tempname); - ival = 1; - fwrite(&ival, sizeof(ival), 1, fxref); - reccnt = 0; - } + fxref = fopen(tempname, "w+t"); + if (fxref == NULL) + err(1, "can't create %s", tempname); + ival = 1; + fwrite(&ival, sizeof(ival), 1, fxref); + reccnt = 0; + } + if (p->fts_info != FTS_F) continue; read_kld(p->fts_path, p->fts_name); @@ -340,7 +391,7 @@ { fprintf(stderr, "%s\n", - "usage: kldxref [-Rdv] [-f hintfile] path [path..]" + "usage: kldxref [-Rpdv] [[-f hintfile] || [-p hintfile]] path [path..]" ); exit(1); }