Make WARNS=6 happy with our init(8):
- Use more ``const''s where suitable. - Define strk() as a static function in global scope. This avoids the "nested extern declaration" warnings. - Use static initialization of strings, rather than referring string constants through char *. - Bump WARNS from 0 to 6.
This commit is contained in:
parent
79f717591c
commit
ab03e6d597
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=140070
@ -7,8 +7,8 @@ MLINKS= init.8 securelevel.8
|
|||||||
BINMODE=500
|
BINMODE=500
|
||||||
PRECIOUSPROG=
|
PRECIOUSPROG=
|
||||||
INSTALLFLAGS=-b -B.bak
|
INSTALLFLAGS=-b -B.bak
|
||||||
|
WARNS?= 6
|
||||||
CFLAGS+=-DDEBUGSHELL -DSECURE -DLOGIN_CAP -DCOMPAT_SYSV_INIT
|
CFLAGS+=-DDEBUGSHELL -DSECURE -DLOGIN_CAP -DCOMPAT_SYSV_INIT
|
||||||
WARNS?= 0
|
|
||||||
DPADD= ${LIBUTIL} ${LIBCRYPT}
|
DPADD= ${LIBUTIL} ${LIBCRYPT}
|
||||||
LDADD= -lutil -lcrypt
|
LDADD= -lutil -lcrypt
|
||||||
|
|
||||||
|
@ -103,6 +103,7 @@ void emergency(const char *, ...) __printflike(1, 2);
|
|||||||
void disaster(int);
|
void disaster(int);
|
||||||
void badsys(int);
|
void badsys(int);
|
||||||
int runshutdown(void);
|
int runshutdown(void);
|
||||||
|
static char *strk(char *);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We really need a recursive typedef...
|
* We really need a recursive typedef...
|
||||||
@ -132,7 +133,7 @@ int devfs;
|
|||||||
void transition(state_t);
|
void transition(state_t);
|
||||||
state_t requested_transition = runcom;
|
state_t requested_transition = runcom;
|
||||||
|
|
||||||
void setctty(char *);
|
void setctty(const char *);
|
||||||
|
|
||||||
typedef struct init_session {
|
typedef struct init_session {
|
||||||
int se_index; /* index of entry in ttys file */
|
int se_index; /* index of entry in ttys file */
|
||||||
@ -279,12 +280,17 @@ main(int argc, char *argv[])
|
|||||||
char *s;
|
char *s;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
iov[0].iov_base = "fstype";
|
char _fstype[] = "fstype";
|
||||||
iov[0].iov_len = sizeof("fstype");
|
char _devfs[] = "devfs";
|
||||||
iov[1].iov_base = "devfs";
|
char _fspath[] = "fspath";
|
||||||
iov[1].iov_len = sizeof("devfs");
|
char _path_dev[]= _PATH_DEV;
|
||||||
iov[2].iov_base = "fspath";
|
|
||||||
iov[2].iov_len = sizeof("fspath");
|
iov[0].iov_base = _fstype;
|
||||||
|
iov[0].iov_len = sizeof(_fstype);
|
||||||
|
iov[1].iov_base = _devfs;
|
||||||
|
iov[1].iov_len = sizeof(_devfs);
|
||||||
|
iov[2].iov_base = _fspath;
|
||||||
|
iov[2].iov_len = sizeof(_fspath);
|
||||||
/*
|
/*
|
||||||
* Try to avoid the trailing slash in _PATH_DEV.
|
* Try to avoid the trailing slash in _PATH_DEV.
|
||||||
* Be *very* defensive.
|
* Be *very* defensive.
|
||||||
@ -297,8 +303,8 @@ main(int argc, char *argv[])
|
|||||||
iov[3].iov_base = s;
|
iov[3].iov_base = s;
|
||||||
iov[3].iov_len = strlen(s) + 1;
|
iov[3].iov_len = strlen(s) + 1;
|
||||||
} else {
|
} else {
|
||||||
iov[3].iov_base = _PATH_DEV;
|
iov[3].iov_base = _path_dev;
|
||||||
iov[3].iov_len = sizeof(_PATH_DEV);
|
iov[3].iov_len = sizeof(_path_dev);
|
||||||
}
|
}
|
||||||
nmount(iov, 4, 0);
|
nmount(iov, 4, 0);
|
||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
@ -537,7 +543,7 @@ clear_session_logs(session_t *sp)
|
|||||||
* Only called by children of init after forking.
|
* Only called by children of init after forking.
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
setctty(char *name)
|
setctty(const char *name)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
@ -561,7 +567,7 @@ single_user(void)
|
|||||||
pid_t pid, wpid;
|
pid_t pid, wpid;
|
||||||
int status;
|
int status;
|
||||||
sigset_t mask;
|
sigset_t mask;
|
||||||
char *shell = _PATH_BSHELL;
|
const char *shell = _PATH_BSHELL;
|
||||||
char *argv[2];
|
char *argv[2];
|
||||||
#ifdef SECURE
|
#ifdef SECURE
|
||||||
struct ttyent *typ;
|
struct ttyent *typ;
|
||||||
@ -645,7 +651,10 @@ single_user(void)
|
|||||||
* Fire off a shell.
|
* Fire off a shell.
|
||||||
* If the default one doesn't work, try the Bourne shell.
|
* If the default one doesn't work, try the Bourne shell.
|
||||||
*/
|
*/
|
||||||
argv[0] = "-sh";
|
|
||||||
|
char name[] = "-sh";
|
||||||
|
|
||||||
|
argv[0] = name;
|
||||||
argv[1] = 0;
|
argv[1] = 0;
|
||||||
execv(shell, argv);
|
execv(shell, argv);
|
||||||
emergency("can't exec %s for single user: %m", shell);
|
emergency("can't exec %s for single user: %m", shell);
|
||||||
@ -723,9 +732,13 @@ runcom(void)
|
|||||||
|
|
||||||
setctty(_PATH_CONSOLE);
|
setctty(_PATH_CONSOLE);
|
||||||
|
|
||||||
argv[0] = "sh";
|
char _sh[] = "sh";
|
||||||
argv[1] = _PATH_RUNCOM;
|
char _path_runcom[] = _PATH_RUNCOM;
|
||||||
argv[2] = runcom_mode == AUTOBOOT ? "autoboot" : 0;
|
char _autoboot[] = "autoboot";
|
||||||
|
|
||||||
|
argv[0] = _sh;
|
||||||
|
argv[1] = _path_runcom;
|
||||||
|
argv[2] = runcom_mode == AUTOBOOT ? _autoboot : 0;
|
||||||
argv[3] = 0;
|
argv[3] = 0;
|
||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0);
|
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0);
|
||||||
@ -871,7 +884,6 @@ find_session(pid_t pid)
|
|||||||
char **
|
char **
|
||||||
construct_argv(char *command)
|
construct_argv(char *command)
|
||||||
{
|
{
|
||||||
char *strk (char *);
|
|
||||||
int argc = 0;
|
int argc = 0;
|
||||||
char **argv = (char **) malloc(((strlen(command) + 1) / 2 + 1)
|
char **argv = (char **) malloc(((strlen(command) + 1) / 2 + 1)
|
||||||
* sizeof (char *));
|
* sizeof (char *));
|
||||||
@ -1477,12 +1489,15 @@ runshutdown(void)
|
|||||||
/*
|
/*
|
||||||
* Run the shutdown script.
|
* Run the shutdown script.
|
||||||
*/
|
*/
|
||||||
argv[0] = "sh";
|
|
||||||
argv[1] = _PATH_RUNDOWN;
|
char _sh[] = "sh";
|
||||||
if (Reboot)
|
char _reboot[] = "reboot";
|
||||||
argv[2] = "reboot";
|
char _single[] = "single";
|
||||||
else
|
char _path_rundown[] = _PATH_RUNDOWN;
|
||||||
argv[2] = "single";
|
|
||||||
|
argv[0] = _sh;
|
||||||
|
argv[1] = _path_rundown;
|
||||||
|
argv[2] = Reboot ? _reboot : _single;
|
||||||
argv[3] = 0;
|
argv[3] = 0;
|
||||||
|
|
||||||
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0);
|
sigprocmask(SIG_SETMASK, &sa.sa_mask, (sigset_t *) 0);
|
||||||
@ -1568,8 +1583,8 @@ runshutdown(void)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
static char *
|
||||||
strk (char *p)
|
strk(char *p)
|
||||||
{
|
{
|
||||||
static char *t;
|
static char *t;
|
||||||
char *q;
|
char *q;
|
||||||
|
Loading…
Reference in New Issue
Block a user