diff options
Diffstat (limited to 'src/transport/tcp_service_legacy.c')
-rw-r--r-- | src/transport/tcp_service_legacy.c | 111 |
1 files changed, 3 insertions, 108 deletions
diff --git a/src/transport/tcp_service_legacy.c b/src/transport/tcp_service_legacy.c index 8f3f43718..129511fec 100644 --- a/src/transport/tcp_service_legacy.c +++ b/src/transport/tcp_service_legacy.c | |||
@@ -849,95 +849,6 @@ LEGACY_SERVICE_get_server_addresses( | |||
849 | } | 849 | } |
850 | 850 | ||
851 | 851 | ||
852 | #ifdef MINGW | ||
853 | /** | ||
854 | * Read listen sockets from the parent process (ARM). | ||
855 | * | ||
856 | * @param sctx service context to initialize | ||
857 | * @return #GNUNET_YES if ok, #GNUNET_NO if not ok (must bind yourself), | ||
858 | * and #GNUNET_SYSERR on error. | ||
859 | */ | ||
860 | static int | ||
861 | receive_sockets_from_parent(struct LEGACY_SERVICE_Context *sctx) | ||
862 | { | ||
863 | const char *env_buf; | ||
864 | int fail; | ||
865 | uint64_t count; | ||
866 | uint64_t i; | ||
867 | HANDLE lsocks_pipe; | ||
868 | |||
869 | env_buf = getenv("GNUNET_OS_READ_LSOCKS"); | ||
870 | if ((NULL == env_buf) || (strlen(env_buf) <= 0)) | ||
871 | return GNUNET_NO; | ||
872 | /* Using W32 API directly here, because this pipe will | ||
873 | * never be used outside of this function, and it's just too much of a bother | ||
874 | * to create a GNUnet API that boxes a HANDLE (the way it is done with socks) | ||
875 | */ | ||
876 | lsocks_pipe = (HANDLE)strtoul(env_buf, NULL, 10); | ||
877 | if ((0 == lsocks_pipe) || (INVALID_HANDLE_VALUE == lsocks_pipe)) | ||
878 | return GNUNET_NO; | ||
879 | fail = 1; | ||
880 | do | ||
881 | { | ||
882 | int ret; | ||
883 | int fail2; | ||
884 | DWORD rd; | ||
885 | |||
886 | ret = ReadFile(lsocks_pipe, &count, sizeof(count), &rd, NULL); | ||
887 | if ((0 == ret) || (sizeof(count) != rd) || (0 == count)) | ||
888 | break; | ||
889 | sctx->lsocks = | ||
890 | GNUNET_malloc(sizeof(struct GNUNET_NETWORK_Handle *) * (count + 1)); | ||
891 | |||
892 | fail2 = 1; | ||
893 | for (i = 0; i < count; i++) | ||
894 | { | ||
895 | WSAPROTOCOL_INFOA pi; | ||
896 | uint64_t size; | ||
897 | socket s; | ||
898 | |||
899 | ret = ReadFile(lsocks_pipe, &size, sizeof(size), &rd, NULL); | ||
900 | if ((0 == ret) || (sizeof(size) != rd) || (sizeof(pi) != size)) | ||
901 | break; | ||
902 | ret = ReadFile(lsocks_pipe, &pi, sizeof(pi), &rd, NULL); | ||
903 | if ((0 == ret) || (sizeof(pi) != rd)) | ||
904 | break; | ||
905 | s = WSASocketA(pi.iAddressFamily, | ||
906 | pi.iSocketType, | ||
907 | pi.iProtocol, | ||
908 | &pi, | ||
909 | 0, | ||
910 | WSA_FLAG_OVERLAPPED); | ||
911 | sctx->lsocks[i] = GNUNET_NETWORK_socket_box_native(s); | ||
912 | if (NULL == sctx->lsocks[i]) | ||
913 | break; | ||
914 | else if (i == count - 1) | ||
915 | fail2 = 0; | ||
916 | } | ||
917 | if (fail2) | ||
918 | break; | ||
919 | sctx->lsocks[count] = NULL; | ||
920 | fail = 0; | ||
921 | } | ||
922 | while (fail); | ||
923 | |||
924 | CloseHandle(lsocks_pipe); | ||
925 | |||
926 | if (fail) | ||
927 | { | ||
928 | LOG(GNUNET_ERROR_TYPE_ERROR, | ||
929 | _("Could not access a pre-bound socket, will try to bind myself\n")); | ||
930 | for (i = 0; (i < count) && (NULL != sctx->lsocks[i]); i++) | ||
931 | GNUNET_break(0 == GNUNET_NETWORK_socket_close(sctx->lsocks[i])); | ||
932 | GNUNET_free_non_null(sctx->lsocks); | ||
933 | sctx->lsocks = NULL; | ||
934 | return GNUNET_NO; | ||
935 | } | ||
936 | return GNUNET_YES; | ||
937 | } | ||
938 | #endif | ||
939 | |||
940 | |||
941 | /** | 852 | /** |
942 | * Setup addr, addrlen, idle_timeout | 853 | * Setup addr, addrlen, idle_timeout |
943 | * based on configuration! | 854 | * based on configuration! |
@@ -961,12 +872,9 @@ setup_service(struct LEGACY_SERVICE_Context *sctx) | |||
961 | { | 872 | { |
962 | struct GNUNET_TIME_Relative idleout; | 873 | struct GNUNET_TIME_Relative idleout; |
963 | int tolerant; | 874 | int tolerant; |
964 | |||
965 | #ifndef MINGW | ||
966 | const char *nfds; | 875 | const char *nfds; |
967 | unsigned int cnt; | 876 | unsigned int cnt; |
968 | int flags; | 877 | int flags; |
969 | #endif | ||
970 | 878 | ||
971 | if (GNUNET_CONFIGURATION_have_value(sctx->cfg, | 879 | if (GNUNET_CONFIGURATION_have_value(sctx->cfg, |
972 | sctx->service_name, | 880 | sctx->service_name, |
@@ -1007,7 +915,6 @@ setup_service(struct LEGACY_SERVICE_Context *sctx) | |||
1007 | else | 915 | else |
1008 | tolerant = GNUNET_NO; | 916 | tolerant = GNUNET_NO; |
1009 | 917 | ||
1010 | #ifndef MINGW | ||
1011 | errno = 0; | 918 | errno = 0; |
1012 | if ((NULL != (nfds = getenv("LISTEN_FDS"))) && | 919 | if ((NULL != (nfds = getenv("LISTEN_FDS"))) && |
1013 | (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && | 920 | (1 == sscanf(nfds, "%u", &cnt)) && (cnt > 0) && (cnt < FD_SETSIZE) && |
@@ -1036,13 +943,6 @@ setup_service(struct LEGACY_SERVICE_Context *sctx) | |||
1036 | } | 943 | } |
1037 | unsetenv("LISTEN_FDS"); | 944 | unsetenv("LISTEN_FDS"); |
1038 | } | 945 | } |
1039 | #else | ||
1040 | if (getenv("GNUNET_OS_READ_LSOCKS") != NULL) | ||
1041 | { | ||
1042 | receive_sockets_from_parent(sctx); | ||
1043 | putenv("GNUNET_OS_READ_LSOCKS="); | ||
1044 | } | ||
1045 | #endif | ||
1046 | 946 | ||
1047 | if ((NULL == sctx->lsocks) && | 947 | if ((NULL == sctx->lsocks) && |
1048 | (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, | 948 | (GNUNET_SYSERR == LEGACY_SERVICE_get_server_addresses(sctx->service_name, |
@@ -1257,7 +1157,6 @@ service_task(void *cls) | |||
1257 | static int | 1157 | static int |
1258 | detach_terminal(struct LEGACY_SERVICE_Context *sctx) | 1158 | detach_terminal(struct LEGACY_SERVICE_Context *sctx) |
1259 | { | 1159 | { |
1260 | #ifndef MINGW | ||
1261 | pid_t pid; | 1160 | pid_t pid; |
1262 | int nullfd; | 1161 | int nullfd; |
1263 | int filedes[2]; | 1162 | int filedes[2]; |
@@ -1324,11 +1223,7 @@ detach_terminal(struct LEGACY_SERVICE_Context *sctx) | |||
1324 | if (-1 == pid) | 1223 | if (-1 == pid) |
1325 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); | 1224 | LOG_STRERROR(GNUNET_ERROR_TYPE_ERROR, "setsid"); |
1326 | sctx->ready_confirm_fd = filedes[1]; | 1225 | sctx->ready_confirm_fd = filedes[1]; |
1327 | #else | 1226 | |
1328 | /* FIXME: we probably need to do something else | ||
1329 | * elsewhere in order to fork the process itself... */ | ||
1330 | FreeConsole(); | ||
1331 | #endif | ||
1332 | return GNUNET_OK; | 1227 | return GNUNET_OK; |
1333 | } | 1228 | } |
1334 | 1229 | ||
@@ -1346,7 +1241,7 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx) | |||
1346 | 1241 | ||
1347 | if (NULL == (user = get_user_name(sctx))) | 1242 | if (NULL == (user = get_user_name(sctx))) |
1348 | return GNUNET_OK; /* keep */ | 1243 | return GNUNET_OK; /* keep */ |
1349 | #ifndef MINGW | 1244 | |
1350 | struct passwd *pws; | 1245 | struct passwd *pws; |
1351 | 1246 | ||
1352 | errno = 0; | 1247 | errno = 0; |
@@ -1377,7 +1272,7 @@ set_user_id(struct LEGACY_SERVICE_Context *sctx) | |||
1377 | return GNUNET_SYSERR; | 1272 | return GNUNET_SYSERR; |
1378 | } | 1273 | } |
1379 | } | 1274 | } |
1380 | #endif | 1275 | |
1381 | GNUNET_free(user); | 1276 | GNUNET_free(user); |
1382 | return GNUNET_OK; | 1277 | return GNUNET_OK; |
1383 | } | 1278 | } |