From 15fa49b5f34fb01f994ead186642799110a977b9 Mon Sep 17 00:00:00 2001 From: danw Date: Mon, 20 Jan 1997 18:22:15 +0000 Subject: [PATCH] Solaris/POSIX changes Source tree should only have Imakefiles, not Makefiles --- dcm/Imakefile | 5 +--- dcm/Makefile | 70 ---------------------------------------------- dcm/dcm.c | 30 +++++++++++++------- dcm/startdcm.c | 43 +++++++++++++++------------- dcm/utils.c | 11 ++++++-- reg_svr/Imakefile | 5 +--- reg_svr/Makefile | 41 --------------------------- reg_svr/reg_svr.c | 20 ++++++------- reg_svr/requests.c | 14 +++++----- reg_svr/startreg.c | 35 +++++++++++++---------- 10 files changed, 92 insertions(+), 182 deletions(-) delete mode 100644 dcm/Makefile delete mode 100644 reg_svr/Makefile diff --git a/dcm/Imakefile b/dcm/Imakefile index 1c00ff65..ed30e4a4 100644 --- a/dcm/Imakefile +++ b/dcm/Imakefile @@ -11,9 +11,6 @@ SRCDIR = $(SRCTOP)/dcm SRCS= startdcm.c dcm.c utils.c CODE=$(SRCS) OBJS=dcm.o utils.o -#ifdef GDSS -GDSSLIB=/mit/gdss/`machtype`/libgdss.a -#endif -program(dcm, $(OBJS),,../server/libmrglue.a ../update/moira_update.o $(GDSSLIB) $(CLIBS) $(SQL_LIB), ${PROGDIR}) +program(dcm, $(OBJS),,../server/libmrglue.a $(LIBGDSS) ../update/moira_update.o $(CLIBS) $(SQL_LIB), ${PROGDIR}) program(startdcm, startdcm.o,,,${PROGDIR}) diff --git a/dcm/Makefile b/dcm/Makefile deleted file mode 100644 index 4d671deb..00000000 --- a/dcm/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# $Source$ -# $Author$ -# $Header$ -# -# (c) Copyright 1988 by the Massachusetts Institute of Technology. -# For copying and distribution information, please see the file -# . - -SMS_DIR = .. -INGRES_DIR = /usr/rtingres -UPDATE_DIR = ${SMS_DIR}/update - -INCDIR = -I${SMS_DIR}/include -CFLAGS = ${INCDIR} -g -LDFLAGS = -L${SMS_DIR}/lib -L${SMS_DIR}/server - -QLIBS= ${INGRES_DIR}/lib/libqlib ${INGRES_DIR}/lib/compatlib - -# Libraries that talk to the MOIRA server: -SERVER_LIBS = -lmoiraglue -lmoira -lgdb -lzephyr -lkrb -ldes -lcom_err $(QLIBS) - -DCM_SRCS = dcm.c utils.c -DCM_OBJS = dcm.o utils.o ../update/moira_update.o - - -all: dcm startdcm - -dcm: ${DCM_OBJS} - rm -f $@ - ${CC} ${LDFLAGS} -o $@ ${DCM_OBJS} ${SERVER_LIBS} - -startdcm: startdcm.o - ${CC} ${LDFLAGS} -o startdcm startdcm.o - -clean: - rm -f *.o core *~ - rm -f dcm startdcm .saber - -install: dcm startdcm - install -c dcm ${SMS_DIR}/bin/dcm - install -c startdcm ${SMS_DIR}/bin/startdcm - -lint: - lint ${INCDIR} ${DCM_SRCS} | grep -v "possible pointer alignment" - - -.saber: Makefile - rm -rf $@ - echo "setopt(\"load_options\", \"${CFLAGS} ${LDFLAGS}\");" >$@ - echo "#define DCM_SRCS \"${DCM_SRCS} ${SMS_UPDATE}\"" >>$@ - echo "#define FOO_SRCS \"${FOO_SRCS}\"" >>$@ - echo "#define GLUE_LIBS \"${GLUE_LIBS}\"" >>$@ - echo "#define SERVER_LIBS \"${SERVER_LIBS}\"" >>$@ - echo "suppress(285); " >>$@ - -depend: - mkdep ${CFLAGS} ${DCM_SRCS} - -# DO NOT DELETE THIS LINE -- mkdep uses it. - -dcm.o: dcm.c /usr/include/stdio.h ../include/update.h /usr/include/sys/file.h -dcm.o: /usr/include/sys/time.h /usr/include/sys/time.h -dcm.o: /usr/include/sys/wait.h /usr/include/signal.h /usr/include/ctype.h -dcm.o: ../include/moira.h ../include/mr_et.h ../include/moira_site.h -dcm.o: ../include/mit-copyright.h ../include/dcm.h -utils.o: utils.c ../include/mit-copyright.h /usr/include/stdio.h -utils.o: /usr/include/strings.h /usr/include/errno.h /usr/include/varargs.h -utils.o: /usr/include/sys/types.h /usr/include/sys/time.h -utils.o: /usr/include/sys/time.h /usr/include/sys/file.h ../include/moira.h -utils.o: ../include/mr_et.h ../include/moira_site.h ../include/dcm.h diff --git a/dcm/dcm.c b/dcm/dcm.c index 89668a09..81ff34ad 100644 --- a/dcm/dcm.c +++ b/dcm/dcm.c @@ -19,12 +19,15 @@ static char rcsid_dcm_c[] = "$Header$"; #include #include #include +#include +#include #include #include #include #include #include "dcm.h" #include "mit-copyright.h" +#include extern char *ctime(); extern char *getenv(); @@ -54,8 +57,9 @@ char *argv[]; dbg = s ? atoi(s) : 0; umask(UMASK); log_flags = 0; - setlinebuf(stderr); - setlinebuf(stdout); + + setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); while(++arg - argv < argc) { if (**arg == '-') @@ -157,7 +161,8 @@ do_services() int status, lock_fd, ex, (*cstat)(); struct timezone tz; register char *p; - union wait waits; + int waits; + struct sigaction action, prevaction; if (dbg & DBG_VERBOSE) com_err(whoami, 0, "starting pass over services"); @@ -217,18 +222,23 @@ do_services() } com_err(whoami, status, " running %s", dfgen_prog); - cstat = signal(SIGCHLD, SIG_DFL); - waits.w_status = system(dfgen_cmd); - signal(SIGCHLD, cstat); - if (waits.w_termsig) { + + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + action.sa_handler = SIG_DFL; + sigaction(SIGCHLD, &action, &prevaction); + waits = system(dfgen_cmd); + sigaction(SIGCHLD, &prevaction, NULL); + if (WIFSIGNALED(waits)) { status = MR_COREDUMP; com_err(whoami, status, " %s exited on signal %d", - dfgen_prog, waits.w_termsig); - } else if (waits.w_retcode) { + dfgen_prog, WTERMSIG(waits)); + } else if (WEXITSTATUS(waits)) { /* extract the process's exit value */ - status = waits.w_retcode + ERROR_TABLE_BASE_sms; + status = WEXITSTATUS(waits) + ERROR_TABLE_BASE_sms; com_err(whoami, status, " %s exited", dfgen_prog); } + if (SOFT_FAIL(status)) { free(qargv[5]); qargv[5] = strsave(error_message(status)); diff --git a/dcm/startdcm.c b/dcm/startdcm.c index 90451d51..e2fdac8b 100644 --- a/dcm/startdcm.c +++ b/dcm/startdcm.c @@ -23,33 +23,33 @@ static char *rcsid_mr_starter_c = "$Header$"; #include #include #include +#include +#include #include #define PROG "dcm" int rdpipe[2]; -extern char *sys_siglist[]; +extern int errno; -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, "exited with code %d\n", - stat.w_retcode); + WEXITSTATUS(stat)); } if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on %s signal%s\n", - sys_siglist[stat.w_termsig], - (stat.w_coredump?"; Core dumped":0)); + sprintf(buf, "exited with signal %d%s\n", + WTERMSIG(stat), + (WCOREDUMP(stat)?"; Core dumped":0)); } write(rdpipe[1], buf, strlen(buf)); close(rdpipe[1]); @@ -62,15 +62,22 @@ main(argc, 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(); - - setreuid(0); - signal(SIGCHLD, cleanup); - + struct sigaction action; + int nfds; + + getrlimit(RLIMIT_NOFILE, &rl); + nfds = rl.rlim_cur; + + action.sa_handler = cleanup; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGCHLD, &action, NULL); + sprintf(buf, "%s/%s.log", SMS_DIR, PROG); logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); if (logf<0) { @@ -94,9 +101,7 @@ main(argc, argv) 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) { diff --git a/dcm/utils.c b/dcm/utils.c index db51555b..6db3e194 100644 --- a/dcm/utils.c +++ b/dcm/utils.c @@ -23,6 +23,8 @@ static char *rcsid_utils_c = "$Header$"; #include #include #include +#include +#include #include #include #include "dcm.h" @@ -97,12 +99,15 @@ int exclusive; { char lock[BUFSIZ]; int fd; + flock_t fl; sprintf(lock, "%s/%s.%s", LOCK_DIR, host, service); - if ((fd = open(lock, O_TRUNC | O_CREAT, 0)) < 0) + fl.l_type = exclusive ? F_WRLCK : F_RDLCK; + fl.l_whence = fl.l_start = fl.l_len = 0; + if ((fd = open(lock, O_TRUNC | O_CREAT | O_RDWR, 0)) < 0) com_err(whoami, errno, ": maybe_lock_update: opening %s", lock); - else if (flock(fd, (exclusive ? LOCK_EX : LOCK_SH) | LOCK_NB) != 0) { - if (errno != EWOULDBLOCK) + else if (fcntl(fd, F_SETLK, &fl) != 0) { + if (errno != EAGAIN) com_err(whoami, errno, ": maybe_lock_update: flock"); else if (dbg & DBG_VERBOSE) com_err(whoami, 0, "%s already locked\n", lock); diff --git a/reg_svr/Imakefile b/reg_svr/Imakefile index fb4aeaba..6796812b 100644 --- a/reg_svr/Imakefile +++ b/reg_svr/Imakefile @@ -11,9 +11,6 @@ SRCDIR = $(SRCTOP)/reg_svr SRCS= startreg.c reg_svr.c requests.c reg_svr.h CODE=$(SRCS) OBJS=requests.o reg_svr.o -#ifdef GDSS -GDSSLIB=/mit/gdss/`machtype`/libgdss.a -#endif -program(reg_svr, $(OBJS),,../server/libmrglue.a -lkadm $(GDSSLIB) $(CLIBS) $(SQL_LIB), ${PROGDIR}) +program(reg_svr, $(OBJS),,../server/libmrglue.a -lkadm $(LIBGDSS) $(CLIBS) $(SQL_LIB), ${PROGDIR}) program(startreg, startreg.o,,,${PROGDIR}) diff --git a/reg_svr/Makefile b/reg_svr/Makefile deleted file mode 100644 index b33767c3..00000000 --- a/reg_svr/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -# -# $Source$ -# $Author$ -# $Locker$ -# $Header$ -# -# (c) Copyright 1988 by the Massachusetts Institute of Technology. -# For copying and distribution information, please see the file -# . - - -CFLAGS= -O -I../include -I../lib -SRCS = requests.c reg_svr.c startreg.c -OBJS = requests.o reg_svr.o - -all: reg_svr startreg - -reg_svr: $(OBJS) - cc ${CFLAGS} -o reg_svr $(OBJS) -L../lib \ - ../server/libmoiraglue.a /mit/gdss/vax/libgdss.a \ - -lmoira -lkadm -lkrb -ldes -lzephyr -lhesiod -lcom_err \ - /usr/rtingres/lib/libqlib /usr/rtingres/lib/compatlib - -reg_svr.o requests.o: reg_svr.h - -startreg: startreg.o - cc -o startreg startreg.o - -clean: /tmp - rm -f a.out core *.o - rm -f reg_svr startreg - rm -f unreg_user.c unreg_user - -install: all - install -c reg_svr ../bin/reg_svr - install -c startreg ../bin/startreg - -depend: - mkdep ${CFLAGS} ${SRCS} - -# DO NOT DELETE THIS LINE -- mkdep uses it. diff --git a/reg_svr/reg_svr.c b/reg_svr/reg_svr.c index 60dd1006..1bf8dd3f 100644 --- a/reg_svr/reg_svr.c +++ b/reg_svr/reg_svr.c @@ -56,8 +56,8 @@ main(argc,argv) whoami = argv[0]; /* Error messages sent one line at a time */ - setlinebuf(stderr); - setlinebuf(stdout); + setvbuf(stderr, NULL, _IOLBF, BUFSIZ); + setvbuf(stdout, NULL, _IOLBF, BUFSIZ); set_com_err_hook(reg_com_err_hook); /* Initialize com_err error tables */ @@ -318,7 +318,7 @@ int find_user(message) /* Zero the mit_id field in the formatted packet structure. This being zeroed means that no user was found. */ - bzero(message->db.mit_id,sizeof(message->db.mit_id)); + memset(message->db.mit_id,0,sizeof(message->db.mit_id)); if (status == SUCCESS) { @@ -460,7 +460,7 @@ int ureg_kadm_init() if (!inited) { inited++; - bzero(krbrealm, sizeof(krbrealm)); + memset(krbrealm, 0, sizeof(krbrealm)); if (status = krb_get_lrealm(krbrealm, 1)) { status += krb_err_base; com_err(whoami, status, " fetching kerberos realm"); @@ -527,7 +527,7 @@ int reserve_krb(login) #endif DEBUG if ((status = ureg_kadm_init()) == SUCCESS) { - bzero((char *)&new, sizeof(new)); + memset(&new, 0, sizeof(new)); SET_FIELD(KADM_DESKEY, new.fields); SET_FIELD(KADM_NAME, new.fields); @@ -541,7 +541,7 @@ int reserve_krb(login) if (status != KADM_SUCCESS) com_err(whoami, status, " while reserving principal"); - bzero((char *)&new, sizeof(new)); + memset(&new, 0, sizeof(new)); } dest_tkt(); @@ -563,7 +563,7 @@ int setpass_krb(login, password) u_long *lkey = (u_long *)key; if ((status = ureg_kadm_init()) == SUCCESS) { - bzero((char *)&new, sizeof(new)); + memset(&new, 0, sizeof(new)); SET_FIELD(KADM_DESKEY, new.fields); SET_FIELD(KADM_NAME, new.fields); @@ -983,7 +983,7 @@ char *retval; creds.length = ntohl(*((int *)bp)); bp += sizeof(int); - bcopy(bp, creds.dat, creds.length); + memcpy(creds.dat, bp, creds.length); creds.mbz = 0; bp += creds.length; @@ -1014,7 +1014,7 @@ char *retval; keys, auth.session, 0); id = buf; - passwd = index(buf, ','); + passwd = strchr(buf, ','); *passwd++ = 0; #ifdef DEBUG com_err(whoami, 0, "Got id: %s, passwd %d chars", id, strlen(passwd)); @@ -1039,7 +1039,7 @@ char *retval; return(status); } - bzero((char *)&kv, sizeof(kv)); + memset(&kv, 0, sizeof(kv)); SET_FIELD(KADM_DESKEY, kv.fields); SET_FIELD(KADM_NAME, kv.fields); SET_FIELD(KADM_INST, kv.fields); diff --git a/reg_svr/requests.c b/reg_svr/requests.c index 98ec3289..d0559000 100644 --- a/reg_svr/requests.c +++ b/reg_svr/requests.c @@ -87,7 +87,7 @@ void req_initialize() com_err(whoami,errno," socket"); exit(1); } - bzero((char *)&sin,(int)sizeof(sin)); + memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_port = sp->s_port; @@ -215,11 +215,11 @@ int format_pkt(packet, pktlenp, seqno, cl_status, message) U_32BIT vers = htonl((U_32BIT)CUR_UREG_VERSION); cl_status = htonl((U_32BIT)cl_status); /* Put current user registration protocol version into the packet */ - bcopy((char *)&vers, packet, sizeof(U_32BIT)); + memcpy(packet, &vers, sizeof(U_32BIT)); /* Put sequence number into the packet */ - bcopy((char *)&seqno, packet+sizeof(U_32BIT), sizeof(U_32BIT)); + memcpy(packet+sizeof(U_32BIT), &seqno, sizeof(U_32BIT)); /* Put error status into the packet */ - bcopy((char *)&cl_status, packet+ 2*sizeof(U_32BIT), sizeof(U_32BIT)); + memcpy(packet+ 2*sizeof(U_32BIT), &cl_status, sizeof(U_32BIT)); /* Find out how much of the message to copy; truncate if too short. */ /* How much room is there left? */ @@ -292,7 +292,7 @@ parse_pkt(packet, pktlen, message) if (status == SUCCESS) { /* Extract the user registration protocol version from the packet */ - bcopy(packet, (char *)&message->version, sizeof(long)); + memcpy(&message->version, packet, sizeof(long)); /* Convert byte order from network to host */ message->version = ntohl(message->version); /* Verify version */ @@ -312,7 +312,7 @@ parse_pkt(packet, pktlen, message) if (status == SUCCESS) { /* Extract the sequence number from the packet */ - bcopy(packet, (char *)&CUR_REQ.seqno, sizeof(long)); + memcpy(&CUR_REQ.seqno, packet, sizeof(long)); packet += sizeof(U_32BIT); pktlen -= sizeof(U_32BIT); @@ -324,7 +324,7 @@ parse_pkt(packet, pktlen, message) if (status == SUCCESS) { /* Extract the request from the packet */ - bcopy(packet, (char *)(&message->request), sizeof(U_32BIT)); + memcpy(&message->request, packet, sizeof(U_32BIT)); message->request = ntohl(message->request); packet += sizeof(U_32BIT); pktlen -= sizeof(U_32BIT); diff --git a/reg_svr/startreg.c b/reg_svr/startreg.c index 9cd4e21c..92d6fc6c 100644 --- a/reg_svr/startreg.c +++ b/reg_svr/startreg.c @@ -23,33 +23,35 @@ static char *rcsid_mr_starter_c = "$Header$"; #include #include #include +#include +#include +#include #include #define PROG "reg_svr" int rdpipe[2]; -extern char *sys_siglist[]; cleanup() { - union wait stat; + int stat; 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, "exited with code %d\n", - stat.w_retcode); + WEXITSTATUS(stat)); } if (WIFSIGNALED(stat)) { - sprintf(buf, "exited on %s signal%s\n", - sys_siglist[stat.w_termsig], - (stat.w_coredump?"; Core dumped":0)); + sprintf(buf, "exited on signal %d%s\n", + WTERMSIG(stat), + (WCOREDUMP(stat)?"; Core dumped":0)); } write(rdpipe[1], buf, strlen(buf)); close(rdpipe[1]); @@ -62,14 +64,21 @@ main(argc, 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; - setreuid(0); - signal(SIGCHLD, cleanup); + getrlimit(RLIMIT_NOFILE, &rl); + nfds = rl.rlim_cur; + + action.sa_handler = cleanup; + action.sa_flags = 0; + sigemptyset(&action.sa_mask); + sigaction(SIGCHLD, &action, NULL); sprintf(buf, "%s/%s.log", SMS_DIR, PROG); logf = open(buf, O_CREAT|O_WRONLY|O_APPEND, 0640); @@ -94,9 +103,7 @@ main(argc, argv) 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) { -- 2.45.2