static int daemonize = 1;
struct config *config;
+
char *
hostname(void)
{
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:
*
}
/* 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);
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)
#include <stdint.h>
#include <stdio.h>
+#ifndef __unused
+#ifdef __GNUC__
+#define __unused __attribute__((unused))
+#else
+#define __unused
+#endif /* __GNUC__ */
+#endif
#define VERSION "DragonFly Mail Agent"
#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 */