runit

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit cc85452e8332ac01f79119d6e621008a0f3f1e60
parent baa458d8556e3ba64a60e46ba40774790ca3ed65
Author: Morel BĂ©renger <berengermorel76@gmail.com>
Date:   Mon, 30 Sep 2024 04:16:30 +0200

consider all targeted systems have C99 and POSIX 2008+ support

Diffstat:
Msrc/chpst.c | 5+++--
Msrc/fifo.c | 6------
Msrc/iopause.c | 52+++-------------------------------------------------
Msrc/lock_ex.c | 5-----
Msrc/lock_exnb.c | 5-----
Msrc/prot.c | 7-------
Msrc/runit.c | 30+++++++++---------------------
Msrc/runsv.c | 10+++++-----
Msrc/runsvdir.c | 17++++++++++-------
Msrc/sig_block.c | 13-------------
Msrc/sig_catch.c | 5-----
Msrc/sig_pause.c | 5-----
Msrc/svlogd.c | 14+++++++-------
Msrc/tai.h | 6+++---
Msrc/tai_pack.c | 2+-
Msrc/tai_unpack.c | 2+-
Msrc/utmpset.c | 28++++++++++++++--------------
Msrc/wait_nohang.c | 5-----
Msrc/wait_pid.c | 26--------------------------
19 files changed, 56 insertions(+), 187 deletions(-)

