summaryrefslogtreecommitdiff
path: root/src/condredirect.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/condredirect.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/condredirect.c')
-rw-r--r--src/condredirect.c77
1 files changed, 36 insertions, 41 deletions
diff --git a/src/condredirect.c b/src/condredirect.c
index 6f2d89a..534dac7 100644
--- a/src/condredirect.c
+++ b/src/condredirect.c
@@ -1,81 +1,76 @@
#include <unistd.h>
-#include "sig.h"
-#include "exit.h"
+
+#include "buffer.h"
#include "env.h"
+#include "exit.h"
+#include "fmt.h"
#include "logmsg.h"
-#include "wait.h"
#include "seek.h"
+#include "sig.h"
+#include "wait.h"
+
#include "qmail.h"
-#include "buffer.h"
-#include "fmt.h"
#define WHO "condredirect"
struct qmail qqt;
-ssize_t mywrite(int fd,char *buf,int len)
+ssize_t mywrite(int fd, char *buf, int len)
{
- qmail_put(&qqt,buf,len);
+ qmail_put(&qqt, buf, len);
return len;
}
char inbuf[BUFFER_INSIZE];
-buffer bi = BUFFER_INIT(read,0,inbuf,sizeof(inbuf));
+buffer bi = BUFFER_INIT(read, 0, inbuf, sizeof(inbuf));
char outbuf[1];
-buffer bo = BUFFER_INIT(mywrite,-1,outbuf,sizeof(outbuf));
+buffer bo = BUFFER_INIT(mywrite, -1, outbuf, sizeof(outbuf));
char num[FMT_ULONG];
-int main(int argc,char **argv)
+int main(int argc, char **argv)
{
char *sender;
char *dtline;
int pid;
int wstat;
char *qqx;
-
- if (!argv[1] || !argv[2])
- logmsg(WHO,100,USAGE,"condredirect newaddress program [ arg ... ]");
-
+
+ if (!argv[1] || !argv[2]) logmsg(WHO, 100, USAGE, "condredirect newaddress program [ arg ... ]");
+
pid = fork();
- if (pid == -1)
- logmsg(WHO,111,FATAL,"unable to fork: ");
+ if (pid == -1) logmsg(WHO, 111, FATAL, "unable to fork: ");
if (pid == 0) {
- execvp(argv[2],argv + 2);
+ execvp(argv[2], argv + 2);
if (errno) _exit(111);
_exit(100);
}
- if (wait_pid(&wstat,pid) == -1)
- logmsg(WHO,111,FATAL,"wait failed");
- if (wait_crashed(wstat))
- logmsg(WHO,111,FATAL,"child crashed");
+ if (wait_pid(&wstat, pid) == -1) logmsg(WHO, 111, FATAL, "wait failed");
+ if (wait_crashed(wstat)) logmsg(WHO, 111, FATAL, "child crashed");
switch (wait_exitcode(wstat)) {
- case 0: break;
- case 111: logmsg(WHO,111,FATAL,"temporary child error");
- default: _exit(0);
+ case 0: break;
+ case 111: logmsg(WHO, 111, FATAL, "temporary child error");
+ default: _exit(0);
}
- if (seek_begin(0) == -1)
- logmsg(WHO,111,FATAL,"unable to rewind: ");
+ if (seek_begin(0) == -1) logmsg(WHO, 111, FATAL, "unable to rewind: ");
sig_pipeignore();
-
+
sender = env_get("SENDER");
- if (!sender) logmsg(WHO,100,ERROR,"SENDER not set");
+ if (!sender) logmsg(WHO, 100, ERROR, "SENDER not set");
dtline = env_get("DTLINE");
- if (!dtline) logmsg(WHO,100,ERROR,"DTLINE not set");
-
- if (qmail_open(&qqt) == -1)
- logmsg(WHO,111,FATAL,"unable to fork: ");
- qmail_puts(&qqt,dtline);
- if (buffer_copy(&bo,&bi) != 0)
- logmsg(WHO,111,FATAL,"unable to read message: ");
+ if (!dtline) logmsg(WHO, 100, ERROR, "DTLINE not set");
+
+ if (qmail_open(&qqt) == -1) logmsg(WHO, 111, FATAL, "unable to fork: ");
+ qmail_puts(&qqt, dtline);
+ if (buffer_copy(&bo, &bi) != 0) logmsg(WHO, 111, FATAL, "unable to read message: ");
buffer_flush(&bo);
-
- num[fmt_ulong(num,qmail_qp(&qqt))] = 0;
- qmail_from(&qqt,sender);
- qmail_to(&qqt,argv[1]);
+ num[fmt_ulong(num, qmail_qp(&qqt))] = 0;
+
+ qmail_from(&qqt, sender);
+ qmail_to(&qqt, argv[1]);
qqx = qmail_close(&qqt);
- if (*qqx) logmsg(WHO,*qqx == 'D' ? 100 : 111,FATAL,qqx + 1);
- logmsg(WHO,0,LOG,B("qp ",num));
+ if (*qqx) logmsg(WHO, *qqx == 'D' ? 100 : 111, FATAL, qqx + 1);
+ logmsg(WHO, 0, LOG, B("qp ", num));
}