11de7b4b8SPedro F. Giffuni /*-
21de7b4b8SPedro F. Giffuni * SPDX-License-Identifier: BSD-4-Clause
31de7b4b8SPedro F. Giffuni *
40f6b2cb3SPaul Traina * Copyright (c) 1993,1995 Paul Kranenburg
5b9ae52e3SPaul Richards * All rights reserved.
6b9ae52e3SPaul Richards *
7b9ae52e3SPaul Richards * Redistribution and use in source and binary forms, with or without
8b9ae52e3SPaul Richards * modification, are permitted provided that the following conditions
9b9ae52e3SPaul Richards * are met:
10b9ae52e3SPaul Richards * 1. Redistributions of source code must retain the above copyright
11b9ae52e3SPaul Richards * notice, this list of conditions and the following disclaimer.
12b9ae52e3SPaul Richards * 2. Redistributions in binary form must reproduce the above copyright
13b9ae52e3SPaul Richards * notice, this list of conditions and the following disclaimer in the
14b9ae52e3SPaul Richards * documentation and/or other materials provided with the distribution.
15b9ae52e3SPaul Richards * 3. All advertising materials mentioning features or use of this software
16b9ae52e3SPaul Richards * must display the following acknowledgement:
17b9ae52e3SPaul Richards * This product includes software developed by Paul Kranenburg.
18b9ae52e3SPaul Richards * 4. The name of the author may not be used to endorse or promote products
1909e3d49dSJordan K. Hubbard * derived from this software without specific prior written permission
20b9ae52e3SPaul Richards *
21b9ae52e3SPaul Richards * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22b9ae52e3SPaul Richards * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23b9ae52e3SPaul Richards * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24b9ae52e3SPaul Richards * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25b9ae52e3SPaul Richards * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26b9ae52e3SPaul Richards * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27b9ae52e3SPaul Richards * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28b9ae52e3SPaul Richards * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29b9ae52e3SPaul Richards * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30b9ae52e3SPaul Richards * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31b9ae52e3SPaul Richards */
32b9ae52e3SPaul Richards
33b9ae52e3SPaul Richards #include <sys/param.h>
34b9ae52e3SPaul Richards #include <sys/types.h>
35b9ae52e3SPaul Richards #include <sys/stat.h>
36b9ae52e3SPaul Richards #include <sys/mman.h>
37b9ae52e3SPaul Richards #include <a.out.h>
38b50d7faeSPhilippe Charnier #include <ctype.h>
39b50d7faeSPhilippe Charnier #include <dirent.h>
405e6220d9SDavid E. O'Brien #include <elf-hints.h>
41b50d7faeSPhilippe Charnier #include <err.h>
42b50d7faeSPhilippe Charnier #include <errno.h>
43b50d7faeSPhilippe Charnier #include <fcntl.h>
443f2c6f55SKonstantin Belousov #include <stdbool.h>
45699e1b82SRich Murphey #include <stdio.h>
46699e1b82SRich Murphey #include <stdlib.h>
47b9ae52e3SPaul Richards #include <string.h>
48699e1b82SRich Murphey #include <unistd.h>
49b9ae52e3SPaul Richards
50a565ca59SJohn Polstra #include "ldconfig.h"
51af911587SKonstantin Belousov #include "rtld_paths.h"
5280c71499SPeter Wemm
5365f3be91SAlfonso Gregory static void usage(void) __dead2;
54b9ae52e3SPaul Richards
55b9ae52e3SPaul Richards int
main(int argc,char ** argv)5606eda379SXin LI main(int argc, char **argv)
57b9ae52e3SPaul Richards {
583f2c6f55SKonstantin Belousov const char *hints_file;
5950a40d09SEd Maste int c;
60*484de86fSStefan Eßer bool is_32, justread, merge, rescan, force_be;
613f2c6f55SKonstantin Belousov
62*484de86fSStefan Eßer force_be = is_32 = justread = merge = rescan = false;
63b9ae52e3SPaul Richards
64c905e45dSPeter Wemm while (argc > 1) {
65c905e45dSPeter Wemm if (strcmp(argv[1], "-aout") == 0) {
6650a40d09SEd Maste errx(1, "aout is not supported");
67c905e45dSPeter Wemm } else if (strcmp(argv[1], "-elf") == 0) {
6866422f5bSPeter Wemm argc--;
6966422f5bSPeter Wemm argv++;
70c905e45dSPeter Wemm } else if (strcmp(argv[1], "-32") == 0) {
713f2c6f55SKonstantin Belousov is_32 = true;
72c905e45dSPeter Wemm argc--;
73c905e45dSPeter Wemm argv++;
74c905e45dSPeter Wemm } else {
75c905e45dSPeter Wemm break;
76c905e45dSPeter Wemm }
7766422f5bSPeter Wemm }
78cfa4d739SJohn Polstra
798b7cc20fSWarner Losh if (is_32)
801e635e87SJessica Clarke hints_file = __PATH_ELF_HINTS("32");
81c905e45dSPeter Wemm else
8250a40d09SEd Maste hints_file = _PATH_ELF_HINTS;
83e0dfecadSStefan Eßer while((c = getopt(argc, argv, "BRf:imrsv")) != -1) {
84b9ae52e3SPaul Richards switch (c) {
85e0dfecadSStefan Eßer case 'B':
86e0dfecadSStefan Eßer force_be = true;
87e0dfecadSStefan Eßer break;
88d4ba5766SPeter Wemm case 'R':
893f2c6f55SKonstantin Belousov rescan = true;
90d4ba5766SPeter Wemm break;
917c6da7dcSJohn Polstra case 'f':
927c6da7dcSJohn Polstra hints_file = optarg;
937c6da7dcSJohn Polstra break;
94643dcf40SJohn Polstra case 'i':
953f2c6f55SKonstantin Belousov insecure = true;
96643dcf40SJohn Polstra break;
97f606c848SSatoshi Asami case 'm':
983f2c6f55SKonstantin Belousov merge = true;
99b9ae52e3SPaul Richards break;
100b9ae52e3SPaul Richards case 'r':
1013f2c6f55SKonstantin Belousov justread = true;
102b9ae52e3SPaul Richards break;
103f606c848SSatoshi Asami case 's':
104b828161dSKonstantin Belousov /* was nostd */
105f606c848SSatoshi Asami break;
106f606c848SSatoshi Asami case 'v':
107*484de86fSStefan Eßer /* was verbose */
108f606c848SSatoshi Asami break;
109b9ae52e3SPaul Richards default:
110b50d7faeSPhilippe Charnier usage();
111b9ae52e3SPaul Richards break;
112b9ae52e3SPaul Richards }
113b9ae52e3SPaul Richards }
114b9ae52e3SPaul Richards
1153ede04c7SKonstantin Belousov if (justread) {
116a565ca59SJohn Polstra list_elf_hints(hints_file);
1173ede04c7SKonstantin Belousov } else {
1183ede04c7SKonstantin Belousov if (argc == optind)
1193ede04c7SKonstantin Belousov rescan = true;
120a565ca59SJohn Polstra update_elf_hints(hints_file, argc - optind,
121e0dfecadSStefan Eßer argv + optind, merge || rescan, force_be);
1223ede04c7SKonstantin Belousov }
1233f2c6f55SKonstantin Belousov exit(0);
124a565ca59SJohn Polstra }
125a565ca59SJohn Polstra
126b50d7faeSPhilippe Charnier static void
usage(void)127f709df34SEd Schouten usage(void)
128b50d7faeSPhilippe Charnier {
129b50d7faeSPhilippe Charnier fprintf(stderr,
130*484de86fSStefan Eßer "usage: ldconfig [-32] [-BRimr] [-f hints_file]"
1313f2c6f55SKonstantin Belousov "[directory | file ...]\n");
132b50d7faeSPhilippe Charnier exit(1);
133b50d7faeSPhilippe Charnier }
134