… | |
… | |
7 | #include <cstdlib> |
7 | #include <cstdlib> |
8 | #include <cstdarg> |
8 | #include <cstdarg> |
9 | #include <cstring> |
9 | #include <cstring> |
10 | |
10 | |
11 | #include <unistd.h> |
11 | #include <unistd.h> |
|
|
12 | #include <fcntl.h> |
12 | #include <sys/types.h> |
13 | #include <sys/types.h> |
13 | #include <sys/stat.h> |
14 | #include <sys/stat.h> |
14 | #include <sys/socket.h> |
15 | #include <sys/socket.h> |
15 | #include <sys/un.h> |
16 | #include <sys/un.h> |
16 | |
17 | |
… | |
… | |
50 | { |
51 | { |
51 | perror ("unable to create listening socket"); |
52 | perror ("unable to create listening socket"); |
52 | exit (EXIT_FAILURE); |
53 | exit (EXIT_FAILURE); |
53 | } |
54 | } |
54 | |
55 | |
|
|
56 | fcntl (fd, F_SETFD, FD_CLOEXEC); |
|
|
57 | |
55 | sockaddr_un sa; |
58 | sockaddr_un sa; |
56 | |
59 | |
57 | sa.sun_family = AF_UNIX; |
60 | sa.sun_family = AF_UNIX; |
58 | strcpy (sa.sun_path, sockname); |
61 | strcpy (sa.sun_path, sockname); |
59 | |
62 | |
… | |
… | |
81 | void unix_listener::accept_cb (io_watcher &w, short revents) |
84 | void unix_listener::accept_cb (io_watcher &w, short revents) |
82 | { |
85 | { |
83 | int fd2 = accept (fd, 0, 0); |
86 | int fd2 = accept (fd, 0, 0); |
84 | |
87 | |
85 | if (fd2 >= 0) |
88 | if (fd2 >= 0) |
|
|
89 | { |
|
|
90 | fcntl (fd2, F_SETFD, FD_CLOEXEC); |
86 | new server (fd2); |
91 | new server (fd2); |
|
|
92 | } |
87 | } |
93 | } |
88 | |
94 | |
89 | void server::log_msg (const char *msg) |
95 | void server::log_msg (const char *msg) |
90 | { |
96 | { |
91 | send ("MSG"), send (msg); |
97 | send ("MSG"), send (msg); |