]>
git.saurik.com Git - apple/syslog.git/blob - syslogd.tproj/remote.c
2 * Copyright (c) 2004-2008 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/types.h>
26 #include <sys/socket.h>
27 #include <netinet/in.h>
28 #include <netinet/tcp.h>
29 #include <arpa/inet.h>
42 #include <asl_memory.h>
45 #define forever for(;;)
47 #define MY_ID "remote"
49 #define LOCKDOWN_PATH "/var/run/lockdown"
50 #define SYSLOG_SOCK_PATH "/var/run/lockdown/syslog.sock"
51 #define ASL_REMOTE_PORT 203
63 typedef uint32_t notify_state_t
;
64 extern int notify_set_state(int, notify_state_t
);
66 typedef uint64_t notify_state_t
;
69 extern char *asl_list_to_string(asl_search_result_t
*list
, uint32_t *outlen
);
70 extern size_t asl_memory_size(asl_memory_t
*s
);
71 extern uint32_t db_query(aslresponse query
, aslresponse
*res
, uint64_t startid
, int count
, int flags
, uint64_t *lastid
, int32_t ruid
, int32_t rgid
);
73 #define SESSION_WRITE(f,x) if (write(f, x, strlen(x)) < 0) goto exit_session
76 remote_db_size(uint32_t sel
)
78 if (sel
== DB_TYPE_FILE
) return global
.db_file_max
;
79 if (sel
== DB_TYPE_MEMORY
) return global
.db_memory_max
;
80 if (sel
== DB_TYPE_MINI
) return global
.db_mini_max
;
85 remote_db_set_size(uint32_t sel
, uint32_t size
)
87 if (sel
== DB_TYPE_FILE
) global
.db_file_max
= size
;
88 if (sel
== DB_TYPE_MEMORY
) global
.db_memory_max
= size
;
89 if (sel
== DB_TYPE_MINI
) global
.db_mini_max
= size
;
94 remote_db_stats(uint32_t sel
)
99 if (sel
== DB_TYPE_FILE
) asl_store_statistics(global
.file_db
, &m
);
100 if (sel
== DB_TYPE_MEMORY
) asl_memory_statistics(global
.memory_db
, &m
);
101 if (sel
== DB_TYPE_MINI
) asl_mini_memory_statistics(global
.mini_db
, &m
);
108 int i
, *sp
, s
, wfd
, status
, pfmt
, watch
, wtoken
, nfd
, do_prompt
, filter
;
110 asl_search_result_t ql
;
115 char str
[1024], *p
, *qs
, *out
;
118 uint64_t low_id
, high_id
;
119 notify_state_t nstate
;
122 if (x
== NULL
) pthread_exit(NULL
);
133 if (global
.dbtype
& DB_TYPE_MEMORY
) dbselect
= DB_TYPE_MEMORY
;
134 else if (global
.dbtype
& DB_TYPE_MINI
) dbselect
= DB_TYPE_MINI
;
135 else if (global
.dbtype
& DB_TYPE_FILE
) dbselect
= DB_TYPE_FILE
;
142 memset(&ql
, 0, sizeof(asl_search_result_t
));
144 snprintf(str
, sizeof(str
) - 1, "\n========================\nASL is here to serve you\n");
145 if (write(s
, str
, strlen(str
)) < 0)
158 snprintf(str
, sizeof(str
) - 1, "> ");
159 SESSION_WRITE(s
, str
);
163 memset(str
, 0, sizeof(str
));
171 FD_SET(wfd
, &readfds
);
172 if (wfd
> nfd
) nfd
= wfd
;
175 status
= select(nfd
+ 1, &readfds
, NULL
, NULL
, NULL
);
177 if ((wfd
!= -1) && (FD_ISSET(wfd
, &readfds
)))
179 len
= read(wfd
, &i
, sizeof(int));
182 if (FD_ISSET(s
, &readfds
))
184 len
= read(s
, str
, sizeof(str
) - 1);
185 if (len
<= 0) goto exit_session
;
187 while ((len
> 1) && ((str
[len
- 1] == '\n') || (str
[len
- 1] == '\r')))
193 if ((!strcmp(str
, "q")) || (!strcmp(str
, "quit")) || (!strcmp(str
, "exit")))
195 snprintf(str
, sizeof(str
) - 1, "Goodbye\n");
196 write(s
, str
, strlen(str
));
202 if ((!strcmp(str
, "?")) || (!strcmp(str
, "help")))
204 snprintf(str
, sizeof(str
) - 1, "Commands\n");
205 SESSION_WRITE(s
, str
);
206 snprintf(str
, sizeof(str
) - 1, " quit exit session\n");
207 SESSION_WRITE(s
, str
);
208 snprintf(str
, sizeof(str
) - 1, " select [val] get [set] current database\n");
209 SESSION_WRITE(s
, str
);
210 snprintf(str
, sizeof(str
) - 1, " val must be \"file\", \"mem\", or \"mini\"\n");
211 SESSION_WRITE(s
, str
);
212 snprintf(str
, sizeof(str
) - 1, " file [on/off] enable / disable file store\n");
213 SESSION_WRITE(s
, str
);
214 snprintf(str
, sizeof(str
) - 1, " memory [on/off] enable / disable memory store\n");
215 SESSION_WRITE(s
, str
);
216 snprintf(str
, sizeof(str
) - 1, " mini [on/off] enable / disable mini memory store\n");
217 SESSION_WRITE(s
, str
);
218 snprintf(str
, sizeof(str
) - 1, " stats database statistics\n");
219 SESSION_WRITE(s
, str
);
220 snprintf(str
, sizeof(str
) - 1, " flush flush database\n");
221 SESSION_WRITE(s
, str
);
222 snprintf(str
, sizeof(str
) - 1, " dbsize [val] get [set] database size (# of records)\n");
223 SESSION_WRITE(s
, str
);
224 snprintf(str
, sizeof(str
) - 1, " filter [val] get [set] current database filter\n");
225 SESSION_WRITE(s
, str
);
226 snprintf(str
, sizeof(str
) - 1, " [p]anic (emergency) [a]lert [c]ritical [e]rror\n");
227 SESSION_WRITE(s
, str
);
228 snprintf(str
, sizeof(str
) - 1, " [w]arning [n]otice [i]nfo [d]ebug\n");
229 SESSION_WRITE(s
, str
);
230 snprintf(str
, sizeof(str
) - 1, " watch print new messages as they arrive\n");
231 SESSION_WRITE(s
, str
);
232 snprintf(str
, sizeof(str
) - 1, " stop stop watching for new messages\n");
233 SESSION_WRITE(s
, str
);
234 snprintf(str
, sizeof(str
) - 1, " raw use raw format for printing messages\n");
235 SESSION_WRITE(s
, str
);
236 snprintf(str
, sizeof(str
) - 1, " std use standard format for printing messages\n");
237 SESSION_WRITE(s
, str
);
238 snprintf(str
, sizeof(str
) - 1, " * show all log messages\n");
239 SESSION_WRITE(s
, str
);
240 snprintf(str
, sizeof(str
) - 1, " * key val equality search for messages (single key/value pair)\n");
241 SESSION_WRITE(s
, str
);
242 snprintf(str
, sizeof(str
) - 1, " * op key val search for matching messages (single key/value pair)\n");
243 SESSION_WRITE(s
, str
);
244 snprintf(str
, sizeof(str
) - 1, " * [op key val] ... search for matching messages (multiple key/value pairs)\n");
245 SESSION_WRITE(s
, str
);
246 snprintf(str
, sizeof(str
) - 1, " operators: = < > ! (not equal) T (key exists) R (regex)\n");
247 SESSION_WRITE(s
, str
);
248 snprintf(str
, sizeof(str
) - 1, " modifiers (must follow operator):\n");
249 SESSION_WRITE(s
, str
);
250 snprintf(str
, sizeof(str
) - 1, " C=casefold N=numeric S=substring A=prefix Z=suffix\n");
251 SESSION_WRITE(s
, str
);
252 snprintf(str
, sizeof(str
) - 1, "\n");
253 SESSION_WRITE(s
, str
);
256 else if (!strcmp(str
, "stats"))
258 stats
= remote_db_stats(dbselect
);
259 out
= asl_format_message(stats
, ASL_MSG_FMT_RAW
, ASL_TIME_FMT_SEC
, ASL_ENCODE_NONE
, &outlen
);
260 write(s
, out
, outlen
);
265 else if (!strcmp(str
, "flush"))
267 else if (!strncmp(str
, "select", 6))
270 while ((*p
== ' ') || (*p
== '\t')) p
++;
273 if (dbselect
== 0) snprintf(str
, sizeof(str
) - 1, "no store\n");
274 else if (dbselect
== DB_TYPE_FILE
) snprintf(str
, sizeof(str
) - 1, "file store\n");
275 else if (dbselect
== DB_TYPE_MEMORY
) snprintf(str
, sizeof(str
) - 1, "memory store\n");
276 else if (dbselect
== DB_TYPE_MINI
) snprintf(str
, sizeof(str
) - 1, "mini memory store\n");
277 SESSION_WRITE(s
, str
);
281 if (!strncmp(p
, "file", 4))
283 if ((global
.dbtype
& DB_TYPE_FILE
) == 0)
285 snprintf(str
, sizeof(str
) - 1, "file database is not enabled\n");
286 SESSION_WRITE(s
, str
);
290 dbselect
= DB_TYPE_FILE
;
292 else if (!strncmp(p
, "mem", 3))
294 if ((global
.dbtype
& DB_TYPE_MEMORY
) == 0)
296 snprintf(str
, sizeof(str
) - 1, "memory database is not enabled\n");
297 SESSION_WRITE(s
, str
);
301 dbselect
= DB_TYPE_MEMORY
;
303 else if (!strncmp(p
, "mini", 4))
305 if ((global
.dbtype
& DB_TYPE_MINI
) == 0)
307 if (global
.mini_db
!= NULL
)
309 snprintf(str
, sizeof(str
) - 1, "mini memory database is enabled for disaster messages\n");
310 SESSION_WRITE(s
, str
);
314 snprintf(str
, sizeof(str
) - 1, "mini memory database is not enabled\n");
315 SESSION_WRITE(s
, str
);
320 dbselect
= DB_TYPE_MINI
;
324 snprintf(str
, sizeof(str
) - 1, "unknown database type\n");
325 SESSION_WRITE(s
, str
);
329 snprintf(str
, sizeof(str
) - 1, "OK\n");
330 SESSION_WRITE(s
, str
);
333 else if (!strncmp(str
, "file", 4))
336 while ((*p
== ' ') || (*p
== '\t')) p
++;
339 snprintf(str
, sizeof(str
) - 1, "file database is %senabled\n", (global
.dbtype
& DB_TYPE_FILE
) ? "" : "not ");
340 SESSION_WRITE(s
, str
);
341 if ((global
.dbtype
& DB_TYPE_FILE
) != 0) dbselect
= DB_TYPE_FILE
;
345 if (!strcmp(p
, "on")) global
.dbtype
|= DB_TYPE_FILE
;
346 else if (!strcmp(p
, "off")) global
.dbtype
&= ~ DB_TYPE_FILE
;
348 snprintf(str
, sizeof(str
) - 1, "OK\n");
349 SESSION_WRITE(s
, str
);
352 else if (!strncmp(str
, "memory", 6))
355 while ((*p
== ' ') || (*p
== '\t')) p
++;
358 snprintf(str
, sizeof(str
) - 1, "memory database is %senabled\n", (global
.dbtype
& DB_TYPE_MEMORY
) ? "" : "not ");
359 SESSION_WRITE(s
, str
);
360 if ((global
.dbtype
& DB_TYPE_MEMORY
) != 0) dbselect
= DB_TYPE_MEMORY
;
364 if (!strcmp(p
, "on")) global
.dbtype
|= DB_TYPE_MEMORY
;
365 else if (!strcmp(p
, "off")) global
.dbtype
&= ~ DB_TYPE_MEMORY
;
367 snprintf(str
, sizeof(str
) - 1, "OK\n");
368 SESSION_WRITE(s
, str
);
371 else if (!strncmp(str
, "mini", 4))
374 while ((*p
== ' ') || (*p
== '\t')) p
++;
377 snprintf(str
, sizeof(str
) - 1, "mini database is %senabled\n", (global
.dbtype
& DB_TYPE_MINI
) ? "" : "not ");
378 SESSION_WRITE(s
, str
);
379 if ((global
.dbtype
& DB_TYPE_MINI
) != 0) dbselect
= DB_TYPE_MINI
;
383 if (!strcmp(p
, "on")) global
.dbtype
|= DB_TYPE_MINI
;
384 else if (!strcmp(p
, "off")) global
.dbtype
&= ~ DB_TYPE_MINI
;
386 snprintf(str
, sizeof(str
) - 1, "OK\n");
387 SESSION_WRITE(s
, str
);
390 else if (!strncmp(str
, "dbsize", 6))
394 snprintf(str
, sizeof(str
) - 1, "no store\n");
395 SESSION_WRITE(s
, str
);
400 while ((*p
== ' ') || (*p
== '\t')) p
++;
403 snprintf(str
, sizeof(str
) - 1, "DB size %u\n", remote_db_size(dbselect
));
404 SESSION_WRITE(s
, str
);
409 remote_db_set_size(dbselect
, i
);
411 snprintf(str
, sizeof(str
) - 1, "OK\n");
412 SESSION_WRITE(s
, str
);
415 else if (!strncmp(str
, "filter", 6))
418 while ((*p
== ' ') || (*p
== '\t')) p
++;
421 snprintf(str
, sizeof(str
) - 1, "%s%s%s%s%s%s%s%s\n",
422 (global
.asl_log_filter
& ASL_FILTER_MASK_EMERG
) ? "p" : "",
423 (global
.asl_log_filter
& ASL_FILTER_MASK_ALERT
) ? "a" : "",
424 (global
.asl_log_filter
& ASL_FILTER_MASK_CRIT
) ? "c" : "",
425 (global
.asl_log_filter
& ASL_FILTER_MASK_ERR
) ? "e" : "",
426 (global
.asl_log_filter
& ASL_FILTER_MASK_WARNING
) ? "w" : "",
427 (global
.asl_log_filter
& ASL_FILTER_MASK_NOTICE
) ? "n" : "",
428 (global
.asl_log_filter
& ASL_FILTER_MASK_INFO
) ? "i" : "",
429 (global
.asl_log_filter
& ASL_FILTER_MASK_DEBUG
) ? "d" : "");
430 SESSION_WRITE(s
, str
);
435 if ((*p
>= '0') && (*p
<= '7'))
438 filter
= ASL_FILTER_MASK_UPTO(i
);
444 if ((*p
== 'p') || (*p
== 'P')) filter
|= ASL_FILTER_MASK_EMERG
;
445 else if ((*p
== 'a') || (*p
== 'A')) filter
|= ASL_FILTER_MASK_ALERT
;
446 else if ((*p
== 'c') || (*p
== 'C')) filter
|= ASL_FILTER_MASK_CRIT
;
447 else if ((*p
== 'e') || (*p
== 'E')) filter
|= ASL_FILTER_MASK_ERR
;
448 else if ((*p
== 'w') || (*p
== 'W')) filter
|= ASL_FILTER_MASK_WARNING
;
449 else if ((*p
== 'n') || (*p
== 'N')) filter
|= ASL_FILTER_MASK_NOTICE
;
450 else if ((*p
== 'i') || (*p
== 'I')) filter
|= ASL_FILTER_MASK_INFO
;
451 else if ((*p
== 'd') || (*p
== 'D')) filter
|= ASL_FILTER_MASK_DEBUG
;
456 status
= notify_register_check(NOTIFY_SYSTEM_ASL_FILTER
, &i
);
457 if (status
!= NOTIFY_STATUS_OK
)
459 snprintf(str
, sizeof(str
) - 1, "FAILED %d\n", status
);
460 SESSION_WRITE(s
, str
);
465 status
= notify_set_state(i
, nstate
);
466 if (status
!= NOTIFY_STATUS_OK
)
468 snprintf(str
, sizeof(str
) - 1, "FAILED %d\n", status
);
469 SESSION_WRITE(s
, str
);
473 status
= notify_post(NOTIFY_SYSTEM_ASL_FILTER
);
476 global
.asl_log_filter
= filter
;
478 snprintf(str
, sizeof(str
) - 1, "OK\n");
479 SESSION_WRITE(s
, str
);
484 else if (!strcmp(str
, "stop"))
489 notify_cancel(wtoken
);
496 if (query
!= NULL
) free(query
);
499 snprintf(str
, sizeof(str
) - 1, "OK\n");
500 SESSION_WRITE(s
, str
);
504 snprintf(str
, sizeof(str
) - 1, "not watching!\n");
505 SESSION_WRITE(s
, str
);
508 else if (!strcmp(str
, "raw"))
513 else if (!strcmp(str
, "std"))
518 else if (!strcmp(str
, "watch"))
522 snprintf(str
, sizeof(str
) - 1, "already watching!\n");
523 SESSION_WRITE(s
, str
);
527 status
= notify_register_file_descriptor(SELF_DB_NOTIFICATION
, &wfd
, 0, &wtoken
);
530 snprintf(str
, sizeof(str
) - 1, "notify_register_file_descriptor failed: %d\n", status
);
531 SESSION_WRITE(s
, str
);
537 snprintf(str
, sizeof(str
) - 1, "OK\n");
538 SESSION_WRITE(s
, str
);
541 else if ((str
[0] == '*') || (str
[0] == 'T') || (str
[0] == '=') || (str
[0] == '!') || (str
[0] == '<') || (str
[0] == '>'))
543 memset(&ql
, 0, sizeof(asl_search_result_t
));
544 if (query
!= NULL
) free(query
);
549 while ((*p
== ' ') || (*p
== '\t')) p
++;
558 asprintf(&qs
, "Q %s", p
);
559 query
= asl_msg_from_string(qs
);
562 else if ((*p
== 'T') || (*p
== '=') || (*p
== '!') || (*p
== '<') || (*p
== '>') || (*p
== 'R'))
565 asprintf(&qs
, "Q [%s]", p
);
566 query
= asl_msg_from_string(qs
);
572 asprintf(&qs
, "Q [= %s]", p
);
573 query
= asl_msg_from_string(qs
);
579 snprintf(str
, sizeof(str
) - 1, "unrecognized command\n");
580 SESSION_WRITE(s
, str
);
581 snprintf(str
, sizeof(str
) - 1, "enter \"help\" for help\n");
582 SESSION_WRITE(s
, str
);
594 if (watch
== 0) low_id
= 0;
596 memset(&res
, 0, sizeof(aslresponse
));
598 status
= db_query(&ql
, (aslresponse
*)&res
, low_id
, 0, 0, &high_id
, 0, 0);
600 if ((watch
== 1) && (high_id
>= low_id
)) low_id
= high_id
+ 1;
606 snprintf(str
, sizeof(str
) - 1, "-nil-\n");
607 SESSION_WRITE(s
, str
);
611 if (do_prompt
!= 2) do_prompt
= 0;
614 else if (pfmt
== PRINT_RAW
)
618 snprintf(str
, sizeof(str
) - 1, "\n");
619 SESSION_WRITE(s
, str
);
623 out
= asl_list_to_string((asl_search_result_t
*)res
, &outlen
);
624 write(s
, out
, outlen
);
627 snprintf(str
, sizeof(str
) - 1, "\n");
628 SESSION_WRITE(s
, str
);
634 snprintf(str
, sizeof(str
) - 1, "\n");
635 SESSION_WRITE(s
, str
);
638 for (i
= 0; i
< res
->count
; i
++)
640 out
= asl_format_message(res
->msg
[i
], ASL_MSG_FMT_STD
, ASL_TIME_FMT_LCL
, ASL_ENCODE_SAFE
, &outlen
);
641 write(s
, out
, outlen
);
646 aslresponse_free(res
);
657 if (watch
== 1) notify_cancel(wtoken
);
658 if (query
!= NULL
) asl_free(query
);
663 remote_acceptmsg(int fd
, int tcp
)
666 int s
, status
, flags
, *sp
;
669 struct sockaddr_storage from
;
671 fromlen
= sizeof(struct sockaddr_un
);
672 if (tcp
== 1) fromlen
= sizeof(struct sockaddr_storage
);
674 memset(&from
, 0, sizeof(from
));
676 s
= accept(fd
, (struct sockaddr
*)&from
, &fromlen
);
679 asldebug("%s: accept: %s\n", MY_ID
, strerror(errno
));
683 flags
= fcntl(s
, F_GETFL
, 0);
684 flags
&= ~ O_NONBLOCK
;
685 status
= fcntl(s
, F_SETFL
, flags
);
688 asldebug("%s: fcntl: %s\n", MY_ID
, strerror(errno
));
696 setsockopt(s
, IPPROTO_TCP
, TCP_NODELAY
, &flags
, sizeof(int));
699 sp
= malloc(sizeof(int));
702 asldebug("%s: malloc: %s\n", MY_ID
, strerror(errno
));
709 pthread_attr_init(&attr
);
710 pthread_attr_setdetachstate(&attr
, PTHREAD_CREATE_DETACHED
);
711 pthread_create(&t
, &attr
, (void *(*)(void *))session
, (void *)sp
);
712 pthread_attr_destroy(&attr
);
718 remote_acceptmsg_local(int fd
)
720 return remote_acceptmsg(fd
, 0);
724 remote_acceptmsg_tcp(int fd
)
726 return remote_acceptmsg(fd
, 1);
730 remote_init_lockdown(void)
732 int status
, reuse
, fd
;
733 struct sockaddr_un local
;
735 fd
= socket(AF_UNIX
, SOCK_STREAM
, 0);
738 asldebug("%s: socket: %s\n", MY_ID
, strerror(errno
));
743 status
= setsockopt(fd
, SOL_SOCKET
, SO_REUSEPORT
, &reuse
, sizeof(int));
746 asldebug("%s: setsockopt: %s\n", MY_ID
, strerror(errno
));
751 /* make sure the lockdown directory exists */
752 mkdir(LOCKDOWN_PATH
, 0777);
754 memset(&local
, 0, sizeof(local
));
755 local
.sun_family
= AF_UNIX
;
756 strlcpy(local
.sun_path
, SYSLOG_SOCK_PATH
, sizeof(local
.sun_path
));
757 unlink(local
.sun_path
);
759 status
= bind(fd
, (struct sockaddr
*)&local
, sizeof(local
.sun_family
) + sizeof(local
.sun_path
));
763 asldebug("%s: bind: %s\n", MY_ID
, strerror(errno
));
768 status
= fcntl(fd
, F_SETFL
, O_NONBLOCK
);
771 asldebug("%s: fcntl: %s\n", MY_ID
, strerror(errno
));
776 status
= listen(fd
, 5);
779 asldebug("%s: listen: %s\n", MY_ID
, strerror(errno
));
784 chmod(SYSLOG_SOCK_PATH
, 0666);
786 aslevent_addfd(fd
, 0, remote_acceptmsg_local
, NULL
, NULL
);
791 remote_init_tcp(int family
)
793 int status
, reuse
, fd
;
794 struct sockaddr_in a4
;
795 struct sockaddr_in6 a6
;
799 fd
= socket(family
, SOCK_STREAM
, 0);
802 asldebug("%s: socket: %s\n", MY_ID
, strerror(errno
));
807 status
= setsockopt(fd
, SOL_SOCKET
, SO_REUSEPORT
, &reuse
, sizeof(int));
810 asldebug("%s: setsockopt: %s\n", MY_ID
, strerror(errno
));
815 memset(&(a4
.sin_addr
), 0, sizeof(struct in_addr
));
816 a4
.sin_family
= AF_INET
;
817 a4
.sin_port
= htons(ASL_REMOTE_PORT
);
819 memset(&(a6
.sin6_addr
), 0, sizeof(struct in6_addr
));
820 a6
.sin6_family
= AF_INET6
;
821 a6
.sin6_port
= htons(ASL_REMOTE_PORT
);
823 s
= (struct sockaddr
*)&a4
;
824 len
= sizeof(struct sockaddr_in
);
826 if (family
== AF_INET6
)
828 s
= (struct sockaddr
*)&a6
;
829 len
= sizeof(struct sockaddr_in6
);
832 status
= bind(fd
, s
, len
);
835 asldebug("%s: bind: %s\n", MY_ID
, strerror(errno
));
840 status
= fcntl(fd
, F_SETFL
, O_NONBLOCK
);
843 asldebug("%s: fcntl: %s\n", MY_ID
, strerror(errno
));
848 status
= listen(fd
, 5);
851 asldebug("%s: listen: %s\n", MY_ID
, strerror(errno
));
856 aslevent_addfd(fd
, 0, remote_acceptmsg_tcp
, NULL
, NULL
);
863 asldebug("%s: init\n", MY_ID
);
866 rfdl
= remote_init_lockdown();
870 rfd4
= remote_init_tcp(AF_INET
);
874 rfd6
= remote_init_tcp(AF_INET6
);
883 if (rfdl
>= 0) close(rfdl
);
886 if (rfd4
>= 0) close(rfd4
);
889 if (rfd6
>= 0) close(rfd6
);
899 return remote_init();