Author: Bleep <tomh@inxpress.net>
[ircu2.10.12-pk.git] / ircd / support.c
index ebc17950ecf43c790432b756f49201ac662564d5..6f9821173a88e6f523d2f83840baa8c39019066c 100644 (file)
  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * $Id$
  */
-
-#include "sys.h"
-#ifdef _SEQUENT_
-#include <sys/timers.h>
-#include <stddef.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <stdarg.h>
-#include <signal.h>
-#include "h.h"
-#include "send.h"
+#include "support.h"
+#include "fileio.h"
 #include "ircd.h"
+#include "ircd_chattr.h"
 #include "s_bsd.h"
-#include "support.h"
+#include "s_debug.h"
+#include "send.h"
 #include "sprintf_irc.h"
-#include "common.h"
-#include "fileio.h"
-
-RCSTAG_CC("$Id$");
-
-#ifndef HAVE_STRTOKEN
-/*
- * strtoken.c
- *
- * Walk through a string of tokens, using a set of separators.
- * -argv 9/90
- */
-char *strtoken(char **save, char *str, char *fs)
-{
-  char *pos = *save;           /* keep last position across calls */
-  Reg1 char *tmp;
-
-  if (str)
-    pos = str;                 /* new string scan */
-
-  while (pos && *pos && strchr(fs, *pos) != NULL)
-    pos++;                     /* skip leading separators */
-
-  if (!pos || !*pos)
-    return (pos = *save = NULL);       /* string contains only sep's */
-
-  tmp = pos;                   /* now, keep position of the token */
-
-  while (*pos && strchr(fs, *pos) == NULL)
-    pos++;                     /* skip content of the token */
-
-  if (*pos)
-    *pos++ = '\0';             /* remove first sep after the token */
-  else
-    pos = NULL;                        /* end of string */
-
-  *save = pos;
-  return (tmp);
-}
-#endif /* !HAVE_STRTOKEN */
-
-#ifndef HAVE_STRERROR
-/*
- * strerror
- *
- * Returns an appropriate system error string to a given errno.
- * -argv 11/90
- */
-
-char *strerror(int err_no)
-{
-  static char buff[40];
-  char *errp;
-
-  errp = (err_no > sys_nerr ? (char *)NULL : sys_errlist[err_no]);
-
-  if (errp == (char *)NULL)
-  {
-    errp = buff;
-    sprintf_irc(errp, "Unknown Error %d", err_no);
-  }
-  return errp;
-}
-
-#endif /* !HAVE_STRERROR */
-
-/*
- * inetntoa --    Changed the parameter to NOT take a pointer.
- *                -Run 4/8/97
- * inetntoa --    Changed name to remove collision possibility and
- *                so behaviour is garanteed to take a pointer arg.
- *                -avalon 23/11/92
- * inet_ntoa --   Returned the dotted notation of a given
- *                internet number (some ULTRIX don't have this)
- *                -argv 11/90.
- * inet_ntoa --   Its broken on some Ultrix/Dynix too. -avalon
- */
-char *inetntoa(struct in_addr in)
-{
-  static char buf[16];
-  Reg1 unsigned char *s = (unsigned char *)&in.s_addr;
-  Reg2 unsigned char a, b, c, d;
-
-  a = *s++;
-  b = *s++;
-  c = *s++;
-  d = *s++;
-  sprintf_irc(buf, "%u.%u.%u.%u", a, b, c, d);
-
-  return buf;
-}
-
-#ifndef HAVE_INET_NETOF
-/*
- *    inet_netof --   return the net portion of an internet number
- *                    argv 11/90
- */
-int inet_netof(struct in_addr in)
-{
-  int addr = in.s_net;
-
-  if (addr & 0x80 == 0)
-    return ((int)in.s_net);
-
-  if (addr & 0x40 == 0)
-    return ((int)in.s_net * 256 + in.s_host);
-
-  return ((int)in.s_net * 256 + in.s_host * 256 + in.s_lh);
-}
-
-#endif /* !HAVE_INET_NETOF */
+#include "sys.h"
 
-#ifndef HAVE_GETTIMEOFDAY
-/* This is copied from ircu3.0.0 (with permission), not vica versa. */
-int gettimeofday(struct timeval *tv, void * /*UNUSED*/)
-{
-  register int ret;
-  static struct timespec tp;
-
-  if ((ret = getclock(TIMEOFDAY, &tp)))
-    return ret;
-  tv->tv_sec = (long)tp.tv_sec;
-  tv->tv_usec = (tp.tv_nsec + 500) / 1000;
-  return 0;
-}
-#endif /* !HAVE_GETTIMEOFDAY */
+#include <signal.h>   /* kill */
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
 
 #ifdef DEBUGMODE
 
@@ -178,11 +53,7 @@ void dumpcore(const char *pattern, ...)
   if (!lastd)
     lastd = now;
   else if (now - lastd < 60 && dumps > 2)
-#ifdef __cplusplus
-    s_die(0);
-#else
-    s_die();
-#endif
+    server_die("too many core dumps");
   if (now - lastd > 60)
   {
     lastd = now;
@@ -196,33 +67,29 @@ void dumpcore(const char *pattern, ...)
     kill(p, 3);
     kill(p, 9);
   }
-  write_pidfile();
   sprintf_irc(corename, "core.%d", p);
   rename("core", corename);
   Debug((DEBUG_FATAL, "Dumped core : core.%d", p));
   sendto_ops("Dumped core : core.%d", p);
   vdebug(DEBUG_FATAL, pattern, vl);
   vsendto_ops(pattern, vl);
-#ifdef __cplusplus
-  s_die(0);
-#else
-  s_die();
-#endif
-
   va_end(vl);
+
+  server_die("debug core dump");
+
 }
 #endif
 
 int check_if_ipmask(const char *mask)
 {
   int has_digit = 0;
-  register const char *p;
+  const char *p;
 
   for (p = mask; *p; ++p)
     if (*p != '*' && *p != '?' && *p != '.')
     {
-      if (!isDigit(*p))
-       return 0;
+      if (!IsDigit(*p))
+        return 0;
       has_digit = -1;
     }