简体   繁体   中英

C: Implicit declaration of function ‘vsyslog’

I am trying to implement a sys logger for my pam module. My code is as follows:

#define __USE_BSD
#include <syslog.h>
#include <stdarg.h>

#include <string.h>

static void _log(int level, const char *format, ...) {
    va_list args;
    va_start(args, format);
    openlog("my_app", LOG_CONS|LOG_PID|LOG_PERROR, LOG_AUTH);
    vsyslog(level, format, args);
    va_end(args);
    closelog();
}

PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh,
    int flags,int argc, const char **argv ) {

    /* Something... */

    _log(LOG_INFO, "username check");
    if (strcmp(username, "jdoe") != 0) {
        _log(LOG_ERR, "Auth error");
        return PAM_IGNORE;
    }

    /* Something else... *

}

But, when I compile, Eclipse CDT returns me a warning:

../src/mypam.c:33:5: warning: implicit declaration of function ‘vsyslog’ [-Wimplicit-function-declaration]

How could I fix it? Note that I am using CentOS 7 as dev machine.

Fixed, by defining both __USE_BSD and _BSD_SOURCE as follows:

#define __USE_BSD
#define _BSD_SOURCE
#include <syslog.h>
#include <stdarg.h>

// ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM