]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/tools.h
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / tools.h
index 3effa13cbeb33c1c61f04d90cd3ded1ea8d841b8..3834f513ef11dfc6db7f8d3aef71662fb331fb4a 100644 (file)
 /*
- * DEBUG: section 21    Misc Functions
- * AUTHOR: Harvest Derived
- *
- * SQUID Web Proxy Cache          http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- *  Squid is the result of efforts by numerous individuals from
- *  the Internet community; see the CONTRIBUTORS file for full
- *  details.   Many organizations have provided support for Squid's
- *  development; see the SPONSORS file for full details.  Squid is
- *  Copyrighted (C) 2001 by the Regents of the University of
- *  California; see the COPYRIGHT file for full details.  Squid
- *  incorporates software developed and/or copyrighted by other
- *  sources; see the CREDITS file for full details.
- *
- *  This program 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 this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
+ * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
  *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 21    Misc Functions */
+
 #ifndef SQUID_TOOLS_H_
 #define SQUID_TOOLS_H_
 
-#include "Packer.h"
-#include "SquidString.h"
+#include "sbuf/SBuf.h"
 #include "typedefs.h"
 
 class MemBuf;
 
 extern int DebugSignal;
 
-extern void kb_incr(kb_t *, size_t);
-extern void parseEtcHosts(void);
-extern int getMyPort(void);
-extern void setUmask(mode_t mask);
-extern void strwordquote(MemBuf * mb, const char *str);
+/// The Squid -n parameter service name.
+/// Default is APP_SHORTNAME ('squid').
+extern SBuf service_name;
+
+void parseEtcHosts(void);
+int getMyPort(void);
+void setUmask(mode_t mask);
+void strwordquote(MemBuf * mb, const char *str);
+
+class Packable;
+
+/* a common objPackInto interface; used by debugObj */
+typedef void (*ObjPackMethod) (void *obj, Packable * p);
 
 /* packs, then prints an object using debugs() */
-extern void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm);
-
-extern const char *getMyHostname(void);
-extern const char *uniqueHostname(void);
-
-extern void death(int sig);
-extern void sigusr2_handle(int sig);
-extern void sig_child(int sig);
-extern void sig_shutdown(int sig); ///< handles shutdown notifications from kids
-extern void leave_suid(void);
-extern void enter_suid(void);
-extern void no_suid(void);
-extern void writePidFile(void);
-extern void setMaxFD(void);
-extern void setSystemLimits(void);
-extern void squid_signal(int sig, SIGHDLR *, int flags);
-extern pid_t readPidFile(void);
-extern void keepCapabilities(void);
-extern void BroadcastSignalIfAny(int& sig);
+void debugObj(int section, int level, const char *label, void *obj, ObjPackMethod pm);
+
+/// callback type for signal handlers
+typedef void SIGHDLR(int sig);
+
+const char *getMyHostname(void);
+const char *uniqueHostname(void);
+
+void death(int sig);
+void sigusr2_handle(int sig);
+void sig_child(int sig);
+void sig_shutdown(int sig); ///< handles shutdown notifications from kids
+void leave_suid(void);
+void enter_suid(void);
+void no_suid(void);
+void setMaxFD(void);
+void setSystemLimits(void);
+void squid_signal(int sig, SIGHDLR *, int flags);
+void keepCapabilities(void);
+void BroadcastSignalIfAny(int& sig);
 
 /// whether the current process is the parent of all other Squid processes
-extern bool IamMasterProcess();
+bool IamMasterProcess();
 /**
  *   whether the current process is dedicated to doing things that only
  *   a single process should do, such as PID file maintenance and WCCP
  */
-extern bool IamPrimaryProcess();
+bool IamPrimaryProcess();
 /// whether the current process coordinates worker processes
-extern bool IamCoordinatorProcess();
+bool IamCoordinatorProcess();
 /// whether the current process handles HTTP transactions and such
-extern bool IamWorkerProcess();
+bool IamWorkerProcess();
 /// whether the current process is dedicated to managing a cache_dir
-extern bool IamDiskProcess();
+bool IamDiskProcess();
 /// Whether we are running in daemon mode
-extern bool InDaemonMode(); // try using specific Iam*() checks above first
+bool InDaemonMode(); // try using specific Iam*() checks above first
 /// Whether there should be more than one worker process running
-extern bool UsingSmp(); // try using specific Iam*() checks above first
+bool UsingSmp(); // try using specific Iam*() checks above first
 /// number of Kid processes as defined in src/ipc/Kid.h
-extern int NumberOfKids();
+int NumberOfKids();
 /// a string describing this process roles such as worker or coordinator
-extern String ProcessRoles();
+SBuf ProcessRoles();
+
+void debug_trap(const char *);
+
+void logsFlush(void);
+
+void squid_getrusage(struct rusage *r);
+double rusage_cputime(struct rusage *r);
+int rusage_maxrss(struct rusage *r);
+int rusage_pagefaults(struct rusage *r);
+void releaseServerSockets(void);
+void PrintRusage(void);
+void dumpMallocStats(void);
+
+#if _SQUID_NEXT_
+typedef union wait PidStatus;
+#else
+typedef int PidStatus;
+#endif
 
-extern void debug_trap(const char *);
-extern void *xmemset(void *dst, int, size_t);
+/**
+ * Compatibility wrapper function for waitpid
+ * \pid the pid of child proccess to wait for.
+ * \param status the exit status returned by waitpid
+ * \param flags WNOHANG or 0
+ */
+pid_t WaitForOnePid(pid_t pid, PidStatus &status, int flags);
 
-extern void logsFlush(void);
+/**
+ * Wait for state changes in any of the kid processes.
+ * Equivalent to waitpid(-1, ...) system call
+ * \param status the exit status returned by waitpid
+ * \param flags WNOHANG or 0
+ */
+inline pid_t WaitForAnyPid(PidStatus &status, int flags)
+{
+    return WaitForOnePid(-1, status, flags);
+}
 
-extern void squid_getrusage(struct rusage *r);
-extern double rusage_cputime(struct rusage *r);
-extern int rusage_maxrss(struct rusage *r);
-extern int rusage_pagefaults(struct rusage *r);
-extern void releaseServerSockets(void);
-extern void PrintRusage(void);
-extern void dumpMallocStats(void);
+#if _SQUID_WINDOWS_
+/// xstrerror(errno) equivalent for Windows errors returned by GetLastError()
+SBuf WindowsErrorMessage(DWORD errorId);
+#endif // _SQUID_WINDOWS_
 
 #endif /* SQUID_TOOLS_H_ */
+