fiss-minit

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

commit 47ce17b4c1606cab6fc9f4eacffa101a81840029
parent 2d6ffecb8d234554e9008ed12ff6a53f4ae0f9cb
Author: leitner <leitner>
Date:   Mon, 26 Nov 2001 17:40:26 +0000

import more changes from libowfat

Diffstat:
MMakefile | 4++--
Mfmt.h | 2--
Mminit.c | 17+++++++++--------
Mmsvc.c | 12++++++------
Astr.h | 43+++++++++++++++++++++++++++++++++++++++++++
Astr_len.c | 12++++++++++++
6 files changed, 72 insertions(+), 18 deletions(-)

diff --git a/Makefile b/Makefile @@ -8,12 +8,12 @@ CROSS= #CROSS=arm-linux- LDFLAGS=-s -minit: minit.o split.o openreadclose.o fmt_ulong.o +minit: minit.o split.o openreadclose.o fmt_ulong.o str_len.o $(DIET) $(CROSS)$(CC) $(LDFLAGS) -o minit $^ msvc: msvc.o fmt_ulong.o buffer_1.o buffer_2.o buffer_puts.o \ buffer_putsflush.o buffer_putulong.o buffer_put.o byte_copy.o \ -buffer_flush.o buffer_stubborn.o buffer_putflush.o +buffer_flush.o buffer_stubborn.o buffer_putflush.o str_len.o $(DIET) $(CROSS)$(CC) $(LDFLAGS) -o msvc $^ %.o: %.c diff --git a/fmt.h b/fmt.h @@ -1,8 +1,6 @@ #ifndef FMT_H #define FMT_H -#include "str.h" - #define FMT_ULONG 40 /* enough space to hold 2^128 - 1 in decimal, plus \0 */ #define FMT_8LONG 44 /* enough space to hold 2^128 - 1 in octal, plus \0 */ #define FMT_XLONG 33 /* enough space to hold 2^128 - 1 in hexadecimal, plus \0 */ diff --git a/minit.c b/minit.c @@ -14,6 +14,7 @@ #include <linux/kd.h> #include <sys/ioctl.h> #include "fmt.h" +#include "str.h" #define MINITROOT "/etc/minit" @@ -103,7 +104,7 @@ int loadservice(char *service) { tmp.circular=0; tmp.__stdin=0; tmp.__stdout=1; { - char *logservice=alloca(strlen(service)+5); + char *logservice=alloca(str_len(service)+5); strcpy(logservice,service); strcat(logservice,"/log"); tmp.logservice=loadservice(logservice); @@ -131,7 +132,7 @@ void handlekilled(pid_t killed) { { char buf[50]; snprintf(buf,50," %d\n",killed); - write(2,buf,strlen(buf)); + write(2,buf,str_len(buf)); } #endif if (killed == (pid_t)-1) { @@ -270,7 +271,7 @@ int startservice(int service,int pause) { if (service<0) return 0; #if 0 write(1,"startservice ",13); - write(1,root[service].name,strlen(root[service].name)); + write(1,root[service].name,str_len(root[service].name)); write(1,"\n",1); #endif if (root[service].circular) @@ -292,12 +293,12 @@ int startservice(int service,int pause) { #if 0 write(1,"started service ",17); - write(1,root[service].name,strlen(root[service].name)); + write(1,root[service].name,str_len(root[service].name)); write(1," -> ",4); { char buf[10]; snprintf(buf,10,"%d\n",pid); - write(1,buf,strlen(buf)); + write(1,buf,str_len(buf)); } #endif close(dir); @@ -314,7 +315,7 @@ void sulogin() { /* exiting on an initialization failure is not a good idea for } static void _puts(const char* s) { - write(1,s,strlen(s)); + write(1,s,str_len(s)); } void childhandler() { @@ -436,7 +437,7 @@ main(int argc, char *argv[]) { int idx,tmp; buf[i]=0; -/* write(1,buf,strlen(buf)); write(1,"\n",1); */ +/* write(1,buf,str_len(buf)); write(1,"\n",1); */ if (buf[0]!='s' && ((idx=findservice(buf+1))<0)) error: write(outfd,"0",1); @@ -453,7 +454,7 @@ error: goto ok; case 'P': { - unsigned char *x=buf+strlen(buf)+1; + unsigned char *x=buf+str_len(buf)+1; unsigned char c; tmp=0; while ((c=*x++-'0')<10) tmp=tmp*10+c; diff --git a/msvc.c b/msvc.c @@ -15,7 +15,7 @@ pid_t __readpid(char *service) { int len; buf[0]='p'; strncpy(buf+1,service,1400); - write(infd,buf,strlen(buf)); + write(infd,buf,str_len(buf)); len=read(outfd,buf,1500); if (len<0) return 0; buf[len]=0; @@ -27,7 +27,7 @@ int respawn(char *service,int yesno) { int len; buf[0]=yesno?'R':'r'; strncpy(buf+1,service,1400); - write(infd,buf,strlen(buf)); + write(infd,buf,str_len(buf)); len=read(outfd,buf,1500); return (len!=1 || buf[0]=='0'); } @@ -38,9 +38,9 @@ int setpid(char *service, pid_t pid) { int len; buf[0]='P'; strncpy(buf+1,service,1400); - tmp=buf+strlen(buf)+1; + tmp=buf+str_len(buf)+1; tmp[fmt_ulong(tmp,pid)]=0; - write(infd,buf,strlen(buf)+strlen(tmp)+2); + write(infd,buf,str_len(buf)+str_len(tmp)+2); len=read(outfd,buf,1500); return (len!=1 || buf[0]=='0'); } @@ -50,7 +50,7 @@ int startservice(char *service) { int len; buf[0]='s'; strncpy(buf+1,service,1400); - write(infd,buf,strlen(buf)); + write(infd,buf,str_len(buf)); len=read(outfd,buf,1500); return (len!=1 || buf[0]=='0'); } @@ -60,7 +60,7 @@ unsigned long uptime(char *service) { int len; buf[0]='u'; strncpy(buf+1,service,1400); - write(infd,buf,strlen(buf)); + write(infd,buf,str_len(buf)); len=read(outfd,buf,1500); if (len<0) return 0; buf[len]=0; diff --git a/str.h b/str.h @@ -0,0 +1,43 @@ +#ifndef STR_H +#define STR_H + +#include <sys/cdefs.h> +#ifndef __pure__ +#define __pure__ +#endif + +/* str_copy copies leading bytes from in to out until \0. + * return number of copied bytes. */ +extern unsigned int str_copy(char *out,const char *in); + +/* str_diff returns negative, 0, or positive, depending on whether the + * string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than, + * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'. + * If the strings are different, str_diff does not read bytes past the + * first difference. */ +extern int str_diff(const char *a,const char *b) __pure__; + +/* str_diffn returns negative, 0, or positive, depending on whether the + * string a[0], a[1], ..., a[n]=='\0' is lexicographically smaller than, + * equal to, or greater than the string b[0], b[1], ..., b[m-1]=='\0'. + * If the strings are different, str_diffn does not read bytes past the + * first difference. The strings will be considered equal if the first + * limit characters match. */ +extern int str_diffn(const char *a,const char *b,unsigned int limit) __pure__; + +/* str_len returns the index of \0 in s */ +extern unsigned int str_len(const char *s) __pure__; + +/* str_chr returns the index of the first occurance of needle or \0 in haystack */ +extern unsigned int str_chr(const char *haystack,char needle) __pure__; + +/* str_rchr returns the index of the last occurance of needle or \0 in haystack */ +extern unsigned int str_rchr(const char *haystack,char needle) __pure__; + +/* str_start returns 1 if the b is a prefix of a, 0 otherwise */ +extern int str_start(const char *a,const char *b) __pure__; + +/* convenience shortcut to test for string equality */ +#define str_equal(s,t) (!str_diff((s),(t))) + +#endif diff --git a/str_len.c b/str_len.c @@ -0,0 +1,12 @@ +#include "str.h" + +unsigned int str_len(const char *in) { + register const char* t=in; + for (;;) { + if (!*t) break; ++t; + if (!*t) break; ++t; + if (!*t) break; ++t; + if (!*t) break; ++t; + } + return t-in; +}