[exim-dev] Using log_create() from src/src/log.c

Góra strony
Delete this message
Reply to this message
Autor: Todd Lyons
Data:  
Dla: exim-dev
Temat: [exim-dev] Using log_create() from src/src/log.c
I am working on my dmarc.c code, adding a function to write dmarc
results to a file in the same format the opendmarc itself does, so
that a sysadmin could use the opendmarc tools to 1) import data to a
database 2) send out reports 3) age the data.

In log.c, there is a function named log_create. You pass it a const
unsigned string for the filename, it creates the file and passes back
a file descriptor. The problem I'm having is that the function is not
declared anywhere. I cannot figure out why building log.c doesn't
complain, but I do know that it's used only in log.c, nowhere else, no
doubt that has something to do with it. In my dmarc.c, I have
included "exim.h" and "functions.h", and I get this error:

dmarc.c: In function ‘dmarc_write_history_file’:
dmarc.c:373:3: warning: implicit declaration of function ‘log_create’
[-Wimplicit-function-declaration]

See the code I pasted below for what it is complaining about.

Thinking I was brilliant, I added 'extern const int log_create(uschar
*);' to my dmarc.c, and it then builds dmarc.o properly. But the
linking of the exim binary fails:

gcc -o exim -g acl.o child.o crypt16.o daemon.o dbfn.o debug.o
deliver.o directory.o dns.o drtables.o enq.o exim.o expand.o filter.o
filtertest.o globals.o dkim.o dmarc.o header.o host.o ip.o log.o lss.o
match.o moan.o os.o parse.o queue.o rda.o readconf.o receive.o retry.o
rewrite.o rfc2047.o route.o search.o sieve.o smtp_in.o smtp_out.o
spool_in.o spool_out.o std-crypto.o store.o string.o tls.o tod.o
transport.o tree.o verify.o lookups/lf_quote.o lookups/lf_check_file.o
lookups/lf_sqlperform.o local_scan.o perl.o malware.o mime.o regex.o
spam.o spool_mbox.o demime.o bmi_spam.o spf.o srs.o dcc.o version.o \
      routers/routers.a transports/transports.a lookups/lookups.a \
      auths/auths.a pdkim/pdkim.a \
      -lresolv -lnsl -lcrypt -lm    \
       -ldb -L/usr/lib/mysql -lmysqlclient -lsasl2 \
      -Wl,-E  -fstack-protector -L/usr/local/lib
-L/usr/lib/perl/5.14/CORE -lperl -ldl -lm -lpthread -lc -lcrypt -lssl
-lcrypto   -lpcre -lspf2 -L/work/fakeroot/usr/local/lib
-L/work/fakeroot/usr/local/lib/ -lopendmarc
-Wl,-rpath,/work/fakeroot/usr/local/lib/
dmarc.o: In function `dmarc_write_history_file':
/work/home/exim-build/projects/exim/src/build-Linux-i386/dmarc.c:373:
undefined reference to `log_create'
collect2: ld returned 1 exit status


Is there a way to get my dmarc.c to properly call and link the
existing log_create?
Do I have to copy the code into my own function?
Other?
Like I said, I'm not really sure how it is working in the first place
since it's not declared anywhere.

Here is my code:

int dmarc_write_history_file()
{
static int history_file_fd;
ssize_t written_len;

  /* new exim configuration setting */
  if (dmarc_history_file == NULL)
    return DMARC_HIST_DISABLED;


  /* globally dmarc.c scoped buffer */
  if (history_buffer == NULL)
    return DMARC_HIST_EMPTY;


history_file_fd = log_create(dmarc_history_file);

  if (history_file_fd < 0)
    return DMARC_HIST_FILE_ERR;
  written_len = write_to_fd_buf(history_file_fd,
                                history_buffer,
                                sizeof history_buffer);
  if (written_len == 0)
    return DMARC_HIST_WRITE_ERR;
  (void)close(history_file_fd);
  return DMARC_HIST_OK;
}


Any suggestions and comments are welcome.

...Todd
--
The total budget at all receivers for solving senders' problems is $0.
If you want them to accept your mail and manage it the way you want,
send it the way the spec says to. --John Levine