logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0005-Avoid-use-of-statement-expressions.patch (8931B)


  1. From 979d85c842898463192c7e7dae87798c1df6d471 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Fri, 30 Apr 2021 20:02:41 -0700
  4. Subject: [PATCH] Avoid use of statement-expressions
  5. ---
  6. Makefile.am | 2 +-
  7. acpi_listen.c | 6 +++---
  8. acpid.c | 4 ++--
  9. event.c | 5 +++--
  10. input_layer.c | 4 ++--
  11. libc_compat.h | 40 ----------------------------------------
  12. libnetlink.c | 17 +++++++++--------
  13. netlink.c | 4 ++--
  14. proc.c | 5 +++--
  15. ud_socket.c | 5 +++--
  16. 10 files changed, 28 insertions(+), 64 deletions(-)
  17. delete mode 100644 libc_compat.h
  18. diff --git a/Makefile.am b/Makefile.am
  19. index 417528f..1c80ca4 100644
  20. --- a/Makefile.am
  21. +++ b/Makefile.am
  22. @@ -14,7 +14,7 @@ bin_PROGRAMS = acpi_listen
  23. acpid_SOURCES = acpid.c acpi_ids.c connection_list.c event.c input_layer.c inotify_handler.c libnetlink.c log.c netlink.c proc.c sock.c ud_socket.c \
  24. acpid.h acpi_genetlink.h acpi_ids.h config.h connection_list.h event.h genetlink.h inotify_handler.h input_layer.h \
  25. - libnetlink.h log.h netlink.h proc.h sock.h ud_socket.h libc_compat.h
  26. + libnetlink.h log.h netlink.h proc.h sock.h ud_socket.h
  27. acpi_listen_SOURCES = acpi_listen.c log.c ud_socket.c
  28. diff --git a/acpi_listen.c b/acpi_listen.c
  29. index 63a1cc3..674cc80 100644
  30. --- a/acpi_listen.c
  31. +++ b/acpi_listen.c
  32. @@ -39,8 +39,6 @@
  33. #include "acpid.h"
  34. #include "ud_socket.h"
  35. -#include "libc_compat.h"
  36. -
  37. static int handle_cmdline(int *argc, char ***argv);
  38. static char *read_line(int fd);
  39. @@ -217,8 +215,10 @@ read_line(int fd)
  40. memset(buf+i, 0, buflen-i);
  41. while (i < buflen) {
  42. - r = TEMP_FAILURE_RETRY (read(fd, buf+i, 1) );
  43. + r = read(fd, buf+i, 1);
  44. if (r < 0) {
  45. + if (errno == EINTR)
  46. + continue;
  47. /* we should do something with the data */
  48. fprintf(stderr, "ERR: read(): %s\n",
  49. strerror(errno));
  50. diff --git a/acpid.c b/acpid.c
  51. index cb1875a..6538578 100644
  52. --- a/acpid.c
  53. +++ b/acpid.c
  54. @@ -41,7 +41,6 @@
  55. #include "input_layer.h"
  56. #include "inotify_handler.h"
  57. #include "netlink.h"
  58. -#include "libc_compat.h"
  59. static int handle_cmdline(int *argc, char ***argv);
  60. static void close_fds(void);
  61. @@ -153,7 +152,8 @@ main(int argc, char **argv)
  62. readfds = *get_fdset();
  63. /* wait on data */
  64. - nready = TEMP_FAILURE_RETRY(select(get_highestfd() + 1, &readfds, NULL, NULL, NULL));
  65. + do nready = select(get_highestfd() + 1, &readfds, NULL, NULL, NULL);
  66. + while (nready == -1 && errno == EINTR);
  67. if (nready < 0) {
  68. acpid_log(LOG_ERR, "select(): %s", strerror(errno));
  69. diff --git a/event.c b/event.c
  70. index 6c67062..033466e 100644
  71. --- a/event.c
  72. +++ b/event.c
  73. @@ -39,7 +39,6 @@
  74. #include "log.h"
  75. #include "sock.h"
  76. #include "ud_socket.h"
  77. -#include "libc_compat.h"
  78. #include "event.h"
  79. /*
  80. @@ -754,8 +753,10 @@ safe_write(int fd, const char *buf, int len)
  81. int ntries = NTRIES;
  82. do {
  83. - r = TEMP_FAILURE_RETRY (write(fd, buf+ttl, len-ttl) );
  84. + r = write(fd, buf+ttl, len-ttl);
  85. if (r < 0) {
  86. + if (errno == EINTR)
  87. + continue;
  88. if (errno != EAGAIN) {
  89. /* a legit error */
  90. return r;
  91. diff --git a/input_layer.c b/input_layer.c
  92. index 00246b3..f6bddef 100644
  93. --- a/input_layer.c
  94. +++ b/input_layer.c
  95. @@ -42,7 +42,6 @@
  96. #include "log.h"
  97. #include "connection_list.h"
  98. #include "event.h"
  99. -#include "libc_compat.h"
  100. #include "input_layer.h"
  101. @@ -352,7 +351,8 @@ static void process_input(int fd)
  102. struct connection *c;
  103. char str2[100];
  104. - nbytes = TEMP_FAILURE_RETRY ( read(fd, &event, sizeof(event)) );
  105. + do nbytes = read(fd, &event, sizeof(event));
  106. + while (nbytes == -1 && errno == EINTR);
  107. if (nbytes == 0) {
  108. acpid_log(LOG_WARNING, "input layer connection closed");
  109. diff --git a/libc_compat.h b/libc_compat.h
  110. deleted file mode 100644
  111. index 39f2336..0000000
  112. --- a/libc_compat.h
  113. +++ /dev/null
  114. @@ -1,40 +0,0 @@
  115. -/*
  116. - * libc_compat.h - implement defs/macros missing from some libcs
  117. - *
  118. - * Copyright (C) 1999-2000 Andrew Henroid
  119. - * Copyright (C) 2001 Sun Microsystems
  120. - * Portions Copyright (C) 2004 Tim Hockin (thockin@hockin.org)
  121. - *
  122. - * This program is free software; you can redistribute it and/or modify
  123. - * it under the terms of the GNU General Public License as published by
  124. - * the Free Software Foundation; either version 2 of the License, or
  125. - * (at your option) any later version.
  126. - *
  127. - * This program is distributed in the hope that it will be useful,
  128. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  129. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  130. - * GNU General Public License for more details.
  131. - *
  132. - * You should have received a copy of the GNU General Public License
  133. - * along with this program; if not, write to the Free Software
  134. - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  135. - */
  136. -
  137. -#ifndef LIBC_COMPAT_H__
  138. -#define LIBC_COMPAT_H__
  139. -
  140. -/* Evaluate EXPRESSION, and repeat as long as it returns -1 with `errno'
  141. - set to EINTR. This macro is present on glibc/uclibc but may not be in other cases. */
  142. -
  143. -#ifndef ____GLIBC__
  144. -#ifndef TEMP_FAILURE_RETRY
  145. -#define TEMP_FAILURE_RETRY(expression) \
  146. - (__extension__ \
  147. - ({ long int __result; \
  148. - do __result = (long int) (expression); \
  149. - while (__result == -1L && errno == EINTR); \
  150. - __result; }))
  151. -#endif
  152. -#endif /* __GLIBC__ */
  153. -
  154. -#endif /* LIBC_COMPAT_H__ */
  155. diff --git a/libnetlink.c b/libnetlink.c
  156. index d94bd5f..7ad00df 100644
  157. --- a/libnetlink.c
  158. +++ b/libnetlink.c
  159. @@ -31,8 +31,6 @@
  160. #include <time.h>
  161. #include <sys/uio.h>
  162. -#include "libc_compat.h"
  163. -
  164. #include "libnetlink.h"
  165. void rtnl_close(struct rtnl_handle *rth)
  166. @@ -180,10 +178,11 @@ int rtnl_dump_filter(struct rtnl_handle *rth,
  167. struct nlmsghdr *h;
  168. iov.iov_len = sizeof(buf);
  169. - status = TEMP_FAILURE_RETRY ( recvmsg(rth->fd, &msg, MSG_CMSG_CLOEXEC) );
  170. + status = recvmsg(rth->fd, &msg, MSG_CMSG_CLOEXEC);
  171. if (status < 0) {
  172. - perror("OVERRUN");
  173. + if (errno != EINTR)
  174. + perror("OVERRUN");
  175. continue;
  176. }
  177. @@ -281,10 +280,11 @@ int rtnl_talk(struct rtnl_handle *rtnl, struct nlmsghdr *n, pid_t peer,
  178. while (1) {
  179. iov.iov_len = sizeof(buf);
  180. - status = TEMP_FAILURE_RETRY ( recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC) );
  181. + status = recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC);
  182. if (status < 0) {
  183. - perror("OVERRUN");
  184. + if (errno != EINTR)
  185. + perror("OVERRUN");
  186. continue;
  187. }
  188. if (status == 0) {
  189. @@ -383,10 +383,11 @@ int rtnl_listen(struct rtnl_handle *rtnl,
  190. iov.iov_base = buf;
  191. while (1) {
  192. iov.iov_len = sizeof(buf);
  193. - status = TEMP_FAILURE_RETRY ( recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC) );
  194. + status = recvmsg(rtnl->fd, &msg, MSG_CMSG_CLOEXEC);
  195. if (status < 0) {
  196. - perror("OVERRUN");
  197. + if (errno != EINTR)
  198. + perror("OVERRUN");
  199. continue;
  200. }
  201. if (status == 0) {
  202. diff --git a/netlink.c b/netlink.c
  203. index 8254762..695bb33 100644
  204. --- a/netlink.c
  205. +++ b/netlink.c
  206. @@ -48,7 +48,6 @@
  207. #include "libnetlink.h"
  208. #include "genetlink.h"
  209. #include "acpi_genetlink.h"
  210. -#include "libc_compat.h"
  211. #include "acpi_ids.h"
  212. #include "connection_list.h"
  213. @@ -151,7 +150,8 @@ process_netlink(int fd)
  214. iov.iov_len = sizeof(buf);
  215. /* read the data into the buffer */
  216. - status = TEMP_FAILURE_RETRY ( recvmsg(fd, &msg, MSG_CMSG_CLOEXEC) );
  217. + do status = recvmsg(fd, &msg, MSG_CMSG_CLOEXEC);
  218. + while (status == -1 && errno == EINTR);
  219. /* if there was a problem, print a message and keep trying */
  220. if (status < 0) {
  221. diff --git a/proc.c b/proc.c
  222. index f96b913..295cb73 100644
  223. --- a/proc.c
  224. +++ b/proc.c
  225. @@ -31,7 +31,6 @@
  226. #include "log.h"
  227. #include "event.h"
  228. #include "connection_list.h"
  229. -#include "libc_compat.h"
  230. #include "proc.h"
  231. @@ -137,8 +136,10 @@ read_line(int fd)
  232. /* only go to BUFLEN-1 so there will always be a 0 at the end */
  233. while (i < BUFLEN-1) {
  234. - r = TEMP_FAILURE_RETRY(read(fd, buf+i, 1));
  235. + r = read(fd, buf+i, 1);
  236. if (r < 0) {
  237. + if (errno == EINTR)
  238. + continue;
  239. /* we should do something with the data */
  240. acpid_log(LOG_ERR, "read(): %s",
  241. strerror(errno));
  242. diff --git a/ud_socket.c b/ud_socket.c
  243. index 83b2aa9..15a3b4a 100644
  244. --- a/ud_socket.c
  245. +++ b/ud_socket.c
  246. @@ -21,7 +21,6 @@
  247. #include "acpid.h"
  248. #include "log.h"
  249. #include "ud_socket.h"
  250. -#include "libc_compat.h"
  251. int
  252. ud_create_socket(const char *name, mode_t socketmode)
  253. @@ -87,8 +86,10 @@ ud_accept(int listenfd, struct ucred *cred)
  254. struct sockaddr_un cliaddr;
  255. socklen_t len = sizeof(struct sockaddr_un);
  256. - newsock = TEMP_FAILURE_RETRY (accept4(listenfd, (struct sockaddr *)&cliaddr, &len, SOCK_CLOEXEC|SOCK_NONBLOCK));
  257. + newsock = accept4(listenfd, (struct sockaddr *)&cliaddr, &len, SOCK_CLOEXEC|SOCK_NONBLOCK);
  258. if (newsock < 0) {
  259. + if (errno == EINTR)
  260. + continue;
  261. return newsock;
  262. }
  263. if (cred) {
  264. --
  265. 2.37.3