commit 1ce0bc1816d8106eb24325af8a418d9cdcbcabeb
parent 567631f57b416fdff2d195f23a9506e74cdf0185
Author: leitner <leitner>
Date: Thu, 24 Apr 2003 14:58:15 +0000
strip /etc/minit/ before service name
Diffstat:
4 files changed, 45 insertions(+), 17 deletions(-)
diff --git a/CHANGES b/CHANGES
@@ -11,6 +11,8 @@
this removes a race condition when the forked service terminates
before pidfilehack notifies minit of the PID
msvc now accepts more than one service after -o, -d, ...
+ msvc now accepts /etc/minit/sshd instead of sshd as service name
+ better error handling in msvc (more and better error messages)
0.8:
call waitpid repeatedly until it returns "no children".
diff --git a/Makefile b/Makefile
@@ -13,7 +13,8 @@ minit: minit.o split.o openreadclose.o fmt_ulong.o str_len.o
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 str_len.o
+buffer_flush.o buffer_stubborn.o buffer_putflush.o str_len.o \
+str_start.o
$(DIET) $(CROSS)$(CC) $(LDFLAGS) -o msvc $^
%.o: %.c
diff --git a/msvc.c b/msvc.c
@@ -3,6 +3,7 @@
#include <signal.h>
#include <stdio.h>
#include <string.h>
+#include "str.h"
#include "fmt.h"
#include "buffer.h"
@@ -10,13 +11,27 @@ static int infd,outfd;
static char buf[1500];
+void addservice(char* service) {
+ char* x;
+ if (str_start(service,"/etc/minit/"))
+ service+=11;
+ x=service+str_len(service)-1;
+ while (x>service && *x=='/') { *x=0; --x; }
+ strncpy(buf+1,service,1400);
+ buf[1400]=0;
+}
+
+int addreadwrite(char* service) {
+ addservice(service);
+ write(infd,buf,str_len(buf));
+ return read(outfd,buf,1500);
+}
+
/* return PID, 0 if error */
pid_t __readpid(char *service) {
int len;
buf[0]='p';
- strncpy(buf+1,service,1400);
- write(infd,buf,str_len(buf));
- len=read(outfd,buf,1500);
+ len=addreadwrite(service);
if (len<0) return 0;
buf[len]=0;
return atoi(buf);
@@ -26,9 +41,7 @@ pid_t __readpid(char *service) {
int respawn(char *service,int yesno) {
int len;
buf[0]=yesno?'R':'r';
- strncpy(buf+1,service,1400);
- write(infd,buf,str_len(buf));
- len=read(outfd,buf,1500);
+ len=addreadwrite(service);
return (len!=1 || buf[0]=='0');
}
@@ -37,7 +50,7 @@ int setpid(char *service, pid_t pid) {
char *tmp;
int len;
buf[0]='P';
- strncpy(buf+1,service,1400);
+ addservice(service);
tmp=buf+str_len(buf)+1;
tmp[fmt_ulong(tmp,pid)]=0;
write(infd,buf,str_len(buf)+str_len(tmp)+2);
@@ -49,9 +62,7 @@ int setpid(char *service, pid_t pid) {
int check_remove(char *service) {
int len;
buf[0]='C';
- strncpy(buf+1,service,1400);
- write(infd,buf,str_len(buf));
- len=read(outfd,buf,1500);
+ len=addreadwrite(service);
return (len!=1 || buf[0]=='0');
}
@@ -59,9 +70,7 @@ int check_remove(char *service) {
int startservice(char *service) {
int len;
buf[0]='s';
- strncpy(buf+1,service,1400);
- write(infd,buf,str_len(buf));
- len=read(outfd,buf,1500);
+ len=addreadwrite(service);
return (len!=1 || buf[0]=='0');
}
@@ -69,9 +78,7 @@ int startservice(char *service) {
unsigned long uptime(char *service) {
int len;
buf[0]='u';
- strncpy(buf+1,service,1400);
- write(infd,buf,str_len(buf));
- len=read(outfd,buf,1500);
+ len=addreadwrite(service);
if (len<0) return 0;
buf[len]=0;
return atoi(buf);
@@ -120,6 +127,10 @@ main(int argc,char *argv[]) {
buffer_putulong(buffer_1,len);
buffer_putsflush(buffer_1," seconds\n");
if (pid==0) return 2; else if (pid==1) return 3; else return 0;
+ } else {
+ buffer_puts(buffer_2,"msvc: ");
+ buffer_puts(buffer_2,argv[1]);
+ buffer_putsflush(buffer_2,": no such service.\n");
}
goto error;
} else {
diff --git a/str_start.c b/str_start.c
@@ -0,0 +1,14 @@
+#include "str.h"
+
+/* str_start returns 1 if the b is a prefix of a, 0 otherwise */
+int str_start(const char* a, const char* b) {
+ register const char* s=a;
+ register const char* t=b;
+ for (;;) {
+ if (!*t) return 1; if (*s!=*t) break; ++s; ++t;
+ if (!*t) return 1; if (*s!=*t) break; ++s; ++t;
+ if (!*t) return 1; if (*s!=*t) break; ++s; ++t;
+ if (!*t) return 1; if (*s!=*t) break; ++s; ++t;
+ }
+ return 0;
+}