View | Details | Raw Unified | Return to bug 60892
Collapse All | Expand All

(-)kldxref.new.c (-12 / +63 lines)
Lines 2-7 Link Here
2
 * Copyright (c) 2000, Boris Popov
2
 * Copyright (c) 2000, Boris Popov
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Modified by Stacy Olivas (olivas@digiflux.org)
6
 * -Added the option "-p [path]" to allow creation of hints file at an alternate location
7
 *
5
 * Redistribution and use in source and binary forms, with or without
8
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
9
 * modification, are permitted provided that the following conditions
7
 * are met:
10
 * are met:
Lines 50-58 Link Here
50
#include <stdlib.h>
53
#include <stdlib.h>
51
#include <unistd.h>
54
#include <unistd.h>
52
#include <errno.h>
55
#include <errno.h>
56
#include <stdio.h>
53
57
54
#include "ef.h"
58
#include "ef.h"
55
59
60
#define DEBUG		1	/* Set to 1 for debugging output */
61
56
#define	MAXRECSIZE	1024
62
#define	MAXRECSIZE	1024
57
#define check(val)	if ((error = (val)) != 0) break
63
#define check(val)	if ((error = (val)) != 0) break
58
64
Lines 81-86 Link Here
81
FILE *fxref;
87
FILE *fxref;
82
88
83
static const char *xref_file = "linker.hints";
89
static const char *xref_file = "linker.hints";
90
static const char *xref_path = "";		/* path for creating hints file */
91
static int xref_flag = 0;  			/* 1 = filename specified */
84
92
85
static char recbuf[MAXRECSIZE];
93
static char recbuf[MAXRECSIZE];
86
static int recpos, reccnt;
94
static int recpos, reccnt;
Lines 261-266 Link Here
261
	strcpy(p, "lhint.XXXXXX");
269
	strcpy(p, "lhint.XXXXXX");
262
	if (mkstemp(dest) == -1)
270
	if (mkstemp(dest) == -1)
263
		err(1, "%s", dest);
271
		err(1, "%s", dest);
272
#if DEBUG
273
        printf("--> Temp file: %s\n", dest);
274
#endif
264
}
275
}
265
276
266
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
277
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
Lines 275-281 Link Here
275
	fts_options = FTS_PHYSICAL;
286
	fts_options = FTS_PHYSICAL;
276
/*	SLIST_INIT(&kldlist);*/
287
/*	SLIST_INIT(&kldlist);*/
277
288
278
	while ((opt = getopt(argc, argv, "Rdf:v")) != -1) {
289
	while ((opt = getopt(argc, argv, "Rdf:p:v")) != -1) {
279
		switch (opt) {
290
		switch (opt) {
280
		case 'd':
291
		case 'd':
281
			dflag = 1;
292
			dflag = 1;
Lines 283-288 Link Here
283
		case 'f':
294
		case 'f':
284
			xref_file = optarg;
295
			xref_file = optarg;
285
			break;
296
			break;
297
                case 'p':			/* alternate path specified */
298
                        xref_path = optarg;
299
                        xref_flag = 1;		
300
			break;
286
		case 'v':
301
		case 'v':
287
			verbose++;
302
			verbose++;
288
			break;
303
			break;
Lines 299-311 Link Here
299
	argc -= optind;
314
	argc -= optind;
300
	argv += optind;
315
	argv += optind;
301
316
317
#if DEBUG
318
/* print out variable info set from command line args */
319
        printf("--> xref_file: %s\n" 
320
               "--> xref_path: %s\n"
321
               "--> xref_flag: %d\n", xref_file, xref_path, xref_flag);
322
#endif
302
	ftsp = fts_open(argv, fts_options, 0);
323
	ftsp = fts_open(argv, fts_options, 0);
303
	if (ftsp == NULL)
324
	if (ftsp == NULL)
304
		exit(1);
325
		exit(1);
305
326
306
	for (;;) {
327
	for (;;) {
307
		p = fts_read(ftsp);
328
		p = fts_read(ftsp);
308
		if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref) {
329
		if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref && !xref_flag) {
309
			fclose(fxref);
330
			fclose(fxref);
310
			if (reccnt) {
331
			if (reccnt) {
311
				rename(tempname, xrefname);
332
				rename(tempname, xrefname);
Lines 314-332 Link Here
314
				unlink(xrefname);
335
				unlink(xrefname);
315
			}
336
			}
316
		}
337
		}
338
339
/* if xref_flag is set, only cleanup after everything is finished. */
340
                if (p == NULL && !dflag && xref_flag)
341
                {
342
                   fclose(fxref);
343
                   if (reccnt) {
344
                           rename(tempname, xrefname);
345
                   } else {
346
                           unlink(tempname);
347
                           unlink(xrefname);
348
                   }
349
                }
317
		if (p == NULL)
350
		if (p == NULL)
318
			break;
351
			break;
319
		if (p && p->fts_info == FTS_D && !dflag) {
352
353
/* if xref_flag is set, create temp file in path specified */
354
                if (p && p->fts_info == FTS_D && !dflag && xref_flag == 1) {
355
                        snprintf(xrefname, sizeof(xrefname), "%s/%s", xref_path, xref_file);
356
#if DEBUG
357
                        printf("--> xrefname: %s\n", xrefname);
358
#endif
359
                        maketempfile(tempname, xref_path);
360
                        xref_flag++;
361
                        fxref = fopen(tempname, "w+t");
362
                        if (fxref == NULL)
363
                                err(1, "can't create %s", tempname);
364
                        ival = 1;
365
                        fwrite(&ival, sizeof(ival), 1, fxref);
366
                        reccnt = 0;
367
                }
368
369
		if (p && p->fts_info == FTS_D && !dflag && !xref_flag) {
320
			snprintf(xrefname, sizeof(xrefname), "%s/%s",
370
			snprintf(xrefname, sizeof(xrefname), "%s/%s",
321
			    ftsp->fts_path, xref_file);
371
		           ftsp->fts_path, xref_file);
322
			maketempfile(tempname, ftsp->fts_path);
372
			maketempfile(tempname, ftsp->fts_path);
323
			fxref = fopen(tempname, "w+t");
373
  		        fxref = fopen(tempname, "w+t");
324
			if (fxref == NULL)
374
		        if (fxref == NULL)
325
				err(1, "can't create %s", tempname);
375
			        err(1, "can't create %s", tempname);
326
			ival = 1;
376
		        ival = 1;
327
			fwrite(&ival, sizeof(ival), 1, fxref);
377
		        fwrite(&ival, sizeof(ival), 1, fxref);
328
			reccnt = 0;
378
		        reccnt = 0;
329
		}
379
               }
380
             
330
		if (p->fts_info != FTS_F)
381
		if (p->fts_info != FTS_F)
331
			continue;
382
			continue;
332
		read_kld(p->fts_path, p->fts_name);
383
		read_kld(p->fts_path, p->fts_name);
Lines 340-346 Link Here
340
{
391
{
341
392
342
	fprintf(stderr, "%s\n",
393
	fprintf(stderr, "%s\n",
343
	    "usage: kldxref [-Rdv] [-f hintfile] path [path..]"
394
	    "usage: kldxref [-Rpdv] [[-f hintfile] || [-p hintfile]] path [path..]"
344
	);
395
	);
345
	exit(1);
396
	exit(1);
346
}
397
}

Return to bug 60892