- for portability make sure that we never use "" as a pathname, always convert

it to "."
- include sockio.h if needed to define SIOCGIFCONF (for svr4)
- use POSIX signals and wait macros
- add -S silent flag, so that the client does not print messages unless there
  is something wrong
- use flock or lockf as appropriate
- use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
  don't depend on the major() = 255 hack; it only works on legacy systems.
- use gzip -cf to make sure that gzip compresses the file even when the file
  would expand.
- punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...

To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
This commit is contained in:
christos 1996-09-05 16:50:01 +00:00
parent 82f0b829e8
commit b33b1aed5c
12 changed files with 358 additions and 90 deletions

View File

@ -40,15 +40,22 @@
# If you have crypt/crypt.c and /usr/lib/libcrypt.a, you will be building
# a system that uses the SUP crypt mechanism by default.
#
# If building on non 4.4BSD systems, you'll need the vis(3) and the daemon(3)
# functions from libc and libutil
#SITE = SUNOS
#SITE = SOLARIS
SITE = NETBSD
#SITE = CMUCS
NETBSD_DEFINES = -UMACH -DVAR_TMP -DHAS_DAEMON -DHAS_POSIX_DIR
SOLARIS_DEFINES = -UMACH -DVAR_TMP -DHAS_POSIX_DIR -DNEED_VSNPRINTF
AFS_DEFINES = -DAFS -I/usr/afsws/include
OSF_DEFINES = -UMACH -DOSF -D_BSD -noshrlib -g -DNEED_VSNPRINTF -DVAR_TMP
SUNOS_DEFINES = -UMACH -D_BSD -DNEED_VSNPRINTF -DVAR_TMP -DHAS_POSIX_DIR -DHAS_DAEMON -DNEED_DAEMON
CMUCS_DEFINES = -DMACH -DDOPRINT_VA -DNEED_VPRINTF
NON_MACH_DEFINES = -UMACH
#DEFS = -UCMUCS -UCMU ${${SITE}_DEFINES}
DEFS = -UCMUCS -UCMU ${NETBSD_DEFINES}
#INSTALLATION PARAMETERS
NETBSD_BINDIR = /usr/local/sbin
@ -60,8 +67,9 @@ CFLAGS = ${DEFS} -O -I.
SUPCL = supcmain.o supcvers.o supcparse.o supcname.o \
supcmisc.o supcmeat.o
SUPS = scm.o scmio.o stree.o log.o supmsg.o netcrypt.o
EXTRA = atoo.o errmsg.o expand.o ffilecopy.o filecopy.o nxtarg.o \
path.o quit.o run.o salloc.o skipto.o vprintf.o
EXTRA = atoo.o errmsg.o expand.o ffilecopy.o filecopy.o \
nxtarg.o path.o quit.o run.o salloc.o skipto.o \
vprintf.o
PROGRAMS = sup supscan supfilesrv
@ -78,12 +86,18 @@ USE_CRYPT = yes
NETBSD_LIBS = -lcrypt -lutil
CMUCS_LIBS = -lsys
OSF_LIBS = -lbsd
LIBS = libextra.a
EXTRALIBS = libextra.a
sup_OFILES = ${SUPCL} ${SUPS}
supfilesrv_OFILES = supfilesrv.o scan.o ${SUPS}
supfilesrv_LIBS = libextra.a
supscan_OFILES = supscan.o stree.o scan.o
SOLARIS_LIBS = -lsocket -lnsl
SUNOS_LIBS =
.for i in ${SITE}
DEFS = -UCMUCS -UCMU ${${i}_DEFINES}
LIBS = ${EXTRALIBS} ${${i}_LIBS}
.endfor
all: ${PROGRAMS}
.if defined(USE_CRYPT)
@ -92,13 +106,13 @@ all: ${PROGRAMS}
.endif
sup: ${sup_OFILES} ${LIBS}
${CC} ${CFLAGS} -o sup ${sup_OFILES} ${LIBS} ${NETBSD_LIBS}
${CC} ${CFLAGS} -o sup ${sup_OFILES} ${LIBS} ${LIBS}
supfilesrv: ${supfilesrv_OFILES} ${supfilesrv_LIBS}
${CC} ${CFLAGS} -o supfilesrv ${supfilesrv_OFILES} ${supfilesrv_LIBS} ${NETBSD_LIBS}
${CC} ${CFLAGS} -o supfilesrv ${supfilesrv_OFILES} ${supfilesrv_LIBS} ${LIBS}
supscan: ${supscan_OFILES} ${LIBS}
${CC} ${CFLAGS} -o supscan ${supscan_OFILES} ${LIBS} ${NETBSD_LIBS}
${CC} ${CFLAGS} -o supscan ${supscan_OFILES} ${LIBS}
libextra.a: ${EXTRA}
ar r libextra.a $?

