config.log
config.h
config.status
+Makefile
*.new
if ! test -f $(etcsubdir)/system.override; then \
$(INSTALL_DATA) -o root -g root system.override $(etcsubdir); fi
-daemon: overlord.o process.o servexec.o parserlexer.o debug.o lib.o
+daemon: overlord.o process.o servexec.o parserlexer.o debug.o lib.o both.o
+ $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+client: client.o both.o
$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
lexer.l: language.i4
sed -e '/<version><\/version>/ s/>/&$(VERSION)/' \
spec.sgml.in >$@.new && mv -f $@.new $@
-client.o: config.h common.h pcsum.h version.h
+client.o: config.h common.h pcsum.h both.h version.h
-process.o: config.h common.h pcsum.h daemon.h lib.h tokens.h
+process.o: config.h common.h pcsum.h both.h daemon.h lib.h tokens.h
overlord.o: config.h common.h pcsum.h daemon.h
--- /dev/null
+/*
+ * userv - both.c
+ * Useful very-low-level utility routines, used in both client and daemon.
+ * These do not (and cannot) depend on infrastructure eg syscallerror,
+ * because these are not the same.
+ *
+ * Copyright (C)1999 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Some nasty people can return 0/EOF + EINTR from stdio !
+ * These functions attempt to work around this braindamage by retrying
+ * the call after clearerr. If this doesn't work then clearly your
+ * libc is _completely_ fubar rather than just somewhat fubar.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+#include "both.h"
+
+int working_getc(FILE *file) {
+ int c;
+
+ for (;;) {
+ c= getc(file);
+ if (c != EOF || errno != EINTR) return c;
+ clearerr(file);
+ }
+}
+
+size_t working_fread(void *ptr, size_t sz, FILE *file) {
+ size_t done, nr;
+
+ done= 0;
+ for (;;) {
+ nr= fread((char*)ptr + done, 1, sz-done, file);
+ done += nr;
+ if (done == sz || !ferror(file) || errno != EINTR) return done;
+ clearerr(file);
+ }
+}
--- /dev/null
+/*
+ * userv - lib.c
+ * Useful very-low-level utility routines' declarations,
+ * for both client and daemon.
+ *
+ * Copyright (C)1999 Ian Jackson
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with userv; if not, write to the Free Software
+ * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef BOTH_H
+#define BOTH_H
+
+int working_getc(FILE *file);
+size_t working_fread(void *ptr, size_t sz, FILE *file);
+
+#endif
#include "config.h"
#include "common.h"
+#include "both.h"
#include "version.h"
enum fdmodifiervalues {
static void xfread(void *p, size_t sz, FILE *file) {
size_t nr;
- nr= fread(p,1,sz,file);
+ nr= working_fread(p,sz,file);
if (nr != sz) protoreaderror(file,"in data");
}
protoerror("stderr message length %d is far too long",
progress_r->data.errmsg.messagelen);
for (i=0; i<progress_r->data.errmsg.messagelen; i++) {
- c= getc(file); if (c==EOF) protoreaderror(file,"in error message");
+ c= working_getc(file);
+ if (c==EOF) protoreaderror(file,"in error message");
if (isprint(c)) putc(c,stderr);
else fprintf(stderr,"\\x%02x",(unsigned char)c);
}
if (child == 0 || (child == -1 && errno == ECHILD)) break;
if (child == -1) syscallerror("wait for child process (in sigchld handler)");
for (fd=0; fd<fdsetupsize && fdsetup[fd].catpid != child; fd++);
+fprintf(stderr,"chld found pid=%ld fd=%d setupsize=%d\n",(long)child,fd,fdsetupsize);
if (fd>=fdsetupsize) continue; /* perhaps the caller gave us children */
if ((WIFEXITED(status) && WEXITSTATUS(status)==0) ||
(WIFSIGNALED(status) && WTERMSIG(status)==SIGPIPE) ||
struct sigaction sig;
char catnamebuf[sizeof(int)*3+30];
int fd, reading;
+ pid_t child;
for (fd=0; fd<fdsetupsize; fd++) {
if (!fdsetup[fd].filename) continue;
if (fdsetup[fd].copyfd<0)
syscallerror("open file `%s' for fd %d",fdsetup[fd].filename,fd);
}
- fdsetup[fd].catpid= fork();
- if (fdsetup[fd].catpid==-1) syscallerror("fork for cat for fd %d",fd);
- if (!fdsetup[fd].catpid) {
+ blocksignals(SIG_BLOCK);
+ child= fork();
+ fdsetup[fd].catpid= child;
+ blocksignals(SIG_UNBLOCK);
+ if (child==-1) syscallerror("fork for cat for fd %d",fd);
+ if (!child) {
snprintf(catnamebuf,sizeof(catnamebuf),"cat fd%d",fd);
catnamebuf[sizeof(catnamebuf)-1]= 0;
sig.sa_handler= SIG_DFL;
be security-critical, and the bug can be avoided by not using
"-quoted strings in configuration files.)
+ * Fixed spurious failure with `Interrupted system call' on systems
+ where fread can fail due to read giving EINTR (blech!)
+
+ * Fixed race when fd closed at startup, which could cause
+ `system call failure: kill cat for <fd>: No such process'.
+
* Fixed spurious assertion failure if user's home directory not
accessible.
-
* Fixed a couple of memory and fd leaks in error exits from
include-directory and include-lookup in parser.c.
* Debian package description mentions use by system admin.
- --
+ -- Ian Jackson <ian@davenant.greenend.org.uk> Sat, 30 Jan 1999 22:54:29 +0000
*** Main changelog file included here - see far down this file for the
* userv - lib.c
* useful utility routines, used in daemon, but not very dependent on it
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1997,1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* userv - lib.c
* useful utility routines' imports and exports, used in daemon
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1997,1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* about m4 quoting &c., but we have to #include it so that the C
* objects from the lexer are available.
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* userv - process.c
* daemon code to process one request (is parent of service process)
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
#include "config.h"
#include "common.h"
+#include "both.h"
#include "daemon.h"
#include "lib.h"
#include "tokens.h"
static void xfread(void *p, size_t sz) {
size_t nr;
- nr= fread(p,1,sz,srfile); if (nr == sz) return;
+ nr= working_fread(p,sz,srfile); if (nr == sz) return;
if (ferror(srfile)) syscallerror("reading from client");
blocksignals();
assert(feof(srfile));
* userv - execserv.c
* daemon code which executes actual service (ie child process)
*
- * Copyright (C)1996-1997 Ian Jackson
+ * Copyright (C)1996-1997,1999 Ian Jackson
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by