View | Details | Raw Unified | Return to bug 157488
Collapse All | Expand All

(-)nagircbot/Makefile (-1 / +1 lines)
Lines 6-12 Link Here
6
#
6
#
7
7
8
PORTNAME=	nagircbot
8
PORTNAME=	nagircbot
9
PORTVERSION=	0.0.20
9
PORTVERSION=	0.0.33
10
CATEGORIES=	net-mgmt irc
10
CATEGORIES=	net-mgmt irc
11
MASTER_SITES=	http://www.vanheusden.com/nagircbot/
11
MASTER_SITES=	http://www.vanheusden.com/nagircbot/
12
EXTRACT_SUFX=	.tgz
12
EXTRACT_SUFX=	.tgz
(-)nagircbot/distinfo (-2 / +2 lines)
Lines 1-2 Link Here
1
SHA256 (nagircbot-0.0.20.tgz) = 22164ff2290c4bf2bebda60d5c09438f61e1973529d03a53bebd3bb36e43fc59
1
SHA256 (nagircbot-0.0.33.tgz) = 7a7c63a409bdad125b19ec852a772746eda2b1feef71bbdf58bd2a2c785a0887
2
SIZE (nagircbot-0.0.20.tgz) = 17548
2
SIZE (nagircbot-0.0.33.tgz) = 20085
(-)nagircbot/files/patch-Makefile (-10 / +6 lines)
Lines 1-19 Link Here
1
--- Makefile.orig	Mon Nov 27 06:21:58 2006
1
--- Makefile.orig	2011-01-18 05:39:10.000000000 -0500
2
+++ Makefile	Sat Apr 28 14:14:16 2007
2
+++ Makefile	2011-05-31 22:06:29.000000000 -0400
3
@@ -1,9 +1,10 @@
3
@@ -3,7 +3,7 @@
4
 VERSION=0.0.20
4
 VERSION=0.0.33
5
 
5
 
6
 DEBUG= -g  -D_DEBUG #-fprofile-arcs -ftest-coverage # -pg -g
6
 DEBUG= -g  -D_DEBUG #-fprofile-arcs -ftest-coverage # -pg -g
7
-CXXFLAGS+=-Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG)
7
-CXXFLAGS+=-Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG)
8
+CXXFLAGS+=-DUSE_MMAP -Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG)
8
+CXXFLAGS+=-DUSE_MMAP -Wall -O2 -DVERSION=\"${VERSION}\" $(DEBUG)
9
 CFLAGS+=${CXXFLAGS}
9
 CFLAGS+=${CXXFLAGS}
10
-LDFLAGS+=$(DEBUG) -lstdc++
10
 LDFLAGS+=$(DEBUG) -lcrypto -lssl -lstdc++
11
+LDFLAGS+=$(DEBUG) -lstdc++ -lutil
12
+PREFIX?=/usr/local
13
 
11
 
14
 OBJS=error.o log.o utils.o br.o pl.o anna.o
12
@@ -15,7 +15,7 @@
15
 
16
@@ -13,7 +14,7 @@
17
 	$(CC) -Wall -W $(OBJS) $(LDFLAGS) -o nagircbot
13
 	$(CC) -Wall -W $(OBJS) $(LDFLAGS) -o nagircbot
18
 
14
 
19
 install: nagircbot
15
 install: nagircbot
(-)nagircbot/files/patch-anna.cpp (-119 / +27 lines)
Lines 1-75 Link Here
1
--- anna.cpp.orig	Mon Nov 27 06:21:58 2006
1
--- anna.cpp.orig	2011-01-18 05:39:10.000000000 -0500
2
+++ anna.cpp	Sat Apr 28 19:27:02 2007
2
+++ anna.cpp	2011-05-31 22:45:11.000000000 -0400
3
@@ -12,6 +12,8 @@
3
@@ -23,6 +23,7 @@
4
 #include <stdlib.h>
4
 #include "ssl.h"
5
 #include <signal.h>
6
 #include <pwd.h>
7
+#include <sys/param.h>
8
+#include <libutil.h>
9
 
10
 #include "utils.h"
11
 #include "pl.h"
12
@@ -19,6 +21,7 @@
13
 #include "error.h"
14
 #include "log.h"
5
 #include "log.h"
15
 }
6
 }
16
+#include "anna.h"
7
+#include "anna.h"
17
 
8
 
18
 #define S_DISCONNECTED		1
9
 #define S_DISCONNECTED		1
19
 #define S_CONNECTED		2
10
 #define S_CONNECTED		2
20
@@ -39,6 +42,7 @@
11
@@ -43,6 +44,7 @@
21
 int minimum_time_for_successfull_login = 25; // one needs to be on-channel for at least 5 seconds to be considered a successfull login
12
 int minimum_time_for_successfull_login = 25; // one needs to be on-channel for at least 5 seconds to be considered a successfull login
22
 int join_timeout = 5;	// it should take no longer then 5 seconds to join a channel, otherwhise: abort connection and retry
