#endif lint
#include <mit-copyright.h>
+#include <errno.h>
#include <stdio.h>
-#include <strings.h>
+#include <string.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/wait.h>
#include <sys/signal.h>
#include <sys/ioctl.h>
+#include <time.h>
+#include <fcntl.h>
+#include <sys/resource.h>
#include <moira_site.h>
+
#define PROG "moirad"
-char *whoami
int rdpipe[2];
-extern char *sys_siglist[];
+extern int errno;
+char *whoami;
-cleanup()
+void cleanup()
{
- union wait stat;
+ int stat, serrno = errno;
char buf[BUFSIZ];
- extern int errno;
- int serrno = errno;
buf[0]='\0';
- while (wait3(&stat, WNOHANG, 0) > 0) {
+ while (waitpid(-1, &stat, WNOHANG) > 0) {
if (WIFEXITED(stat)) {
- if (stat.w_retcode) {
+ if (WEXITSTATUS(stat)) {
sprintf(buf,
- "moirad exited with code %d\n",
- stat.w_retcode);
+ "exited with code %d\n",
+ WEXITSTATUS(stat));
send_zgram("startmoira", buf);
+ }
}
if (WIFSIGNALED(stat)) {
- sprintf(buf, "moirad exited on %s signal%s\n",
- sys_siglist[stat.w_termsig],
- (stat.w_coredump?"; Core dumped":0));
- if(stat.w_coredump) send_zgram("startmoira", buf);
+ sprintf(buf, "exited on signal %d%s\n",
+ WTERMSIG(stat),
+ (WCOREDUMP(stat)?"; Core dumped":0));
+ if(WCOREDUMP(stat)) send_zgram("startmoira", buf);
}
write(rdpipe[1], buf, strlen(buf));
close(rdpipe[1]);
}
main(argc, argv)
- int argc;
- char **argv;
+ int argc;
+ char *argv[];
{
char buf[BUFSIZ];
FILE *log, *prog;
int logf, inf, i, done, pid, tty;
+ struct rlimit rl;
extern int errno;
extern char *sys_errlist[];
- int nfds = getdtablesize();
+ struct sigaction action;
+ int nfds;
whoami = argv[0];
+
+ getrlimit(RLIMIT_NOFILE, &rl);
+ nfds = rl.rlim_cur;
- setreuid(0);
- signal(SIGCHLD, cleanup);
+ action.sa_handler = cleanup;
+ action.sa_flags = 0;
+ sigemptyset(&action.sa_mask);
+ sigaction(SIGCHLD, &action, NULL);
sprintf(buf, "%s/moira.log", SMS_DIR);
logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640);
dup2(inf, 1);
dup2(inf, 2);
- tty = open("/dev/tty");
- ioctl(tty, TIOCNOTTY, 0);
- close(tty);
+ setpgrp();
sprintf(buf, "%s/%s", BIN_DIR, PROG);
if ((pid = fork()) == 0) {
do {
char *time_s;
- extern char *ctime();
long foo;
done = 0;
errno = 0;
if (fgets(buf, BUFSIZ, prog) == NULL) {
- if (errno) {
+ if (errno && errno!=EINTR) {
strcpy(buf, "Unable to read from program: ");
strcat(buf, sys_errlist[errno]);
strcat(buf, "\n");
} while (!done);
exit(0);
}
-
-
-
-