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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2569 - (show annotations) (download) (as text)
Tue Apr 10 11:24:58 2007 UTC (11 years, 6 months ago) by uberlord
File MIME type: text/x-csrc
File size: 2496 byte(s)
Fix indentation
1 /*
2 rc-depend
3 rc service dependency and ordering
4 Copyright 2006-2007 Gentoo Foundation
5 Released under the GPLv2
6 */
7
8 #include <sys/types.h>
9 #include <sys/stat.h>
10
11 #include <stdbool.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15
16 #include "einfo.h"
17 #include "rc.h"
18 #include "rc-misc.h"
19 #include "strlist.h"
20
21 int main (int argc, char **argv)
22 {
23 char **types = NULL;
24 char **services = NULL;
25 char **depends = NULL;
26 rc_depinfo_t *deptree = NULL;
27 rc_depinfo_t *di;
28 char *service;
29 int options = RC_DEP_TRACE;
30 bool first = true;
31 int i;
32 bool update = false;
33 char *runlevel = getenv ("RC_SOFTLEVEL");
34
35 if (! runlevel)
36 runlevel = rc_get_runlevel ();
37
38 for (i = 1; i < argc; i++)
39 {
40 if (strcmp (argv[i], "--update") == 0)
41 {
42 if (! update)
43 {
44 rc_update_deptree (true);
45 update = true;
46 }
47 continue;
48 }
49
50 if (strcmp (argv[i], "--strict") == 0)
51 {
52 options |= RC_DEP_STRICT;
53 continue;
54 }
55
56 if (strcmp (argv[i], "--notrace") == 0)
57 {
58 options &= RC_DEP_TRACE;
59 continue;
60 }
61
62 if (argv[i][0] == '-')
63 {
64 argv[i]++;
65 types = rc_strlist_add (types, argv[i]);
66 }
67 else
68 {
69 if ((deptree = rc_load_deptree ()) == NULL)
70 eerrorx ("failed to load deptree");
71
72 di = rc_get_depinfo (deptree, argv[i]);
73 if (! di)
74 eerror ("no dependency info for service `%s'", argv[i]);
75 else
76 services = rc_strlist_add (services, argv[i]);
77 }
78 }
79
80 if (! services)
81 {
82 rc_strlist_free (types);
83 rc_free_deptree (deptree);
84 if (update)
85 return (EXIT_SUCCESS);
86 eerrorx ("no services specified");
87 }
88
89 /* If we don't have any types, then supply some defaults */
90 if (! types)
91 {
92 types = rc_strlist_add (NULL, "ineed");
93 rc_strlist_add (types, "iuse");
94 }
95
96 depends = rc_get_depends (deptree, types, services, runlevel, options);
97
98 if (depends)
99 {
100 STRLIST_FOREACH (depends, service, i)
101 {
102 if (first)
103 first = false;
104 else
105 printf (" ");
106
107 if (service)
108 printf ("%s", service);
109
110 }
111 printf ("\n");
112 }
113
114 rc_strlist_free (types);
115 rc_strlist_free (services);
116 rc_strlist_free (depends);
117 rc_free_deptree (deptree);
118
119 return (EXIT_SUCCESS);
120 }

  ViewVC Help
Powered by ViewVC 1.1.20