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 while enable output compress #293

Open
flat2010 opened this issue Aug 19, 2020 · 1 comment
Open

Build Error while enable output compress #293

flat2010 opened this issue Aug 19, 2020 · 1 comment

Comments

@flat2010
Copy link

flat2010 commented Aug 19, 2020

Files involved

joy-master/joy_config.h
joy-master/src/p2f.c

Platform

Ubuntu 14.04 4.4.0-148

Problem

Step1: modify joy_config.h as follows:

/* Compression is enabled */
#define COMPRESSED_OUTPUT 1
#undef  FORCED_COMPRESSED_OUTPUT_OFF

Step2: modify p2f.c as follows:

// decomment line 1831
zflush(ctx->output);

Step3: then make

$make

Error occurs:

../src/p2f.c: In function 'flow_record_list_print_json':
../src/include/output.h:115:35: error: too few arguments to function 'gzflush'
     #define zflush(FILEp)        (gzflush(FILEp))
                                   ^~~~~~~
../src/p2f.c:1831:5: note: in expansion of macro 'zflush'
     zflush(ctx->output);
     ^~~~~~
In file included from ../src/include/output.h:103,
                 from ../src/include/hdr_dsc.h:47,
                 from ../src/include/p2f.h:59,
                 from ../src/include/pkt_proc.h:47,
                 from ../src/p2f.c:58:
/usr/local/include/zlib.h:1531:21: note: declared here
 ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));

This will happen when zflush called if gzip enabled.

Reason

According to Linux specification, gzflush needs 2 parameters which the last should be either:

  • Z_SYNC_FLUSH
  • Z_FULL_FLUSH
  • Z_FINISH

But there's only 1 parameter in definition of zflush:

#ifdef USE_BZIP2
    ···
    #define zflush(FILEp)        (BZ2_bzflush(FILEp))
    ···
#else
    ···
   // gzflush needs 2  parameters
    #define zflush(FILEp)        (gzflush(FILEp))
    ···

Fix

  1. Modify definition of gzflush, pass a right macro value as the 2nd parameter;
@flat2010
Copy link
Author

flat2010 commented Aug 19, 2020

Original:

// output.h
#else
    /** gzip compressed output */
    #include <zlib.h>
    typedef gzFile zfile;

    #define zopen(fname, ...)    (gzopen(fname, __VA_ARGS__))

    #ifdef WIN32
        #define zattach(FILEp, ...)  (gzdopen(_fileno(FILEp), __VA_ARGS__))
    #else
        #define zattach(FILEp, ...)  (gzdopen(fileno(FILEp), __VA_ARGS__))
    #endif

    #define zprintf(output, ...) (gzprintf(output, __VA_ARGS__))
    #define zflush(FILEp)        (gzflush(FILEp))
    #define zclose(output)       (gzclose(output))
    #define zsuffix              ".gz"
#endif

My fix:

// output.h
#else
    /** gzip compressed output */
    #include <zlib.h>
    typedef gzFile zfile;

    #define zopen(fname, ...)    (gzopen(fname, __VA_ARGS__))

    #ifdef WIN32
        #define zattach(FILEp, ...)  (gzdopen(_fileno(FILEp), __VA_ARGS__))
        #define zflush(FILEp)        (gzflush(FILEp))
    #else
        #define zattach(FILEp, ...)  (gzdopen(fileno(FILEp), __VA_ARGS__))
        // here we  pass Z_FINISH to gzflush
        #define zflush(FILEp)        (gzflush(FILEp, Z_FINISH))
    #endif

    #define zprintf(output, ...) (gzprintf(output, __VA_ARGS__))
    #define zclose(output)       (gzclose(output))
    #define zsuffix              ".gz"
#endif

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

1 participant