summaryrefslogtreecommitdiff
path: root/usr/src/tools/protocmp/exception_list.c
blob: 5701168b3765f60ef1a2bc45805d394004f30261 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 *
 * Copyright 2015 PALO, Richard
 *
 * Copyright (c) 2018, Joyent, Inc.
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "list.h"
#include "exception_list.h"
#include "arch.h"

/*
 * This is global so that the protodir reading functions can rely on the
 * exception list to weed out innocuous problems in the IHV gate.
 */
elem_list exception_list;

#define	FS	" \t\n"

static int
parse_exception_line(char *line, elem_list *list)
{
	char	*name, *arch;
	elem	*e;

	if ((name = strtok(line, FS)) == NULL) {
		/* don't complain; this is only a blank line */
		return (0);
	}

	if ((arch = strtok(NULL, FS)) == NULL) {
		arch = "all";
	}

	e = (elem *) malloc(sizeof (elem));
	if (e == NULL) {
		perror("malloc");
		exit(1);
	}

	e->inode = 0;
	e->perm = 0;
	e->ref_cnt = 0;
	e->flag = 0;
	e->major = 0;
	e->minor = 0;
	e->link_parent = NULL;
	e->link_sib = NULL;
	e->symsrc = NULL;
	e->file_type = DIR_T;

	while ((e->arch = assign_arch(arch)) == 0) {
		if ((arch = strtok(NULL, FS)) == NULL) {
			free(e);
			return (0);
		}
	}

	(void) strcpy(e->name, name);
	add_elem(list, e);

	return (1);
}

int
read_in_exceptions(const char *exception_file, int verbose)
{
	FILE	*except_fp;
	char	buf[BUFSIZ];
	int	count = 0;

	exception_file = exception_file ? exception_file : EXCEPTION_FILE;

	if (verbose) {
		(void) printf("reading in exceptions from %s...\n",
		    exception_file);
	}

	if ((except_fp = fopen(exception_file, "r")) == NULL) {
		perror(exception_file);
		return (0);
	}
	while (fgets(buf, BUFSIZ, except_fp)) {
		if (buf[0] != '#')	/* allow for comments */
			count += parse_exception_line(buf, &exception_list);
	}
	if (verbose)
		(void) printf("read in %d exceptions...\n", count);

	return (count);
}