8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / cmd / svc / mfstscan / mfstscan.c
blob70b21903d1717042eaf6b90fe4c6becd7f710779
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
26 #include <sys/types.h>
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <libintl.h>
31 #include <libscf.h>
32 #include <libuutil.h>
33 #include <locale.h>
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <sys/stat.h>
38 #include <unistd.h>
40 #include "manifest_find.h"
41 #include "manifest_hash.h"
43 #define MAX_DEPTH 24
46 * mfstscan - service manifest change detection utility
48 * mfstscan walks the given filesystem hierarchies, and reports those manifests
49 * with changed or absent hash entries. Manifests are expected to end with a
50 * .xml suffix--other files will be ignored.
53 static void
54 usage()
56 (void) fprintf(stderr, gettext("Usage: %s [-t] path ...\n"),
57 uu_getpname());
58 exit(UU_EXIT_USAGE);
61 int
62 main(int argc, char *argv[])
64 manifest_info_t **entry;
65 manifest_info_t **manifests;
66 scf_handle_t *hndl = NULL;
67 int i;
68 int paths_walked = 0;
69 struct stat sb;
70 int status;
71 int tflag = 0;
73 (void) uu_setpname(argv[0]);
75 while ((i = getopt(argc, argv, "t")) != -1) {
76 switch (i) {
77 case 't':
78 tflag = 1;
79 paths_walked = 1;
80 break;
81 case '?':
82 default:
83 usage();
84 /*NOTREACHED*/
88 if (optind >= argc)
89 usage();
91 if ((hndl = scf_handle_create(SCF_VERSION)) == NULL)
92 uu_die(gettext("Unexpected libscf error: %s. Exiting.\n"),
93 scf_strerror(scf_error()));
95 if (scf_handle_bind(hndl) != SCF_SUCCESS)
96 uu_die(gettext("Couldn't bind to svc.configd.\n"));
98 for (i = optind; i < argc; i++) {
99 if (tflag) {
100 char *pname = mhash_filename_to_propname(argv[i],
101 B_FALSE);
103 if (pname != NULL)
104 (void) puts(pname);
105 else
106 uu_warn(gettext("cannot resolve pathname "
107 "for %s"), argv[i]);
109 continue;
112 if (stat(argv[i], &sb) == -1) {
113 uu_warn(gettext("cannot stat %s"), argv[i]);
114 continue;
117 status = find_manifests(hndl, argv[i], &manifests,
118 CHECKHASH|CHECKEXT);
119 if (status < 0) {
120 uu_warn(gettext("file tree walk of %s encountered "
121 "error. %s\n"), argv[i], strerror(errno));
122 } else {
123 paths_walked++;
124 if (manifests != NULL) {
125 for (entry = manifests;
126 *entry != NULL;
127 entry++) {
128 (void) printf("%s\n",
129 (*entry)->mi_path);
131 free_manifest_array(manifests);
137 if (!paths_walked)
138 uu_die(gettext("no paths walked\n"));
140 if (hndl != NULL) {
141 (void) scf_handle_unbind(hndl);
142 (void) scf_handle_destroy(hndl);
145 return (0);