# HG changeset patch # User Mychaela Falconia # Date 1580665225 0 # Node ID 41b3e010808dc068f4bcb60bf6a27e63ebbaa9ff # Parent fb3deb215cb01695789d9d2fed7221c029c7a96a libpwon started, compiles diff -r fb3deb215cb0 -r 41b3e010808d libpwon/Makefile --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpwon/Makefile Sun Feb 02 17:40:25 2020 +0000 @@ -0,0 +1,13 @@ +CC= gcc +CFLAGS= -O2 +OBJS= forkoff.o readconf.o +LIB= libpwon.a + +all: ${LIB} + +${LIB}: ${OBJS} + ar rcu $@ ${OBJS} + ranlib $@ + +clean: + rm -f *.[oa] errs diff -r fb3deb215cb0 -r 41b3e010808d libpwon/forkoff.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpwon/forkoff.c Sun Feb 02 17:40:25 2020 +0000 @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +extern char bootctrl_pwon_cmd[]; + +static char shell_pathname[] = "/bin/sh"; + +void +fork_exec_pwon_cmd() +{ + int i; + + i = vfork(); + if (i < 0) { + perror("vfork"); + exit(1); + } + if (i) + return; + execl(shell_pathname, "sh", "-c", bootctrl_pwon_cmd, (char *) 0); + perror(shell_pathname); + _exit(1); +} diff -r fb3deb215cb0 -r 41b3e010808d libpwon/readconf.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libpwon/readconf.c Sun Feb 02 17:40:25 2020 +0000 @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include + +static char conf_file_pathname[] = "/opt/freecalypso/bootctrl.conf"; + +#define MAX_BOOTCTRL_CONF_LINE 510 + +char bootctrl_pwon_cmd[MAX_BOOTCTRL_CONF_LINE+1]; + +find_bootctrl_entry(soughtname) + char *soughtname; +{ + FILE *inf; + char linebuf[MAX_BOOTCTRL_CONF_LINE+2]; + int lineno; + char *cp, *np; + + inf = fopen(conf_file_pathname, "r"); + if (!inf) { + perror(conf_file_pathname); + return(-1); + } + for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { + cp = index(linebuf, '\n'); + if (!cp) { + fprintf(stderr, + "%s line %d: too long or missing newline\n", + conf_file_pathname, lineno); + fclose(inf); + return(-1); + } + *cp = '\0'; + for (cp = linebuf; isspace(*cp); cp++) + ; + if (*cp == '\0' || *cp == '#') + continue; + for (np = cp; *cp && !isspace(*cp); cp++) + ; + if (!*cp) { +invalid_syntax: fprintf(stderr, "%s line %d: invalid syntax\n", + conf_file_pathname, lineno); + fclose(inf); + return(-1); + } + *cp++ = '\0'; + while (isspace(*cp)) + cp++; + if (*cp == '\0' || *cp == '#') + goto invalid_syntax; + if (!strcmp(np, soughtname)) { + strcpy(bootctrl_pwon_cmd, cp); + fclose(inf); + return(0); + } + } + fclose(inf); + fprintf(stderr, "error: no \"%s\" entry found in %s\n", soughtname, + conf_file_pathname); + return(-1); +}