0001-Don-t-compile-programs-using-fork-on-MMU-less-system.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. From 5ed3b4ded6cf3e4de6fc8c8739b84231b0285b0e Mon Sep 17 00:00:00 2001
  2. From: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  3. Date: Fri, 5 May 2023 08:57:45 +0200
  4. Subject: [PATCH] Don't compile programs using fork() on MMU-less systems
  5. Systems that lack a MMU cannot use fork() to create the child process.
  6. The patch does not compile the affected programs on MMU-less systems.
  7. Co-developed-by: Marc Kleine-Budde <mkl@pengutronix.de>
  8. Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
  9. Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
  10. Upstream: https://github.com/linux-can/can-utils/commit/5ed3b4ded6cf3e4de6fc8c8739b84231b0285b0e
  11. ---
  12. CMakeLists.txt | 15 ++++++++++++---
  13. GNUmakefile.am | 10 +++++++---
  14. Makefile | 16 +++++++++++++---
  15. check_cc.sh | 16 ++++++++++++++++
  16. configure.ac | 2 ++
  17. fork_test.c | 27 +++++++++++++++++++++++++++
  18. 6 files changed, 77 insertions(+), 9 deletions(-)
  19. create mode 100755 check_cc.sh
  20. create mode 100644 fork_test.c
  21. diff --git a/CMakeLists.txt b/CMakeLists.txt
  22. index 09ccd805de66..aee8ff7fca02 100644
  23. --- a/CMakeLists.txt
  24. +++ b/CMakeLists.txt
  25. @@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.3)
  26. project(can-utils LANGUAGES C)
  27. +include (CheckFunctionExists)
  28. include (CheckSymbolExists)
  29. include (GNUInstallDirs)
  30. @@ -25,12 +26,13 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME")
  31. include_directories (.)
  32. include_directories (./include)
  33. +check_function_exists(fork HAVE_FORK)
  34. +
  35. set(PROGRAMS_CANLIB
  36. asc2log
  37. canbusload
  38. candump
  39. cangen
  40. - canlogserver
  41. canplayer
  42. cansend
  43. cansequence
  44. @@ -39,6 +41,10 @@ set(PROGRAMS_CANLIB
  45. slcanpty
  46. )
  47. +if(HAVE_FORK)
  48. + list(APPEND PROGRAMS_CANLIB canlogserver)
  49. +endif()
  50. +
  51. set(PROGRAMS_J1939
  52. j1939acd
  53. j1939cat
  54. @@ -49,7 +55,6 @@ set(PROGRAMS_J1939
  55. set(PROGRAMS
  56. ${PROGRAMS_CANLIB}
  57. - bcmserver
  58. canfdtest
  59. cangw
  60. cansniffer
  61. @@ -57,13 +62,17 @@ set(PROGRAMS
  62. isotpperf
  63. isotprecv
  64. isotpsend
  65. - isotpserver
  66. isotpsniffer
  67. isotptun
  68. slcan_attach
  69. slcand
  70. )
  71. +if(HAVE_FORK)
  72. + list(APPEND PROGRAMS bcmserver)
  73. + list(APPEND PROGRAMS isotpserver)
  74. +endif()
  75. +
  76. add_executable(can-calc-bit-timing
  77. calc-bit-timing/can-calc-bit-timing.c
  78. )
  79. diff --git a/GNUmakefile.am b/GNUmakefile.am
  80. index 5a7ad75f682e..e818754db3a4 100644
  81. --- a/GNUmakefile.am
  82. +++ b/GNUmakefile.am
  83. @@ -75,14 +75,12 @@ EXTRA_DIST += \
  84. bin_PROGRAMS = \
  85. asc2log \
  86. - bcmserver \
  87. can-calc-bit-timing \
  88. canbusload \
  89. candump \
  90. canfdtest \
  91. cangen \
  92. cangw \
  93. - canlogserver \
  94. canplayer \
  95. cansend \
  96. cansequence \
  97. @@ -91,7 +89,6 @@ bin_PROGRAMS = \
  98. isotpperf \
  99. isotprecv \
  100. isotpsend \
  101. - isotpserver \
  102. isotpsniffer \
  103. isotptun \
  104. j1939acd \
  105. @@ -106,6 +103,13 @@ bin_PROGRAMS = \
  106. slcanpty \
  107. testj1939
  108. +if HAVE_FORK
  109. +bin_PROGRAMS += \
  110. + bcmserver \
  111. + canlogserver \
  112. + isotpserver
  113. +endif
  114. +
  115. j1939acd_LDADD = libj1939.la
  116. j1939cat_LDADD = libj1939.la
  117. j1939spy_LDADD = libj1939.la
  118. diff --git a/Makefile b/Makefile
  119. index 29eef997b290..a26ff3d75e67 100644
  120. --- a/Makefile
  121. +++ b/Makefile
  122. @@ -45,6 +45,8 @@ MAKEFLAGS := -k
  123. CFLAGS := -O2 -Wall -Wno-parentheses
  124. +HAVE_FORK := $(shell ./check_cc.sh "$(CC)" fork_test.c)
  125. +
  126. CPPFLAGS += \
  127. -I. \
  128. -Iinclude \
  129. @@ -66,10 +68,14 @@ PROGRAMS_ISOTP := \
  130. isotpperf \
  131. isotprecv \
  132. isotpsend \
  133. - isotpserver \
  134. isotpsniffer \
  135. isotptun
  136. +ifeq ($(HAVE_FORK),1)
  137. +PROGRAMS_ISOTP += \
  138. + isotpserver
  139. +endif
  140. +
  141. PROGRAMS_J1939 := \
  142. j1939acd \
  143. j1939cat \
  144. @@ -87,14 +93,12 @@ PROGRAMS := \
  145. $(PROGRAMS_J1939) \
  146. $(PROGRAMS_SLCAN) \
  147. asc2log \
  148. - bcmserver \
  149. can-calc-bit-timing \
  150. canbusload \
  151. candump \
  152. canfdtest \
  153. cangen \
  154. cansequence \
  155. - canlogserver \
  156. canplayer \
  157. cansend \
  158. cansniffer \
  159. @@ -103,6 +107,12 @@ PROGRAMS := \
  160. mcp251xfd-dump \
  161. slcanpty
  162. +ifeq ($(HAVE_FORK),1)
  163. +PROGRAMS += \
  164. + canlogserver \
  165. + bcmserver
  166. +endif
  167. +
  168. all: $(PROGRAMS)
  169. clean:
  170. diff --git a/check_cc.sh b/check_cc.sh
  171. new file mode 100755
  172. index 000000000000..d85ad129da9d
  173. --- /dev/null
  174. +++ b/check_cc.sh
  175. @@ -0,0 +1,16 @@
  176. +#!/bin/sh
  177. +# SPDX-License-Identifier: GPL-2.0-only
  178. +# check_cc.sh - Helper to test userspace compilation support
  179. +# Copyright (c) 2015 Andrew Lutomirski
  180. +
  181. +CC="$1"
  182. +TESTPROG="$2"
  183. +shift 2
  184. +
  185. +if [ -n "$CC" ] && $CC -o /dev/null "$TESTPROG" -O0 "$@"; then
  186. + echo 1
  187. +else
  188. + echo 0
  189. +fi
  190. +
  191. +exit 0
  192. diff --git a/configure.ac b/configure.ac
  193. index 5493c9c7ccdf..9bf62a5c6409 100644
  194. --- a/configure.ac
  195. +++ b/configure.ac
  196. @@ -76,6 +76,8 @@ AC_CHECK_FUNCS([ \
  197. strtoul \
  198. ])
  199. +AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork_works" = "yes")
  200. +
  201. # glibc versions before 2.17 needs to link with -lrt for clock_nanosleep
  202. AC_SEARCH_LIBS([clock_nanosleep], [rt])
  203. diff --git a/fork_test.c b/fork_test.c
  204. new file mode 100644
  205. index 000000000000..036692392483
  206. --- /dev/null
  207. +++ b/fork_test.c
  208. @@ -0,0 +1,27 @@
  209. +/* SPDX-License-Identifier: GPL-2.0-only */
  210. +/*
  211. + * Copyright (C) 2023 Dario Binacchi <dario.binacchi@amarulasolutions.com>
  212. + *
  213. + * This program is free software; you can redistribute it and/or modify
  214. + * it under the terms of the version 2 of the GNU General Public License
  215. + * as published by the Free Software Foundation
  216. + *
  217. + * This program is distributed in the hope that it will be useful,
  218. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  219. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  220. + * GNU General Public License for more details.
  221. + *
  222. + * You should have received a copy of the GNU General Public License
  223. + * along with this program; if not, see <http://www.gnu.org/licenses/>.
  224. + */
  225. +
  226. +#include <stdio.h>
  227. +#include <sys/types.h>
  228. +#include <unistd.h>
  229. +
  230. +int main(int argc, char **argv)
  231. +{
  232. + fork();
  233. +
  234. + return 0;
  235. +}
  236. --
  237. 2.32.0