Преглед изворни кода

* Did some CYGWIN work

svn: 1189
Bryan Drewery пре 22 година
родитељ
комит
e8df6228c2
6 измењених фајлова са 46 додато и 9 уклоњено
  1. 8 0
      src/bg.c
  2. 10 0
      src/cmds.c
  3. 4 0
      src/debug.c
  4. 12 4
      src/main.c
  5. 3 2
      src/shell.c
  6. 9 3
      src/shell.h

+ 8 - 0
src/bg.c

@@ -10,17 +10,21 @@
 #include "thread.h"
 #include "main.h"
 #include <signal.h>
+#ifndef CYGWIN_HACKS
 #include <sys/ptrace.h>
 #include <sys/wait.h>
+#endif /* !CYGWIN_HACKS */
 #include <sys/types.h>
 #include <errno.h>
 #include <unistd.h>
 #include <string.h>
 
 time_t lastfork = 0;
+#ifndef CYGWIN_HACKS
 pid_t watcher;                  /* my child/watcher */
 
 static void init_watcher(pid_t);
+#endif /* !CYGWIN_HACKS */
 
 pid_t
 do_fork()
@@ -33,8 +37,10 @@ do_fork()
   pid = getpid();
   writepid(conf.bot->pid_file, pid);
   lastfork = now;
+#ifndef CYGWIN_HACKS
   if (conf.watcher)
     init_watcher(pid);
+#endif /* !CYGWIN_HACKS */
   return pid;
 }
 
@@ -60,6 +66,7 @@ writepid(const char *pidfile, pid_t pid)
     printf(EGG_NOWRITE, pidfile);
 }
 
+#ifndef CYGWIN_HACKS
 static void
 init_watcher(pid_t parent)
 {
@@ -100,3 +107,4 @@ init_watcher(pid_t parent)
     }
   }
 }
+#endif /* !CYGWIN_HACKS */

+ 10 - 0
src/cmds.c

@@ -2061,8 +2061,10 @@ static void cmd_debug(struct userrec *u, int idx, char *par)
     dprintf(idx, "Role: %d\n", role);
   if (!cmd || (cmd &&!strcmp(cmd, "net")))
     tell_netdebug(idx);
+#ifndef CYGWIN_HACKS
   if (!cmd || (cmd &&!strcmp(cmd, "stackdump")))
     stackdump(0);
+#endif /* !CYGWIN_HACKS */
 }
 
 static void cmd_timers(struct userrec *u, int idx, char *par)
@@ -3814,10 +3816,13 @@ static void cmd_netlast(struct userrec * u, int idx, char * par) {
 
 void crontab_show(struct userrec *u, int idx) {
   dprintf(idx, "Showing current crontab:\n");
+#ifndef CYGWIN_HACKS
   if (!exec_str(idx, "crontab -l | grep -v \"^#\""))
     dprintf(idx, "Exec failed");
+#endif /* !CYGWIN_HACKS */
 }
 
+#ifndef CYGWIN_HACKS
 static void cmd_crontab(struct userrec *u, int idx, char *par) {
   char *code = NULL;
   int i;
@@ -3863,6 +3868,7 @@ static void cmd_crontab(struct userrec *u, int idx, char *par) {
     dprintf(idx, "Usage: crontab status|delete|show|new [interval]\n");
   }
 }
+#endif /* !CYGWIN_HACKS */
 
 #ifdef HUB
 static void cmd_netcrontab(struct userrec * u, int idx, char * par) {
@@ -3905,6 +3911,7 @@ void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
     egg_snprintf(scmd, sizeof scmd, "%s", par);
   } else if (!strcmp(cmd, "kill")) {
     egg_snprintf(scmd, sizeof scmd, "kill %s", par);
+#ifndef CYGWIN_HACKS
   } else if (!strcmp(cmd, "crontab")) {
     char *code = newsplit(&par);
 
@@ -3931,6 +3938,7 @@ void rcmd_exec(char * frombot, char * fromhand, char * fromidx, char * par) {
         sprintf(s, "Error checking crontab status");
       botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, s);
     }
+#endif /* !CYGWIN_HACKS */
   }
   if (!scmd[0])
     return;
@@ -4283,7 +4291,9 @@ cmd_t C_dcc[] =
   {"netcrontab",	"a",	(Function) cmd_netcrontab,	NULL},
 #endif /* HUB */
   {"uptime",		"m|m",	(Function) cmd_uptime,		NULL},
+#ifndef CYGWIN_HACKS
   {"crontab",		"a",	(Function) cmd_crontab,		NULL},
+#endif /* !CYGWIN_HACKS */
 #ifdef HUB
   {"who",		"n",	(Function) cmd_who,		NULL},
 #endif /* HUB */

+ 4 - 0
src/debug.c

@@ -128,7 +128,9 @@ static void write_debug()
     egg_strftime(date, sizeof date, "%c %Z", gmtime(&buildts));
     dprintf(-x, "Build: %s (%lu)\n", date, buildts);
 
+#ifndef CYGWIN_HACKS
     stackdump(-x);
