1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * file.c - file dependency vertex code
29 *
30 * In principle, file dependencies should be retested on mount/unmount
31 * events, and dependency error flow used to determine whether a lost file
32 * affects the dependent service. If mount/unmount events are not available,
33 * the kstat facility (which registers or deregisters a statistic at
34 * mount/umount) could be used as an indirect filesystem event detector.
35 *
36 * In practice, file dependencies are checked only for existence at start
37 * time.
38 */
39
40 #include <sys/stat.h>
41 #include <sys/types.h>
42 #include <errno.h>
43 #include <stdio.h>
44 #include <string.h>
45 #include <strings.h>
46
47 #include <startd.h>
48
49 int
file_ready(graph_vertex_t * v)50 file_ready(graph_vertex_t *v)
51 {
52 char *fn;
53 struct stat sbuf;
54 int r;
55 char *file_fmri = v->gv_name;
56
57 /*
58 * Advance through file: FMRI until we have an absolute file path.
59 */
60 if (strncmp(file_fmri, "file:///", sizeof ("file:///") - 1) == 0) {
61 fn = file_fmri + sizeof ("file://") - 1;
62 } else if (strncmp(file_fmri, "file://localhost/",
63 sizeof ("file://localhost/") - 1) == 0) {
64 fn = file_fmri + sizeof ("file://localhost") - 1;
65 } else if (strncmp(file_fmri, "file://", sizeof ("file://") - 1)
66 == 0) {
67 fn = file_fmri + sizeof ("file://") - 1;
68
69 /*
70 * Again, search for the next '/'.
71 */
72 if ((fn = strchr(fn, '/')) == NULL)
73 return (0);
74 }
75
76 /*
77 * If stat(2) succeeds for that path, then the dependency is satisfied.
78 */
79 do {
80 r = stat(fn, &sbuf);
81 } while (r == -1 && errno == EINTR);
82
83 return (r == -1 ? 0 : 1);
84 }
85