13
 int join_timeout = 5;	// it should take no longer then 5 seconds to join a channel, otherwhise: abort connection and retry
23
 int max_n_join_tries = 2;	// try 2 times to get on a channel
14
 int max_n_join_tries = 2;	// try 2 times to get on a channel
24
+int throttle_delay = 1; // don't send more than one message per 1 seconds
15
+int throttle_delay = 1; // don't send more than one message per 1 seconds
25
 char *server = "localhost:6667";	/* default irc server */
16
 char *server = "localhost:6667";	/* default irc server */
26
 char *channel = "#nagircbot";	/* default channel to connect to */
17
 char *channel = "#nagircbot";	/* default channel to connect to */
27
 char *nick = "nagircbot";
18
 char *nick_prefix = "";   /* prefix text for all messages sent to channel */
28
@@ -56,7 +60,7 @@
19
@@ -53,7 +55,7 @@
29
 int max_time_last_host_update = 300, max_time_oldest_host_update = 3600, max_time_last_host_check = 300, max_time_oldest_host_check = 3 * 86400, max_time_last_service_check = 20 * 60, max_time_oldest_service_check = 3 * 86400, max_time_oldest_next_service_check = 20 * 60;
20
 int one_line = 1;
30
 
21
 char *username = "Nagios IRC Bot " VERSION ", (C) www.vanheusden.com";	/* complete username */
31
 char *state_str[4] = { " OK ", "WARN", "CRIT", " ?? " };
22
 int verbose = 255;		/* default is log everything */
32
-char *color_str[4] = { mystrdup("_3,1 "), mystrdup("_8,1 "), mystrdup("_4,1 "), mystrdup("_11,1 ") }; /* FIXME */
23
-char *statuslog = "/usr/local/nagios/var/status.log";
33
+char *color_str[4] = { mystrdup("_9,1 "), mystrdup("_8,1 "), mystrdup("_4,1 "), mystrdup("_11,1 ") }; /* FIXME */
24
+char *statuslog = "/var/spool/nagios/status.dat";
34
 struct stats *prev = NULL;
25
 int statuslog_version = 2;
35
 int n_prev = 0;
26
 int statuslog_location = L_FILE;
36
 char topic[4096] = { 0 };
27
 char use_colors = 0;
37
@@ -105,13 +109,18 @@
28
@@ -174,6 +176,13 @@
38
 	if (irc_set_nick(fd, nick) == -1)
39
 		return -1;
40
 
41
+    /* "Currently this requires that clients send a PASS command before sending
42
+     * the NICK/USER combination and servers *must* send a PASS command before
43
+     * any SERVER command." */
44
+	if (password != NULL) {
45
+        if (send_irc(fd, "PASS %s", password) == -1)
46
+			return -1;
47
+	}
48
+
49
 	/* FIXME: localhost must be, ehr, local host */
50
 	if (send_irc(fd, "USER %s \"localhost\" \"%s\" :%s", user, server, username) == -1)
51
 		return -1;
52
 
53
-	if (password != NULL && send_irc(fd, "PASS %s", password) == -1)
54
-		return -1;
55
-
56
 	return 0;
57
 }
58
 
29
 
59
@@ -153,6 +162,12 @@
30
 int irc_privmsg(server_t server_conn, char *channel, char *msg)
60
 
61
 int irc_privmsg(int fd, char *channel, char *msg)
62
 {
31
 {
63
+    static time_t last_msg = time(NULL);
32
+	static time_t last_msg = time(NULL);
64
+    time_t diff = time(NULL) - last_msg;
33
+	time_t diff = time(NULL) - last_msg;
65
+    if (diff < throttle_delay) {
34
+	if (diff < throttle_delay) {
66
+            sleep(throttle_delay - diff);
35
+		sleep(throttle_delay - diff);
67
+    }
36
+	}
68
+    time(&last_msg);
37
+	time(&last_msg);
69
 	return send_irc(fd, "PRIVMSG %s :%s", channel, msg);
38
+
39
 	return send_irc(server_conn, "PRIVMSG %s :%s", channel, msg);
70
 }
40
 }
71
 
41
 
72
@@ -166,7 +181,7 @@
42
@@ -192,7 +201,7 @@
73
 
43
 
74
 		/* open file or connection to nagios status socket */
44
 		/* open file or connection to nagios status socket */
75
 		if (is_file == 1)     /* file */
45
 		if (is_file == 1)     /* file */
Lines 78-84 Link Here
78
 		else
48
 		else
79
 			fd = connect_to(statuslog);
49
 			fd = connect_to(statuslog);
80
 		if (fd == -1)
50
 		if (fd == -1)
81
@@ -416,7 +431,7 @@
51
@@ -490,7 +499,7 @@
82
 	if (verbose > 1) dolog("reload_statuslog started");
52
 	if (verbose > 1) dolog("reload_statuslog started");
83
 
53
 
84
 	if (statuslog_location == L_FILE)     /* file */
54
 	if (statuslog_location == L_FILE)     /* file */
