| 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 "builtins.h"
|
| 17 |
#include "einfo.h"
|
| 18 |
#include "rc.h"
|
| 19 |
#include "rc-misc.h"
|
| 20 |
#include "strlist.h"
|
| 21 |
|
| 22 |
int rc_depend (int argc, char **argv)
|
| 23 |
{
|
| 24 |
char **types = NULL;
|
| 25 |
char **services = NULL;
|
| 26 |
char **depends = NULL;
|
| 27 |
rc_depinfo_t *deptree = NULL;
|
| 28 |
rc_depinfo_t *di;
|
| 29 |
char *service;
|
| 30 |
int options = RC_DEP_TRACE;
|
| 31 |
bool first = true;
|
| 32 |
int i;
|
| 33 |
bool update = false;
|
| 34 |
char *runlevel = getenv ("RC_SOFTLEVEL");
|
| 35 |
|
| 36 |
if (! runlevel)
|
| 37 |
runlevel = rc_get_runlevel ();
|
| 38 |
|
| 39 |
for (i = 1; i < argc; i++) {
|
| 40 |
if (strcmp (argv[i], "--update") == 0) {
|
| 41 |
if (! update) {
|
| 42 |
rc_update_deptree (true);
|
| 43 |
update = true;
|
| 44 |
}
|
| 45 |
continue;
|
| 46 |
}
|
| 47 |
|
| 48 |
if (strcmp (argv[i], "--strict") == 0) {
|
| 49 |
options |= RC_DEP_STRICT;
|
| 50 |
continue;
|
| 51 |
}
|
| 52 |
|
| 53 |
if (strcmp (argv[i], "--notrace") == 0) {
|
| 54 |
options &= RC_DEP_TRACE;
|
| 55 |
continue;
|
| 56 |
}
|
| 57 |
|
| 58 |
if (argv[i][0] == '-') {
|
| 59 |
argv[i]++;
|
| 60 |
rc_strlist_add (&types, argv[i]);
|
| 61 |
} else {
|
| 62 |
if ((deptree = rc_load_deptree ()) == NULL)
|
| 63 |
eerrorx ("failed to load deptree");
|
| 64 |
|
| 65 |
di = rc_get_depinfo (deptree, argv[i]);
|
| 66 |
if (! di)
|
| 67 |
eerror ("no dependency info for service `%s'", argv[i]);
|
| 68 |
else
|
| 69 |
rc_strlist_add (&services, argv[i]);
|
| 70 |
}
|
| 71 |
}
|
| 72 |
|
| 73 |
if (! services) {
|
| 74 |
rc_strlist_free (types);
|
| 75 |
rc_free_deptree (deptree);
|
| 76 |
if (update)
|
| 77 |
return (EXIT_SUCCESS);
|
| 78 |
eerrorx ("no services specified");
|
| 79 |
}
|
| 80 |
|
| 81 |
/* If we don't have any types, then supply some defaults */
|
| 82 |
if (! types) {
|
| 83 |
rc_strlist_add (&types, "ineed");
|
| 84 |
rc_strlist_add (&types, "iuse");
|
| 85 |
}
|
| 86 |
|
| 87 |
depends = rc_get_depends (deptree, types, services, runlevel, options);
|
| 88 |
|
| 89 |
if (depends) {
|
| 90 |
STRLIST_FOREACH (depends, service, i) {
|
| 91 |
if (first)
|
| 92 |
first = false;
|
| 93 |
else
|
| 94 |
printf (" ");
|
| 95 |
|
| 96 |
if (service)
|
| 97 |
printf ("%s", service);
|
| 98 |
|
| 99 |
}
|
| 100 |
printf ("\n");
|
| 101 |
}
|
| 102 |
|
| 103 |
rc_strlist_free (types);
|
| 104 |
rc_strlist_free (services);
|
| 105 |
rc_strlist_free (depends);
|
| 106 |
rc_free_deptree (deptree);
|
| 107 |
|
| 108 |
return (EXIT_SUCCESS);
|
| 109 |
}
|