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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2577 - (show annotations) (download) (as text)
Wed Apr 11 12:44:47 2007 UTC (7 years, 5 months ago) by uberlord
File MIME type: text/x-csrc
File size: 2106 byte(s)
Cuddle up to LKML C style
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 if (strcmp (argv[i], "--update") == 0) {
40 if (! update) {
41 rc_update_deptree (true);
42 update = true;
43 }
44 continue;
45 }
46
47 if (strcmp (argv[i], "--strict") == 0) {
48 options |= RC_DEP_STRICT;
49 continue;
50 }
51
52 if (strcmp (argv[i], "--notrace") == 0) {
53 options &= RC_DEP_TRACE;
54 continue;
55 }
56
57 if (argv[i][0] == '-') {
58 argv[i]++;
59 types = rc_strlist_add (types, argv[i]);
60 } else {
61 if ((deptree = rc_load_deptree ()) == NULL)
62 eerrorx ("failed to load deptree");
63
64 di = rc_get_depinfo (deptree, argv[i]);
65 if (! di)
66 eerror ("no dependency info for service `%s'", argv[i]);
67 else
68 services = rc_strlist_add (services, argv[i]);
69 }
70 }
71
72 if (! services) {
73 rc_strlist_free (types);
74 rc_free_deptree (deptree);
75 if (update)
76 return (EXIT_SUCCESS);
77 eerrorx ("no services specified");
78 }
79
80 /* If we don't have any types, then supply some defaults */
81 if (! types) {
82 types = rc_strlist_add (NULL, "ineed");
83 rc_strlist_add (types, "iuse");
84 }
85
86 depends = rc_get_depends (deptree, types, services, runlevel, options);
87
88 if (depends) {
89 STRLIST_FOREACH (depends, service, i) {
90 if (first)
91 first = false;
92 else
93 printf (" ");
94
95 if (service)
96 printf ("%s", service);
97
98 }
99 printf ("\n");
100 }
101
102 rc_strlist_free (types);
103 rc_strlist_free (services);
104 rc_strlist_free (depends);
105 rc_free_deptree (deptree);
106
107 return (EXIT_SUCCESS);
108 }

  ViewVC Help
Powered by ViewVC 1.1.20