chkconfig patch: list level and SYSV SYSLOG order

Gerhard Wiesinger lists at wiesinger.com
Sun Jan 18 10:42:05 UTC 2004


Hello!

Wrote a small patch (attached) for chkconfig (1.3.9) to have a sysv init
list for a runlevel:

Behaviour should not be changed when the additional switches are not
used:

Examples:
Start:
chkconfig --skip-xinetd --priority --show-level 5 --list | sort -k 2 -n
microcode_ctl   0       99      0:off   1:off   2:on    3:on    4:on    5:on    6:off
kudzu           5       95      0:off   1:off   2:off   3:on    4:on    5:on    6:off
ip6tables       8       92      0:off   1:off   2:on    3:on    4:on    5:on    6:off
ipchains        8       92      0:off   1:off   2:on    3:on    4:on    5:on    6:off
iptables        8       92      0:off   1:off   2:on    3:on    4:on    5:on    6:off
isdn            9       91      0:off   1:off   2:on    3:on    4:on    5:on    6:off
network         10      90      0:off   1:off   2:on    3:on    4:on    5:on    6:off
syslog          12      88      0:off   1:off   2:on    3:on    4:on    5:on    6:off
irqbalance      13      87      0:off   1:off   2:off   3:on    4:on    5:on    6:off
...

Kill:
chkconfig --skip-xinetd --priority --show-level 5 --list | sort -k 3 -n
messagebus      97      3       0:off   1:off   2:off   3:on    4:on    5:on    6:off
rhnsd           97      3       0:off   1:off   2:off   3:on    4:on    5:on    6:off
anacron         95      5       0:off   1:off   2:on    3:on    4:on    5:on    6:off
atd             95      5       0:off   1:off   2:off   3:on    4:on    5:on    6:off
....

BTW: shouldn't syslog be before network, isdn and even iptables?
I see cipe output when the network starts on the console but this should
go to syslog, shouldn't it?

Otherwise
CIPE driver vers 1.4.5 (c) Olaf Titz 1996-2000, 100 channels,
is displayed on the console.

So syslog levels should be 6 for start and also 93 for kill.

Old:
# chkconfigorig: 2345 12 88
New:
# chkconfig: 2345 6 93

chkconfig syslog reset

Fedora=FC1

Ciao,
Gerhard
-------------- next part --------------
--- chkconfig.c.orig	2004-01-18 09:51:20.000000000 +0100
+++ chkconfig.c	2004-01-18 10:50:21.000000000 +0100
@@ -22,7 +22,7 @@
     fprintf(stderr, _("This may be freely redistributed under the terms of "
 			"the GNU Public License.\n"));
     fprintf(stderr, "\n");
-    fprintf(stderr, _("usage:   %s --list [name]\n"), progname);
+    fprintf(stderr, _("usage:   %s [--priority] [--skip-xinetd] [--show-level <level>] --list [name]\n"), progname);
     fprintf(stderr, _("         %s --add <name>\n"), progname);
     fprintf(stderr, _("         %s --del <name>\n"), progname);
     fprintf(stderr, _("         %s [--level <levels>] <name> %s)\n"), progname, "<on|off|reset>");
@@ -183,7 +183,7 @@
     return 0;
 }
 
-static int showServiceInfo(char * name, int forgiving) {
+static int showServiceInfo(char * name, int forgiving, int priority, int level) {
     int rc;
     int i;
     struct service s;
@@ -206,16 +206,28 @@
 	return forgiving ? 0 : 1;
     }
 
+    int show = 1;
+    if (level != -1)
+    {
+	show = isOn(s.name, level);
+    }
+
+    if (show)
+    {
     printf("%-15s", s.name);
     if (s.type == TYPE_XINETD) {
 	    printf("\t%s\n", s.levels ? _("on") : _("off"));
 	    return 0;
     }
 
+    if (priority)
+	    printf("\t%d\t%d", s.sPriority, s.kPriority);
+
     for (i = 0; i < 7; i++) {
 	printf("\t%d:%s", i, isOn(s.name, i) ? _("on") : _("off"));
     }
     printf("\n");
+    }
 
     return 0;
 }
@@ -235,14 +247,14 @@
 }
 	
 
-static int listService(char * item) {
+static int listService(char * item, int priority, int skipxinetd, int level) {
     DIR * dir;
     struct dirent * ent;
     struct stat sb;
     char fn[1024];
     int err = 0;
 
-    if (item) return showServiceInfo(item, 0);
+    if (item) return showServiceInfo(item, 0, priority, level);
 
     if (!(dir = opendir(RUNLEVELS "/init.d"))) {
 	fprintf(stderr, _("failed to open %s/init.d: %s\n"), RUNLEVELS,
@@ -272,7 +284,7 @@
 	}
 	if (!S_ISREG(sb.st_mode)) continue;
 
-	if (showServiceInfo(ent->d_name, 1)) {
+	if (showServiceInfo(ent->d_name, 1, priority, level)) {
 	    closedir(dir);
 	    return 1;
 	}
@@ -286,7 +298,7 @@
 
     closedir(dir);
 	
-    if (isXinetdEnabled()) {
+    if (isXinetdEnabled() && !skipxinetd) {
 	    printf(_("xinetd based services:\n"));
 	    if (!(dir = opendir(XINETDDIR))) {
 		    fprintf(stderr, _("failed to open directory %s: %s\n"),
@@ -357,7 +369,7 @@
 }
 
 int main(int argc, char ** argv) {
-    int listItem = 0, addItem = 0, delItem = 0;
+    int listItem = 0, priorityItem=0, skipxinetdItem=0, showlevelItem=-1, addItem = 0, delItem = 0;
     int rc, i, x;
     int LSB = 0;
     char * levels = NULL;
@@ -367,6 +379,9 @@
 	    { "add", '\0', 0, &addItem, 0 },
 	    { "del", '\0', 0, &delItem, 0 },
 	    { "list", '\0', 0, &listItem, 0 },
+	    { "priority", '\0', 0, &priorityItem, 0 },
+	    { "skip-xinetd", '\0', 0, &skipxinetdItem, 0 },
+	    { "show-level", '\0', POPT_ARG_INT, &showlevelItem, 0 },
 	    { "level", '\0', POPT_ARG_STRING, &levels, 0 },
 	    { "levels", '\0', POPT_ARG_STRING, &levels, 0 },
 	    { "help", 'h', POPT_ARG_NONE, &help, 0 },
@@ -436,7 +451,9 @@
 
 	if (item && poptGetArg(optCon)) usage();
 
-	return listService(item);
+	if (showlevelItem < -1 || showlevelItem > 6) usage();
+
+	return listService(item, priorityItem, skipxinetdItem, showlevelItem);
     } else {
 	char * name = (char *)poptGetArg(optCon);
 	char * state = (char *)poptGetArg(optCon);


More information about the fedora-devel-list mailing list