diff --git a/src/chpst.c b/src/chpst.c @@ -3,6 +3,8 @@ #include <sys/time.h> #include <sys/resource.h> #include <unistd.h> +#include <sys/types.h> +#include <dirent.h> #include "sgetopt.h" #include "error.h" #include "strerr.h" @@ -18,7 +20,6 @@ #include "byte.h" #include "open.h" #include "openreadclose.h" -#include "direntry.h" #define USAGE_MAIN " [-vP012] [-u user[:group]] [-U user[:group]] [-b argv0] [-e dir] [-/ root] [-C pwd] [-n nice] [-l|-L lock] [-m n] [-d n] [-o n] [-p n] [-f n] [-c n] prog" #define FATAL "chpst: fatal: " @@ -110,7 +111,7 @@ void euidgid(char *user, unsigned int ext) { void edir(const char *dirname) { int wdir; DIR *dir; - direntry *d; + struct dirent *d; int i; if ((wdir =open_read(".")) == -1) diff --git a/src/fifo.c b/src/fifo.c @@ -2,11 +2,5 @@ #include <sys/types.h> #include <sys/stat.h> -#include "hasmkffo.h" -#include "fifo.h" -#ifdef HASMKFIFO int fifo_make(const char *fn,int mode) { return mkfifo(fn,mode); } -#else -int fifo_make(const char *fn,int mode) { return mknod(fn,S_IFIFO | mode,0); } -#endif diff --git a/src/iopause.c b/src/iopause.c @@ -1,10 +1,10 @@ /* Public domain. */ #include "taia.h" -#include "select.h" -#include "iopause.h" +#include <sys/select.h> +#include <poll.h> -void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *stamp) +void iopause(struct pollfd *x,unsigned int len,struct taia *deadline,struct taia *stamp) { struct taia t; int millisecs; @@ -24,55 +24,9 @@ void iopause(iopause_fd *x,unsigned int len,struct taia *deadline,struct taia *s for (i = 0;i < len;++i) x[i].revents = 0; -#ifdef IOPAUSE_POLL - poll(x,len,millisecs); /* XXX: some kernels apparently need x[0] even if len is 0 */ /* XXX: how to handle EAGAIN? are kernels really this dumb? */ /* XXX: how to handle EINVAL? when exactly can this happen? */ -#else -{ - - struct timeval tv; - fd_set rfds; - fd_set wfds; - int nfds; - int fd; - - FD_ZERO(&rfds); - FD_ZERO(&wfds); - - nfds = 1; - for (i = 0;i < len;++i) { - fd = x[i].fd; - if (fd < 0) continue; - if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/ - - if (fd >= nfds) nfds = fd + 1; - if (x[i].events & IOPAUSE_READ) FD_SET(fd,&rfds); - if (x[i].events & IOPAUSE_WRITE) FD_SET(fd,&wfds); - } - - tv.tv_sec = millisecs / 1000; - tv.tv_usec = 1000 * (millisecs % 1000); - - if (select(nfds,&rfds,&wfds,(fd_set *) 0,&tv) <= 0) - return; - /* XXX: for EBADF, could seek out and destroy the bad descriptor */ - - for (i = 0;i < len;++i) { - fd = x[i].fd; - if (fd < 0) continue; - if (fd >= 8 * sizeof(fd_set)) continue; /*XXX*/ - - if (x[i].events & IOPAUSE_READ) - if (FD_ISSET(fd,&rfds)) x[i].revents |= IOPAUSE_READ; - if (x[i].events & IOPAUSE_WRITE) - if (FD_ISSET(fd,&wfds)) x[i].revents |= IOPAUSE_WRITE; - } - -} -#endif - } diff --git a/src/lock_ex.c b/src/lock_ex.c @@ -3,11 +3,6 @@ #include <sys/types.h> #include <sys/file.h> #include <fcntl.h> -#include "hasflock.h" #include "lock.h" -#ifdef HASFLOCK int lock_ex(int fd) { return flock(fd,LOCK_EX); } -#else -int lock_ex(int fd) { return lockf(fd,1,0); } -#endif diff --git a/src/lock_exnb.c b/src/lock_exnb.c @@ -3,11 +3,6 @@ #include <sys/types.h> #include <sys/file.h> #include <fcntl.h> -#include "hasflock.h" #include "lock.h" -#ifdef HASFLOCK int lock_exnb(int fd) { return flock(fd,LOCK_EX | LOCK_NB); } -#else -int lock_exnb(int fd) { return lockf(fd,2,0); } -#endif diff --git a/src/prot.c b/src/prot.c @@ -1,6 +1,5 @@ /* Public domain. */ -#include "hasshsgr.h" #include "prot.h" #include <sys/types.h> @@ -9,13 +8,7 @@ int prot_gid(gid_t gid) { -#ifdef HASSHORTSETGROUPS - short x[2]; - x[0] = gid; x[1] = 73; /* catch errors */ - if (setgroups(1,x) == -1) return -1; -#else if (setgroups(1,&gid) == -1) return -1; -#endif return setgid(gid); /* _should_ be redundant, but on some systems it isn't */ } diff --git a/src/runit.c b/src/runit.c @@ -5,16 +5,15 @@ #include <signal.h> #include <unistd.h> #include <fcntl.h> +#include <poll.h> #include "runit.h" #include "sig.h" #include "strerr.h" #include "error.h" -#include "iopause.h" #include "coe.h" #include "ndelay.h" #include "wait.h" #include "open.h" -#include "reboot_system.h" /* #define DEBUG */ @@ -48,11 +47,7 @@ int main (int argc, const char * const *argv, char * const *envp) { int pid, pid2; int wstat; int st; - iopause_fd x; -#ifndef IOPAUSE_POLL - fd_set rfds; - struct timeval t; -#endif + struct pollfd x; char ch; int ttyfd; struct stat s; @@ -89,7 +84,7 @@ int main (int argc, const char * const *argv, char * const *envp) { #ifdef RB_DISABLE_CAD /* activate ctrlaltdel handling, glibc, dietlibc */ - if (RB_DISABLE_CAD == 0) reboot_system(0); + if (RB_DISABLE_CAD == 0) reboot(0); #endif strerr_warn3(INFO, VERSION, ": booting.", 0); @@ -139,21 +134,14 @@ int main (int argc, const char * const *argv, char * const *envp) { } x.fd =selfpipe[0]; - x.events =IOPAUSE_READ; + x.events =POLLIN; for (;;) { int child; sig_unblock(sig_child); sig_unblock(sig_cont); sig_unblock(sig_int); -#ifdef IOPAUSE_POLL poll(&x, 1, 14000); -#else - t.tv_sec =14; t.tv_usec =0; - FD_ZERO(&rfds); - FD_SET(x.fd, &rfds); - select(x.fd +1, &rfds, (fd_set*)0, (fd_set*)0, &t); -#endif sig_block(sig_cont); sig_block(sig_child); sig_block(sig_int); @@ -307,28 +295,28 @@ int main (int argc, const char * const *argv, char * const *envp) { if ((stat(REBOOT, &s) != -1) && (s.st_mode & S_IXUSR)) { strerr_warn2(INFO, "system reboot.", 0); sync(); - reboot_system(RB_AUTOBOOT); + reboot(RB_AUTOBOOT); } else { #ifdef RB_POWER_OFF strerr_warn2(INFO, "power off...", 0); sync(); - reboot_system(RB_POWER_OFF); + reboot(RB_POWER_OFF); sleep(2); #endif #ifdef RB_HALT_SYSTEM strerr_warn2(INFO, "system halt.", 0); sync(); - reboot_system(RB_HALT_SYSTEM); + reboot(RB_HALT_SYSTEM); #else #ifdef RB_HALT strerr_warn2(INFO, "system halt.", 0); sync(); - reboot_system(RB_HALT); + reboot(RB_HALT); #else strerr_warn2(INFO, "system reboot.", 0); sync(); - reboot_system(RB_AUTOBOOT); + reboot(RB_AUTOBOOT); #endif #endif } diff --git a/src/runsv.c b/src/runsv.c @@ -3,6 +3,7 @@ #include <unistd.h> #include <stdio.h> #include <signal.h> +#include <poll.h> #include "strerr.h" #include "error.h" #include "taia.h" @@ -13,7 +14,6 @@ #include "fifo.h" #include "open.h" #include "lock.h" -#include "iopause.h" #include "wait.h" #include "fd.h" #include "buffer.h" @@ -515,7 +515,7 @@ int main(int argc, char **argv) { coe(fd); } for (;;) { - iopause_fd x[3]; + struct pollfd x[3]; struct taia deadline; struct taia now; char ch; @@ -527,12 +527,12 @@ int main(int argc, char **argv) { startservice(&svd[0]); x[0].fd =selfpipe[0]; - x[0].events =IOPAUSE_READ; + x[0].events =POLLIN; x[1].fd =svd[0].fdcontrol; - x[1].events =IOPAUSE_READ; + x[1].events =POLLIN; if (haslog) { x[2].fd =svd[1].fdcontrol; - x[2].events =IOPAUSE_READ; + x[2].events =POLLIN; } taia_now(&now); taia_uint(&deadline, 3600); diff --git a/src/runsvdir.c b/src/runsvdir.c @@ -2,7 +2,10 @@ #include <sys/stat.h> #include <unistd.h> #include <signal.h> -#include "direntry.h" +#include <sys/types.h> +#include <dirent.h> +#include <poll.h> +#include <stdint.h> #include "strerr.h" #include "error.h" #include "wait.h" @@ -12,9 +15,9 @@ #include "fd.h" #include "str.h" #include "coe.h" -#include "iopause.h" #include "sig.h" #include "ndelay.h" +#include "taia.h" #define USAGE " [-P] dir" #define VERSION "$Id$" @@ -36,7 +39,7 @@ int check =1; char *rplog =0; int rploglen; int logpipe[2]; -iopause_fd io[1]; +struct pollfd io[1]; struct taia stamplog; int exitsoon =0; int pgrp =0; @@ -79,7 +82,7 @@ void runsv(int no, char *name) { void runsvdir() { DIR *dir; - direntry *d; + struct dirent *d; int i; struct stat s; @@ -154,7 +157,7 @@ int setup_log() { return(-1); } io[0].fd =logpipe[0]; - io[0].events =IOPAUSE_READ; + io[0].events = POLLIN; taia_now(&stamplog); return(1); } @@ -233,7 +236,7 @@ int main(int argc, char **argv) { dev =s.st_dev; ino =s.st_ino; check =0; - if (now.sec.x <= (4611686018427387914ULL +(uint64)mtime)) + if (now.sec.x <= (4611686018427387914ULL +(uint64_t)mtime)) sleep(1); runsvdir(); while (fchdir(curdir) == -1) { @@ -265,7 +268,7 @@ int main(int argc, char **argv) { iopause(0, 0, &deadline, &now); sig_unblock(sig_child); - if (rplog && (io[0].revents | IOPAUSE_READ)) + if (rplog && (io[0].revents | POLLIN)) while (read(logpipe[0], &ch, 1) > 0) if (ch) { for (i =6; i < rploglen; i++) diff --git a/src/sig_block.c b/src/sig_block.c @@ -2,39 +2,26 @@ #include <signal.h> #include "sig.h" -#include "hassgprm.h" void sig_block(int sig) { -#ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigaddset(&ss,sig); sigprocmask(SIG_BLOCK,&ss,(sigset_t *) 0); -#else - sigblock(1 << (sig - 1)); -#endif } void sig_unblock(int sig) { -#ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigaddset(&ss,sig); sigprocmask(SIG_UNBLOCK,&ss,(sigset_t *) 0); -#else - sigsetmask(sigsetmask(~0) & ~(1 << (sig - 1))); -#endif } void sig_blocknone(void) { -#ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigprocmask(SIG_SETMASK,&ss,(sigset_t *) 0); -#else - sigsetmask(0); -#endif } diff --git a/src/sig_catch.c b/src/sig_catch.c @@ -2,17 +2,12 @@ #include <signal.h> #include "sig.h" -#include "hassgact.h" void sig_catch(int sig,void (*f)()) { -#ifdef HASSIGACTION struct sigaction sa; sa.sa_handler = f; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(sig,&sa,(struct sigaction *) 0); -#else - signal(sig,f); /* won't work under System V, even nowadays---dorks */ -#endif } diff --git a/src/sig_pause.c b/src/sig_pause.c @@ -2,15 +2,10 @@ #include <signal.h> #include "sig.h" -#include "hassgprm.h" void sig_pause(void) { -#ifdef HASSIGPROCMASK sigset_t ss; sigemptyset(&ss); sigsuspend(&ss); -#else - sigpause(0); -#endif } diff --git a/src/svlogd.c b/src/svlogd.c @@ -4,11 +4,13 @@ #include <sys/socket.h> #include <netinet/in.h> #include <time.h> +#include <poll.h> #include <sys/time.h> -#include <dirent.h> #include <unistd.h> #include <stdio.h> #include <string.h> +#include <sys/types.h> +#include <dirent.h> #include "pmatch.h" #include "fmt_ptime.h" #include "alloc.h" @@ -28,11 +30,9 @@ #include "str.h" #include "byte.h" #include "scan.h" -#include "direntry.h" #include "taia.h" #include "fmt.h" #include "ndelay.h" -#include "iopause.h" #define USAGE " [-ttv] [-r c] [-R abc] [-l len] [-b buflen] dir ..." #define VERSION "$Id$" @@ -71,7 +71,7 @@ unsigned int reopenasap =0; unsigned int linecomplete =1; unsigned int tmaxflag =0; int fdudp =-1; -iopause_fd in; +struct pollfd in; struct logdir { int fddir; @@ -221,7 +221,7 @@ unsigned int processorstop(struct logdir *ld) { void rmoldest(struct logdir *ld) { DIR *d; - direntry *f; + struct dirent *f; char oldest[FMT_PTIME]; int n =0; @@ -319,7 +319,7 @@ int buffer_pwrite(int n, char *s, unsigned int len) { while ((i =write((dir +n)->fdcur, s, len)) == -1) { if ((errno == ENOSPC) && ((dir +n)->nmin < (dir +n)->nmax)) { DIR *d; - direntry *f; + struct dirent *f; char oldest[FMT_PTIME]; int j =0; @@ -721,7 +721,7 @@ int main(int argc, const char **argv) { if (! line) die_nomem(); fndir =argv; in.fd =0; - in.events =IOPAUSE_READ; + in.events = POLLIN; ndelay_on(in.fd); sig_block(sig_term); diff --git a/src/tai.h b/src/tai.h @@ -3,13 +3,13 @@ #ifndef TAI_H #define TAI_H -#include "uint64.h" +#include <stdint.h> struct tai { - uint64 x; + uint64_t x; } ; -#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u))) +#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64_t) (u))) extern void tai_now(struct tai *); diff --git a/src/tai_pack.c b/src/tai_pack.c @@ -4,7 +4,7 @@ void tai_pack(char *s,const struct tai *t) { - uint64 x; + uint64_t x; x = t->x; s[7] = x & 255; x >>= 8; diff --git a/src/tai_unpack.c b/src/tai_unpack.c @@ -4,7 +4,7 @@ void tai_unpack(const char *s,struct tai *t) { - uint64 x; + uint64_t x; x = (unsigned char) s[0]; x <<= 8; x += (unsigned char) s[1]; diff --git a/src/utmpset.c b/src/utmpset.c @@ -4,7 +4,7 @@ #include <sys/stat.h> #include <unistd.h> #include <string.h> -#include "uw_tmp.h" +#include <utmp.h> #include "strerr.h" #include "sgetopt.h" #include "seek.h" @@ -25,16 +25,16 @@ void usage(void) { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } int utmp_logout(const char *line) { int fd; - uw_tmp ut; + struct utmp ut; time_t t; int ok =-1; - if ((fd =open(UW_TMP_UFILE, O_RDWR, 0)) < 0) - strerr_die4sys(111, FATAL, "unable to open ", UW_TMP_UFILE, ": "); + if ((fd =open(UTMP_FILE, O_RDWR, 0)) < 0) + strerr_die4sys(111, FATAL, "unable to open ", UTMP_FILE, ": "); if (lock_ex(fd) == -1) - strerr_die4sys(111, FATAL, "unable to lock: ", UW_TMP_UFILE, ": "); + strerr_die4sys(111, FATAL, "unable to lock: ", UTMP_FILE, ": "); - while (read(fd, &ut, sizeof(uw_tmp)) == sizeof(uw_tmp)) { + while (read(fd, &ut, sizeof(struct utmp)) == sizeof(struct utmp)) { if (!ut.ut_name[0] || (str_diff(ut.ut_line, line) != 0)) continue; memset(ut.ut_name, 0, sizeof ut.ut_name); memset(ut.ut_host, 0, sizeof ut.ut_host); @@ -43,8 +43,8 @@ int utmp_logout(const char *line) { #ifdef DEAD_PROCESS ut.ut_type =DEAD_PROCESS; #endif - if (lseek(fd, -(off_t)sizeof(uw_tmp), SEEK_CUR) == -1) break; - if (write(fd, &ut, sizeof(uw_tmp)) != sizeof(uw_tmp)) break; + if (lseek(fd, -(off_t)sizeof(struct utmp), SEEK_CUR) == -1) break; + if (write(fd, &ut, sizeof(struct utmp)) != sizeof(struct utmp)) break; ok =1; break; } @@ -55,19 +55,19 @@ int wtmp_logout(const char *line) { int fd; int len; struct stat st; - uw_tmp ut; + struct utmp ut; time_t t; - if ((fd = open_append(UW_TMP_WFILE)) == -1) - strerr_die4sys(111, FATAL, "unable to open ", UW_TMP_WFILE, ": "); + if ((fd = open_append(WTMP_FILE)) == -1) + strerr_die4sys(111, FATAL, "unable to open ", WTMP_FILE, ": "); if (lock_ex(fd) == -1) - strerr_die4sys(111, FATAL, "unable to lock ", UW_TMP_WFILE, ": "); + strerr_die4sys(111, FATAL, "unable to lock ", WTMP_FILE, ": "); if (fstat(fd, &st) == -1) { close(fd); return(-1); } - memset(&ut, 0, sizeof(uw_tmp)); + memset(&ut, 0, sizeof(struct utmp)); if ((len =str_len(line)) > sizeof ut.ut_line) len =sizeof ut.ut_line -2; byte_copy(ut.ut_line, len, line); if (time(&t) == -1) { @@ -78,7 +78,7 @@ int wtmp_logout(const char *line) { #ifdef DEAD_PROCESS ut.ut_type =DEAD_PROCESS; #endif - if (write(fd, &ut, sizeof(uw_tmp)) != sizeof(uw_tmp)) { + if (write(fd, &ut, sizeof(struct utmp)) != sizeof(struct utmp)) { ftruncate(fd, st.st_size); close(fd); return(-1); diff --git a/src/wait_nohang.c b/src/wait_nohang.c @@ -2,13 +2,8 @@ #include <sys/types.h> #include <sys/wait.h> -#include "haswaitp.h" int wait_nohang(wstat) int *wstat; { -#ifdef HASWAITPID return waitpid(-1,wstat,WNOHANG); -#else - return wait3(wstat,WNOHANG,(struct rusage *) 0); -#endif } diff --git a/src/wait_pid.c b/src/wait_pid.c @@ -3,9 +3,6 @@ #include <sys/types.h> #include <sys/wait.h> #include "error.h" -#include "haswaitp.h" - -#ifdef HASWAITPID int wait_pid(wstat,pid) int *wstat; int pid; { @@ -16,26 +13,3 @@ int wait_pid(wstat,pid) int *wstat; int pid; while ((r == -1) && (errno == error_intr)); return r; } - -#else - -/* XXX untested */ -/* XXX breaks down with more than two children */ -static int oldpid = 0; -static int oldwstat; /* defined if(oldpid) */ - -int wait_pid(wstat,pid) int *wstat; int pid; -{ - int r; - - if (pid == oldpid) { *wstat = oldwstat; oldpid = 0; return pid; } - - do { - r = wait(wstat); - if ((r != pid) && (r != -1)) { oldwstat = *wstat; oldpid = r; continue; } - } - while ((r == -1) && (errno == error_intr)); - return r; -} - -#endif