Lines 87-151 Link Here
87
 	else
57
 	else
88
 		fd_sl = connect_to(statuslog);
58
 		fd_sl = connect_to(statuslog);
89
 
59
 
90
@@ -712,6 +727,7 @@
91
 	printf("-z user	user to run as\n");
92
 	printf("-H     show only state type 'HARD' (default)\n");
93
 	printf("-S     show also state type 'SOFT'\n");
94
+	printf("-P file store the pid in a file\n");
95
 }
96
 
97
 int main(int argc, char *argv[])
98
@@ -724,14 +740,19 @@
99
 	time_t time_join_channel_started = (time_t)0;
100
 	time_t time_tcp_connected = (time_t)0;
101
 	int join_tries = 0;
102
-	char *runas = NULL;
103
+	char *runas = NULL, *pidfile = NULL;
104
+     	pid_t otherpid;
105
+
106
 
107
 	color_str[0][0] = color_str[1][0] = color_str[2][0] = color_str[3][0] = 3;
108
 
109
-	while((c = getopt(argc, argv, "xXF:f:i:hHSs:c:Ctn:u:U:p:T:mvdVz:")) != -1)
110
+	while((c = getopt(argc, argv, "xXP:F:f:i:hHSs:c:Ctn:u:U:p:T:mvdVz:")) != -1)
111
 	{
112
 		switch(c)
113
 		{
114
+			case 'P':
115
+				pidfile = optarg;
116
+				break;
117
 			case 'z':
118
 				runas = optarg;
119
 				break;
120
@@ -867,6 +888,14 @@
121
 		}
122
 	}
123
 
124
+     pfh = pidfile_open(pidfile, 0600, &otherpid);
125
+     if (pfh == NULL) {
126
+             if (errno == EEXIST)
127
+                     error_exit("Daemon already running, pid: %d.", otherpid);
128
+             /* If we cannot create pidfile from other reasons, only warn. */
129
+             dolog("Cannot open or create pidfile");
130
+     }
131
+
132
 	if (do_fork)
133
 	{
134
 		if (daemon(0, 0) == -1)
135
@@ -875,6 +904,9 @@
136
 		}
137
 	}
138
 
139
+     pidfile_write(pfh);
140
+
141
+
142
 	signal(SIGPIPE, SIG_IGN);
143
 
144
 	for(;;)
145
@@ -1056,5 +1088,6 @@
146
 		}
147
 	}
148
 
149
+	pidfile_remove(pfh);
150
 	return 0;
151
 }
(-)nagircbot/files/patch-br.h (-7 / +6 lines)
Lines 1-15 Link Here
1
--- br.h.orig	Mon Nov 27 06:21:58 2006
1
--- br.h.orig	2011-01-18 05:39:10.000000000 -0500
2
+++ br.h	Sat Apr 28 13:45:23 2007
2
+++ br.h	2011-05-31 22:12:14.000000000 -0400
3
@@ -16,6 +16,8 @@
3
@@ -1,5 +1,7 @@
4
  *
4
 /* (C) 2006-2010 by folkert@vanheusden.com GPLv2 applies */
5
  */
6
 
5
 
7
+#include <sys/types.h>
6
+#include <sys/types.h>
8
+
7
+
9
 /* code taken from linux kernel */
8
 /* code taken from linux kernel */
10
 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
9
 #if __GNUC__ == 2 && __GNUC_MINOR__ < 96
11
 #define __builtin_expect(x, expected_value) (x)
10
 #define __builtin_expect(x, expected_value) (x)
12
@@ -33,7 +35,7 @@
11
@@ -17,7 +19,7 @@
13
         char *buffer;
12
         char *buffer;
14
         long long int buffer_length, buffer_pointer;
13
         long long int buffer_length, buffer_pointer;
15
 	char *mmap_addr, *cur_offset;
14
 	char *mmap_addr, *cur_offset;
Lines 18-24 Link Here
18
 
17
 
19
         int number_of_bytes_in_buffer(void);
18
         int number_of_bytes_in_buffer(void);
20
         int read_into_buffer(void);
19
         int read_into_buffer(void);
21
@@ -46,5 +48,5 @@
20
@@ -30,5 +32,5 @@
22
 
21
 
23
         char * read_line(void);
22
         char * read_line(void);
24
 
23
 
(-)nagircbot/files/patch-error.c (-11 lines)
Lines 7-20 Link Here
7
+#include <sys/param.h>
7
+#include <sys/param.h>
8
+#include <libutil.h>
8
+#include <libutil.h>
9
+#include "anna.h"
9
+#include "anna.h"
10
 
11
 void error_exit(char *format, ...)
12
 {
13
@@ -17,6 +20,7 @@
14
 
15
 	fprintf(stderr, "%s: errno=%d (if applicable)\n", buffer, errno);
16
 	syslog(LOG_ERR, "'%s': %m", buffer);
17
+	pidfile_remove(pfh);
18
 
19
 	exit(EXIT_FAILURE);
20
 }

Return to bug 157488