/*
- * $Id: comm.cc,v 1.290 1998/10/13 23:33:33 wessels Exp $
+ * $Id: comm.cc,v 1.291 1998/11/12 23:07:34 wessels Exp $
*
* DEBUG: section 5 Socket Functions
* AUTHOR: Harvest Derived
F->flags.called_connect = 1;
Counter.syscalls.sock.connects++;
x = connect(sock, (struct sockaddr *) address, sizeof(*address));
- debug(5, 9) ("connect FD %d: %s\n", sock, xstrerror());
+ if (x < 0)
+ debug(5, 9) ("connect FD %d: %s\n", sock, xstrerror());
} else {
errlen = sizeof(err);
x = getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen);
/*
- * $Id: ipc.cc,v 1.12 1998/11/12 06:28:12 wessels Exp $
+ * $Id: ipc.cc,v 1.13 1998/11/12 23:07:35 wessels Exp $
*
* DEBUG: section 54 Interprocess Communication
* AUTHOR: Duane Wessels
debug(50, 0) ("ipcCreate: FD %d accept: %s\n", crfd, xstrerror());
_exit(1);
}
- debug(54, 3) ("ipcCreate: accepted new FD %d\n", fd);
+ debug(54, 3) ("ipcCreate: CHILD accepted new FD %d\n", fd);
close(crfd);
cwfd = crfd = fd;
} else if (type == IPC_UDP_SOCKET) {
snprintf(env_str, tmp_s, "SQUID_DEBUG=%s", Config.debugOptions);
putenv(env_str);
#endif
+ dup2(fileno(debug_log), 2);
+ if (fileno(debug_log) > 2)
+ fclose(debug_log);
dup2(crfd, 0);
dup2(cwfd, 1);
- dup2(fileno(debug_log), 2);
- fclose(debug_log);
/*
* Solaris pthreads seems to close FD 0 upon fork(), so don't close
* this FD if its 0, 1, or 2.
/*
- * $Id: main.cc,v 1.276 1998/11/12 06:28:14 wessels Exp $
+ * $Id: main.cc,v 1.277 1998/11/12 23:07:36 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
comm_init();
comm_select_init();
- /* we have to init fdstat here. */
- fd_open(0, FD_LOG, "stdin");
- fd_open(1, FD_LOG, "stdout");
- fd_open(2, FD_LOG, "stderr");
-
+ if (opt_no_daemon) {
+ /* we have to init fdstat here. */
+ fd_open(0, FD_LOG, "stdin");
+ fd_open(1, FD_LOG, "stdout");
+ fd_open(2, FD_LOG, "stderr");
+ }
mainInitialize();
/* main loop */
int status;
#endif
pid_t pid;
+ int i;
if (*(argv[0]) == '(')
return;
+ openlog(appname, LOG_PID | LOG_NDELAY | LOG_CONS, LOG_LOCAL4);
+ if ((pid = fork()) < 0)
+ syslog(LOG_ALERT, "fork failed: %s", xstrerror());
+ else if (pid > 0)
+ exit(0);
+ if (setsid() < 0)
+ syslog(LOG_ALERT, "setsid failed: %s", xstrerror());
+#ifdef TIOCNOTTY
+ if ((i = open("/dev/tty", O_RDWR)) >= 0) {
+ ioctl(i, TIOCNOTTY, NULL);
+ close(i);
+ }
+#endif
+ for (i = 0; i < Squid_MaxFD; i++)
+ close(i);
+ umask(0);
for (;;) {
- if (fork() == 0) {
+ if ((pid = fork()) == 0) {
/* child */
prog = xstrdup(argv[0]);
argv[0] = xstrdup("(squid)");
execvp(prog, argv);
- fatal("execvp failed");
+ syslog(LOG_ALERT, "execvp failed: %s", xstrerror());
}
- /* parent */ time(&start);
- do {
- squid_signal(SIGINT, SIG_IGN, SA_RESTART);
+ /* parent */
+ syslog(LOG_NOTICE, "Squid Parent: child process %d started", pid);
+ time(&start);
+ squid_signal(SIGINT, SIG_IGN, SA_RESTART);
#ifdef _SQUID_NEXT_
- pid = wait3(&status, 0, NULL);
+ pid = wait3(&status, 0, NULL);
#else
- pid = waitpid(-1, &status, 0);
+ pid = waitpid(-1, &status, 0);
#endif
- } while (pid > 0);
time(&stop);
+ if (WIFEXITED(status)) {
+ syslog(LOG_NOTICE,
+ "Squid Parent: child process %d exited with status %d",
+ pid, WEXITSTATUS(status));
+ } else if (WIFSIGNALED(status)) {
+ syslog(LOG_NOTICE,
+ "Squid Parent: child process %d exited due to signal %d",
+ pid, WTERMSIG(status));
+ } else {
+ syslog(LOG_NOTICE, "Squid Parent: child process %d exited", pid);
+ }
if (stop - start < 10)
failcount++;
else
failcount = 0;
- if (failcount == 5)
+ if (failcount == 5) {
+ syslog(LOG_ALERT, "Exiting due to repeated, frequent failures");
exit(1);
+ }
if (WIFEXITED(status))
if (WEXITSTATUS(status) == 0)
exit(0);
#endif
memClean();
#if !XMALLOC_TRACE
- file_close(0);
- file_close(1);
- file_close(2);
+ if (opt_no_daemon) {
+ file_close(0);
+ file_close(1);
+ file_close(2);
+ }
#endif
fdDumpOpen();
fdFreeMemory();
/*
- * $Id: protos.h,v 1.285 1998/11/12 06:28:20 wessels Exp $
+ * $Id: protos.h,v 1.286 1998/11/12 23:07:37 wessels Exp $
*
*
* SQUID Internet Object Cache http://squid.nlanr.net/Squid/
extern const char *gb_to_str(const gb_t *);
extern void gb_flush(gb_t *); /* internal, do not use this */
extern int stringHasWhitespace(const char *);
+extern void xassert(const char *, const char *, int);
#if USE_HTCP
extern void htcpInit(void);
/*
- * $Id: squid.h,v 1.178 1998/11/12 06:28:24 wessels Exp $
+ * $Id: squid.h,v 1.179 1998/11/12 23:07:38 wessels Exp $
*
* AUTHOR: Duane Wessels
*
#endif
#if PURIFY
-/* disable assert() under purify */
-#define NODEBUG
+#define assert(EX) ((void)0)
+#elif __STDC__
+#define assert(EX) ((EX)?((void)0):xassert( # EX , __FILE__, __LINE__))
+#else
+#define assert(EX) ((EX)?((void)0):xassert("EX", __FILE__, __LINE__))
#endif
#if HAVE_UNISTD_H
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
-#if HAVE_ASSERT_H
-#include <assert.h>
-#else
-#define assert(X) ((void)0)
-#endif
#if HAVE_DIRENT_H
#include <dirent.h>
/*
- * $Id: tools.cc,v 1.170 1998/10/14 21:12:03 wessels Exp $
+ * $Id: tools.cc,v 1.171 1998/11/12 23:07:39 wessels Exp $
*
* DEBUG: section 21 Misc Functions
* AUTHOR: Harvest Derived
if (!store_rebuilding)
storeDirWriteCleanLogs(0);
fatal_common(message);
- exit(1);
+ exit(shutting_down ? 0 : 1);
}
/* printf-style interface for fatal */
{
return (strcspn(s, w_space) != strlen(s));
}
+
+void
+xassert(const char *msg, const char *file, int line)
+{
+ debug(0, 0) ("assertion failed: %s:%d: \"%s\"\n", file, line, msg);
+ if (!shutting_down)
+ abort();
+}