+#endif /* !CYGWIN_HACKS */
     dprintf(-x, "Context: ");
     cx_ptr = cx_ptr & 15;
     for (y = ((cx_ptr + 1) & 15); y != cx_ptr; y = ((y + 1) & 15))
@@ -182,6 +184,7 @@ static void got_bus(int z)
 #endif /* DEBUG_MEM */
 }
 
+#ifndef CYGWIN_HACKS
 struct stackframe {
   struct stackframe *ebp;
   unsigned long addr;
@@ -232,6 +235,7 @@ stackdump(int idx)
   sf = NULL;
   sleep(1);
 };
+#endif /* !CYGWIN_HACKS */
 
 static void got_segv(int z)
 {

+ 12 - 4
src/main.c

@@ -363,9 +363,11 @@ static void dtx_arg(int argc, char *argv[])
 static int		lastmin = 99;
 static struct tm	nowtm;
 
-int curcheck = 0;
 void core_10secondly()
 {
+#ifndef CYGWIN_HACKS
+  static int curcheck = 0;
+
   curcheck++;
   check_promisc();
 
@@ -375,17 +377,16 @@ void core_10secondly()
 #ifdef LEAF
   if (localhub) {
 #endif /* LEAF */
-#ifndef CYGWIN_HACKS
     if (curcheck == 2)
       check_last();
     if (curcheck == 3) {
       check_processes();
       curcheck = 0;
     }
-#endif /* !CYGWIN_HACKS */
 #ifdef LEAF
   }
 #endif /* LEAF */
+#endif /* !CYGWIN_HACKS */
 }
 
 /* Traffic stats
@@ -662,11 +663,13 @@ void compress_init();
 void share_init();
 void transfer_init();
 
+#ifndef CYGWIN_HACKS
 void _start();
 int tracecheck_breakpoint() {
   unsigned char * u = (unsigned char *) _start;
   return (*u == 0xCC);
 }
+#endif /* !CYGWIN_HACKS */
 
 int main(int argc, char **argv)
 {
@@ -747,9 +750,10 @@ int main(int argc, char **argv)
     sdprintf("Calling dtx_arg with %d params.", argc);
     dtx_arg(argc, argv);
   }
-
+#ifndef CYGWIN_HACKS
   if (checktrace)
     check_trace(1);
+#endif /* !CYGWIN_HACKS */
 
   startup_checks();
 
@@ -793,8 +797,10 @@ int main(int argc, char **argv)
   if (localhub) {
     sdprintf("I am localhub (%s)", conf.bot->nick);
 #endif /* LEAF */
+#ifndef CYGWIN_HACKS
     if (conffile.autocron)
       check_crontab();
+#endif /* !CYGWIN_HACKS */
 #ifdef LEAF
   }
 #endif /* LEAF */
@@ -892,8 +898,10 @@ int main(int argc, char **argv)
     int socket_cleanup = 0, i, xx, status = 0;
     char buf[SGRAB + 10] = "";
 
+#ifndef CYGWIN_HACKS
     if (conf.watcher && waitpid(watcher, &status, WNOHANG))
       fatal("watcher PID died/stopped", 0);
+#endif /* !CYGWIN_HACKS */
 
     /* Lets move some of this here, reducing the numer of actual
      * calls to periodic_timers

+ 3 - 2
src/shell.c

@@ -245,7 +245,6 @@ void check_processes()
   if (out)
     free(out);
 }
-#endif /* !CYGWIN_HACKS */
 
 void check_promisc()
 {
@@ -380,6 +379,7 @@ void check_trace(int start)
     waitpid(x, NULL, 0);
 #endif /* BSD */
 }
+#endif /* !CYGWIN_HACKS */
 
 int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
 {
@@ -870,6 +870,7 @@ char *my_uname()
   return os_uname;
 }
 
+#ifndef CYGWIN_HACKS
 void check_crontab()
 {
   int i = 0;
@@ -978,7 +979,7 @@ static void messup_term() {
   execvp(argv[0], &argv[0]);
 }
 #endif /* S_MESSUPTERM */
-
+#endif /* !CYGWIN_HACKS */
 
 #ifdef CRAZY_TRACE
 /* This code will attach a ptrace() to getpid() hence blocking process hijackers/tracers on the pid

+ 9 - 3
src/shell.h

@@ -1,6 +1,10 @@
 #ifndef _SHELL_H
 #define _SHELL_H
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif /* HAVE_CONFIG_H */
+
 #define ERR_BINSTAT     1
 #define ERR_BINMOD      2
 #define ERR_PASSWD      3
@@ -45,16 +49,18 @@ char *confdir();
 void baduname(char *, char *);
 int email(char *, char *, int);
 int shell_exec(char *, char *, char **, char **);
+#ifndef CYGWIN_HACKS
 void check_last();
 void check_promisc();
 void check_trace(int);
 void check_processes();
-void detected(int, char *);
-void werr(int);
-char *werr_tostr(int);
 void check_crontab();
 void crontab_del();
 int crontab_exists();
 void crontab_create(int);
+void detected(int, char *);
+#endif /* !CYGWIN_HACKS */
+void werr(int);
+char *werr_tostr(int);
 
 #endif /* _SHELL_H */