commit 773621efe6fd27d75fe97ebed029622db11cbb4b
parent 3b0ff07af66a812771d8356896661ca94107c594
Author: leitner <leitner>
Date: Fri, 31 Oct 2003 18:01:55 +0000
Several cleanups by Florian Westphal
Diffstat:
5 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/Makefile b/Makefile
@@ -18,8 +18,9 @@ str_start.o
$(DIET) $(CROSS)$(CC) $(LDFLAGS) -o msvc $^
minit-update: minit-update.o buffer_1.o buffer_2.o buffer_puts.o \
-buffer_putsflush.o buffer_put.o buffer_flush.o buffer_stubborn.o buffer_putflush.o byte_copy.o \
-split.o str_len.o openreadclose.o
+buffer_putsflush.o buffer_put.o buffer_flush.o buffer_stubborn.o \
+buffer_putflush.o byte_copy.o split.o str_len.o openreadclose.o \
+str_len.o
$(DIET) $(CROSS)$(CC) $(LDFLAGS) -o minit-update $^
shutdown: shutdown.o split.o openreadclose.o opendevconsole.o
diff --git a/buffer_1.c b/buffer_1.c
@@ -1,5 +1,8 @@
#include <unistd.h>
#include "buffer.h"
+#ifdef __MINGW32__
+#include <io.h>
+#endif
char buffer_1_space[BUFFER_INSIZE];
static buffer it = BUFFER_INIT(write,1,buffer_1_space,sizeof buffer_1_space);
diff --git a/hard-reboot.c b/hard-reboot.c
@@ -2,12 +2,14 @@
#include <sys/reboot.h>
#include <stdlib.h>
+#include "str.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, strlen(ABORTMSG));
- write(2, USAGE, strlen(USAGE));
+ write(2, ABORTMSG, str_len(ABORTMSG));
+ write(2, USAGE, str_len(USAGE));
exit(1);
}
diff --git a/minit.c b/minit.c
@@ -202,9 +202,9 @@ again:
argv[1]=0;
}
argv0=(char*)malloc(PATH_MAX+1);
- if (!argv || !argv0) goto abort;
+ if (!argv || !argv0) _exit(1);
if (readlink("run",argv0,PATH_MAX)<0) {
- if (errno!=EINVAL) goto abort; /* not a symbolic link */
+ if (errno!=EINVAL) _exit(1); /* not a symbolic link */
argv0=strdup("./run");
}
/* chdir("/"); */
@@ -224,10 +224,6 @@ again:
}
execve(argv0,argv,environ);
_exit(1);
- abort:
- free(argv0);
- free(argv);
- _exit(0);
default:
fd=open("sync",O_RDONLY);
if (fd>=0) {
@@ -441,14 +437,15 @@ int main(int argc, char *argv[]) {
/* write(1,buf,str_len(buf)); write(1,"\n",1); */
#ifdef UPDATE
- if(!strcmp(buf,"update")) {
- char *newargs[]={"/sbin/minit", "--update" ,0};
- execve("/sbin/minit",newargs, environ);
- }
+ if(!strcmp(buf,"update")) {
+ char *newargs[]={"/sbin/minit", "--update" ,0};
+ execve("/sbin/minit",newargs, environ);
+ }
+ idx=findservice(buf+1);
- if (((buf[0]!='U') && buf[0]!='s') && ((idx=findservice(buf+1))<0))
+ if (((buf[0]!='U') && buf[0]!='s') && (idx<0))
#else
- if (buf[0]!='s' && ((idx=findservice(buf+1))<0))
+ if (buf[0]!='s' && (idx<0))
#endif
error:
write(outfd,"0",1);
diff --git a/shutdown.c b/shutdown.c
@@ -27,11 +27,14 @@
#include <stdlib.h>
#include <sys/wait.h>
+#include "str.h"
+
#ifdef __dietlibc__
#include <write12.h>
#else
-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)); }
+#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)); }
#endif
#define ALLOW_SUID
@@ -100,7 +103,7 @@ int minit_serviceDown(char *service) {
// get the pid
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) {
buf[len]=0;
@@ -113,7 +116,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, strlen(buf));
+ write(infd, buf, str_len(buf));
read(outfd, buf, 1500);
i=kill(pid, SIGTERM);
if (i == 0) __write2("\t\tdone\n");
@@ -129,7 +132,7 @@ int minit_shutdown(int level) {
infd=open("/etc/minit/in", O_WRONLY);
outfd=open("/etc/minit/out", O_RDONLY);
if (infd>=0) {
- while (lockf(infd, F_LOCK, 1)) {
+ while (lockf(infd, F_TLOCK, 1)) {
__write2("could not acquire lock!\n");
sleep(1);
}