Hi, I would like to know if a patch for supporting kernel modification (using config(8)) along with KARL would be accepted ?
Currently, both are incompatibles. kernel modification is desirable in some cases, at least for disabling ulpt(4) when using cups with USB printer. KARL is desirable too. I would like to add such support in the following way: - add an argument to config(8) to support non-interactive use. Basically, it would be "read from file instead read from stdin". - add a line in kernel Makefile to do kernel modification (only if file /etc/ukc.conf is present) as part of KARL process (after relinking and before checksuming). Please note the place of the config(8) call: the kernel modification would occurs only when KARL is invoked during boot process ("newbsd" target), and not when the kernel is first generated (during the release(8) process). Missing part in the diff is the ukc.conf man page. It would be provided if the direction seems good. Please note that I don't have tested full release(8) process (it would be mandatory for such change). The config(8) changes in detail: config(8) will use scriptfile as input stream (instead of `stdin') if provided. When non-interactive is in use, the following things changes: - on EOF : assume "quit" command (save and exit) instead of err(3) - on bad command : exit(1) instead of ignoring the error and asking for new command. For testing the diff: - compile and install (patched) config(8) first - don't omit the "make config" before building and installing new kernel Some example: # cat /etc/ukc.conf disable ulpt* # /usr/libexec/reorder_kernel # cat /usr/share/relink/kernel/GENERIC.MP/relink.log (SHA256) /bsd: OK LD="ld" sh makegap.sh 0xcccccccc ld -T ld.script -X --warn-common -nopie -o newbsd ${SYSTEM_HEAD} vers.o ${OBJS} text data bss dec hex 8173928 2380088 1093632 11647648 b1baa0 mv newbsd newbsd.gdb ctfstrip -S -o newbsd newbsd.gdb if [ -f /etc/ukc.conf ]; then config -f -F /etc/ukc.conf -e newbsd; fi OpenBSD 6.2-current (GENERIC.MP) #85: Wed Jan 17 09:39:30 CET 2018 semarie@bert.local:/home/openbsd/src/sys/arch/i386/compile/GENERIC.MP Enter 'help' for information ukc> disable ulpt* 398 ulpt* disabled ukc> quit Saving modified kernel. mv -f newbsd bsd umask 077 && cp bsd /nbsd && mv /nbsd /bsd && sha256 -h /var/db/kernel.SHA256 /bsd Kernel has been relinked and is active on next reboot. SHA256 (/bsd) = 81a4916b8b81f0986d6fd63aad83c7fa4e742faa86c436756f1f79731c7ea184 -- Sebastien Marie Index: config.8 =================================================================== RCS file: /cvs/src/usr.sbin/config/config.8,v retrieving revision 1.65 diff -u -p -r1.65 config.8 --- config.8 7 Oct 2017 06:41:43 -0000 1.65 +++ config.8 17 Jan 2018 09:15:47 -0000 @@ -45,6 +45,7 @@ .Nm config .Op Fl u .Op Fl f | o Ar outfile +.Op Fl F Ar scriptfile .Fl e .Ar infile .Sh DESCRIPTION @@ -121,6 +122,12 @@ should be given to specify an alternate .It Fl o Ar outfile Write the modified kernel to .Ar outfile . +.It Fl F Ar scriptfile +Use +.Ar scriptfile +as source of commands for kernel modification. +.Ic quit +is assumed on eof. .It Fl u Check to see if the kernel configuration was modified at boot-time (i.e.\& Index: main.c =================================================================== RCS file: /cvs/src/usr.sbin/config/main.c,v retrieving revision 1.59 diff -u -p -r1.59 main.c --- main.c 22 Jun 2017 15:57:16 -0000 1.59 +++ main.c 17 Jan 2018 09:15:48 -0000 @@ -82,7 +82,7 @@ usage(void) fprintf(stderr, "usage: %s [-p] [-b builddir] [-s srcdir] [config-file]\n" - " %s [-u] [-f | -o outfile] -e infile\n", + " %s [-u] [-f | -o outfile] [-F scriptfile] -e infile\n", __progname, __progname); exit(1); @@ -92,6 +92,7 @@ int pflag = 0; char *sflag = NULL; char *bflag = NULL; char *startdir; +FILE *input = stdin; int main(int argc, char *argv[]) @@ -105,7 +106,7 @@ main(int argc, char *argv[]) err(1, "pledge"); pflag = eflag = uflag = fflag = 0; - while ((ch = getopt(argc, argv, "epfb:s:o:u")) != -1) { + while ((ch = getopt(argc, argv, "epfF:b:s:o:u")) != -1) { switch (ch) { case 'o': @@ -146,6 +147,12 @@ main(int argc, char *argv[]) case 's': sflag = optarg; srcdir = optarg; + break; + + case 'F': + input = fopen(optarg, "r"); + if (input == NULL) + err(2, "cannot read %s", optarg); break; default: Index: misc.c =================================================================== RCS file: /cvs/src/usr.sbin/config/misc.c,v retrieving revision 1.9 diff -u -p -r1.9 misc.c --- misc.c 2 Oct 2011 22:20:49 -0000 1.9 +++ misc.c 17 Jan 2018 09:15:48 -0000 @@ -36,6 +36,7 @@ #include "misc.h" extern int verbose; +extern FILE *input; int ask_cmd(cmd_t *cmd) @@ -43,8 +44,12 @@ ask_cmd(cmd_t *cmd) char lbuf[100], *cp, *buf; /* Get input */ - if (fgets(lbuf, sizeof lbuf, stdin) == NULL) - errx(1, "eof"); + if (fgets(lbuf, sizeof lbuf, input) == NULL) { + if (input == stdin) + errx(1, "eof"); + + strlcpy(lbuf, "quit", sizeof lbuf); + } lbuf[strcspn(lbuf, "\n")] = '\0'; if (verbose) printf("%s\n", lbuf); @@ -69,13 +74,13 @@ ask_yn(const char *str) printf("%s [n] ", str); fflush(stdout); - first = ch = getchar(); + first = ch = getc(input); if (verbose) { printf("%c", ch); fflush(stdout); } while (ch != '\n' && ch != EOF) { - ch = getchar(); + ch = getc(input); if (verbose) { printf("%c\n", ch); fflush(stdout); Index: mkmakefile.c =================================================================== RCS file: /cvs/src/usr.sbin/config/mkmakefile.c,v retrieving revision 1.45 diff -u -p -r1.45 mkmakefile.c --- mkmakefile.c 5 Nov 2017 10:29:24 -0000 1.45 +++ mkmakefile.c 17 Jan 2018 09:15:48 -0000 @@ -517,8 +517,9 @@ emitload(FILE *fp) "\t${SYSTEM_LD_HEAD}\n" "\t${SYSTEM_LD} swap%s.o\n" "\t${SYSTEM_LD_TAIL}\n" + "\tif [ -f /etc/ukc.conf ]; then config -f -F /etc/ukc.conf -e new%s; fi\n" "\tmv -f new%s %s\n\n", - swname, nm, nm) < 0) + swname, nm, nm, nm) < 0) return (1); if (fprintf(fp, "update-link:\n") < 0) Index: ukcutil.c =================================================================== RCS file: /cvs/src/usr.sbin/config/ukcutil.c,v retrieving revision 1.23 diff -u -p -r1.23 ukcutil.c --- ukcutil.c 27 Sep 2017 15:14:52 -0000 1.23 +++ ukcutil.c 17 Jan 2018 09:15:49 -0000 @@ -42,6 +42,7 @@ #include "misc.h" extern int ukc_mod_kernel; +extern FILE *input; struct cfdata * get_cfdata(int idx) @@ -1326,6 +1327,10 @@ again: /* Check for valid command */ if (cmd_table[i].cmd == NULL) { printf("Invalid command '%s'. Try 'help'.\n", cmd.cmd); + + /* abort on non-interactive */ + if (input != stdin) + exit(1); continue; } else strlcpy(cmd.cmd, cmd_table[i].cmd, sizeof cmd.cmd);