Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error on FreeBSD #61

Closed
nokute78 opened this issue Mar 30, 2016 · 4 comments
Closed

Build error on FreeBSD #61

nokute78 opened this issue Mar 30, 2016 · 4 comments

Comments

@nokute78
Copy link
Collaborator

I found this issue when I tested #48.
My environment is FreeBSD 10.2 , gcc 4.8.5. clang 3.4.1.

There are 2 issues.
I want to know how we fix issue1

1. unknown type name 'ucontext_t'

This is compatibility issue.

This is caused these codes at lib/monkey/mk_core/mk_thread.c.
(Monkey project has same issue.)

#if defined (__linux__)
#include <ucontext.h>
#elif defined (__APPLE__)
#include <sys/ucontext.h>
#endif

There is no 'else' case.
It is very simple to replace #elif to #else or add FreeBSD define.

ucontext.h may be obsolete.

On the other hand, I found these articles.

That header is removed on 'POSIX issue7' .
http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap13.html

OpenBSD doesn't have ucontext.h
https://groups.google.com/forum/#!topic/v8-dev/seLPS6grC2A

They recommended to replace these API to POSIX threads.
http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap03.html

getcontext(), makecontext(), swapcontext()
Due to portability issues with these functions, especially with the manipulation of contexts, applications are recommended to be rewritten to use POSIX threads.

Build log

[  3%] Built target msgpack-static
[  4%] Built target jsmn
[  4%] Building C object lib/monkey/mk_core/CMakeFiles/mk_core.dir/mk_thread.c.o
fluent-bit/lib/monkey/mk_core/mk_thread.c:60:5: error: unknown type name 'ucontext_t'
    ucontext_t context;
    ^
fluent-bit/lib/monkey/mk_core/mk_thread.c:72:5: error: unknown type name 'ucontext_t'
    ucontext_t main;
    ^
fluent-bit/lib/monkey/mk_core/mk_thread.c:258:5: warning: implicit declaration of function 'swapcontext' is invalid in C99 [-Wimplicit-function-declaration]
    swapcontext(&dt->context, &sch->main);
    ^
fluent-bit/lib/monkey/mk_core/mk_thread.c:287:9: warning: implicit declaration of function 'getcontext' is invalid in C99 [-Wimplicit-function-declaration]
        getcontext(&dt->context);
        ^
fluent-bit/lib/monkey/mk_core/mk_thread.c:287:9: warning: declaration of built-in function 'getcontext' requires inclusion of the header <ucontext.h> [-Wbuiltin-requires-header]
fluent-bit/lib/monkey/mk_core/mk_thread.c:299:9: warning: implicit declaration of function 'makecontext' is invalid in C99 [-Wimplicit-function-declaration]
        makecontext(&dt->context, (void (*)(void))_mk_thread_entry_point, 1, sch);
        ^
4 warnings and 2 errors generated.
*** Error code 1

Stop.
make[2]: stopped in fluent-bit/build
*** Error code 1

Stop.
make[1]: stopped in fluent-bit/build
*** Error code 1

Stop.
make: stopped in fluent-bit/build
@nokute78
Copy link
Collaborator Author

2. use of undeclared identifier 'IPPROTO_TCP'

This is simple issue.
It is better to include 'netinet/in.h' which has the define 'IPPROTO_TCP'.

Build log

[ 58%] Built target cJSON
[ 59%] Building C object src/CMakeFiles/fluent-bit-static.dir/flb_network.c.o
fluent-bit/src/flb_network.c:123:30: error: use of undeclared identifier 'IPPROTO_TCP'
    ret = setsockopt(sockfd, SOL_TCP, TCP_NODELAY, &on, sizeof(on));
                             ^
fluent-bit/src/flb_network.c:40:17: note: expanded from macro 'SOL_TCP'
#define SOL_TCP IPPROTO_TCP
                ^
fluent-bit/src/flb_network.c:151:31: error: use of undeclared identifier 'IPPROTO_TCP'
    return setsockopt(sockfd, SOL_TCP, TCP_FASTOPEN, &qlen, sizeof(qlen));
                              ^
fluent-bit/src/flb_network.c:40:17: note: expanded from macro 'SOL_TCP'
#define SOL_TCP IPPROTO_TCP
                ^
fluent-bit/src/flb_network.c:341:63: error: incomplete definition of type 'struct sockaddr_in'
        if ((inet_ntop(AF_INET, &((struct sockaddr_in *)&addr)->sin_addr,
                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
fluent-bit/src/flb_network.c:341:43: note: forward declaration of 'struct sockaddr_in'
        if ((inet_ntop(AF_INET, &((struct sockaddr_in *)&addr)->sin_addr,
                                          ^
fluent-bit/src/flb_network.c:349:65: error: incomplete definition of type 'struct sockaddr_in6'
        if ((inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&addr)->sin6_addr,
                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
fluent-bit/src/flb_network.c:349:44: note: forward declaration of 'struct sockaddr_in6'
        if ((inet_ntop(AF_INET6, &((struct sockaddr_in6 *)&addr)->sin6_addr,
                                           ^
4 errors generated.
*** Error code 1

Stop.
make[2]: stopped in fluent-bit/build
*** Error code 1

Stop.
make[1]: stopped in fluent-bit/build
*** Error code 1

Stop.
make: stopped in fluent-bit/build

edsiper added a commit that referenced this issue Mar 30, 2016
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
@edsiper
Copy link
Member

edsiper commented Mar 30, 2016

thanks for catching these problems.

ucontext_t is being deprecated from POSIX years ago, but the main problem and suggestion is to use POSIX threads, for performance reasons this is not good, and that's why ucontext is still around.

In a next version of Fluent Bit I plan to replace ucontext by the workaround with sigsetjmp(3).

About the missing header for FreeBSD I found the following:

so all of them claim that #include <ucontext.h> is the right path, but looks like OSX is wrong.

Anyways I just pushed a fix for Monkey here: monkey/monkey@62f1aa2 and merged into Fluent Bit here: 00e5194

Second issue for missing in.h fixed here: d4e3943

would you please check if the fixes pushed are working ?

@nokute78
Copy link
Collaborator Author

Thank you for your information and updating.

d4e3943 can be built on FreeBSD.
These issues has been fixed. Thanks!

However, Monkey can't be built yet.
I opened new issue. monkey/monkey#235

@nokute78
Copy link
Collaborator Author

Note...

NetBSD: https://www.freebsd.org/cgi/man.cgi?query=ucontext&sektion=3&apropos=0&manpath=FreeBSD+6.1-RELEASE

Well, it's a FreeBSD's.
NetBSD : http://netbsd.gw.com/cgi-bin/man-cgi?ucontext+2.i386

My environment is FreeBSD 10.2 , gcc 4.8.5.

Sorry , I wrote a wrong information.
I used clang 3.4.1.

@nokute78 nokute78 closed this as completed Apr 8, 2016
fujimotos pushed a commit to fujimotos/fluent-bit that referenced this issue Jul 22, 2019
Signed-off-by: Vetési Zoltán <vetesi.zoltan@gmail.com>
allamand pushed a commit to allamand/fluent-bit that referenced this issue Oct 26, 2020
Fix broken link to td-agent-bit installation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants