fiss-minit

A standalone service supervisor based on minit
Log | Files | Refs | README | LICENSE

commit f8dd9a074545f4aebc2bf60ad86aff5e5c86fcee
parent a5ef2b53432ca28ec202b002088c93f94259362b
Author: Friedel Schön <[email protected]>
Date:   Sun, 12 May 2024 02:42:30 +0200

fixing missing dietlibc

Diffstat:
Mftrigger.c | 12++++++------
Mhard-reboot.c | 5+++--
Mminit.c | 4++--
Mopendevconsole.c | 2+-
Mpowersave.c | 2++
Mshutdown.c | 9+++++----
Mwaitport.c | 25+++++++++++++++----------
Awrite12.h | 6++++++
8 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/ftrigger.c b/ftrigger.c @@ -1,3 +1,4 @@ +#include <stdio.h> #include <sys/types.h> #include <unistd.h> #include <sys/stat.h> @@ -5,11 +6,10 @@ #include <sys/inotify.h> #include <stdlib.h> #include <string.h> -#include <buffer.h> #include <errno.h> -#include <sys/poll.h> +#include <poll.h> #include <sys/wait.h> -#include <sys/signal.h> +#include <signal.h> struct trigger { const char* filename,* command; @@ -76,7 +76,7 @@ int main(int argc,char* argv[]) { for (i=0; i<n; ++i) { root[i].idf=-1; if (stat(root[i].filename,&root[i].ss)!=0) - buffer_putmflush(buffer_2,"warning: could not stat file \"",root[i].filename,"\": ",strerror(errno),"\n"); + fprintf(stderr, "warning: could not stat file \"%s\": %s\n", root[i].filename, strerror(errno)); else root[i].idf=inotify_add_watch(in,root[i].filename, IN_CLOSE_WRITE|IN_MOVE_SELF|IN_DELETE_SELF|IN_MODIFY); @@ -113,7 +113,7 @@ again: case 1: break; }; if (read(in,buf,sizeof(buf)) < (ssize_t)sizeof(*ie)) { - buffer_putmflush(buffer_2,"error reading inotify notification: ",strerror(errno),"\n"); + fprintf(stderr, "error reading inotify notification: %s\n", strerror(errno)); exit(111); } @@ -213,7 +213,7 @@ goodevent: if (stat(root[i].filename,&ss)==0 && memcmp(&ss,&root[i].ss,sizeof(ss))) { memcpy(&root[i].ss,&ss,sizeof(ss)); if (v) - buffer_putmflush(buffer_1,"file \"",root[i].filename,"\" changed, running command \"",root[i].command,"\"\n"); + fprintf(stderr, "file \"%s\" changed, running command \"%s\"\n",root[i].filename,root[i].command); if (vfork()==0) { exit(system(root[i].command)); } diff --git a/hard-reboot.c b/hard-reboot.c @@ -3,13 +3,14 @@ #include <stdlib.h> #include <libowfat/str.h> +#include <string.h> #define ABORTMSG "hard-reboot: Aborted.\n" #define USAGE "Say \"hard-reboot (RESTART|HALT|POWER_OFF)\" if you really mean it.\n" void usage(void) { - write(2, ABORTMSG, str_len(ABORTMSG)); - write(2, USAGE, str_len(USAGE)); + write(2, ABORTMSG, strlen(ABORTMSG)); + write(2, USAGE, strlen(USAGE)); exit(1); } diff --git a/minit.c b/minit.c @@ -9,7 +9,7 @@ #include <errno.h> #include <sys/socket.h> #include <sys/un.h> -#include <sys/poll.h> +#include <poll.h> #include <signal.h> #include <sys/wait.h> #include <stdio.h> @@ -18,7 +18,7 @@ #include <stdlib.h> #include <alloca.h> #include <sys/reboot.h> -#include <write12.h> +#include "write12.h" #include <libowfat/fmt.h> #include <libowfat/str.h> diff --git a/opendevconsole.c b/opendevconsole.c @@ -1,6 +1,6 @@ #include <fcntl.h> #include <unistd.h> -#include <write12.h> +#include "write12.h" #include <stdlib.h> void opendevconsole() { diff --git a/powersave.c b/powersave.c @@ -6,6 +6,8 @@ #include <netinet/in.h> #include <sys/socket.h> #include <net/if.h> +#include <unistd.h> +#include <linux/sockios.h> #include <sys/ioctl.h> #include <libowfat/open.h> diff --git a/shutdown.c b/shutdown.c @@ -24,6 +24,7 @@ #include <fcntl.h> #include <stdarg.h> #include <stdio.h> +#include <string.h> #include <stdlib.h> #include <sys/wait.h> @@ -33,8 +34,8 @@ #include <write12.h> #else #include <unistd.h> -static inline int __write1(const char*s) { return write(1,s,str_len(s)); } -static inline int __write2(const char*s) { return write(2,s,str_len(s)); } +static inline int __write1(const char*s) { return write(1,s,strlen(s)); } +static inline int __write2(const char*s) { return write(2,s,strlen(s)); } #endif #define ALLOW_SUID @@ -104,7 +105,7 @@ int minit_serviceDown(char *service) { // get the pid buf[0]='p'; strncpy(buf+1, service, 1400); - write(infd, buf, str_len(buf)); + write(infd, buf, strlen(buf)); len=read(outfd, buf, 1500); if (len != 0) { buf[len]=0; @@ -117,7 +118,7 @@ int minit_serviceDown(char *service) { buf[0]='r'; // we want to disable respawning first strncpy(buf+1, service, 1400); buf[1400]=0; - write(infd, buf, str_len(buf)); + write(infd, buf, strlen(buf)); if (read(outfd, buf, 1500) < 1) __write2("\t(status read failed)"); i=kill(pid, SIGTERM); diff --git a/waitport.c b/waitport.c @@ -1,5 +1,7 @@ +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> #include <unistd.h> -#include <errmsg.h> #include <time.h> #include <string.h> #include <fcntl.h> @@ -36,14 +38,16 @@ static int netstat(const char* addr,unsigned int wantedport) { stralloc_zero(&line); if ((r=buffer_getline_sa(&b,&line))==-1) { close(fd); - die(1,"read error from ",filename); + fprintf(stderr,"read error from %s\n",filename); + exit(1); } if (r==0) break; if (line.len < 1 || line.s[line.len-1]!='\n') { parseerror: close(fd); - die(1,"parse error in ",filename); - } + fprintf(stderr,"parse error from %s\n",filename); + exit(1); + } line.s[line.len-1]=0; /* string is now null terminated */ /* First token is something like "917:", skip */ @@ -115,11 +119,10 @@ int main(int argc,char* argv[],char* envp[]) { char* s=argv[1]; char* t=strchr(s,'/'); - errmsg_iam("waitport"); if (argc<2) usage: - die(0,"usage: waitport ::/111 some.rpcd\n\twaits for a service to bind to TCP port 111 on ::, then executes the rest of the command line"); - + printf("usage: waitport ::/111 some.rpcd\n\twaits for a service to bind to TCP port 111 on ::, then executes the rest of the command line\n"); + exit(0); { if (t) { *t=0; @@ -135,11 +138,13 @@ usage: if (netstat(s,port)) { if (argv[2]) { execve(argv[2],argv+2,envp); - diesys(1,"execve"); - } + fprintf(stderr,"execve: %s\n",strerror(errno)); + exit(1); + } return 0; } nanosleep(&req,&rem); } - die(1,"service on port not showing up"); + fprintf(stderr,"service on port not showing up"); + exit(1); } diff --git a/write12.h b/write12.h @@ -0,0 +1,5 @@ +#pragma once + +#include <stdio.h> + +#define __write2(...) (fprintf(stderr, __VA_ARGS__)) +\ No newline at end of file