dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / svc / startd / file.c
blob0a70932dc0895e1944a95145a33895539bbff077
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * file.c - file dependency vertex code
32 * In principle, file dependencies should be retested on mount/unmount
33 * events, and dependency error flow used to determine whether a lost file
34 * affects the dependent service. If mount/unmount events are not available,
35 * the kstat facility (which registers or deregisters a statistic at
36 * mount/umount) could be used as an indirect filesystem event detector.
38 * In practice, file dependencies are checked only for existence at start
39 * time.
42 #include <sys/stat.h>
43 #include <sys/types.h>
44 #include <errno.h>
45 #include <stdio.h>
46 #include <string.h>
47 #include <strings.h>
49 #include <startd.h>
51 int
52 file_ready(graph_vertex_t *v)
54 char *fn;
55 struct stat sbuf;
56 int r;
57 char *file_fmri = v->gv_name;
60 * Advance through file: FMRI until we have an absolute file path.
62 if (strncmp(file_fmri, "file:///", sizeof ("file:///") - 1) == 0) {
63 fn = file_fmri + sizeof ("file://") - 1;
64 } else if (strncmp(file_fmri, "file://localhost/",
65 sizeof ("file://localhost/") - 1) == 0) {
66 fn = file_fmri + sizeof ("file://localhost") - 1;
67 } else if (strncmp(file_fmri, "file://", sizeof ("file://") - 1)
68 == 0) {
69 fn = file_fmri + sizeof ("file://") - 1;
72 * Again, search for the next '/'.
74 if ((fn = strchr(fn, '/')) == NULL)
75 return (0);
79 * If stat(2) succeeds for that path, then the dependency is satisfied.
81 do {
82 r = stat(fn, &sbuf);
83 } while (r == -1 && errno == EINTR);
85 return (r == -1 ? 0 : 1);