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

Diff of /trunk/src/rc-update.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 2576 Revision 2577
20 20
21static char *applet = NULL; 21static char *applet = NULL;
22 22
23static bool add (const char *runlevel, const char *service) 23static bool add (const char *runlevel, const char *service)
24{ 24{
25 bool retval = true; 25 bool retval = true;
26 26
27 if (! rc_runlevel_exists (runlevel)) 27 if (! rc_runlevel_exists (runlevel)) {
28 {
29 ewarn ("runlevel `%s' does not exist", runlevel); 28 ewarn ("runlevel `%s' does not exist", runlevel);
30 return (false); 29 return (false);
31 } 30 }
32 if (rc_service_in_runlevel (service, runlevel)) 31 if (rc_service_in_runlevel (service, runlevel)) {
33 {
34 ewarn ("%s already installed in runlevel `%s'; skipping", 32 ewarn ("%s already installed in runlevel `%s'; skipping",
35 service, runlevel); 33 service, runlevel);
36 return (false); 34 return (false);
37 } 35 }
38 36
39 if (rc_service_add (runlevel, service)) 37 if (rc_service_add (runlevel, service))
40 einfo ("%s added to runlevel %s", service, runlevel); 38 einfo ("%s added to runlevel %s", service, runlevel);
41 else 39 else {
42 {
43 eerror ("%s: failed to add service `%s' to runlevel `%s': %s", 40 eerror ("%s: failed to add service `%s' to runlevel `%s': %s",
44 applet, service, runlevel, strerror (errno)); 41 applet, service, runlevel, strerror (errno));
45 retval = false; 42 retval = false;
46 } 43 }
47 44
48 return (retval); 45 return (retval);
49} 46}
50 47
51int main (int argc, char **argv) 48int main (int argc, char **argv)
52{ 49{
53 int i; 50 int i;
54 int j; 51 int j;
55 char *service; 52 char *service;
56 char **runlevels = NULL; 53 char **runlevels = NULL;
57 char *runlevel; 54 char *runlevel;
58 55
59 applet = argv[0]; 56 applet = argv[0];
60 if (argc < 2 || 57 if (argc < 2 ||
61 strcmp (argv[1], "show") == 0 || 58 strcmp (argv[1], "show") == 0 ||
62 strcmp (argv[1], "-s") == 0) 59 strcmp (argv[1], "-s") == 0)
63 { 60 {
64 bool verbose = false; 61 bool verbose = false;
65 char **services = rc_services_in_runlevel (NULL); 62 char **services = rc_services_in_runlevel (NULL);
66 63
67 for (i = 2; i < argc; i++) 64 for (i = 2; i < argc; i++) {
68 {
69 if (strcmp (argv[i], "--verbose") == 0 || 65 if (strcmp (argv[i], "--verbose") == 0 ||
70 strcmp (argv[i], "-v") == 0) 66 strcmp (argv[i], "-v") == 0)
71 verbose = true; 67 verbose = true;
72 else 68 else
73 runlevels = rc_strlist_add (runlevels, argv[i]); 69 runlevels = rc_strlist_add (runlevels, argv[i]);
74 } 70 }
75 71
76 if (! runlevels) 72 if (! runlevels)
77 runlevels = rc_get_runlevels (); 73 runlevels = rc_get_runlevels ();
78 74
79 STRLIST_FOREACH (services, service, i) 75 STRLIST_FOREACH (services, service, i) {
80 { 76 char **in = NULL;
81 char **in = NULL; 77 bool inone = false;
82 bool inone = false;
83 78
84 STRLIST_FOREACH (runlevels, runlevel, j) 79 STRLIST_FOREACH (runlevels, runlevel, j) {
85 {
86 if (rc_service_in_runlevel (service, runlevel)) 80 if (rc_service_in_runlevel (service, runlevel)) {
87 {
88 in = rc_strlist_add (in, runlevel); 81 in = rc_strlist_add (in, runlevel);
89 inone = true; 82 inone = true;
90 } 83 } else {
91 else 84 char buffer[PATH_MAX];
92 {
93 char buffer[PATH_MAX];
94 memset (buffer, ' ', strlen (runlevel)); 85 memset (buffer, ' ', strlen (runlevel));
95 buffer[strlen (runlevel)] = 0; 86 buffer[strlen (runlevel)] = 0;
96 in = rc_strlist_add (in, buffer); 87 in = rc_strlist_add (in, buffer);
97 } 88 }
98 } 89 }
99 90
100 if (! inone && ! verbose) 91 if (! inone && ! verbose)
101 continue; 92 continue;
102 93
103 printf (" %20s |", service); 94 printf (" %20s |", service);
104 STRLIST_FOREACH (in, runlevel, j) 95 STRLIST_FOREACH (in, runlevel, j)
105 printf (" %s", runlevel); 96 printf (" %s", runlevel);
106 printf ("\n"); 97 printf ("\n");
107 } 98 }
108 99
109 return (EXIT_SUCCESS); 100 return (EXIT_SUCCESS);
110 } 101 }
111 102
112 if (geteuid () != 0) 103 if (geteuid () != 0)
113 eerrorx ("%s: must be root to add or delete services from runlevels", 104 eerrorx ("%s: must be root to add or delete services from runlevels",
114 applet); 105 applet);
115 106
116 if (! (service = argv[2])) 107 if (! (service = argv[2]))
117 eerrorx ("%s: no service specified", applet); 108 eerrorx ("%s: no service specified", applet);
118 109
119 if (strcmp (argv[1], "add") == 0 || 110 if (strcmp (argv[1], "add") == 0 ||
120 strcmp (argv[1], "-a") == 0) 111 strcmp (argv[1], "-a") == 0)
121 { 112 {
122 if (! service) 113 if (! service)
123 eerrorx ("%s: no service specified", applet); 114 eerrorx ("%s: no service specified", applet);
124 if (! rc_service_exists (service)) 115 if (! rc_service_exists (service))
125 eerrorx ("%s: service `%s' does not exist", applet, service); 116 eerrorx ("%s: service `%s' does not exist", applet, service);
126 117
127 if (argc < 4) 118 if (argc < 4)
128 add (rc_get_runlevel (), service); 119 add (rc_get_runlevel (), service);
129 120
130 for (i = 3; i < argc; i++) 121 for (i = 3; i < argc; i++)
131 add (argv[i], service); 122 add (argv[i], service);
132 123
133 return (EXIT_SUCCESS); 124 return (EXIT_SUCCESS);
134 } 125 }
135 126
136 if (strcmp (argv[1], "delete") == 0 || 127 if (strcmp (argv[1], "delete") == 0 ||
137 strcmp (argv[1], "del") == 0 || 128 strcmp (argv[1], "del") == 0 ||
138 strcmp (argv[1], "-d") == 0) 129 strcmp (argv[1], "-d") == 0)
139 { 130 {
140 for (i = 3; i < argc; i++) 131 for (i = 3; i < argc; i++)
141 runlevels = rc_strlist_add (runlevels, argv[i]); 132 runlevels = rc_strlist_add (runlevels, argv[i]);
142 133
143 if (! runlevels) 134 if (! runlevels)
144 runlevels = rc_strlist_add (runlevels, rc_get_runlevel ()); 135 runlevels = rc_strlist_add (runlevels, rc_get_runlevel ());
145 136
146 STRLIST_FOREACH (runlevels, runlevel, i) 137 STRLIST_FOREACH (runlevels, runlevel, i) {
147 {
148 if (rc_service_in_runlevel (service, runlevel)) 138 if (rc_service_in_runlevel (service, runlevel)) {
149 {
150 if (rc_service_delete (runlevel, service)) 139 if (rc_service_delete (runlevel, service))
151 einfo ("%s removed from runlevel %s", service, runlevel); 140 einfo ("%s removed from runlevel %s", service, runlevel);
152 else 141 else
153 eerror ("%s: failed to remove service `%s' from runlevel `%s': %s", 142 eerror ("%s: failed to remove service `%s' from runlevel `%s': %s",
154 applet, service, runlevel, strerror (errno)); 143 applet, service, runlevel, strerror (errno));
155 } 144 }
156 } 145 }
157 146
158 return (EXIT_SUCCESS); 147 return (EXIT_SUCCESS);
159 } 148 }
160 149
161 eerrorx ("%s: unknown command `%s'", applet, argv[1]); 150 eerrorx ("%s: unknown command `%s'", applet, argv[1]);
162} 151}

Legend:
Removed from v.2576  
changed lines
  Added in v.2577

  ViewVC Help
Powered by ViewVC 1.1.20