Don't compile programs using fork() on MMU-less systems

Systems that lack a MMU cannot use fork() to create the child process.
The patch does not compile the affected programs on MMU-less systems.

Co-developed-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
pull/426/head
Dario Binacchi 2023-05-05 08:57:45 +02:00
parent e44db7366b
commit 5ed3b4ded6
6 changed files with 77 additions and 9 deletions

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.3)
project(can-utils LANGUAGES C) project(can-utils LANGUAGES C)
include (CheckFunctionExists)
include (CheckSymbolExists) include (CheckSymbolExists)
include (GNUInstallDirs) include (GNUInstallDirs)
@ -25,12 +26,13 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSCM_TXTIME=SO_TXTIME")
include_directories (.) include_directories (.)
include_directories (./include) include_directories (./include)
check_function_exists(fork HAVE_FORK)
set(PROGRAMS_CANLIB set(PROGRAMS_CANLIB
asc2log asc2log
canbusload canbusload
candump candump
cangen cangen
canlogserver
canplayer canplayer
cansend cansend
cansequence cansequence
@ -39,6 +41,10 @@ set(PROGRAMS_CANLIB
slcanpty slcanpty
) )
if(HAVE_FORK)
list(APPEND PROGRAMS_CANLIB canlogserver)
endif()
set(PROGRAMS_J1939 set(PROGRAMS_J1939
j1939acd j1939acd
j1939cat j1939cat
@ -49,7 +55,6 @@ set(PROGRAMS_J1939
set(PROGRAMS set(PROGRAMS
${PROGRAMS_CANLIB} ${PROGRAMS_CANLIB}
bcmserver
canfdtest canfdtest
cangw cangw
cansniffer cansniffer
@ -57,13 +62,17 @@ set(PROGRAMS
isotpperf isotpperf
isotprecv isotprecv
isotpsend isotpsend
isotpserver
isotpsniffer isotpsniffer
isotptun isotptun
slcan_attach slcan_attach
slcand slcand
) )
if(HAVE_FORK)
list(APPEND PROGRAMS bcmserver)
list(APPEND PROGRAMS isotpserver)
endif()
add_executable(can-calc-bit-timing add_executable(can-calc-bit-timing
calc-bit-timing/can-calc-bit-timing.c calc-bit-timing/can-calc-bit-timing.c
) )

View File

@ -75,14 +75,12 @@ EXTRA_DIST += \
bin_PROGRAMS = \ bin_PROGRAMS = \
asc2log \ asc2log \
bcmserver \
can-calc-bit-timing \ can-calc-bit-timing \
canbusload \ canbusload \
candump \ candump \
canfdtest \ canfdtest \
cangen \ cangen \
cangw \ cangw \
canlogserver \
canplayer \ canplayer \
cansend \ cansend \
cansequence \ cansequence \
@ -91,7 +89,6 @@ bin_PROGRAMS = \
isotpperf \ isotpperf \
isotprecv \ isotprecv \
isotpsend \ isotpsend \
isotpserver \
isotpsniffer \ isotpsniffer \
isotptun \ isotptun \
j1939acd \ j1939acd \
@ -106,6 +103,13 @@ bin_PROGRAMS = \
slcanpty \ slcanpty \
testj1939 testj1939
if HAVE_FORK
bin_PROGRAMS += \
bcmserver \
canlogserver \
isotpserver
endif
j1939acd_LDADD = libj1939.la j1939acd_LDADD = libj1939.la
j1939cat_LDADD = libj1939.la j1939cat_LDADD = libj1939.la
j1939spy_LDADD = libj1939.la j1939spy_LDADD = libj1939.la

View File

@ -45,6 +45,8 @@ MAKEFLAGS := -k
CFLAGS := -O2 -Wall -Wno-parentheses CFLAGS := -O2 -Wall -Wno-parentheses
HAVE_FORK := $(shell ./check_cc.sh "$(CC)" fork_test.c)
CPPFLAGS += \ CPPFLAGS += \
-I. \ -I. \
-Iinclude \ -Iinclude \
@ -66,10 +68,14 @@ PROGRAMS_ISOTP := \
isotpperf \ isotpperf \
isotprecv \ isotprecv \
isotpsend \ isotpsend \
isotpserver \
isotpsniffer \ isotpsniffer \
isotptun isotptun
ifeq ($(HAVE_FORK),1)
PROGRAMS_ISOTP += \
isotpserver
endif
PROGRAMS_J1939 := \ PROGRAMS_J1939 := \
j1939acd \ j1939acd \
j1939cat \ j1939cat \
@ -87,14 +93,12 @@ PROGRAMS := \
$(PROGRAMS_J1939) \ $(PROGRAMS_J1939) \
$(PROGRAMS_SLCAN) \ $(PROGRAMS_SLCAN) \
asc2log \ asc2log \
bcmserver \
can-calc-bit-timing \ can-calc-bit-timing \
canbusload \ canbusload \
candump \ candump \
canfdtest \ canfdtest \
cangen \ cangen \
cansequence \ cansequence \
canlogserver \
canplayer \ canplayer \
cansend \ cansend \
cansniffer \ cansniffer \
@ -103,6 +107,12 @@ PROGRAMS := \
mcp251xfd-dump \ mcp251xfd-dump \
slcanpty slcanpty
ifeq ($(HAVE_FORK),1)
PROGRAMS += \
canlogserver \
bcmserver
endif
all: $(PROGRAMS) all: $(PROGRAMS)
clean: clean:

16
check_cc.sh 100755
View File

@ -0,0 +1,16 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
# check_cc.sh - Helper to test userspace compilation support
# Copyright (c) 2015 Andrew Lutomirski
CC="$1"
TESTPROG="$2"
shift 2
if [ -n "$CC" ] && $CC -o /dev/null "$TESTPROG" -O0 "$@"; then
echo 1
else
echo 0
fi
exit 0

View File

@ -76,6 +76,8 @@ AC_CHECK_FUNCS([ \
strtoul \ strtoul \
]) ])
AM_CONDITIONAL(HAVE_FORK, test "$ac_cv_func_fork_works" = "yes")
# glibc versions before 2.17 needs to link with -lrt for clock_nanosleep # glibc versions before 2.17 needs to link with -lrt for clock_nanosleep
AC_SEARCH_LIBS([clock_nanosleep], [rt]) AC_SEARCH_LIBS([clock_nanosleep], [rt])

27
fork_test.c 100644
View File

@ -0,0 +1,27 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) 2023 Dario Binacchi <dario.binacchi@amarulasolutions.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the version 2 of the GNU General Public License
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int main(int argc, char **argv)
{
fork();
return 0;
}