Project

General

Profile

Bug #3940 » check_reload_status.patch

Renato Botelho, 10/30/2014 07:47 AM

View differences:

pfPorts/check_reload_status/files/check_reload_status.c
78 78
static void			set_blockmode(int socket, int cmd);
79 79
struct command *	match_command(struct command *target, char *wordpassed);
80 80
struct command *	parse_command(int fd, int argc, char **argv);
81
static void			socket_read_command(int socket, short event, void *arg);
81
static void			socket_read_command(int socket);
82 82
static void			show_command_list(int fd, const struct command *list);
83 83
static void			socket_accept_command(int socket, short event, void *arg);
84
static void			socket_close_command(int fd, struct event *ev);
85 84
static void			socket_read_fcgi(int, short, void *);
86 85
static void			fcgi_send_command(int, short, void *);
87 86
static int			fcgi_open_socket(struct runq *);
......
528 527
}
529 528

  
530 529
static void
531
socket_close_command(int fd, struct event *ev)
532
{
533
	event_del(ev);
534
	free(ev);
535
        close(fd);
536
}
537

  
538
static void
539 530
socket_read_fcgi(int fd, short event, void *arg)
540 531
{
541 532
	struct runq *tmpcmd = arg;
......
623 614
}
624 615

  
625 616
static void
626
socket_read_command(int fd, short event, void *arg)
617
socket_read_command(int fd)
627 618
{
628 619
	struct command *cmd;
629
	struct event *ev = arg;
630 620
	enum { bufsize = 2048 };
631 621
	char buf[bufsize];
632 622
	register int n;
633 623
	char **ap, *argv[bufsize], *p;
634 624
	int i, loop = 0;
635 625

  
636
	if (event == EV_TIMEOUT) {
637
		socket_close_command(fd, ev);
638
		return;
639
	}
640
		
641 626
tryagain:
642 627
	bzero(buf, sizeof(buf));
643 628
	if ((n = read (fd, buf, bufsize)) == -1) {
......
663 648
	for (i = 0; i < n - 1; i++) {
664 649
		if (!isalpha(buf[i]) && !isspace(buf[i]) && !isdigit(buf[i]) && !ispunct(buf[i])) {
665 650
			write(fd, "ERROR:\tonly alphanumeric chars allowd", 37);
666
			socket_close_command(fd, ev);
651
			close(fd);
667 652
			return;
668 653
		}
669 654
	}
......
696 681
socket_accept_command(int fd, __unused short event, __unused void *arg)
697 682
{
698 683
	struct sockaddr_un sun;
699
	struct timeval tv = { 10, 0 };
700
	struct event *ev;
701 684
	socklen_t len;
702 685
	int newfd;
703 686

  
......
708 691
	}
709 692
	set_blockmode(newfd, O_NONBLOCK | FD_CLOEXEC);
710 693

  
711
	if ((ev = malloc(sizeof(*ev))) == NULL) {
712
		syslog(LOG_ERR, "Cannot allocate new struct event.");
713
		close(newfd);
714
		return;
715
	}
716

  
717
	event_set(ev, newfd, EV_READ | EV_PERSIST, socket_read_command, ev);
718
	event_add(ev, &tv);
694
	socket_read_command(newfd);
719 695
}
720 696

  
721 697
static void
(2-2/2)