View File

@ -92,6 +92,8 @@ static void addone();
static int addpath();
static int gethdir();
#define fixit(a) (a[0] ? a : ".")
int expand(spec, buffer, bufsize)
register char *spec;
char **buffer;
@ -134,7 +136,7 @@ static void glob(as)
}
while (*cs == 0 || index(globchars, *cs) == 0) {
if (*cs == 0) {
if (lstat(path, &stb) >= 0) addone(path, "");
if (lstat(fixit(path), &stb) >= 0) addone(path, "");
goto endit;
}
if (addpath(*cs++)) goto endit;
@ -150,7 +152,7 @@ static void glob(as)
return;
}
/* this should not be an lstat */
if (stat(path, &stb) >= 0 && (stb.st_mode&S_IFMT) == S_IFDIR)
if (stat(fixit(path), &stb) >= 0 && (stb.st_mode&S_IFMT) == S_IFDIR)
matchdir(cs);
endit:
pathp = spathp;
@ -168,11 +170,11 @@ static void matchdir(pattern)
#endif
DIR *dirp;
dirp = opendir(path);
dirp = opendir(fixit(path));
if (dirp == NULL)
return;
while ((dp = readdir(dirp)) != NULL) {
#ifdef HAS_POSIX_DIR
#if defined(HAS_POSIX_DIR) && !defined(__SVR4)
if (dp->d_fileno == 0) continue;
#else
if (dp->d_ino == 0) continue;
@ -320,7 +322,7 @@ slash:
while (*s)
if (addpath(*s++)) goto pathovfl;
if (addpath('/')) goto pathovfl;
if (stat(path, &stb) >= 0 &&
if (stat(fixit(path), &stb) >= 0 &&
(stb.st_mode&S_IFMT) == S_IFDIR)
if (*p == 0)
addone(path, "");

View File

@ -48,6 +48,23 @@
**********************************************************************
* HISTORY
* $Log: run.c,v $
* Revision 1.3 1996/09/05 16:50:03 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.2 1995/06/24 16:21:33 christos
* - Don't use system(3) to fork processes. It is a big security hole.
* - Encode the filenames in the scan files using strvis(3), so filenames
@ -153,8 +170,8 @@ int usepath;
{
int wpid;
register int pid;
struct sigvec ignoresig,intsig,quitsig;
union wait status;
struct sigaction ignoresig,intsig,quitsig;
int status;
int execvp(), execv();
int (*execrtn)() = usepath ? execvp : execv;
@ -169,25 +186,25 @@ int usepath;
_exit (0377);
}
ignoresig.sv_handler = SIG_IGN; /* ignore INT and QUIT signals */
ignoresig.sv_mask = 0;
ignoresig.sv_onstack = 0;
sigvec (SIGINT,&ignoresig,&intsig);
sigvec (SIGQUIT,&ignoresig,&quitsig);
ignoresig.sa_handler = SIG_IGN; /* ignore INT and QUIT signals */
sigemptyset(&ignoresig.sa_mask);
ignoresig.sa_flags = 0;
sigaction (SIGINT,&ignoresig,&intsig);
sigaction (SIGQUIT,&ignoresig,&quitsig);
do {
wpid = wait3 (&status.w_status, WUNTRACED, 0);
wpid = wait3 (&status, WUNTRACED, 0);
if (WIFSTOPPED (status)) {
kill (0,SIGTSTP);
wpid = 0;
}
} while (wpid != pid && wpid != -1);
sigvec (SIGINT,&intsig,0); /* restore signals */
sigvec (SIGQUIT,&quitsig,0);
sigaction (SIGINT,&intsig,0); /* restore signals */
sigaction (SIGQUIT,&quitsig,0);
if (WIFSIGNALED (status) || status.w_retcode == 0377)
if (WIFSIGNALED (status) || WEXITSTATUS(status) == 0377)
return (-1);
return (status.w_retcode);
return (WEXITSTATUS(status));
}
/*

View File

@ -28,6 +28,23 @@
**********************************************************************
* HISTORY
* $Log: scan.c,v $
* Revision 1.5 1996/09/05 16:50:04 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.4 1995/10/29 23:54:45 christos
* - runio fails when result != 0 not only < 0
* - print vis-encoded file in the scanner.
@ -110,6 +127,7 @@
#include <sys/dir.h>
#endif
#include <sys/file.h>
#include <unistd.h>
#include "sup.h"
/*************************

View File

@ -69,6 +69,23 @@
* since Tahoe version of <netinet/in.h> does not define them.
*
* $Log: scm.c,v $
* Revision 1.3 1996/09/05 16:50:05 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.2 1995/06/03 21:21:51 christos
* Changes to write ascii timestamps in the when files.
* Looked into making it 64 bit clean, but it is hopeless.
@ -177,6 +194,9 @@
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#ifndef SIOCGIFCONF
#include <sys/sockio.h>
#endif
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
@ -199,6 +219,7 @@ extern int errno;
static char *myhost ();
char scmversion[] = "4.3 BSD";
extern int silent;
/*************************
*** M A C R O S ***
@ -348,7 +369,8 @@ int *t,*b;
s = *t;
*t -= s;
}
(void) scmerr (-1,"Will retry in %d seconds",s);
if (!silent)
(void) scmerr (-1,"Will retry in %d seconds",s);
sleep (s);
return (1);
}
@ -372,8 +394,9 @@ int *retry;
else
return (scmerr (-1,"Can't find %s server description",
server));
(void) scmerr (-1,"%s/tcp: unknown service: using port %d",
server,port);
if (!silent)
(void) scmerr (-1,"%s/tcp: unknown service: using port %d",
server,port);
} else
port = sp->s_port;
(void) bzero ((char *)&sin,sizeof(sin));

View File

@ -23,6 +23,23 @@
.\"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
.\" HISTORY
.\" $Log: sup.1,v $
.\" Revision 1.4 1996/09/05 16:50:06 christos
.\" - for portability make sure that we never use "" as a pathname, always convert
.\" it to "."
.\" - include sockio.h if needed to define SIOCGIFCONF (for svr4)
.\" - use POSIX signals and wait macros
.\" - add -S silent flag, so that the client does not print messages unless there
.\" is something wrong
.\" - use flock or lockf as appropriate
.\" - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
.\" don't depend on the major() = 255 hack; it only works on legacy systems.
.\" - use gzip -cf to make sure that gzip compresses the file even when the file
.\" would expand.
.\" - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
.\"
.\" To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
.\" vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
.\"
.\" Revision 1.3 1995/06/03 21:21:53 christos
.\" Changes to write ascii timestamps in the when files.
.\" Looked into making it 64 bit clean, but it is hopeless.
@ -120,6 +137,9 @@ will print the time
that each collection was last upgraded, rather than
performing actual upgrades.
.TP
.B -S
Operate silently printing messages only on errors.
.TP
.B -N
.I Sup
will trace network messages sent and received that implement the

View File

@ -33,6 +33,23 @@
* across the network to save BandWidth
*
* $Log: supcdefs.h,v $
* Revision 1.3 1996/09/05 16:50:07 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.2 1993/08/04 17:46:16 brezak
* Changes from nate for gzip'ed sup
*
@ -66,6 +83,7 @@
#include <setjmp.h>
#include <pwd.h>
#include <grp.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>
@ -122,6 +140,7 @@ typedef struct collstruct COLLECTION;
#define CFKEEP 01000
#define CFURELSUF 02000
#define CFCOMPRESS 04000
#define CFSILENT 10000
/*************************
*** M A C R O S ***

View File

@ -174,6 +174,23 @@
* across the network to save BandWidth
*
* $Log: supcmain.c,v $
* Revision 1.5 1996/09/05 16:50:08 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.4 1995/09/16 19:01:25 glass
* if the function returns nothing, declare it void
*
@ -341,6 +358,7 @@ COLLECTION *firstC,*thisC; /* collection list pointer */
extern int dontjump; /* disable longjmp */
extern int scmdebug; /* SCM debugging flag */
int silent; /* Silent run, print only errors */
int sysflag; /* system upgrade flag */
int timeflag; /* print times flag */
#if MACH
@ -361,7 +379,7 @@ char **argv;
char *progname,*supfname;
int restart,sfdev,sfino,sfmtime;
struct stat sbuf;
struct sigvec ignvec,oldvec;
struct sigaction ign;
/* initialize global variables */
pgmversion = PGMVERSION; /* export version number */
@ -387,10 +405,10 @@ char **argv;
prtime ();
} else {
/* ignore network pipe signals */
ignvec.sv_handler = SIG_IGN;
ignvec.sv_onstack = 0;
ignvec.sv_mask = 0;
(void) sigvec (SIGPIPE,&ignvec,&oldvec);
ign.sa_handler = SIG_IGN;
ign.sa_flags = 0;
sigemptyset(&ign.sa_mask);
(void) sigaction (SIGPIPE,&ign,NULL);
getnams (); /* find unknown repositories */
for (thisC = firstC; thisC; thisC = thisC->Cnext) {
getcoll (); /* upgrade each collection */
@ -410,8 +428,9 @@ char **argv;
(void) endgrent (); /* close /etc/group */
if (restart == 1) {
int fd;
loginfo ("SUP Restarting %s with new supfile %s",
progname,supfname);
if (!silent)
loginfo("SUP Restarting %s with new supfile %s",
progname,supfname);
for (fd = getdtablesize (); fd > 3; fd--)
(void) close (fd);
execv (progname,argv);
@ -495,6 +514,9 @@ int *oflagsp,*aflagsp;
case 'X':
xpatchflag = TRUE;
break;
case 'S':
silent = TRUE;
break;
case 's':
sysflag = TRUE;
break;
@ -703,8 +725,9 @@ char **argv;
p = "system software";
else
(void) sprintf (p = buf,"file %s",supfname);
loginfo ("SUP %d.%d (%s) for %s at %s",PROTOVERSION,PGMVERSION,
scmversion,p,fmttime (timenow));
if (!silent)
loginfo ("SUP %d.%d (%s) for %s at %s",PROTOVERSION,PGMVERSION,
scmversion,p,fmttime (timenow));
return (salloc (supfname));
}

View File

@ -32,6 +32,23 @@
* across the network to save BandWidth
*
* $Log: supcmeat.c,v $
* Revision 1.7 1996/09/05 16:50:09 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.6 1995/10/29 23:54:47 christos
* - runio fails when result != 0 not only < 0
* - print vis-encoded file in the scanner.
@ -417,17 +434,33 @@ int login ()
(void) sprintf (buf,FILELOCK,collname);
f = open (buf,O_RDONLY,0);
if (f >= 0) {
if (flock (f,(LOCK_EX|LOCK_NB)) < 0) {
if (errno != EWOULDBLOCK)
#if defined(LOCK_EX)
# define TESTLOCK(f) flock(f, LOCK_EX|LOCK_NB)
# define SHARELOCK(f) flock(f, LOCK_SH|LOCK_NB)
# define WAITLOCK(f) flock(f, LOCK_EX)
#elif defined(F_LOCK)
# define TESTLOCK(f) lockf(f, F_TLOCK, 0)
# define SHARELOCK(f) 1
# define WAITLOCK(f) lockf(f, F_LOCK, 0)
#else
# define TESTLOCK(f) (close(f), f = -1, 1)
# define SHARELOCK(f) 1
# define WAITLOCK(f) 1
#endif
if (TESTLOCK(f) < 0) {
if (errno != EWOULDBLOCK && errno != EAGAIN) {
(void) close(f);
goaway ("Can't lock collection %s",collname);
if (flock (f,(LOCK_SH|LOCK_NB)) < 0) {
}
if (SHARELOCK(f) < 0) {
(void) close (f);
if (errno == EWOULDBLOCK)
if (errno == EWOULDBLOCK && errno != EAGAIN)
goaway ("Collection %s is locked by another sup",collname);
goaway ("Can't lock collection %s",collname);
}
vnotify ("SUP Waiting for exclusive access lock\n");
if (flock (f,LOCK_EX) < 0) {
if (WAITLOCK(f) < 0) {
(void) close (f);
goaway ("Can't lock collection %s",collname);
}
@ -1054,7 +1087,7 @@ register char **fname;
execone (t) /* execute command for file */
register TREE *t;
{
union wait w;
int w;
if (thisC->Cflags&CFLIST) {
vnotify ("SUP Would execute %s\n",t->Tname);
@ -1066,18 +1099,18 @@ register TREE *t;
}
vnotify ("SUP Executing %s\n",t->Tname);
w.w_status = system (t->Tname);
if (WIFEXITED(w) && w.w_retcode != 0) {
w = system (t->Tname);
if (WIFEXITED(w) && WEXITSTATUS(w) != 0) {
notify ("SUP: Execute command returned failure status %#o\n",
w.w_retcode);
WEXITSTATUS(w));
thisC->Cnogood = TRUE;
} else if (WIFSIGNALED(w)) {
notify ("SUP: Execute command killed by signal %d\n",
w.w_termsig);
WTERMSIG(w));
thisC->Cnogood = TRUE;
} else if (WIFSTOPPED(w)) {
notify ("SUP: Execute command stopped by signal %d\n",
w.w_stopsig);
WSTOPSIG(w));
thisC->Cnogood = TRUE;
}
return (SCMOK);

View File

@ -27,6 +27,23 @@
**********************************************************************
* HISTORY
* $Log: supcmisc.c,v $
* Revision 1.3 1996/09/05 16:50:10 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.2 1995/06/03 21:21:57 christos
* Changes to write ascii timestamps in the when files.
* Looked into making it 64 bit clean, but it is hopeless.
@ -309,16 +326,19 @@ va_dcl
lockout (on) /* lock out interrupts */
int on;
{
register int x;
static int lockmask;
static sigset_t oset;
sigset_t nset;
if (on) {
x = sigmask (SIGHUP) | sigmask (SIGINT) |
sigmask (SIGQUIT) | sigmask (SIGTERM);
lockmask = sigblock (x);
sigemptyset(&nset);
sigaddset(&nset, SIGHUP);
sigaddset(&nset, SIGINT);
sigaddset(&nset, SIGTERM);
sigaddset(&nset, SIGQUIT);
(void) sigprocmask(SIG_BLOCK, &nset, &oset);
}
else {
(void) sigsetmask (lockmask);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
}

View File

@ -25,11 +25,12 @@
/*
* supfilesrv -- SUP File Server
*
* Usage: supfilesrv [-l] [-P] [-N] [-R]
* Usage: supfilesrv [-l] [-P] [-N] [-R] [-S]
* -l "live" -- don't fork daemon
* -P "debug ports" -- use debugging network ports
* -N "debug network" -- print debugging messages for network i/o
* -R "RCS mode" -- if file is an rcs file, use co to get contents
* -S "Operate silently" -- Only print error messages
*
**********************************************************************
* HISTORY
@ -42,6 +43,23 @@
* across the network to save BandWidth
*
* $Log: supfilesrv.c,v $
* Revision 1.9 1996/09/05 16:50:12 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.8 1995/10/29 23:54:49 christos
* - runio fails when result != 0 not only < 0
* - print vis-encoded file in the scanner.
@ -237,6 +255,7 @@
#include <setjmp.h>
#include <pwd.h>
#include <grp.h>
#include <fcntl.h>
#if __STDC__
#include <stdarg.h>
#else
@ -247,7 +266,12 @@
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/mount.h>
#ifndef HAS_POSIX_DIR
#include <sys/dir.h>
#else
#include <dirent.h>
#endif
#if MACH
#include <sys/ioctl.h>
#endif
@ -260,6 +284,12 @@
#define ACCESS_CODE_OK 0
#define ACCESS_CODE_BADPASSWORD (-2)
#endif CMUCS
#ifdef __SVR4
# include <sys/mkdev.h>
# include <sys/statvfs.h>
#endif
#include "sup.h"
#define MSGFILE
#include "supmsg.h"
@ -317,6 +347,7 @@ int progpid = -1; /* and process id */
jmp_buf sjbuf; /* jump location for network errors */
TREELIST *listTL; /* list of trees to upgrade */
int silent; /* -S flag */
int live; /* -l flag */
int dbgportsq; /* -P flag */
extern int scmdebug; /* -N flag */
@ -359,9 +390,10 @@ main (argc,argv)
int argc;
char **argv;
{
register int x,pid,signalmask;
struct sigvec chldvec,ignvec,oldvec;
void chldsig();
register int x,pid;
sigset_t nset, oset;
struct sigaction chld,ign;
void chldsig ();
long tloc;
/* initialize global variables */
@ -389,16 +421,16 @@ char **argv;
(void) serviceend ();
exit (0);
}
ignvec.sv_handler = SIG_IGN;
ignvec.sv_onstack = 0;
ignvec.sv_mask = 0;
(void) sigvec (SIGHUP,&ignvec,&oldvec);
(void) sigvec (SIGINT,&ignvec,&oldvec);
(void) sigvec (SIGPIPE,&ignvec,&oldvec);
chldvec.sv_handler = chldsig;
chldvec.sv_mask = 0;
chldvec.sv_onstack = 0;
(void) sigvec (SIGCHLD,&chldvec,&oldvec);
ign.sa_handler = SIG_IGN;
sigemptyset(&ign.sa_mask);
ign.sa_flags = 0;
(void) sigaction (SIGHUP,&ign,NULL);
(void) sigaction (SIGINT,&ign,NULL);
(void) sigaction (SIGPIPE,&ign,NULL);
chld.sa_handler = chldsig;
sigemptyset(&chld.sa_mask);
chld.sa_flags = 0;
(void) sigaction (SIGCHLD,&chld,NULL);
nchildren = 0;
for (;;) {
x = service ();
@ -407,7 +439,9 @@ char **argv;
(void) servicekill ();
continue;
}
signalmask = sigblock(sigmask(SIGCHLD));
sigemptyset(&nset);
sigaddset(&nset, SIGCHLD);
sigprocmask(SIG_BLOCK, &nset, &oset);
if ((pid = fork()) == 0) { /* server process */
(void) serviceprep ();
answer ();
@ -416,7 +450,7 @@ char **argv;
}
(void) servicekill (); /* parent */
if (pid > 0) nchildren++;
(void) sigsetmask(signalmask);
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
}
@ -428,7 +462,7 @@ void
chldsig(snum)
int snum;
{
union wait w;
int w;
while (wait3((int *) &w, WNOHANG, (struct rusage *)0) > 0) {
if (nchildren) nchildren--;
@ -470,6 +504,9 @@ char **argv;
argv++;
while (clienthost == NULL && argc > 0 && argv[0][0] == '-') {
switch (argv[0][1]) {
case 'S':
silent = TRUE;
break;
case 'l':
live = TRUE;
break;
@ -720,7 +757,7 @@ setup ()
setupack = FSETUPSAME;
(void) msgsetupack ();
if (protver >= 6) longjmp (sjbuf,TRUE);
goaway ("User not found");
goaway ("User `%s' not found", xuser);
}
(void) free (xuser);
xuser = salloc (pw->pw_dir);
@ -887,6 +924,7 @@ setup ()
}
/* try to lock collection */
(void) sprintf (buf,FILELOCK,collname);
#ifdef LOCK_SH
x = open (buf,O_RDONLY,0);
if (x >= 0) {
if (flock (x,(LOCK_SH|LOCK_NB)) < 0) {
@ -900,6 +938,7 @@ setup ()
}
lockfd = x;
}
#endif
setupack = FSETUPOK;
x = msgsetupack ();
if (x != SCMOK) goaway ("Error sending setup reply to client");
@ -1151,7 +1190,7 @@ TREE *t;
register int x,fd;
register int fdtmp;
char temp_file[STRINGLENGTH], rcs_file[STRINGLENGTH];
union wait status;
int status;
char *uconvert(),*gconvert();
int sendfile ();
int ac;
@ -1200,34 +1239,34 @@ TREE *t;
#endif
av[ac++] = t->Tname;
av[ac++] = NULL;
status.w_status = runio(av,
NULL,
rcs_file,
"/dev/null");
status = runio(av, NULL, rcs_file,
"/dev/null");
/*loginfo("using rcs mode \n");*/
if (status.w_status < 0 || status.w_retcode) {
if (status < 0 || WEXITSTATUS(status)) {
/* Just in case */
unlink(rcs_file);
if (status.w_status < 0) {
goaway ("We died trying to run cvs or rcs");
if (status < 0) {
goaway ("We died trying to run cvs or rcs on %s", rcs_file);
t->Tmode = 0;
}
else {
/*logerr("rcs command failed = %d\n",
status.w_retcode);*/
#if 0
logerr("rcs command failed = %d\n",
WEXITSTATUS(status));
#endif
t->Tflags |= FUPDATE;
}
}
else if (docompress) {
tmpnam(temp_file);
av[0] = "gzip";
av[1] = "-c";
av[1] = "-cf";
av[2] = NULL;
if (runio(av, rcs_file, temp_file, NULL) != 0) {
/* Just in case */
unlink(temp_file);
unlink(rcs_file);
goaway ("We died trying to gzip a file");
goaway ("We died trying to gzip %s", rcs_file);
t->Tmode = 0;
}
fd = open (temp_file,O_RDONLY,0);
@ -1241,12 +1280,12 @@ TREE *t;
if (docompress) {
tmpnam(temp_file);
av[0] = "gzip";
av[1] = "-c";
av[1] = "-cf";
av[2] = NULL;
if (runio(av, t->Tname, temp_file, NULL) != 0) {
/* Just in case */
unlink(temp_file);
goaway ("We died trying to run gzip");
goaway ("We died trying to gzip %s", t->Tname);
t->Tmode = 0;
}
fd = open (temp_file,O_RDONLY,0);
@ -1268,7 +1307,7 @@ TREE *t;
if (dorcs)
unlink(rcs_file);
#endif
if (x != SCMOK) goaway ("Error sending file to client");
if (x != SCMOK) goaway ("Error sending file %s to client", t->Tname);
return (SCMOK);
}
@ -1289,7 +1328,7 @@ TREE *t;
t->Tuser = salloc (uconvert (t->Tuid));
t->Tgroup = salloc (gconvert (t->Tgid));
x = msgrecv (sendfile,0);
if (x != SCMOK) goaway ("Error sending file to client");
if (x != SCMOK) goaway ("Error sending file %s to client", t->Tname);
return (SCMOK);
}
@ -1302,7 +1341,7 @@ va_list ap;
if ((t->Tmode&S_IFMT) != S_IFREG || listonly || (t->Tflags&FUPDATE))
return (SCMOK);
x = writefile (fd);
if (x != SCMOK) goaway ("Error sending file to client");
if (x != SCMOK) goaway ("Error sending file %s to client", t->Tname);
(void) close (fd);
return (SCMOK);
}
@ -1800,10 +1839,28 @@ struct stat *sinfo;
* determined this empirically -- DLC). Without a fstatfs()
* system call, this will have to do for now.
*/
#ifdef __SVR4
{
struct statvfs sf;
if (fstatvfs(handle, &sf) == -1)
return(-1);
return strcmp(sf.f_basetype, "nfs") != 0;
}
#elif defined(__NetBSD__)
{
struct statfs sf;
if (fstatfs(handle, &sf) == -1)
return(-1);
return strcmp(sf.f_fstypename, "nfs") != 0;
}
#else
if (major(sb.st_dev) == 255 || major(sb.st_dev) == 130)
return(0);
else
return(1);
#endif
return(1);
}
/*

View File

@ -28,6 +28,23 @@
**********************************************************************
* HISTORY
* $Log: vprintf.c,v $
* Revision 1.2 1996/09/05 16:50:13 christos
* - for portability make sure that we never use "" as a pathname, always convert
* it to "."
* - include sockio.h if needed to define SIOCGIFCONF (for svr4)
* - use POSIX signals and wait macros
* - add -S silent flag, so that the client does not print messages unless there
* is something wrong
* - use flock or lockf as appropriate
* - use fstatfs or fstatvfs to find out if a filesystem is mounted over nfs,
* don't depend on the major() = 255 hack; it only works on legacy systems.
* - use gzip -cf to make sure that gzip compresses the file even when the file
* would expand.
* - punt on defining vsnprintf if _IOSTRG is not defined; use sprintf...
*
* To compile sup on systems other than NetBSD, you'll need a copy of daemon.c,
* vis.c, vis.h and sys/cdefs.h. Maybe we should keep those in the distribution?
*
* Revision 1.1.1.1 1993/05/21 14:52:19 cgd
* initial import of CMU's SUP to NetBSD
*
@ -113,6 +130,7 @@ vsnprintf(s, n, fmt, args)
char *s, *fmt;
va_list args;
{
#ifdef _IOSTRG
FILE fakebuf;
fakebuf._flag = _IOSTRG+_IOWRT; /* no _IOWRT: avoid stdio bug */
@ -124,5 +142,9 @@ vsnprintf(s, n, fmt, args)
if (fakebuf._cnt<0)
fakebuf._cnt = 0;
return (n-fakebuf._cnt-1);
#else
/* Will blow up. */
vsprintf(s, fmt, args);
#endif
}
#endif /* NEED_VPRINTF || NEED_VSNPRINTF */