From: Simon Schubert Date: Thu, 9 Jul 2009 12:37:14 +0000 (+0200) Subject: dma: several fixes to make dma build on non-BSD OS's X-Git-Tag: v2.4.0~414^2~33 X-Git-Url: https://gitweb.dragonflybsd.org/~nant/dragonfly.git/commitdiff_plain/144b337d5fb21324286871fbca0c90d460e06d9d dma: several fixes to make dma build on non-BSD OS's - replace open(..., O_EXLOCK) with a new open_locked() routine; - define the __unused function attribute; - do not redefine PATH_MAX. Submitted-by: Peter Pentchev --- diff --git a/libexec/dma/dma.c b/libexec/dma/dma.c index 511b936fd6..7d6076d453 100644 --- a/libexec/dma/dma.c +++ b/libexec/dma/dma.c @@ -74,6 +74,7 @@ struct authusers authusers = LIST_HEAD_INITIALIZER(authusers); static int daemonize = 1; struct config *config; + char * hostname(void) { @@ -235,6 +236,27 @@ gentempf(struct queue *queue) return (0); } +static int +open_locked(const char *fname, int flags) +{ +#ifndef O_EXLOCK + int fd, save_errno; + + fd = open(fname, flags, 0); + if (fd < 0) + return(fd); + if (flock(fd, LOCK_EX|((flags & O_NONBLOCK)? LOCK_NB: 0)) < 0) { + save_errno = errno; + close(fd); + errno = save_errno; + return(-1); + } + return(fd); +#else + return(open(fname, flags|O_EXLOCK)); +#endif +} + /* * spool file format: * @@ -542,7 +564,7 @@ deliver_local(struct qitem *it, const char **errmsg) } /* mailx removes users mailspool file if empty, so open with O_CREAT */ - mbox = open(fn, O_WRONLY | O_EXLOCK | O_APPEND | O_CREAT); + mbox = open_locked(fn, O_WRONLY | O_APPEND | O_CREAT); if (mbox < 0) { syslog(LOG_ERR, "%s: local delivery deferred: can not open `%s': %m", it->queueid, fn); @@ -703,7 +725,7 @@ load_queue(struct queue *queue) continue; if (asprintf(&queuefn, "%s/%s", config->spooldir, de->d_name) < 0) goto fail; - fd = open(queuefn, O_RDONLY|O_EXLOCK|O_NONBLOCK); + fd = open_locked(queuefn, O_RDONLY|O_NONBLOCK); if (fd < 0) { /* Ignore locked files */ if (errno == EWOULDBLOCK) diff --git a/libexec/dma/dma.h b/libexec/dma/dma.h index 8a07ba9983..5ab72cefe8 100644 --- a/libexec/dma/dma.h +++ b/libexec/dma/dma.h @@ -46,6 +46,13 @@ #include #include +#ifndef __unused +#ifdef __GNUC__ +#define __unused __attribute__((unused)) +#else +#define __unused +#endif /* __GNUC__ */ +#endif #define VERSION "DragonFly Mail Agent" @@ -53,7 +60,9 @@ #define MIN_RETRY 300 /* 5 minutes */ #define MAX_RETRY (3*60*60) /* retry at least every 3 hours */ #define MAX_TIMEOUT (5*24*60*60) /* give up after 5 days */ +#ifndef PATH_MAX #define PATH_MAX 1024 /* Max path len */ +#endif #define SMTP_PORT 25 /* Default SMTP port */ #define CON_TIMEOUT 120 /* Connection timeout */