Bug 1001

Summary: build error expected declaration specifiers or '...' before '(' token
Product: Sudo Reporter: nkulikov
Component: SudoAssignee: Todd C. Miller <Todd.Miller>
Status: RESOLVED FIXED    
Severity: normal    
Priority: low    
Version: 1.9.8   
Hardware: Other   
OS: Linux   

Description nkulikov 2021-10-07 04:03:01 MDT
We are using quite old kernel (2.6.23+custom patches) and try to cross compile recent version of sudo for sh4 platform. It seems the configure script enable some workarounds from include/sudo_compat.h and here we get the errors like this one:

../../include/sudo_compat.h:595:35: error: expected declaration specifiers or '...' before '(' token
  595 | # define pipe2(_a, _b) sudo_pipe2((_a), (_b))

The preprocessed output (simplified for human reading):

extern int
         sudo_pipe2((
          int __pipedes[2]
         ), (
          int __flags
         ))
         __attribute__ ((__nothrow__ , __leaf__)) ;

I've tried different version of GCC and no one can't compile it. For example Debian gcc output:

$ gcc --version
gcc (Debian 8.3.0-6) 8.3.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat a.c
extern int sudo_pipe2((int __pipedes[2]), (int __flags)) __attribute__ ((__nothrow__ , __leaf__)) ;

$ gcc a.c
a.c:1:23: error: expected declaration specifiers or '...' before '(' token
 extern int sudo_pipe2((int __pipedes[2]), (int __flags)) __attribute__ ((__nothrow__ , __leaf__)) ;
                       ^
a.c:1:43: error: expected declaration specifiers or '...' before '(' token
 extern int sudo_pipe2((int __pipedes[2]), (int __flags)) __attribute__ ((__nothrow__ , __leaf__)) ;
Comment 1 Todd C. Miller 2021-10-07 07:36:36 MDT
This is usually due to a mismatch between the header files and the C library.  It sounds like pipe2 is not present in the sh4 libc so sudo tries to use its own version but there actually is a pipe2 prototype in the headers you are using.

If you cannot fix the header files, adding:

#include <unistd.h>

to sudo_compat.h may work around the problem.
Comment 2 nkulikov 2021-10-10 22:52:09 MDT
That is right, uClibc-ng header has pipe2, dup3 function declarations while implementation is not defined for such old kernel (no ioctls). I've added function definition (by using another ioctls) and compilation went well.

Obviously in this case sudo's workaround macro is not enabled.
Comment 3 Todd C. Miller 2022-01-27 19:54:08 MST
sudo_compat.h now includes unistd.h which should avoid the header issue