Ignore machine-check MSRs
[freebsd-src/fkvm-freebsd.git] / usr.sbin / pkg_install / delete / main.c
blob6075f72ab10b5a3efe9d49e85e0ae87fcf7a82cf
1 /*
3 * FreeBSD install - a package for the installation and maintainance
4 * of non-core utilities.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * Jordan K. Hubbard
16 * 18 July 1993
18 * This is the delete module.
22 #include <sys/cdefs.h>
23 __FBSDID("$FreeBSD$");
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <getopt.h>
28 #include <err.h>
30 #include "lib.h"
31 #include "delete.h"
33 char *Prefix = NULL;
34 Boolean CleanDirs = FALSE;
35 Boolean Interactive = FALSE;
36 Boolean NoDeInstall = FALSE;
37 Boolean Recursive = FALSE;
38 match_t MatchType = MATCH_GLOB;
40 static void usage(void);
42 static char opts[] = "adDfGhinp:rvxX";
43 static struct option longopts[] = {
44 { "all", no_argument, NULL, 'a' },
45 { "clean-dirs", no_argument, NULL, 'd' },
46 { "dry-run", no_argument, NULL, 'n' },
47 { "extended", no_argument, NULL, 'X' },
48 { "force", no_argument, NULL, 'f' },
49 { "help", no_argument, NULL, 'h' },
50 { "interactive",no_argument, NULL, 'i' },
51 { "prefix", required_argument, NULL, 'p' },
52 { "recursive", no_argument, NULL, 'r' },
53 { "regex", no_argument, NULL, 'x' },
54 { "no-glob", no_argument, NULL, 'G' },
55 { "no-script", no_argument, NULL, 'D' },
56 { "no-scripts", no_argument, NULL, 'D' },
57 { "verbose", no_argument, NULL, 'v' },
58 { NULL, 0, NULL, 0 },
61 int
62 main(int argc, char **argv)
64 int ch, error;
65 char **pkgs, **start;
66 char *pkgs_split;
67 const char *tmp;
68 struct stat stat_s;
70 pkgs = start = argv;
71 while ((ch = getopt_long(argc, argv, opts, longopts, NULL)) != -1)
72 switch(ch) {
73 case 'v':
74 Verbose++;
75 break;
77 case 'f':
78 Force = TRUE;
79 break;
81 case 'p':
82 Prefix = optarg;
83 break;
85 case 'D':
86 NoDeInstall = TRUE;
87 break;
89 case 'd':
90 CleanDirs = TRUE;
91 break;
93 case 'n':
94 Fake = TRUE;
95 Verbose = TRUE;
96 break;
98 case 'a':
99 MatchType = MATCH_ALL;
100 break;
102 case 'G':
103 MatchType = MATCH_EXACT;
104 break;
106 case 'x':
107 MatchType = MATCH_REGEX;
108 break;
110 case 'X':
111 MatchType = MATCH_EREGEX;
112 break;
114 case 'i':
115 Interactive = TRUE;
116 break;
118 case 'r':
119 Recursive = TRUE;
120 break;
122 case 'h':
123 default:
124 usage();
125 break;
128 argc -= optind;
129 argv += optind;
131 /* Get all the remaining package names, if any */
132 while (*argv) {
133 /* Don't try to apply heuristics if arguments are regexs */
134 if (MatchType != MATCH_REGEX)
135 while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) {
136 *pkgs_split++ = '\0';
138 * If character after the '/' is alphanumeric, then we've found the
139 * package name. Otherwise we've come across a trailing '/' and
140 * need to continue our quest.
142 if (isalnum(*pkgs_split) || ((MatchType == MATCH_GLOB) && \
143 strpbrk(pkgs_split, "*?[]") != NULL)) {
144 *argv = pkgs_split;
145 break;
148 *pkgs++ = *argv++;
151 /* If no packages, yelp */
152 if (pkgs == start && MatchType != MATCH_ALL)
153 warnx("missing package name(s)"), usage();
154 *pkgs = NULL;
155 tmp = LOG_DIR;
156 (void) stat(tmp, &stat_s);
157 if (!Fake && getuid() && geteuid() != stat_s.st_uid) {
158 if (!Force)
159 errx(1, "you do not own %s, use -f to force", tmp);
160 else
161 warnx("you do not own %s (proceeding anyways)", tmp);
163 if ((error = pkg_perform(start)) != 0) {
164 if (Verbose)
165 warnx("%d package deletion(s) failed", error);
166 return error;
168 else
169 return 0;
172 static void
173 usage()
175 fprintf(stderr, "%s\n%s\n",
176 "usage: pkg_delete [-dDfGinrvxX] [-p prefix] pkg-name ...",
177 " pkg_delete -a [flags]");
178 exit(1);