On Mon, Dec 28, 1998 at 01:27:45AM -0500, Sam wrote:
>
> #include <unistd.h>
> #include <stdlib.h>
>
> int main(int argc, char *argv[])
> {
> char buffy[80];
> time_t t;
>
> if (argc < 2) return (1);
> time(&t);
> sprintf(buffy, "%ld.%ld", (long)t, (long)getpid());
> execl("/bin/sh", "foo.sh", buffy, argv[1], (char *)0);
> return (1);
> }
>
> And in foo.sh:
>
> cd $2 || exit 1
> h=`hostname`
> cat >tmp/$1.$h || exit 1
> exec mv tmp/$1.$h new/$1.$h
>
Why not just using the shell ?
I used the following bash script, together with some tiny c progs
(alarm, rewindstdin, fsync) to run a .qmail-default based virtual
domain setup.
Lars
from your .qmail:
| maildir.sh `return-path-to-maildir`
#!/bin/bash
# usage (from dot-qmail):
#| alarm 86400 maildir.sh `return-path-to-maildir`
# Delivers a message from fd 0 to a maildir.
# Nearly maildir(5) compliant. Yes, you trust your little unix friends ...
# bash, cd, ln, rm, cat, date, sed, hostname, echo. Do you ?
# external programs.
rm="/bin/rm"
ln="/bin/ln"
sed="/bin/sed"
cat="/bin/cat"
hostname="/bin/hostname"
# requires GNU date.
date="/bin/date"
function tryunlink () { $rm -f $tmp >/dev/null 2>&1; }
function dieunlink () { tryunlink; exit $1; }
# install an ALRM signal handler.
trap 'echo "Timeout on maildir delivery. (#4.3.0)" >&2; tryunlink; exit 3' 14
trap 'tryunlink; exit 1' 2 3
# step one from maildir(5).
test -n $1 || exit 2
cd $1 || exit 2
# step two and three. get unique filname in tmp/
node=`$hostname`
tmp="tmp/`$date +%s`.$$@$node"
i=0
while [ -f $tmp ]; do
tmp="tmp/`$date +%s`.$$@$node"
if [ $((i+=1)) -gt 2 ]
then
echo "Cannot find unique filename in tmp" >&2
exit 1
fi
sleep 2
done
new=`echo $tmp | $sed 's#tmp/#new/#'`
# step four. open file in tmp/
exec 4>$tmp || exit 1
# step 5: write the message. Can cat and echo do `NFS-writes' ...
# write Return Path and Delivered-To Header.
echo -n "$RPLINE$DTLINE" 1>&4 || dieunlink 1
# use this to test the ALRM signal handler.
# while true; do sleep 1; done
# write the message data.
$cat - 1>&4 || dieunlink 4
# fsync the message in tmp/
# /usr/local/bin/fsync 4 || dieunlink 1;
# close file in tmp/
exec 4>&- || dieunlink 1
# step six (final): link tmp/ to new/
$ln $tmp $new || dieunlink 1
# OK. got it. try to unlink tmp/
tryunlink
exit 0