|
Lines 55-60
Link Here
|
| 55 |
#include "common/msgq.h" |
55 |
#include "common/msgq.h" |
| 56 |
#include "microdc.h" |
56 |
#include "microdc.h" |
| 57 |
|
57 |
|
|
|
58 |
/* Define the macro below for orphan handle checking (useful for debugging) */ |
| 59 |
#define CHECK_ORPHAN_HANDLES |
| 60 |
|
| 61 |
#ifdef CHECK_ORPHAN_HANDLES |
| 62 |
#define IF_ORPHAN_HANDLES(x) x |
| 63 |
#else |
| 64 |
#define IF_ORPHAN_HANDLES(x) |
| 65 |
#endif |
| 66 |
|
| 58 |
enum { |
67 |
enum { |
| 59 |
VERSION_OPT = 256, |
68 |
VERSION_OPT = 256, |
| 60 |
HELP_OPT |
69 |
HELP_OPT |
|
Lines 489-495
user_disconnect(DCUserConn *uc)
Link Here
|
| 489 |
|
498 |
|
| 490 |
FD_CLR(uc->get_mq->fd, &read_fds); |
499 |
FD_CLR(uc->get_mq->fd, &read_fds); |
| 491 |
FD_CLR(uc->put_mq->fd, &write_fds); |
500 |
FD_CLR(uc->put_mq->fd, &write_fds); |
| 492 |
if (close(uc->get_mq->fd) != 0 || close(uc->put_mq->fd) != 0) |
501 |
// using (close || close) here could cause one of close() to be skipped |
|
|
502 |
if ((close(uc->get_mq->fd) | close(uc->put_mq->fd)) != 0) |
| 493 |
warn(_("Cannot close pipe - %s\n"), errstr); |
503 |
warn(_("Cannot close pipe - %s\n"), errstr); |
| 494 |
msgq_free(uc->get_mq); |
504 |
msgq_free(uc->get_mq); |
| 495 |
uc->get_mq = NULL; |
505 |
uc->get_mq = NULL; |
|
Lines 1109-1117
set_active(bool newactive, uint16_t port)
Link Here
|
| 1109 |
} |
1119 |
} |
| 1110 |
/* Start of disable_search. */ |
1120 |
/* Start of disable_search. */ |
| 1111 |
if (search_socket >= 0) { |
1121 |
if (search_socket >= 0) { |
| 1112 |
if (close(search_socket) < 0) |
1122 |
if (close(search_socket) < 0) |
| 1113 |
warn(_("Cannot close socket - %s\n"), errstr); |
1123 |
warn(_("Cannot close socket - %s\n"), errstr); |
| 1114 |
search_socket = -1; |
1124 |
FD_CLR(search_socket, &read_fds); |
|
|
1125 |
FD_CLR(search_socket, &write_fds); |
| 1126 |
search_socket = -1; |
| 1115 |
} |
1127 |
} |
| 1116 |
/* End of disable_search. */ |
1128 |
/* End of disable_search. */ |
| 1117 |
enable_search(); |
1129 |
enable_search(); |
|
Lines 1306-1339
main (int argc, char **argv)
Link Here
|
| 1306 |
break; |
1318 |
break; |
| 1307 |
} |
1319 |
} |
| 1308 |
|
1320 |
|
| 1309 |
if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) |
1321 |
if (running && FD_ISSET(signal_pipe[0], &res_read_fds)) { |
| 1310 |
read_signal_input(); |
1322 |
FD_CLR(signal_pipe[0], &res_read_fds); |
| 1311 |
if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) |
1323 |
read_signal_input(); |
|
|
1324 |
} |
| 1325 |
if (running && FD_ISSET(STDIN_FILENO, &res_read_fds)) { |
| 1326 |
IF_ORPHAN_HANDLES (FD_CLR(STDIN_FILENO, &res_read_fds)); |
| 1312 |
screen_read_input(); |
1327 |
screen_read_input(); |
| 1313 |
if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) |
1328 |
} |
|
|
1329 |
if (running && listen_socket >= 0 && FD_ISSET(listen_socket, &res_read_fds)) { |
| 1330 |
IF_ORPHAN_HANDLES (FD_CLR(listen_socket, &res_read_fds)); |
| 1314 |
handle_listen_connection(); |
1331 |
handle_listen_connection(); |
| 1315 |
if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) |
1332 |
} |
|
|
1333 |
if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_read_fds)) { |
| 1334 |
IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_read_fds)); |
| 1316 |
hub_input_available(); |
1335 |
hub_input_available(); |
| 1317 |
if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) |
1336 |
} |
|
|
1337 |
if (running && hub_socket >= 0 && FD_ISSET(hub_socket, &res_write_fds)) { |
| 1338 |
IF_ORPHAN_HANDLES (FD_CLR(hub_socket, &res_write_fds)); |
| 1318 |
hub_now_writable(); |
1339 |
hub_now_writable(); |
|
|
1340 |
} |
| 1319 |
if (running) |
1341 |
if (running) |
| 1320 |
check_hub_activity(); |
1342 |
check_hub_activity(); |
| 1321 |
if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) |
1343 |
if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_read_fds)) { |
|
|
1344 |
IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_read_fds)); |
| 1322 |
search_input_available(); |
1345 |
search_input_available(); |
| 1323 |
if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) |
1346 |
} |
|
|
1347 |
if (running && search_socket >= 0 && FD_ISSET(search_socket, &res_write_fds)) { |
| 1348 |
IF_ORPHAN_HANDLES (FD_CLR(search_socket, &res_write_fds)); |
| 1324 |
search_now_writable(); |
1349 |
search_now_writable(); |
| 1325 |
if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) |
1350 |
} |
|
|
1351 |
if (running && FD_ISSET(lookup_request_mq->fd, &res_write_fds)) { |
| 1352 |
IF_ORPHAN_HANDLES (FD_CLR(lookup_request_mq->fd, &res_write_fds)); |
| 1326 |
lookup_request_fd_writable(); |
1353 |
lookup_request_fd_writable(); |
| 1327 |
if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) |
1354 |
} |
|
|
1355 |
if (running && FD_ISSET(lookup_result_mq->fd, &res_read_fds)) { |
| 1356 |
IF_ORPHAN_HANDLES (FD_CLR(lookup_result_mq->fd, &res_read_fds)); |
| 1328 |
lookup_result_fd_readable(); |
1357 |
lookup_result_fd_readable(); |
| 1329 |
if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) |
1358 |
} |
|
|
1359 |
if (running && FD_ISSET(parse_request_mq->fd, &res_write_fds)) { |
| 1360 |
IF_ORPHAN_HANDLES (FD_CLR(parse_request_mq->fd, &res_write_fds)); |
| 1330 |
parse_request_fd_writable(); |
1361 |
parse_request_fd_writable(); |
| 1331 |
if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) |
1362 |
} |
|
|
1363 |
if (running && FD_ISSET(parse_result_mq->fd, &res_read_fds)) { |
| 1364 |
IF_ORPHAN_HANDLES (FD_CLR(parse_result_mq->fd, &res_read_fds)); |
| 1332 |
parse_result_fd_readable(); |
1365 |
parse_result_fd_readable(); |
| 1333 |
if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) |
1366 |
} |
|
|
1367 |
if (running && FD_ISSET(update_request_mq->fd, &res_write_fds)) { |
| 1368 |
IF_ORPHAN_HANDLES (FD_CLR(update_request_mq->fd, &res_write_fds)); |
| 1334 |
update_request_fd_writable(); |
1369 |
update_request_fd_writable(); |
| 1335 |
if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) |
1370 |
} |
|
|
1371 |
if (running && FD_ISSET(update_result_mq->fd, &res_read_fds)) { |
| 1372 |
IF_ORPHAN_HANDLES (FD_CLR(update_result_mq->fd, &res_read_fds)); |
| 1336 |
update_result_fd_readable(); |
1373 |
update_result_fd_readable(); |
|
|
1374 |
} |
| 1337 |
|
1375 |
|
| 1338 |
if (running) { |
1376 |
if (running) { |
| 1339 |
HMapIterator it; |
1377 |
HMapIterator it; |
|
Lines 1341-1353
main (int argc, char **argv)
Link Here
|
| 1341 |
hmap_iterator(user_conns, &it); |
1379 |
hmap_iterator(user_conns, &it); |
| 1342 |
while (running && it.has_next(&it)) { |
1380 |
while (running && it.has_next(&it)) { |
| 1343 |
DCUserConn *uc = it.next(&it); |
1381 |
DCUserConn *uc = it.next(&it); |
| 1344 |
if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) |
1382 |
if (uc->put_mq != NULL && FD_ISSET(uc->put_mq->fd, &res_write_fds)) { |
|
|
1383 |
IF_ORPHAN_HANDLES (FD_CLR(uc->put_mq->fd, &res_write_fds)); |
| 1345 |
user_request_fd_writable(uc); |
1384 |
user_request_fd_writable(uc); |
| 1346 |
if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) |
1385 |
} |
| 1347 |
user_result_fd_readable(uc); |
1386 |
if (uc->get_mq != NULL && FD_ISSET(uc->get_mq->fd, &res_read_fds)) { |
|
|
1387 |
IF_ORPHAN_HANDLES (FD_CLR(uc->get_mq->fd, &res_read_fds)); |
| 1388 |
user_result_fd_readable(uc); |
| 1389 |
} |
| 1348 |
} |
1390 |
} |
| 1349 |
} |
1391 |
} |
| 1350 |
} |
1392 |
|
|
|
1393 |
#ifdef CHECK_ORPHAN_HANDLES |
| 1394 |
/* Check for orphan file handles */ |
| 1395 |
{ |
| 1396 |
int i; |
| 1397 |
for (i = 0; i < FD_SETSIZE; i++) { |
| 1398 |
if (FD_ISSET (i, &res_read_fds)) { |
| 1399 |
warn(_("Orphan READ file handle %d, closing\n"), i); |
| 1400 |
close (i); |
| 1401 |
FD_CLR (i, &read_fds); |
| 1402 |
} |
| 1403 |
if (FD_ISSET (i, &res_write_fds)) { |
| 1404 |
warn(_("Orphan WRITE file handle %d, closing\n"), i); |
| 1405 |
close (i); |
| 1406 |
FD_CLR (i, &write_fds); |
| 1407 |
} |
| 1408 |
} |
| 1409 |
} |
| 1410 |
#endif |
| 1411 |
} |
| 1351 |
|
1412 |
|
| 1352 |
cleanup: |
1413 |
cleanup: |
| 1353 |
|
1414 |
|
|
Lines 1365-1370
cleanup:
Link Here
|
| 1365 |
|
1426 |
|
| 1366 |
byteq_free(search_recvq); |
1427 |
byteq_free(search_recvq); |
| 1367 |
|
1428 |
|
|
|
1429 |
/* Do this before freeing user_conn_unknown_free otherwise we crash */ |
| 1430 |
hmap_foreach_value(user_conns, user_conn_cancel); |
| 1431 |
|
| 1368 |
ptrv_foreach(user_conn_unknown_free, free); |
1432 |
ptrv_foreach(user_conn_unknown_free, free); |
| 1369 |
ptrv_free(user_conn_unknown_free); |
1433 |
ptrv_free(user_conn_unknown_free); |
| 1370 |
|
1434 |
|
|
Lines 1374-1380
cleanup:
Link Here
|
| 1374 |
ptrv_foreach(our_searches, (PtrVForeachCallback) free_search_request); |
1438 |
ptrv_foreach(our_searches, (PtrVForeachCallback) free_search_request); |
| 1375 |
ptrv_free(our_searches); |
1439 |
ptrv_free(our_searches); |
| 1376 |
|
1440 |
|
| 1377 |
hmap_foreach_value(user_conns, user_conn_cancel); |
|
|
| 1378 |
/* XXX: follow up and wait for user connections to die? */ |
1441 |
/* XXX: follow up and wait for user connections to die? */ |
| 1379 |
hmap_free(user_conns); |
1442 |
hmap_free(user_conns); |
| 1380 |
|
1443 |
|
| 1381 |
- |
|
|