Added patch from Didier Gaudin which allows init to load configuration

data from files stored in /etc/inittab.d/
This commit is contained in:
Jesse Smith 2020-01-08 19:42:43 -04:00
parent e48bfdc5dc
commit d4cc79bcb9
4 changed files with 81 additions and 13 deletions

View File

@ -10,6 +10,10 @@ sysvinit (2.97) unreleased; urgency=low
* Added shell script from Trek which converts systemd unit files * Added shell script from Trek which converts systemd unit files
into init.d style scripts. into init.d style scripts.
* Added patch from Didier Gaudin which allows init to load configuration
data from files stored in /etc/inittab.d/
sysvinit (2.96) released; urgency=low sysvinit (2.96) released; urgency=low
[ Jesse Smith ] [ Jesse Smith ]

View File

@ -203,6 +203,7 @@ install: all
$(INSTALL_EXEC) $$i $(ROOT)/usr/bin/ ; \ $(INSTALL_EXEC) $$i $(ROOT)/usr/bin/ ; \
done done
# $(INSTALL_DIR) $(ROOT)/etc/ # $(INSTALL_DIR) $(ROOT)/etc/
$(INSTALL_DIR) $(ROOT)/etc/inittab.d
# $(INSTALL_EXEC) ../doc/initscript.sample $(ROOT)/etc/ # $(INSTALL_EXEC) ../doc/initscript.sample $(ROOT)/etc/
ln -sf halt $(ROOT)/sbin/reboot ln -sf halt $(ROOT)/sbin/reboot
ln -sf halt $(ROOT)/sbin/poweroff ln -sf halt $(ROOT)/sbin/poweroff

View File

@ -63,6 +63,11 @@ Version information is not placed in the top-level Makefile by default
#include <sys/ttydefaults.h> #include <sys/ttydefaults.h>
#include <sys/syslog.h> #include <sys/syslog.h>
#include <sys/time.h> #include <sys/time.h>
/*
* inittab.d
*/
#include <sys/types.h>
#include <dirent.h>
#ifdef WITH_SELINUX #ifdef WITH_SELINUX
# include <selinux/selinux.h> # include <selinux/selinux.h>
@ -1431,6 +1436,7 @@ static
void read_inittab(void) void read_inittab(void)
{ {
FILE *fp; /* The INITTAB file */ FILE *fp; /* The INITTAB file */
FILE *fp_tab; /* The INITTABD files */
CHILD *ch, *old, *i; /* Pointers to CHILD structure */ CHILD *ch, *old, *i; /* Pointers to CHILD structure */
CHILD *head = NULL; /* Head of linked list */ CHILD *head = NULL; /* Head of linked list */
#ifdef INITLVL #ifdef INITLVL
@ -1448,7 +1454,10 @@ void read_inittab(void)
int round; /* round 0 for SIGTERM, 1 for SIGKILL */ int round; /* round 0 for SIGTERM, 1 for SIGKILL */
int foundOne = 0; /* No killing no sleep */ int foundOne = 0; /* No killing no sleep */
int talk; /* Talk to the user */ int talk; /* Talk to the user */
int done = 0; /* Ready yet? */ int done = -1; /* Ready yet? , 2 level : -1 nothing done, 0 inittab done, 1 inittab and inittab.d done */
DIR *tabdir=NULL; /* the INITTAB.D dir */
struct dirent *file_entry; /* inittab.d entry */
char f_name[272]; /* size d_name + strlen /etc/inittad.d/ */
#if DEBUG #if DEBUG
if (newFamily != NULL) { if (newFamily != NULL) {
@ -1464,22 +1473,73 @@ void read_inittab(void)
if ((fp = fopen(INITTAB, "r")) == NULL) if ((fp = fopen(INITTAB, "r")) == NULL)
initlog(L_VB, "No inittab file found"); initlog(L_VB, "No inittab file found");
while(!done) { /*
* Open INITTAB.D directory
*/
if( (tabdir = opendir(INITTABD))==NULL)
initlog(L_VB, "No inittab.d directory found");
while(done!=1) {
/* /*
* Add single user shell entry at the end. * Add single user shell entry at the end.
*/ */
if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) { if(done == -1) {
done = 1; if (fp == NULL || fgets(buf, sizeof(buf), fp) == NULL) {
/* done = 0;
* See if we have a single user entry. /*
*/ * See if we have a single user entry.
for(old = newFamily; old; old = old->next) */
if (strpbrk(old->rlevel, "S")) break; for(old = newFamily; old; old = old->next)
if (old == NULL) if (strpbrk(old->rlevel, "S")) break;
snprintf(buf, sizeof(buf), "~~:S:wait:%s\n", SULOGIN); if (old == NULL)
else snprintf(buf, sizeof(buf), "~~:S:wait:%s\n", SULOGIN);
else
continue;
}
} /* end if( done==-1) */
else if ( done == 0 ){
/* parse /etc/inittab.d and read all .tab files */
if(tabdir!=NULL){
if( (file_entry = readdir(tabdir))!=NULL){
/* ignore files not like *.tab */
if (!strcmp(file_entry->d_name, ".") || !strcmp(file_entry->d_name, ".."))
continue;
if (strlen(file_entry->d_name) < 5 || strcmp(file_entry->d_name + strlen(file_entry->d_name) - 4, ".tab"))
continue;
/*
* initialize filename
*/
memset(f_name,0,sizeof(char)*272);
snprintf(f_name,272,"/etc/inittab.d/%s",file_entry->d_name);
initlog(L_VB, "Reading: %s",f_name);
/*
* read file in inittab.d only one entry per file
*/
if ((fp_tab = fopen(f_name, "r")) == NULL)
continue;
/* read the file while the line contain comment */
while( fgets(buf, sizeof(buf), fp_tab) != NULL) {
for(p = buf; *p == ' ' || *p == '\t'; p++);
if (*p != '#' && *p != '\n')
break;
}
fclose(fp_tab);
/* do some checks */
if( buf == NULL )
continue;
if( strlen( p ) == 0 )
continue;
} /* end of readdir, all is done */
else {
done = 1;
continue;
}
} /* end of if(tabdir!=NULL) */
else {
done = 1;
continue; continue;
} }
} /* end of if ( done == 0 ) */
lineNo++; lineNo++;
/* /*
* Skip comments and empty lines * Skip comments and empty lines
@ -1630,10 +1690,12 @@ void read_inittab(void)
break; break;
} }
} }
/* /*
* We're done. * We're done.
*/ */
if (fp) fclose(fp); if (fp) fclose(fp);
if(tabdir) closedir(tabdir);
#ifdef __linux__ #ifdef __linux__
check_kernel_console(); check_kernel_console();

View File

@ -27,6 +27,7 @@
#define SECURETTY "/etc/securetty" /* List of root terminals */ #define SECURETTY "/etc/securetty" /* List of root terminals */
#define SDALLOW "/etc/shutdown.allow" /* Users allowed to shutdown */ #define SDALLOW "/etc/shutdown.allow" /* Users allowed to shutdown */
#define INITTAB "/etc/inittab" /* Location of inittab */ #define INITTAB "/etc/inittab" /* Location of inittab */
#define INITTABD "/etc/inittab.d" /* Location of inittab.d directory */
#define INIT "/sbin/init" /* Location of init itself. */ #define INIT "/sbin/init" /* Location of init itself. */
#define NOLOGIN "/etc/nologin" /* Stop user logging in. */ #define NOLOGIN "/etc/nologin" /* Stop user logging in. */
#define FASTBOOT "/fastboot" /* Enable fast boot. */ #define FASTBOOT "/fastboot" /* Enable fast boot. */