/[baselayout]/trunk/src/rc-depend.c
Gentoo

Contents of /trunk/src/rc-depend.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2985 - (show annotations) (download) (as text)
Thu Oct 4 13:55:37 2007 UTC (7 years, 6 months ago) by uberlord
File MIME type: text/x-csrc
File size: 3427 byte(s)
Remove debug
1 /*
2 rc-depend
3 rc service dependency and ordering
4 Copyright 2006-2007 Gentoo Foundation
5 Released under the GPLv2
6 */
7
8 #define APPLET "rc-depend"
9
10 #include <sys/types.h>
11 #include <sys/stat.h>
12
13 #include <getopt.h>
14 #include <errno.h>
15 #include <stdbool.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19
20 #include "builtins.h"
21 #include "einfo.h"
22 #include "rc.h"
23 #include "rc-misc.h"
24 #include "strlist.h"
25
26 rc_depinfo_t *_rc_deptree_load (void) {
27 if (rc_deptree_update_needed ()) {
28 int retval;
29
30 ebegin ("Caching service dependencies");
31 retval = rc_deptree_update ();
32 eend (retval, "Failed to update the dependency tree");
33 }
34
35 return (rc_deptree_load ());
36 }
37
38 static char *applet = NULL;
39
40 #include "_usage.h"
41 #define getoptstring "t:suT" getoptstring_COMMON
42 static struct option longopts[] = {
43 { "type", 0, NULL, 't'},
44 { "notrace", 0, NULL, 'T'},
45 { "strict", 0, NULL, 's'},
46 { "update", 0, NULL, 'u'},
47 longopts_COMMON
48 { NULL, 0, NULL, 0}
49 };
50 static const char * const longopts_help[] = {
51 "Type(s) of dependency to list",
52 "Don't trace service dependencies",
53 "Only use what is in the runlevels",
54 "Force an update of the dependency tree",
55 longopts_help_COMMON
56 };
57 #include "_usage.c"
58
59 int rc_depend (int argc, char **argv)
60 {
61 char **types = NULL;
62 char **services = NULL;
63 char **depends = NULL;
64 char **list;
65 rc_depinfo_t *deptree = NULL;
66 char *service;
67 int options = RC_DEP_TRACE;
68 bool first = true;
69 int i;
70 bool update = false;
71 char *runlevel = getenv ("RC_SOFTLEVEL");
72 int opt;
73 char *token;
74
75 applet = argv[0];
76
77 while ((opt = getopt_long (argc, argv, getoptstring,
78 longopts, (int *) 0)) != -1)
79 {
80 switch (opt) {
81 case 's':
82 options |= RC_DEP_STRICT;
83 break;
84 case 't':
85 while ((token = strsep (&optarg, ",")))
86 rc_strlist_addu (&types, token);
87 break;
88 case 'u':
89 update = true;
90 break;
91 case 'T':
92 options &= RC_DEP_TRACE;
93 break;
94
95 case_RC_COMMON_GETOPT
96 }
97 }
98
99 if (update) {
100 bool u = false;
101 ebegin ("Caching service dependencies");
102 u = rc_deptree_update ();
103 eend (u ? 0 : -1, "%s: %s", applet, strerror (errno));
104 if (! u)
105 eerrorx ("Failed to update the dependency tree");
106 }
107
108 if (! runlevel)
109 runlevel = rc_runlevel_get ();
110
111 if (! (deptree = _rc_deptree_load ()))
112 eerrorx ("failed to load deptree");
113
114 while (optind < argc) {
115 list = NULL;
116 rc_strlist_add (&list, argv[optind]);
117 errno = 0;
118 depends = rc_deptree_depends (deptree, NULL, list, runlevel, 0);
119 if (! depends && errno == ENOENT)
120 eerror ("no dependency info for service `%s'", argv[optind]);
121 else
122 rc_strlist_add (&services, argv[optind]);
123
124 rc_strlist_free (depends);
125 rc_strlist_free (list);
126 optind++;
127 }
128
129 if (! services) {
130 rc_strlist_free (types);
131 rc_deptree_free (deptree);
132 if (update)
133 return (EXIT_SUCCESS);
134 eerrorx ("no services specified");
135 }
136
137 /* If we don't have any types, then supply some defaults */
138 if (! types) {
139 rc_strlist_add (&types, "ineed");
140 rc_strlist_add (&types, "iuse");
141 }
142
143 depends = rc_deptree_depends (deptree, types, services, runlevel, options);
144
145 if (depends) {
146 STRLIST_FOREACH (depends, service, i) {
147 if (first)
148 first = false;
149 else
150 printf (" ");
151
152 if (service)
153 printf ("%s", service);
154
155 }
156 printf ("\n");
157 }
158
159 rc_strlist_free (types);
160 rc_strlist_free (services);
161 rc_strlist_free (depends);
162 rc_deptree_free (deptree);
163 return (EXIT_SUCCESS);
164 }

  ViewVC Help
Powered by ViewVC 1.1.20