Check-in [7c87881fd0]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Use poll which is portable
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | scgi
Files: files | file ages | folders
SHA1:7c87881fd0872ac326217bbb4e8d46fd9cdfc8ca
User & Date: bapt 2015-04-23 17:08:03
Context
2015-04-23
17:10
Cleanup headers check-in: ac89e3afa7 user: bapt tags: scgi
17:08
Use poll which is portable check-in: 7c87881fd0 user: bapt tags: scgi
16:02
Load properly comments check-in: 1f8c4959f1 user: bapt tags: scgi
Changes

Changes to web/main.c.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
...
161
162
163
164
165
166
167

168
169
170
171
172

173
174
175
176
177
178
179
180
181




182
183
184





185



186
187
188
189
190
191
192




#include <unistd.h>
#include <err.h>
#include <syslog.h>
#include <signal.h>
#include <string.h>
#include <sys/types.h>
#include <sys/event.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <netdb.h>
#include <sys/sbuf.h>
#include <fcntl.h>
#include <errno.h>
#include <ctype.h>
#include <ucl.h>

#include "cblogweb.h"

#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif

ucl_object_t *conf = NULL;
int fd;
const char *unix_sock_path = NULL;

static void
client_process(int fd)
{
	pid_t me;
	socklen_t sz;
	struct sockaddr_storage ss;
	int cfd, c;
	size_t hdr = 0;
	char *tofree, *header;
	size_t next;


	sz = sizeof(ss);
	cfd = accept(fd, (struct sockaddr *)&ss, &sz);
	if (cfd < 0)
		err(EXIT_FAILURE, "fork()");

	me = fork();
	if (me < 0)
		err(EXIT_FAILURE, "fork()");
	if (me > 0) {
		close(cfd);
		return;
	}

	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	if (STDIN_FILENO != dup2(cfd, STDIN_FILENO))
		err(EXIT_FAILURE, "fork()");
	if (STDOUT_FILENO != dup2(cfd, STDOUT_FILENO))
		err(EXIT_FAILURE, "fork()");
................................................................................

	ucl_object_unref(conf);
	conf = o;
}

static void
serve(void) {

	int kq;
	struct kevent ke;

	if ((kq = kqueue()) == -1) {
		warn("kqueue()");

		close_socket(EXIT_FAILURE);
	}

	EV_SET(&ke, fd,  EVFILT_READ, EV_ADD, 0, 0, NULL);
	kevent(kq, &ke, 1, NULL, 0, NULL);

	for (;;) {
		kevent(kq, NULL, 0, &ke, 1, NULL);
		if (ke.flags & (EV_ERROR | EV_EOF))




			err(EXIT_FAILURE, "An error occured");

		if (ke.filter == EVFILT_READ)





			client_process(ke.ident);



	}
}

int
main(int argc, char **argv, char **envp)
{
	struct sockaddr_un un;
>
>
>
>





<
<
<
<
<
<
<
<
<


|












|

<
<
<
<



>

<
<

|
<
<
<
<
<
<
<
<







 







>
|
<

|
<
>
|
|
<
<
<
<

<
<
>
>
>
>

|
<
>
>
>
>
>
|
>
>
>







1
2
3
4
5
6
7
8
9









10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26




27
28
29
30
31


32
33








34
35
36
37
38
39
40
...
143
144
145
146
147
148
149
150
151

152
153

154
155
156




157


158
159
160
161
162
163

164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <sys/stat.h>
#include <sys/socket.h>
#include <sys/un.h>

#include <unistd.h>
#include <err.h>
#include <syslog.h>
#include <signal.h>
#include <string.h>









#include <errno.h>
#include <ctype.h>
#include <poll.h>

#include "cblogweb.h"

#ifndef UNIX_PATH_MAX
#define UNIX_PATH_MAX 108
#endif

ucl_object_t *conf = NULL;
int fd;
const char *unix_sock_path = NULL;

static void
client_process(int cfd)
{




	size_t hdr = 0;
	char *tofree, *header;
	size_t next;
	char c;



	if (cfd < 0)
		err(EXIT_FAILURE, "accept()");









	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	if (STDIN_FILENO != dup2(cfd, STDIN_FILENO))
		err(EXIT_FAILURE, "fork()");
	if (STDOUT_FILENO != dup2(cfd, STDOUT_FILENO))
		err(EXIT_FAILURE, "fork()");
................................................................................

	ucl_object_unref(conf);
	conf = o;
}

static void
serve(void) {
	struct pollfd pfd;
	int clfd;


	memset(&pfd, 0, sizeof(pfd));

	pfd.fd = fd;
	pfd.events = POLLIN|POLLERR;





	for (;;) {


		pfd.revents = 0;
		if (poll(&pfd, 1, -1) < 0) {
			if (errno == EAGAIN)
				continue;
			err(EXIT_FAILURE, "An error occured");
		}

		if (! (pfd.revents & POLLIN))
			continue;

		clfd = accept(pfd.fd, NULL, NULL);
		if (fork() == 0) {
			client_process(fd);
			/* Not reached */
		}
		close(clfd);
	}
}

int
main(int argc, char **argv, char **envp)
{
	struct sockaddr_un un;