Run virtual machines on iOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

256 lines
8.0 KiB

  1. diff -aur a/Makefile.in b/Makefile.in
  2. --- a/Makefile.in 2018-08-22 04:32:02.000000000 -0700
  3. +++ b/Makefile.in 2019-04-23 11:52:06.000000000 -0700
  4. @@ -422,7 +422,7 @@
  5. valgrind_tools = @valgrind_tools@
  6. NULL =
  7. ACLOCAL_AMFLAGS = -I m4
  8. -SUBDIRS = subprojects/spice-common server docs tools
  9. +SUBDIRS = subprojects/spice-common server docs
  10. pkgconfigdir = $(libdir)/pkgconfig
  11. pkgconfig_DATA = spice-server.pc
  12. DISTCHECK_CONFIGURE_FLAGS = \
  13. From 23e9f84657479298f2527dc84ba64f00d811bc96 Mon Sep 17 00:00:00 2001
  14. From: osy <50960678+osy@users.noreply.github.com>
  15. Date: Wed, 24 Apr 2019 18:50:25 -0700
  16. Subject: [PATCH 1/2] OSX: added support for OSX/iOS
  17. Fix some Apple specific issues such as lack of %m print format and buggy TCP_NOPUSH implementation
  18. ---
  19. server/red-stream.c | 16 +++++++++++++++-
  20. server/red-worker.c | 2 ++
  21. server/reds.c | 18 +++++++++++++++++-
  22. 3 files changed, 34 insertions(+), 2 deletions(-)
  23. diff --git a/server/red-stream.c b/server/red-stream.c
  24. index 18c4a935..3fec87cf 100644
  25. --- a/server/red-stream.c
  26. +++ b/server/red-stream.c
  27. @@ -39,7 +39,7 @@
  28. #include "reds.h"
  29. // compatibility for *BSD systems
  30. -#ifndef TCP_CORK
  31. +#if !defined(TCP_CORK) && !defined(__APPLE__)
  32. #define TCP_CORK TCP_NOPUSH
  33. #endif
  34. @@ -100,6 +100,7 @@ struct RedStreamPrivate {
  35. SpiceCoreInterfaceInternal *core;
  36. };
  37. +#if !defined(__APPLE__) // TCP_CORK doesn't exist and TCP_NOPUSH is broken
  38. /**
  39. * Set TCP_CORK on socket
  40. */
  41. @@ -109,6 +110,7 @@ static int socket_set_cork(int socket, int enabled)
  42. SPICE_VERIFY(sizeof(enabled) == sizeof(int));
  43. return setsockopt(socket, IPPROTO_TCP, TCP_CORK, &enabled, sizeof(enabled));
  44. }
  45. +#endif
  46. static ssize_t stream_write_cb(RedStream *s, const void *buf, size_t size)
  47. {
  48. @@ -223,6 +225,7 @@ bool red_stream_write_all(RedStream *stream, const void *in_buf, size_t n)
  49. bool red_stream_set_auto_flush(RedStream *s, bool auto_flush)
  50. {
  51. +#if !defined(__APPLE__)
  52. if (s->priv->use_cork == !auto_flush) {
  53. return true;
  54. }
  55. @@ -239,15 +242,18 @@ bool red_stream_set_auto_flush(RedStream *s, bool auto_flush)
  56. socket_set_cork(s->socket, 0);
  57. s->priv->corked = false;
  58. }
  59. +#endif
  60. return true;
  61. }
  62. void red_stream_flush(RedStream *s)
  63. {
  64. +#if !defined(__APPLE__)
  65. if (s->priv->corked) {
  66. socket_set_cork(s->socket, 0);
  67. socket_set_cork(s->socket, 1);
  68. }
  69. +#endif
  70. }
  71. #if HAVE_SASL
  72. @@ -352,8 +358,16 @@ int red_stream_send_msgfd(RedStream *stream, int fd)
  73. memcpy(CMSG_DATA(cmsg), &fd, fd_size);
  74. }
  75. +#if defined(__APPLE__)
  76. + int set = 1;
  77. + setsockopt(stream->socket, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
  78. +#endif
  79. do {
  80. +#if defined(__APPLE__)
  81. + r = sendmsg(stream->socket, &msgh, 0);
  82. +#else
  83. r = sendmsg(stream->socket, &msgh, MSG_NOSIGNAL);
  84. +#endif
  85. } while (r < 0 && (errno == EINTR || errno == EAGAIN));
  86. return r;
  87. diff --git a/server/red-worker.c b/server/red-worker.c
  88. index ccab9d96..04c695bb 100644
  89. --- a/server/red-worker.c
  90. +++ b/server/red-worker.c
  91. @@ -1391,7 +1391,9 @@ bool red_worker_run(RedWorker *worker)
  92. spice_error("create thread failed %d", r);
  93. }
  94. pthread_sigmask(SIG_SETMASK, &curr_sig_mask, NULL);
  95. +#if !defined(__APPLE__) // not supported
  96. pthread_setname_np(worker->thread, "SPICE Worker");
  97. +#endif
  98. return r == 0;
  99. }
  100. diff --git a/server/reds.c b/server/reds.c
  101. index 85043a88..f1e19b87 100644
  102. --- a/server/reds.c
  103. +++ b/server/reds.c
  104. @@ -3555,6 +3555,7 @@ static const int video_codec_caps[] = {
  105. static const char* parse_next_video_codec(const char *codecs, char **encoder,
  106. char **codec)
  107. {
  108. + size_t len;
  109. if (!codecs) {
  110. return NULL;
  111. }
  112. @@ -3562,8 +3563,22 @@ static const char* parse_next_video_codec(const char *codecs, char **encoder,
  113. if (!*codecs) {
  114. return NULL;
  115. }
  116. + len = strcspn(codecs, ";");
  117. int n;
  118. *encoder = *codec = NULL;
  119. +#if defined(__APPLE__)
  120. + char *aencoder = malloc(len);
  121. + char *acodec = malloc(len);
  122. + if (sscanf(codecs, "%[0-9a-zA-Z_]:%[0-9a-zA-Z_]%n", aencoder, acodec, &n) == 2) {
  123. + // this avoids accepting "encoder:codec" followed by garbage like "$%*"
  124. + if (codecs[n] != ';' && codecs[n] != '\0') {
  125. + free(acodec);
  126. + acodec = NULL;
  127. + }
  128. + }
  129. + *encoder = aencoder;
  130. + *codec = acodec;
  131. +#else
  132. if (sscanf(codecs, "%m[0-9a-zA-Z_]:%m[0-9a-zA-Z_]%n", encoder, codec, &n) == 2) {
  133. // this avoids accepting "encoder:codec" followed by garbage like "$%*"
  134. if (codecs[n] != ';' && codecs[n] != '\0') {
  135. @@ -3571,7 +3586,8 @@ static const char* parse_next_video_codec(const char *codecs, char **encoder,
  136. *codec = NULL;
  137. }
  138. }
  139. - return codecs + strcspn(codecs, ";");
  140. +#endif
  141. + return codecs + len;
  142. }
  143. static void reds_set_video_codecs_from_string(RedsState *reds, const char *codecs)
  144. --
  145. 2.28.0
  146. From 9fe644b11858d803d51a5b162be0b18d864fc5c3 Mon Sep 17 00:00:00 2001
  147. From: osy <50960678+osy@users.noreply.github.com>
  148. Date: Wed, 28 Jul 2021 17:22:25 -0700
  149. Subject: [PATCH 2/2] net-utils: fix EINVAL error on AF_UNIX sockets on darwin
  150. ---
  151. server/net-utils.c | 26 +++++++++++++++++++++++---
  152. 1 file changed, 23 insertions(+), 3 deletions(-)
  153. diff --git a/server/net-utils.c b/server/net-utils.c
  154. index ca8a4e7f..8265f15e 100644
  155. --- a/server/net-utils.c
  156. +++ b/server/net-utils.c
  157. @@ -34,6 +34,25 @@
  158. #include "net-utils.h"
  159. +static inline bool
  160. +darwin_einval_on_unix_socket(int fd, int err)
  161. +{
  162. +#if defined(__APPLE__)
  163. + if (err == EINVAL || err == EOPNOTSUPP) {
  164. + union {
  165. + struct sockaddr sa;
  166. + char buf[1024];
  167. + } addr;
  168. + socklen_t len = sizeof(addr);
  169. +
  170. + if (getsockname(fd, &addr.sa, &len) == 0 && addr.sa.sa_family == AF_UNIX) {
  171. + return true;
  172. + }
  173. + }
  174. +#endif
  175. + return false;
  176. +}
  177. +
  178. /**
  179. * red_socket_set_keepalive:
  180. * @fd: a socket file descriptor
  181. @@ -46,7 +65,7 @@ bool red_socket_set_keepalive(int fd, bool enable, int timeout)
  182. int keepalive = !!enable;
  183. if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &keepalive, sizeof(keepalive)) == -1) {
  184. - if (errno != ENOTSUP) {
  185. + if (errno != ENOTSUP && !darwin_einval_on_unix_socket(fd, errno)) {
  186. g_warning("setsockopt for keepalive failed, %s", strerror(errno));
  187. return false;
  188. }
  189. @@ -58,7 +77,7 @@ bool red_socket_set_keepalive(int fd, bool enable, int timeout)
  190. #ifdef HAVE_TCP_KEEPIDLE
  191. if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &timeout, sizeof(timeout)) == -1) {
  192. - if (errno != ENOTSUP) {
  193. + if (errno != ENOTSUP && !darwin_einval_on_unix_socket(fd, errno)) {
  194. g_warning("setsockopt for keepalive timeout failed, %s", strerror(errno));
  195. return false;
  196. }
  197. @@ -81,7 +100,8 @@ bool red_socket_set_no_delay(int fd, bool no_delay)
  198. if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY,
  199. &optval, sizeof(optval)) != 0) {
  200. - if (errno != ENOTSUP && errno != ENOPROTOOPT) {
  201. + if (errno != ENOTSUP && errno != ENOPROTOOPT &&
  202. + !darwin_einval_on_unix_socket(fd, errno)) {
  203. spice_warning("setsockopt failed, %s", strerror(errno));
  204. return false;
  205. }
  206. --
  207. 2.28.0
  208. From 3977c49109906b9ab26950e301a5ad684c36a57d Mon Sep 17 00:00:00 2001
  209. From: osy <50960678+osy@users.noreply.github.com>
  210. Date: Tue, 2 Nov 2021 12:56:54 -0700
  211. Subject: [PATCH] reds: always send monitors config
  212. Windows VDagent needs this to apply the resolution changes.
  213. ---
  214. server/reds.c | 2 +-
  215. 1 file changed, 1 insertion(+), 1 deletion(-)
  216. diff --git a/server/reds.c b/server/reds.c
  217. index f1e19b87..2fa2cfae 100644
  218. --- a/server/reds.c
  219. +++ b/server/reds.c
  220. @@ -1182,7 +1182,7 @@ void reds_on_main_agent_data(RedsState *reds, MainChannelClient *mcc, const void
  221. return;
  222. case AGENT_MSG_FILTER_MONITORS_CONFIG:
  223. reds_on_main_agent_monitors_config(reds, mcc, message, size);
  224. - return;
  225. + break;
  226. case AGENT_MSG_FILTER_PROTO_ERROR:
  227. red_channel_client_shutdown(RED_CHANNEL_CLIENT(mcc));
  228. return;
  229. --
  230. 2.28.0