commit c842e2a3086b3598d2e83726a98c92359f3dfdca
parent b0ab3b4e0ecf62bf6f551d00fdf06308402fd604
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date: Sun, 6 Oct 2024 18:24:01 +0200
use strict-prototypes warning and friends
Friends are:
* strict-prototypes
* missing-prototypes
* implicit-function-declaration
* incompatible-function-pointer-types
* cast-qual
Diffstat:
35 files changed, 287 insertions(+), 193 deletions(-)
diff --git a/build.ninja b/build.ninja
@@ -9,12 +9,20 @@ include conf.ninja
# _DEFAULT_SOURCE (the BSD one is deprecated) but
# I am unsure if that would bring in non-standard
# features, that I would rather avoid doing.
+#TODO investigate why _DEFAULT_SOURCE is actually
+# required by 2 subprojects, and if it really is
+# standard.
CCFLAGS = $$CCFLAGS $
-DVERSION='"TODO..."' $
-std=c11 $
-D_POSIX_C_SOURCE=200809L $
-D_XOPEN_SOURCE=500L $
+ -Werror=strict-prototypes $
-Werror=missing-variable-declarations $
+ -Werror=missing-prototypes $
+ -Werror=implicit-function-declaration $
+ -Werror=incompatible-function-pointer-types $
+ -Werror=cast-qual $
subninja src/librunit.ninja
subninja src/runsv.ninja
diff --git a/src/alloc.c b/src/alloc.c
@@ -12,8 +12,7 @@ static aligned realspace[SPACE / ALIGNMENT];
#define space ((char *) realspace)
static unsigned int avail = SPACE; /* multiple of ALIGNMENT; 0<=avail<=SPACE */
-/*@null@*//*@out@*/char *alloc(n)
-unsigned int n;
+/*@null@*//*@out@*/char *alloc( size_t n )
{
char *x;
n = ALIGNMENT + n - (n & (ALIGNMENT - 1)); /* XXX: could overflow */
@@ -23,8 +22,7 @@ unsigned int n;
return x;
}
-void alloc_free(x)
-char *x;
+void alloc_free( char* x)
{
if (x >= space)
if (x < space + SPACE)
diff --git a/src/alloc.h b/src/alloc.h
@@ -3,8 +3,10 @@
#ifndef ALLOC_H
#define ALLOC_H
-extern /*@null@*//*@out@*/char *alloc();
-extern void alloc_free();
-extern int alloc_re();
+#include <stddef.h>
+
+extern /*@null@*//*@out@*/char *alloc( size_t n );
+extern void alloc_free( char* );
+extern int alloc_re( char** x, size_t m, size_t n);
#endif
diff --git a/src/alloc_re.c b/src/alloc_re.c
@@ -3,10 +3,7 @@
#include "alloc.h"
#include "byte.h"
-int alloc_re(x,m,n)
-char **x;
-unsigned int m;
-unsigned int n;
+int alloc_re( char** x, size_t m, size_t n)
{
char *y;
diff --git a/src/buffer.c b/src/buffer.c
@@ -2,7 +2,7 @@
#include "buffer.h"
-void buffer_init(buffer *s,int (*op)(),int fd,char *buf,unsigned int len)
+void buffer_init(buffer *s,buffer_op op,int fd,char *buf,unsigned int len)
{
s->x = buf;
s->fd = fd;
diff --git a/src/buffer.h b/src/buffer.h
@@ -3,19 +3,20 @@
#ifndef BUFFER_H
#define BUFFER_H
+typedef int (*buffer_op)( int fd, const char* buf, unsigned int len );
typedef struct buffer {
char *x;
unsigned int p;
unsigned int n;
int fd;
- int (*op)();
+ buffer_op op;
} buffer;
#define BUFFER_INIT(op,fd,buf,len) { (buf), 0, (len), (fd), (op) }
#define BUFFER_INSIZE 8192
#define BUFFER_OUTSIZE 8192
-extern void buffer_init(buffer *,int (*)(),int,char *,unsigned int);
+extern void buffer_init(buffer *,buffer_op op,int,char *,unsigned int);
extern int buffer_flush(buffer *);
extern int buffer_put(buffer *,const char *,unsigned int);
diff --git a/src/buffer_get.c b/src/buffer_get.c
@@ -4,7 +4,7 @@
#include "byte.h"
#include "error.h"
-static int oneread(int (*op)(),int fd,char *buf,unsigned int len)
+static int oneread(buffer_op op,int fd,char *buf,unsigned int len)
{
int r;
diff --git a/src/buffer_put.c b/src/buffer_put.c
@@ -5,7 +5,7 @@
#include "byte.h"
#include "error.h"
-static int allwrite(int (*op)(),int fd,const char *buf,unsigned int len)
+static int allwrite(int (*op)( int fd, const char* buf, unsigned int len ),int fd,const char *buf,unsigned int len)
{
int w;
diff --git a/src/byte.h b/src/byte.h
@@ -3,12 +3,14 @@
#ifndef BYTE_H
#define BYTE_H
-extern unsigned int byte_chr();
-extern unsigned int byte_rchr();
-extern void byte_copy();
-extern void byte_copyr();
-extern int byte_diff();
-extern void byte_zero();
+#include <stddef.h>
+
+extern unsigned int byte_chr( char* s, register size_t n, int c );
+extern unsigned int byte_rchr( void );
+extern void byte_copy( register char* to, register size_t n, register char* from );
+extern void byte_copyr( register char *to, register unsigned int n, register char *from );
+extern int byte_diff( register char* s, register size_t n, register char* t );
+extern void byte_zero( void );
#define byte_equal(s,n,t) (!byte_diff((s),(n),(t)))
diff --git a/src/byte_chr.c b/src/byte_chr.c
@@ -2,10 +2,7 @@
#include "byte.h"
-unsigned int byte_chr(s,n,c)
-char *s;
-register unsigned int n;
-int c;
+unsigned int byte_chr( char* s, register size_t n, int c )
{
register char ch;
register char *t;
diff --git a/src/byte_copy.c b/src/byte_copy.c
@@ -2,10 +2,7 @@
#include "byte.h"
-void byte_copy(to,n,from)
-register char *to;
-register unsigned int n;
-register char *from;
+void byte_copy( register char* to, register size_t n, register char* from)
{
for (;;) {
if (!n) return; *to++ = *from++; --n;
diff --git a/src/byte_cr.c b/src/byte_cr.c
@@ -2,10 +2,7 @@
#include "byte.h"
-void byte_copyr(to,n,from)
-register char *to;
-register unsigned int n;
-register char *from;
+void byte_copyr( register char *to, register unsigned int n, register char *from )
{
to += n;
from += n;
diff --git a/src/byte_diff.c b/src/byte_diff.c
@@ -2,10 +2,7 @@
#include "byte.h"
-int byte_diff(s,n,t)
-register char *s;
-register unsigned int n;
-register char *t;
+int byte_diff( register char* s, register size_t n, register char* t )
{
for (;;) {
if (!n) return 0; if (*s != *t) break; ++s; ++t; --n;
diff --git a/src/chpst.c b/src/chpst.c
@@ -3,6 +3,7 @@
#include <sys/time.h>
#include <sys/resource.h>
#include <unistd.h>
+#include <grp.h>
#include <sys/types.h>
#include <dirent.h>
#include "sgetopt.h"
@@ -27,16 +28,18 @@
static const char *progname;
static stralloc sa;
-void fatal(const char *m) { strerr_die3sys(111, FATAL, m, ": "); }
-void fatal2(const char *m0, const char *m1) {
+static void fatal(const char *m) { strerr_die3sys(111, FATAL, m, ": "); }
+static void fatal2(const char *m0, const char *m1)
+{
strerr_die5sys(111, FATAL, m0, ": ", m1, ": ");
}
-void fatalx(const char *m0, const char *m1) {
+static void fatalx(const char *m0, const char *m1)
+{
strerr_die4x(111, FATAL, m0, ": ", m1);
}
-void warn(const char *m) { strerr_warn2(WARNING, m, 0); }
-void die_nomem() { strerr_die2x(111, FATAL, "out of memory."); }
-void usage() { strerr_die4x(100, "usage: ", progname, USAGE_MAIN, "\n"); }
+static void warn(const char *m) { strerr_warn2(WARNING, m, 0); }
+static void die_nomem( void ) { strerr_die2x(111, FATAL, "out of memory."); }
+static void usage( void ) { strerr_die4x(100, "usage: ", progname, USAGE_MAIN, "\n"); }
static char *set_user =0;
static char *env_user =0;
@@ -63,7 +66,8 @@ static const char *root =0;
static const char *pwd =0;
static unsigned int lockdelay;
-void suidgid(char *user, unsigned int ext) {
+static void suidgid(char *user, unsigned int ext)
+{
struct uidgid ugid;
if (ext) {
@@ -83,7 +87,8 @@ void suidgid(char *user, unsigned int ext) {
if (setuid(ugid.uid) == -1) fatal("unable to setuid");
}
-void euidgid(char *user, unsigned int ext) {
+static void euidgid(char *user, unsigned int ext)
+{
struct uidgid ugid;
char bufnum[FMT_ULONG];
@@ -105,7 +110,8 @@ void euidgid(char *user, unsigned int ext) {
if (! pathexec_env("UID", bufnum)) die_nomem();
}
-void edir(const char *dirname) {
+static void edir(const char *dirname)
+{
int wdir;
DIR *dir;
struct dirent *d;
@@ -150,11 +156,13 @@ void edir(const char *dirname) {
close(wdir);
}
-void slock_die(const char *m, const char *f, unsigned int x) {
+static void slock_die(const char *m, const char *f, unsigned int x)
+{
if (! x) fatal2(m, f);
_exit(0);
}
-void slock(const char *f, unsigned int d, unsigned int x) {
+static void slock(const char *f, unsigned int d, unsigned int x)
+{
int fd;
if ((fd =open_append(f)) == -1) slock_die("unable to open lock", f, x);
@@ -165,7 +173,8 @@ void slock(const char *f, unsigned int d, unsigned int x) {
if (lock_exnb(fd) == -1) slock_die("unable to lock", f, x);
}
-void limit(int what, long l) {
+static void limit(int what, long l)
+{
struct rlimit r;
if (getrlimit(what, &r) == -1) fatal("unable to getrlimit()");
@@ -175,7 +184,8 @@ void limit(int what, long l) {
r.rlim_cur =l;
if (setrlimit(what, &r) == -1) fatal("unable to setrlimit()");
}
-void slimit() {
+static void slimit()
+{
if (limitd >= -1) {
#ifdef RLIMIT_DATA
limit(RLIMIT_DATA, limitd);
@@ -259,12 +269,12 @@ void slimit() {
}
/* argv[0] */
-void setuidgid(int, const char *const *);
-void envuidgid(int, const char *const *);
-void envdir(int, const char *const *);
-void pgrphack(int, const char *const *);
-void setlock(int, const char *const *);
-void softlimit(int, const char *const *);
+static void setuidgid(int, const char *const *);
+static void envuidgid(int, const char *const *);
+static void envdir(int, const char *const *);
+static void pgrphack(int, const char *const *);
+static void setlock(int, const char *const *);
+static void softlimit(int, const char *const *);
int main(int argc, const char **argv) {
int opt;
@@ -290,9 +300,9 @@ int main(int argc, const char **argv) {
while ((opt =getopt(argc, argv, "u:U:b:e:m:d:o:p:f:c:r:t:/:C:n:l:L:vP012V"))
!= opteof)
switch(opt) {
- case 'u': set_user =(char*)optarg; break;
- case 'U': env_user =(char*)optarg; break;
- case 'b': argv0 =(char*)optarg; break;
+ case 'u': set_user =(char const*)optarg; break;
+ case 'U': env_user =(char const*)optarg; break;
+ case 'b': argv0 =(char const*)optarg; break;
case 'e': env_dir =optarg; break;
case 'm':
if (optarg[scan_ulong(optarg, &ul)]) usage();
@@ -369,36 +379,42 @@ int main(int argc, const char **argv) {
#define USAGE_SETLOCK " [ -nNxX ] file program [ arg ... ]"
#define USAGE_SOFTLIMIT " [-a allbytes] [-c corebytes] [-d databytes] [-f filebytes] [-l lockbytes] [-m membytes] [-o openfiles] [-p processes] [-r residentbytes] [-s stackbytes] [-t cpusecs] child"
-void setuidgid_usage() {
+static void setuidgid_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_SETUIDGID, "\n");
}
-void setuidgid(int argc, const char *const *argv) {
+static void setuidgid(int argc, const char *const *argv)
+{
const char *account;
if (! (account =*++argv)) setuidgid_usage();
if (! *++argv) setuidgid_usage();
- suidgid((char*)account, 0);
+ suidgid((char const*)account, 0);
pathexec(argv);
fatal2("unable to run", *argv);
}
-void envuidgid_usage() {
+static void envuidgid_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_ENVUIDGID, "\n");
}
-void envuidgid(int argc, const char *const *argv) {
+static void envuidgid(int argc, const char *const *argv)
+{
const char *account;
if (! (account =*++argv)) envuidgid_usage();
if (! *++argv) envuidgid_usage();
- euidgid((char*)account, 0);
+ euidgid((char const*)account, 0);
pathexec(argv);
fatal2("unable to run", *argv);
}
-void envdir_usage() {
+static void envdir_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_ENVDIR, "\n");
}
-void envdir(int argc, const char *const *argv) {
+static void envdir(int argc, const char *const *argv)
+{
const char *dir;
if (! (dir =*++argv)) envdir_usage();
@@ -408,20 +424,24 @@ void envdir(int argc, const char *const *argv) {
fatal2("unable to run", *argv);
}
-void pgrphack_usage() {
+static void pgrphack_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_PGRPHACK, "\n");
}
-void pgrphack(int argc, const char *const *argv) {
+static void pgrphack(int argc, const char *const *argv)
+{
if (! *++argv) pgrphack_usage();
setsid();
pathexec(argv);
fatal2("unable to run", *argv);
}
-void setlock_usage() {
+static void setlock_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_SETLOCK, "\n");
}
-void setlock(int argc, const char *const *argv) {
+static void setlock(int argc, const char *const *argv)
+{
int opt;
unsigned int delay =0;
unsigned int x =0;
@@ -445,17 +465,20 @@ void setlock(int argc, const char *const *argv) {
_exit(0);
}
-void softlimit_usage() {
+static void softlimit_usage()
+{
strerr_die4x(100, "usage: ", progname, USAGE_SOFTLIMIT, "\n");
}
-void getlarg(long *l) {
+static void getlarg(long *l)
+{
unsigned long ul;
if (str_equal(optarg, "=")) { *l =-1; return; }
if (optarg[scan_ulong(optarg, &ul)]) usage();
*l =ul;
}
-void softlimit(int argc, const char *const *argv) {
+static void softlimit(int argc, const char *const *argv)
+{
int opt;
while ((opt =getopt(argc,argv,"a:c:d:f:l:m:o:p:r:s:t:")) != opteof)
diff --git a/src/chpst.ninja b/src/chpst.ninja
@@ -2,6 +2,8 @@ PROJECT = chpst
SRC = ./src/
DST = ./build/$PROJECT/src/
+CCFLAGS = $CCFLAGS -D_DEFAULT_SOURCE
+
build $DST/$PROJECT.c.o: cc $SRC/$PROJECT.c
build $DST/../$PROJECT: ld $
diff --git a/src/fmt_ptime.c b/src/fmt_ptime.c
@@ -2,7 +2,7 @@
#include "fmt_ptime.h"
#include "fmt.h"
-unsigned int fmt_ptime2(char *s, struct taia *ta, char sep) {
+static unsigned int fmt_ptime2(char *s, struct taia *ta, char sep) {
struct tm *t;
time_t u;
diff --git a/src/iopause.c b/src/iopause.c
@@ -4,6 +4,8 @@
#include <sys/select.h>
#include <poll.h>
+#include "iopause.h"
+
void iopause(struct pollfd *x,unsigned int len,struct taia *deadline,struct taia *stamp)
{
struct taia t;
diff --git a/src/iopause.h b/src/iopause.h
@@ -0,0 +1,9 @@
+#ifndef IOPAUSE_H
+#define IOPAUSE_H
+
+struct pollfd;
+struct taia;
+
+void iopause(struct pollfd *x,unsigned int len,struct taia *deadline,struct taia *stamp);
+
+#endif
diff --git a/src/pmatch.c b/src/pmatch.c
@@ -1,21 +1,22 @@
+#include "pmatch.h"
-int pmatch(const char *p, const char *s, unsigned int len) {
+bool pmatch(const char* p, const char* s, unsigned int len) {
for (;;) {
char c =*p++;
if (! c) return(! len);
switch(c) {
case '*':
- if (! (c =*p)) return(1);
+ if (! (c =*p)) return true;
for (;;) {
- if (! len) return(0);
+ if (! len) return false;
if (*s == c) break;
++s; --len;
}
continue;
case '+':
- if ((c =*p++) != *s) return(0);
+ if ((c =*p++) != *s) return false;
for (;;) {
- if (! len) return(1);
+ if (! len) return true;
if (*s != c) break;
++s; --len;
}
@@ -23,18 +24,18 @@ int pmatch(const char *p, const char *s, unsigned int len) {
/*
case '?':
if (*p == '?') {
- if (*s != '?') return(0);
+ if (*s != '?') return false;
++p;
}
++s; --len;
continue;
*/
default:
- if (! len) return(0);
- if (*s != c) return(0);
+ if (! len) return false;
+ if (*s != c) return false;
++s; --len;
continue;
}
}
- return(0);
+ return false;
}
diff --git a/src/pmatch.h b/src/pmatch.h
@@ -1,6 +1,8 @@
#ifndef PMATCH_H
#define PMATCH_H
-extern unsigned int pmatch(const char *, const char *, unsigned int);
+#include <stdbool.h>
+
+extern bool pmatch(const char* p, const char* s, unsigned int len );
#endif
diff --git a/src/runit-init.c b/src/runit-init.c
@@ -15,9 +15,9 @@
static const char *progname;
-void usage(void) { strerr_die4x(0, "usage: ", progname, USAGE, "\n"); }
+static void usage(void) { strerr_die4x(0, "usage: ", progname, USAGE, "\n"); }
-void runit_halt () {
+static void runit_halt () {
if (open_trunc(STOPIT) == -1)
strerr_die4sys(111, FATAL, "unable to create ", STOPIT, ": ");
if (chmod(STOPIT, 0100) == -1)
@@ -29,7 +29,7 @@ void runit_halt () {
_exit(0);
}
-void runit_reboot () {
+static void runit_reboot () {
if (open_trunc(STOPIT) == -1)
strerr_die4sys(111, FATAL, "unable to create ", STOPIT, ": ");
if (chmod(STOPIT, 0100) == -1)
@@ -52,7 +52,7 @@ int main (int argc, const char * const *argv, char * const *envp) {
prog[0] ="runit";
/* kernel is starting init, runit does the job. */
- execve(RUNIT, (char *const *)prog, envp);
+ execve(RUNIT, (char const *const *)prog, envp);
/* serious error */
strerr_die4sys(111, FATAL, "unable to start ", prog[0], ": ");
diff --git a/src/runit.c b/src/runit.c
@@ -31,17 +31,20 @@ static int selfpipe[2];
static int sigc =0;
static int sigi =0;
-void sig_cont_handler (void) {
+static void sig_cont_handler( int s )
+{
sigc++;
write(selfpipe[1], "", 1);
}
-void sig_int_handler (void) {
+static void sig_int_handler( int s )
+{
sigi++;
write(selfpipe[1], "", 1);
}
-void sig_child_handler (void) { write(selfpipe[1], "", 1); }
+static void sig_child_handler( int s ) { write(selfpipe[1], "", 1); }
-int main (int argc, const char * const *argv, char * const *envp) {
+int main (int argc, const char * const *argv, char * const *envp)
+{
const char * prog[2];
int pid, pid2;
int wstat;
@@ -128,7 +131,7 @@ int main (int argc, const char * const *argv, char * const *envp) {
sig_unblock(sig_term);
strerr_warn3(INFO, "enter stage: ", stage[st], 0);
- execve(*prog, (char *const *)prog, envp);
+ execve(*prog, (char const *const *)prog, envp);
strerr_die4sys(0, FATAL, "unable to start child: ", stage[st], ": ");
}
@@ -216,7 +219,7 @@ int main (int argc, const char * const *argv, char * const *envp) {
if (!pid2) {
/* child */
strerr_warn3(INFO, "enter stage: ", prog[0], 0);
- execve(*prog, (char *const *) prog, envp);
+ execve(*prog, (char const *const *) prog, envp);
strerr_die4sys(0, FATAL, "unable to start child: ", prog[0], ": ");
}
if (wait_pid(&wstat, pid2) == -1)
diff --git a/src/runsv.c b/src/runsv.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <signal.h>
#include <poll.h>
+#include "iopause.h"
#include "strerr.h"
#include "error.h"
#include "taia.h"
@@ -59,36 +60,44 @@ static int pidchanged =1;
static int logpipe[2];
static char *dir;
-void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+static void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-void fatal(char *m) {
+static void fatal(char *m)
+{
strerr_die5sys(111, "runsv ", dir, ": fatal: ", m, ": ");
}
-void fatal2(char *m1, char *m2) {
+static void fatal2(char *m1, char *m2)
+{
strerr_die6sys(111, "runsv ", dir, ": fatal: ", m1, m2, ": ");
}
-void fatalx(char *m1, char *m2) {
+static void fatalx(char *m1, char *m2)
+{
strerr_die5x(111, "runsv ", dir, ": fatal: ", m1, m2);
}
-void warn(char *m) {
+static void warn(char *m)
+{
strerr_warn5("runsv ", dir, ": warning: ", m, ": ", &strerr_sys);
}
-void warn2(char *m1, char *m2) {
+static void warn2(char *m1, char *m2)
+{
strerr_warn6("runsv ", dir, ": warning: ", m1, m2, ": ", &strerr_sys);
}
-void warnx(char *m1, char *m2, char *m3) {
+static void warnx(char *m1, char *m2, char *m3)
+{
strerr_warn6("runsv ", dir, ": warning: ", m1, m2, m3, 0);
}
-void stopservice(struct svdir *);
+static void stopservice(struct svdir *);
-void s_child() { write(selfpipe[1], "", 1); }
-void s_term() {
+static void s_child() { write(selfpipe[1], "", 1); }
+static void s_term()
+{
sigterm =1;
write(selfpipe[1], "", 1); /* XXX */
}
-void update_status(struct svdir *s) {
+static void update_status(struct svdir *s)
+{
unsigned long l;
int fd;
char status[20];
@@ -204,7 +213,8 @@ void update_status(struct svdir *s) {
if (rename(fstatusnew, fstatus) == -1)
warn2("unable to rename status.new to ", fstatus);
}
-unsigned int custom(struct svdir *s, char c) {
+static unsigned int custom(struct svdir *s, char c)
+{
int pid;
int w;
char a[10];
@@ -242,7 +252,8 @@ unsigned int custom(struct svdir *s, char c) {
}
return(0);
}
-void stopservice(struct svdir *s) {
+static void stopservice(struct svdir *s)
+{
if (s->pid && ! custom(s, 't')) {
kill(s->pid, SIGTERM);
s->ctrl |=C_TERM;
@@ -258,7 +269,8 @@ void stopservice(struct svdir *s) {
}
}
-void startservice(struct svdir *s) {
+static void startservice(struct svdir *s)
+{
int p;
char *run[4];
char code[FMT_ULONG];
@@ -318,7 +330,8 @@ void startservice(struct svdir *s) {
s->ctrl =C_NOOP;
update_status(s);
}
-int ctrl(struct svdir *s, char c) {
+static int ctrl(struct svdir *s, char c)
+{
switch(c) {
case 'd': /* down */
s->want =W_DOWN;
diff --git a/src/runsvchdir.c b/src/runsvchdir.c
@@ -12,19 +12,23 @@
static char *progname;
static char *new;
-void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+static void usage( void ) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-void fatal(char *m1, char *m2) {
+static void fatal(char *m1, char *m2)
+{
strerr_die5sys(111, progname, ": fatal: ", m1, m2, ": ");
}
-void fatalx(char *m1, char *m2) {
+static void fatalx(char *m1, char *m2)
+{
strerr_die4x(111, progname, ": fatal: ", m1, m2);
}
-void warn(char *m1, char *m2) {
+static void warn(char *m1, char *m2)
+{
strerr_warn5(progname, ": fatal: ", m1, m2, ": ", &strerr_sys);
}
-int main (int argc, char **argv) {
+int main (int argc, char **argv)
+{
struct stat s;
int dev;
int ino;
diff --git a/src/runsvdir.c b/src/runsvdir.c
@@ -6,6 +6,7 @@
#include <dirent.h>
#include <poll.h>
#include <stdint.h>
+#include "iopause.h"
#include "strerr.h"
#include "error.h"
#include "wait.h"
@@ -44,20 +45,21 @@ static struct taia stamplog;
static int exitsoon =0;
static int pgrp =0;
-void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-void fatal(char *m1, char *m2) {
+static void usage ( void ) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+static void fatal(char *m1, char *m2) {
strerr_die6sys(100, "runsvdir ", svdir, ": fatal: ", m1, m2, ": ");
}
-void warn(char *m1, char *m2) {
+static void warn(char *m1, char *m2) {
strerr_warn6("runsvdir ", svdir, ": warning: ", m1, m2, ": ", &strerr_sys);
}
-void warn3x(char *m1, char *m2, char *m3) {
+static void warn3x(char *m1, char *m2, char *m3) {
strerr_warn6("runsvdir ", svdir, ": warning: ", m1, m2, m3, 0);
}
-void s_term() { exitsoon =1; }
-void s_hangup() { exitsoon =2; }
+static void s_term() { exitsoon =1; }
+static void s_hangup() { exitsoon =2; }
-void runsv(int no, char *name) {
+static void runsv(int no, char *name)
+{
int pid;
if ((pid =fork()) == -1) {
@@ -80,7 +82,8 @@ void runsv(int no, char *name) {
sv[no].pid =pid;
}
-void runsvdir() {
+static void runsvdir( void )
+{
DIR *dir;
struct dirent *d;
int i;
@@ -139,7 +142,8 @@ void runsvdir() {
}
}
-int setup_log() {
+static int setup_log( void )
+{
if ((rploglen =str_len(rplog)) < 7) {
warn3x("log must have at least seven characters.", 0, 0);
return(0);
@@ -162,7 +166,8 @@ int setup_log() {
return(1);
}
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
struct stat s;
time_t mtime =0;
int wstat;
diff --git a/src/sig.c b/src/sig.c
@@ -12,5 +12,5 @@ const int sig_kill = SIGKILL;
const int sig_pipe = SIGPIPE;
const int sig_term = SIGTERM;
-void (*sig_defaulthandler)() = SIG_DFL;
-void (*sig_ignorehandler)() = SIG_IGN;
+void (*sig_defaulthandler)(int) = SIG_DFL;
+void (*sig_ignorehandler)(int) = SIG_IGN;
diff --git a/src/sig.h b/src/sig.h
@@ -12,10 +12,9 @@ extern const int sig_kill;
extern const int sig_pipe;
extern const int sig_term;
-extern void (*sig_defaulthandler)();
-extern void (*sig_ignorehandler)();
-
-extern void sig_catch(int,void (*)());
+extern void (*sig_defaulthandler)(int);
+extern void (*sig_ignorehandler)(int);
+extern void sig_catch(int,void (*)(int));
#define sig_ignore(s) (sig_catch((s),sig_ignorehandler))
#define sig_uncatch(s) (sig_catch((s),sig_defaulthandler))
diff --git a/src/sig_catch.c b/src/sig_catch.c
@@ -3,7 +3,7 @@
#include <signal.h>
#include "sig.h"
-void sig_catch(int sig,void (*f)())
+void sig_catch(int sig,void (*f)(int))
{
struct sigaction sa;
sa.sa_handler = f;
diff --git a/src/sv.c b/src/sv.c
@@ -50,20 +50,24 @@ static int curdir, fd, r;
static char svstatus[20];
static char sulong[FMT_ULONG];
-void usage() {
+static void usage()
+{
if (!lsb) strerr_die4x(100, "usage: ", progname, USAGE, "\n");
strerr_die4x(2, "usage: ", progname, USAGELSB, "\n");
}
-void done(unsigned int e) { if (curdir != -1) fchdir(curdir); _exit(e); }
-void fatal(char *m1) {
+static void done(unsigned int e) { if (curdir != -1) fchdir(curdir); _exit(e); }
+static void fatal(char *m1)
+{
strerr_warn3(FATAL, m1, ": ", &strerr_sys);
done(lsb ? 151 : 100);
}
-void fatal2(char *m1, char *m2) {
+static void fatal2(char *m1, char *m2)
+{
strerr_warn4(FATAL, m1, m2, ": ", &strerr_sys);
done(lsb ? 151 : 100);
}
-void out(char *p, char *m1) {
+static void out(char *p, char *m1)
+{
buffer_puts(buffer_1, p);
buffer_puts(buffer_1, *service);
if (islog) buffer_puts(buffer_1, "/log");
@@ -76,18 +80,19 @@ void out(char *p, char *m1) {
buffer_puts(buffer_1, "\n");
buffer_flush(buffer_1);
}
-void fail(char *m1) { ++rc; out(FAIL, m1); }
-void failx(char *m1) { errno =0; fail(m1); }
-void warn(char *m1) { ++rc; out(WARN, m1); }
-void warnx(char *m1) { errno =0; warn(m1); }
-void ok(char *m1) { errno =0; out(OK, m1); }
+static void fail(char *m1) { ++rc; out(FAIL, m1); }
+static void failx(char *m1) { errno =0; fail(m1); }
+static void warn(char *m1) { ++rc; out(WARN, m1); }
+static void warnx(char *m1) { errno =0; warn(m1); }
+static void ok(char *m1) { errno =0; out(OK, m1); }
-void outs(const char *s) { buffer_puts(buffer_1, s); }
-void flush(const char *s) { outs(s); buffer_flush(buffer_1); }
-void outs2(const char *s) { buffer_puts(buffer_2, s); }
-void flush2(const char *s) { outs2(s); buffer_flush(buffer_2); }
+static void outs(const char *s) { buffer_puts(buffer_1, s); }
+static void flush(const char *s) { outs(s); buffer_flush(buffer_1); }
+static void outs2(const char *s) { buffer_puts(buffer_2, s); }
+static void flush2(const char *s) { outs2(s); buffer_flush(buffer_2); }
-int svstatus_get() {
+static int svstatus_get()
+{
if ((fd =open_write("supervise/ok")) == -1) {
if (errno == error_nodevice) {
*acts == 'x' ? ok("runsv not running") : failx("runsv not running");
@@ -110,7 +115,7 @@ int svstatus_get() {
}
return(1);
}
-unsigned int svstatus_print(char *m) {
+static unsigned int svstatus_print(char *m) {
int pid;
int normallyup =0;
struct stat s;
@@ -149,7 +154,8 @@ unsigned int svstatus_print(char *m) {
if (pid && svstatus[18]) outs(", got TERM");
return(pid ? 1 : 2);
}
-int status(char *unused) {
+static int status(char *unused)
+{
int rc;
rc =svstatus_get();
@@ -173,7 +179,8 @@ int status(char *unused) {
return(rc);
}
-int checkscript() {
+static int checkscript()
+{
char *prog[2];
struct stat s;
int pid, w;
@@ -208,7 +215,8 @@ int checkscript() {
return(!wait_exitcode(w));
}
-int check(char *a) {
+static int check(char *a)
+{
unsigned int pid;
if ((r =svstatus_get()) == -1) return(-1);
@@ -246,7 +254,8 @@ int check(char *a) {
outs(OK); svstatus_print(*service); flush("\n");
return(1);
}
-int control(char *a) {
+static int control(char *a)
+{
if (svstatus_get() <= 0) return(-1);
if (svstatus[17] == *a)
if (*a != 'd' || svstatus[18] == 1) return(0); /* once w/o term */
@@ -266,7 +275,8 @@ int control(char *a) {
return(1);
}
-int main(int argc, char **argv) {
+int main(int argc, char **argv)
+{
unsigned int i, done;
char *x;
diff --git a/src/sv.ninja b/src/sv.ninja
@@ -2,6 +2,8 @@ PROJECT = sv
SRC = ./src/
DST = ./build/$PROJECT/src/
+CCFLAGS = $CCFLAGS -D_DEFAULT_SOURCE
+
build $DST/$PROJECT.c.o: cc $SRC/$PROJECT.c
build $DST/../$PROJECT: ld $
diff --git a/src/svlogd.c b/src/svlogd.c
@@ -11,6 +11,7 @@
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
+#include "iopause.h"
#include "pmatch.h"
#include "fmt_ptime.h"
#include "alloc.h"
@@ -98,26 +99,30 @@ static struct logdir {
} *dir;
static unsigned int dirn =0;
-void usage() { strerr_die4x(111, "usage: ", progname, USAGE, "\n"); }
-void die_nomem() { strerr_die2x(111, FATAL, "out of memory."); }
-void fatal(char *m0) { strerr_die3sys(111, FATAL, m0, ": "); }
-void fatalx(char *m0) { strerr_die2x(111, FATAL, m0); }
-void fatal2(char *m0, char *m1) {
+static void usage() { strerr_die4x(111, "usage: ", progname, USAGE, "\n"); }
+static void die_nomem() { strerr_die2x(111, FATAL, "out of memory."); }
+static void fatal(char *m0) { strerr_die3sys(111, FATAL, m0, ": "); }
+static void fatalx(char *m0) { strerr_die2x(111, FATAL, m0); }
+static void fatal2(char *m0, char *m1)
+{
strerr_die5sys(111, FATAL, m0, ": ", m1, ": ");
}
-void warn(char *m0) { strerr_warn3(WARNING, m0, ": ", &strerr_sys); }
-void warn2(char *m0, char *m1) {
+static void warn(char *m0) { strerr_warn3(WARNING, m0, ": ", &strerr_sys); }
+static void warn2(char *m0, char *m1)
+{
strerr_warn5(WARNING, m0, ": ", m1, ": ", &strerr_sys);
}
-void warnx(char *m0, char *m1) { strerr_warn4(WARNING, m0, ": ", m1, 0); }
-void pause_nomem() { strerr_warn2(PAUSE, "out of memory.", 0); sleep(3); }
-void pause1(char *m0) { strerr_warn3(PAUSE, m0, ": ", &strerr_sys); sleep(3); }
-void pause2(char *m0, char *m1) {
+static void warnx(char *m0, char *m1) { strerr_warn4(WARNING, m0, ": ", m1, 0); }
+static void pause_nomem() { strerr_warn2(PAUSE, "out of memory.", 0); sleep(3); }
+static void pause1(char *m0) { strerr_warn3(PAUSE, m0, ": ", &strerr_sys); sleep(3); }
+static void pause2(char *m0, char *m1)
+{
strerr_warn5(PAUSE, m0, ": ", m1, ": ", &strerr_sys);
sleep(3);
}
-unsigned int processorstart(struct logdir *ld) {
+static unsigned int processorstart(struct logdir *ld)
+{
int pid;
if (! ld->processor.len) return(0);
@@ -178,7 +183,8 @@ unsigned int processorstart(struct logdir *ld) {
ld->ppid =pid;
return(1);
}
-unsigned int processorstop(struct logdir *ld) {
+static unsigned int processorstop(struct logdir *ld)
+{
char f[28];
if (ld->ppid) {
@@ -219,7 +225,8 @@ unsigned int processorstop(struct logdir *ld) {
return(1);
}
-void rmoldest(struct logdir *ld) {
+static void rmoldest(struct logdir *ld)
+{
DIR *d;
struct dirent *f;
char oldest[FMT_PTIME];
@@ -251,7 +258,8 @@ void rmoldest(struct logdir *ld) {
}
}
-unsigned int rotate(struct logdir *ld) {
+static unsigned int rotate(struct logdir *ld)
+{
char tmp[FMT_ULONG +1];
if (ld->fddir == -1) { ld->tmax =0; return(0); }
@@ -308,7 +316,8 @@ unsigned int rotate(struct logdir *ld) {
return(1);
}
-int buffer_pwrite(int n, char *s, unsigned int len) {
+static int buffer_pwrite(int n, char const *s, unsigned int len)
+{
int i;
if ((dir +n)->sizemax) {
@@ -364,7 +373,8 @@ int buffer_pwrite(int n, char *s, unsigned int len) {
return(i);
}
-void logdir_close(struct logdir *ld) {
+static void logdir_close(struct logdir *ld)
+{
if (ld->fddir == -1) return;
if (verbose) strerr_warn3(INFO, "close: ", ld->name, 0);
close(ld->fddir);
@@ -384,7 +394,7 @@ void logdir_close(struct logdir *ld) {
}
/* taken from libdjbdns */
-unsigned int ip4_scan(const char *s,char ip[4])
+static unsigned int ip4_scan(const char *s,char ip[4])
{
unsigned int i;
unsigned int len;
@@ -401,23 +411,24 @@ unsigned int ip4_scan(const char *s,char ip[4])
return len;
}
-unsigned int logdir_open(struct logdir *ld, const char *fn) {
+static unsigned int logdir_open(struct logdir *ld, const char *fn)
+{
int i;
if ((ld->fddir =open_read(fn)) == -1) {
- warn2("unable to open log directory", (char*)fn);
+ warn2("unable to open log directory", (char const*)fn);
return(0);
}
coe(ld->fddir);
if (fchdir(ld->fddir) == -1) {
logdir_close(ld);
- warn2("unable to change directory", (char*)fn);
+ warn2("unable to change directory", (char const*)fn);
return(0);
}
ld->fdlock =open_append("lock");
if ((ld->fdlock == -1) || (lock_exnb(ld->fdlock) == -1)) {
logdir_close(ld);
- warn2("unable to lock directory", (char*)fn);
+ warn2("unable to lock directory", (char const*)fn);
while (fchdir(fdwdir) == -1)
pause1("unable to change to initial working directory");
return(0);
@@ -428,7 +439,7 @@ unsigned int logdir_open(struct logdir *ld, const char *fn) {
ld->sizemax =1000000;
ld->nmax =ld->nmin =10;
ld->tmax =0;
- ld->name =(char*)fn;
+ ld->name =(char const*)fn;
ld->ppid =0;
ld->match ='+';
ld->udpaddr.sin_family =AF_INET;
@@ -563,7 +574,8 @@ unsigned int logdir_open(struct logdir *ld, const char *fn) {
return(1);
}
-void logdirs_reopen(void) {
+static void logdirs_reopen(void)
+{
int l;
int ok =0;
@@ -576,7 +588,8 @@ void logdirs_reopen(void) {
if (! ok) fatalx("no functional log directories.");
}
-int buffer_pread(int fd, char *s, unsigned int len) {
+static int buffer_pread(int fd, char const*s, unsigned int len)
+{
int i;
for (i =0; i < dirn; ++i) buffer_flush(&dir[i].b);
@@ -617,11 +630,13 @@ int buffer_pread(int fd, char *s, unsigned int len) {
if (i > 0) linecomplete =(s[i -1] == '\n');
return(i);
}
-void sig_term_handler(void) {
+static void sig_term_handler( int s )
+{
if (verbose) strerr_warn2(INFO, "sigterm received.", 0);
exitasap =1;
}
-void sig_child_handler(void) {
+static void sig_child_handler( int s )
+{
int pid, l;
if (verbose) strerr_warn2(INFO, "sigchild received.", 0);
@@ -633,16 +648,19 @@ void sig_child_handler(void) {
break;
}
}
-void sig_alarm_handler(void) {
+static void sig_alarm_handler( int s )
+{
if (verbose) strerr_warn2(INFO, "sigalarm received.", 0);
rotateasap =1;
}
-void sig_hangup_handler(void) {
+static void sig_hangup_handler( int s )
+{
if (verbose) strerr_warn2(INFO, "sighangup received.", 0);
reopenasap =1;
}
-void logmatch(struct logdir *ld) {
+static void logmatch(struct logdir *ld)
+{
int i;
ld->match ='+';
@@ -663,7 +681,8 @@ void logmatch(struct logdir *ld) {
i +=byte_chr(&ld->inst.s[i], ld->inst.len -i, 0);
}
}
-int main(int argc, const char **argv) {
+int main(int argc, const char **argv)
+{
int i;
int opt;
diff --git a/src/uidgid.c b/src/uidgid.c
@@ -5,6 +5,8 @@
#include "str.h"
#include "scan.h"
+static unsigned int uidgids_set(struct uidgid *u, char *ug);
+
/* user */
unsigned int uidgid_get(struct uidgid *u, char *ug) {
struct passwd *pwd =0;
diff --git a/src/utmpset.c b/src/utmpset.c
@@ -19,9 +19,10 @@
static const char *progname;
-void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
+static void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
-int utmp_logout(const char *line) {
+static int utmp_logout(const char *line)
+{
int fd;
struct utmp ut;
time_t t;
@@ -49,7 +50,8 @@ int utmp_logout(const char *line) {
close(fd);
return(ok);
}
-int wtmp_logout(const char *line) {
+static int wtmp_logout(const char *line)
+{
int fd;
int len;
struct stat st;
@@ -85,7 +87,8 @@ int wtmp_logout(const char *line) {
return(1);
}
-int main (int argc, const char * const *argv, const char * const *envp) {
+int main (int argc, const char * const *argv, const char * const *envp)
+{
int opt;
int wtmp =0;
diff --git a/src/wait.h b/src/wait.h
@@ -3,9 +3,7 @@
#ifndef WAIT_H
#define WAIT_H
-extern int wait_pid();
-extern int wait_stop();
-extern int wait_stopnohang();
+extern int wait_pid( int* wstat, int pid );
#define wait_crashed(w) ((w) & 127)
#define wait_exitcode(w) ((w) >> 8)
diff --git a/src/wait_pid.c b/src/wait_pid.c
@@ -3,8 +3,9 @@
#include <sys/types.h>
#include <sys/wait.h>
#include "error.h"
+#include "wait.h"
-int wait_pid(wstat,pid) int *wstat; int pid;
+int wait_pid( int* wstat, int pid )
{
int r;