1 diff -Nru chkconfig-1.2.22/chkconfig.c chkconfig-1.2.22.new/chkconfig.c
2 --- chkconfig-1.2.22/chkconfig.c Sun Mar 25 03:29:32 2001
3 +++ chkconfig-1.2.22.new/chkconfig.c Sun Mar 25 03:31:17 2001
5 readServiceError(rc, name);
8 - if (s.type == TYPE_XINETD) return 0;
10 for (level = 0; level < 7; level++) {
11 if (!findServiceEntries(name, level, &globres)) {
16 - if (s.type == TYPE_XINETD) return 0;
18 for (i = 0; i < 7; i++) {
19 if ((1 << i) & s.levels)
20 doSetService(s, i, 1);
24 printf("%-15s", s.name);
25 - if (s.type == TYPE_XINETD) {
26 - printf("\t%s\n", s.levels ? _("on") : _("off"));
30 for (i = 0; i < 7; i++) {
31 printf("\t%d:%s", i, isOn(s.name, i) ? _("on") : _("off"));
36 -static int isXinetdEnabled() {
40 - if (readServiceInfo("xinetd", &s, 0)) {
43 - for (i = 0; i < 7; i++) {
44 - if (isOn("xinetd", i))
51 static int listService(char * item) {
59 - if (isXinetdEnabled()) {
60 - printf(_("xinetd based services:\n"));
61 - if (!(dir = opendir(XINETDDIR))) {
62 - fprintf(stderr, _("failed to open directory %s: %s"),
63 - XINETDDIR, strerror(err));
66 - while ((ent = readdir(dir))) {
70 - /* Skip any file starting with a . */
71 - if (ent->d_name[0] == '.') continue;
73 - /* Skip files with known bad extensions */
74 - if ((dn = strrchr(ent->d_name, '.')) != NULL &&
75 - (!strcmp(dn, ".rpmsave") || !strcmp(dn, ".rpmnew") || !strcmp(dn, ".rpmorig") || !strcmp(dn, ".swp")))
78 - dn = ent->d_name + strlen(ent->d_name) - 1;
79 - if (*dn == '~' || *dn == ',')
82 - readXinetdServiceInfo(ent->d_name, &s, 0);
83 - printf("\t%s:\t%s\n", s.name, s.levels ? _("on") : _("off"));
94 - if (s.type == TYPE_INIT_D) {
95 - for (i = 0; i < 7; i++) {
96 - if (!((1 << i) & where)) continue;
98 - if (state == 1 || state == 0)
100 - else if (s.levels & (1 << i))
104 - doSetService(s, i, what);
106 - } else if (s.type == TYPE_XINETD) {
107 - setXinetdService(s, state);
108 - system("/etc/init.d/xinetd reload >/dev/null 2>&1");
109 + for (i = 0; i < 7; i++) {
110 + if (!((1 << i) & where)) continue;
112 + if (state == 1 || state == 0)
114 + else if (s.levels & (1 << i))
118 + doSetService(s, i, what);
122 diff -Nru chkconfig-1.2.22/leveldb.c chkconfig-1.2.22.new/leveldb.c
123 --- chkconfig-1.2.22/leveldb.c Sun Mar 25 03:29:32 2001
124 +++ chkconfig-1.2.22.new/leveldb.c Sun Mar 25 03:31:47 2001
129 -int readXinetdServiceInfo(char *name, struct service * service, int honorHide) {
130 - char * filename = alloca(strlen(name) + strlen(XINETDDIR) + 50);
132 - struct service serv = { NULL, -1, -1, -1, NULL, 1, -1 };
135 - char * eng_desc = NULL, *start;
137 - snprintf(filename, strlen(name)+strlen(XINETDDIR)+50, XINETDDIR "/%s", name);
139 - if ((fd = open(filename, O_RDONLY)) < 0) return -1;
141 - buf = malloc(sb.st_size+1);
142 - if (read(fd,buf,sb.st_size)!=sb.st_size) {
148 - serv.name = strdup(name);
149 - buf[sb.st_size] = '\0';
152 - ptr = strchr(buf,'\n');
155 - while (isspace(*buf) && buf < ptr) buf++;
156 - if (!strncmp(buf,"default:", 9)) {
158 - while(isspace(*buf)) buf++;
159 - if (!strncmp(buf+9,"on",2)) {
164 - } else if (!strncmp(buf,"description:",12)) {
166 - if (readDescription(buf,start+sb.st_size,
167 - &serv.desc,&eng_desc)) {
168 - if (serv.desc) free(serv.desc);
172 - serv.desc = eng_desc;
173 - } else if (eng_desc)
183 - while (isspace(*buf) && buf < ptr) buf++;
184 - if (!strncmp(buf,"disable", 7)) {
185 - buf = strstr(buf,"=");
189 - } while(isspace(*buf));
191 - if (buf && strncmp(buf,"yes",3)) {
192 - serv.levels = parseLevels("0123456",0);
193 - if (serv.enabled == -1)
197 - if (serv.enabled == -1)
211 int readServiceInfo(char * name, struct service * service, int honorHide) {
212 char * filename = alloca(strlen(name) + strlen(RUNLEVELS) + 50);
215 sprintf(filename, RUNLEVELS "/init.d/%s", name);
217 if ((fd = open(filename, O_RDONLY)) < 0) {
218 - return readXinetdServiceInfo(name,service,honorHide);
229 -int setXinetdService(struct service s, int on) {
231 - char oldfname[100], newfname[100];
233 - char *buf, *ptr, *tmp;
237 - on = s.enabled ? 1 : 0;
239 - snprintf(oldfname,100,"%s/%s",XINETDDIR,s.name);
240 - if ( (oldfd = open(oldfname,O_RDONLY)) == -1 ) {
244 - buf = malloc(sb.st_size+1);
245 - if (read(oldfd,buf,sb.st_size)!=sb.st_size) {
251 - buf[sb.st_size] = '\0';
252 - snprintf(newfname,100,"%s/%s.XXXXXX",XINETDDIR,s.name);
253 - newfd = mkstemp(newfname);
260 - ptr = strchr(buf,'\n');
265 - while (isspace(*buf)) buf++;
266 - if (strncmp(buf,"disable", 7) && strlen(buf)) {
267 - write(newfd,tmp,strlen(tmp));
268 - write(newfd,"\n",1);
269 - if (buf[0] == '{') {
270 - snprintf(tmpstr,50,"\tdisable\t= %s", on ? "no" : "yes");
271 - write(newfd,tmpstr,strlen(tmpstr));
272 - write(newfd,"\n",1);
278 - chmod(newfname,0644);
280 - return(rename(newfname,oldfname));
283 int doSetService(struct service s, int level, int on) {
284 diff -Nru chkconfig-1.2.22/ntsysv.c chkconfig-1.2.22.new/ntsysv.c
285 --- chkconfig-1.2.22/ntsysv.c Mon Mar 5 06:51:54 2001
286 +++ chkconfig-1.2.22.new/ntsysv.c Sun Mar 25 03:33:04 2001
288 states = alloca(sizeof(*states) * numServices);
290 for (i = 0; i < numServices; i++) {
291 - if (services[i].type == TYPE_XINETD) {
292 - checkboxes[i] = newtCheckbox(-1, i, services[i].name,
293 - services[i].levels ? '*' : ' ', NULL,
296 - for (j = 0; j < 7; j++) {
297 - if (levels & (1 << j)) {
298 - if (isOn(services[i].name, j)) break;
300 + for (j = 0; j < 7; j++) {
301 + if (levels & (1 << j)) {
302 + if (isOn(services[i].name, j)) break;
304 - checkboxes[i] = newtCheckbox(-1, i, services[i].name,
305 - (j != 7) ? '*' : ' ', NULL,
308 + checkboxes[i] = newtCheckbox(-1, i, services[i].name,
309 + (j != 7) ? '*' : ' ', NULL,
311 newtFormAddComponent(subform, checkboxes[i]);
315 if (!update) return 1;
317 for (i = 0; i < numServices; i++) {
318 - if (services[i].type == TYPE_XINETD)
319 - setXinetdService(services[i], states[i] == '*');
321 - for (j = 0; j < 7; j++) {
322 - if (levels & (1 << j))
323 - doSetService(services[i], j, states[i] == '*');
325 + for (j = 0; j < 7; j++) {
326 + if (levels & (1 << j))
327 + doSetService(services[i], j, states[i] == '*');
336 - if (!stat("/usr/sbin/xinetd",&sb)) {
337 - if (!(dir = opendir(XINETDDIR))) {
338 - fprintf(stderr, "failed to open " XINETDDIR ": %s\n",
343 - while ((ent = readdir(dir))) {
344 - if (strchr(ent->d_name, '~') || strchr(ent->d_name, ',') ||
345 - strchr(ent->d_name, '.')) continue;
347 - sprintf(fn, "%s/%s", XINETDDIR, ent->d_name);
353 - if (!S_ISREG(sb.st_mode)) continue;
355 - if (numServices == numServicesAlloced) {
356 - numServicesAlloced += 10;
357 - services = realloc(services,
358 - numServicesAlloced * sizeof(*services));
361 - rc = readXinetdServiceInfo(ent->d_name, services + numServices, honorHide);
364 - fprintf(stderr, _("error reading info for service %s: %s\n"),
365 - ent->d_name, strerror(errno));
373 - fprintf(stderr, _("error reading from directory %s: %s\n"),
374 - XINETDDIR, strerror(err));
379 qsort(services, numServices, sizeof(*services), serviceNameCmp);
381 *servicesPtr = services;