nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 1dd7b07f688d0fa38353914d2a2c4d4393abd430
parent 774f27053a7eaec5799e3a4a33b583d5a464439c
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Mon,  8 Jul 2019 17:50:01 +0200

honor DESTDIR on install

This allows installation into a staging directory to ease packaging.

Diffstat:
MCHANGES | 1+
MMakefile | 14++++++++------
Minstall.c | 66+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/CHANGES b/CHANGES @@ -1,3 +1,4 @@ +20190708 code: use DESTDIR environment variable as root directory in install. 20071130 version: netqmail 1.06 20071130 legal: qmail-1.03 is now in the public domain 20051103 doc: dot-qmail.9 updated for changed (19980613) conf-patrn default, tnx ADM diff --git a/Makefile b/Makefile @@ -741,16 +741,18 @@ seek.h fork.h install: \ load install.o fifo.o hier.o auto_qmail.o auto_split.o auto_uids.o \ -strerr.a substdio.a open.a error.a str.a fs.a +strerr.a substdio.a open.a error.a env.a str.a fs.a stralloc.a alloc.a ./load install fifo.o hier.o auto_qmail.o auto_split.o \ - auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a + auto_uids.o strerr.a substdio.a open.a error.a env.a str.a fs.a \ + stralloc.a alloc.a install-big: \ load install-big.o fifo.o install.o auto_qmail.o auto_split.o \ -auto_uids.o strerr.a substdio.a open.a error.a str.a fs.a +auto_uids.o strerr.a substdio.a open.a error.a env.a str.a fs.a stralloc.a \ +alloc.a ./load install-big fifo.o install.o auto_qmail.o \ auto_split.o auto_uids.o strerr.a substdio.a open.a error.a \ - str.a fs.a + env.a str.a fs.a stralloc.a alloc.a install-big.o: \ compile install-big.c auto_qmail.h auto_split.h auto_uids.h fmt.h \ @@ -758,8 +760,8 @@ fifo.h ./compile install-big.c install.o: \ -compile install.c substdio.h strerr.h error.h open.h readwrite.h \ -exit.h +compile install.c substdio.h strerr.h env.h error.h fifo.h open.h \ +readwrite.h exit.h alloc.h str.h stralloc.h ./compile install.c instcheck: \ diff --git a/install.c b/install.c @@ -1,9 +1,14 @@ #include "substdio.h" #include "strerr.h" +#include "env.h" #include "error.h" +#include "fifo.h" #include "open.h" #include "readwrite.h" #include "exit.h" +#include "alloc.h" +#include "str.h" +#include "stralloc.h" extern void hier(); @@ -11,19 +16,62 @@ extern void hier(); int fdsourcedir = -1; +static void die_nomem() +{ + strerr_die2sys(111,FATAL,"out of memory"); +} + +static void ddhome(dd,home) +stralloc *dd; +char *home; +{ + const char *denv = env_get("DESTDIR"); + if (denv) + if (!stralloc_copys(dd,denv)) die_nomem(); + + if (!stralloc_catb(dd,home,str_len(home))) die_nomem(); + if (!stralloc_0(dd)) die_nomem(); +} + +static int mkdir_p(home,mode) +char *home; +int mode; +{ + stralloc parent = { 0 }; + unsigned int sl; + int r = mkdir(home,mode); + if (!r || errno != error_noent) + return r; + + /* try parent first */ + sl = str_rchr(home, '/'); + if (!stralloc_copyb(&parent,home,sl)) die_nomem(); + if (!stralloc_0(&parent)) die_nomem(); + r = mkdir_p(parent.s); + alloc_free(parent.s); + if (r && errno != error_exist) + return r; + + return mkdir(home,mode); +} + void h(home,uid,gid,mode) char *home; int uid; int gid; int mode; { - if (mkdir(home,0700) == -1) + stralloc dh = { 0 }; + ddhome(&dh, home); + home=dh.s; + if (mkdir_p(home,mode) == -1) if (errno != error_exist) strerr_die4sys(111,FATAL,"unable to mkdir ",home,": "); if (chown(home,uid,gid) == -1) strerr_die4sys(111,FATAL,"unable to chown ",home,": "); if (chmod(home,mode) == -1) strerr_die4sys(111,FATAL,"unable to chmod ",home,": "); + alloc_free(dh.s); } void d(home,subdir,uid,gid,mode) @@ -33,6 +81,9 @@ int uid; int gid; int mode; { + stralloc dh = { 0 }; + ddhome(&dh, home); + home=dh.s; if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (mkdir(subdir,0700) == -1) @@ -42,6 +93,7 @@ int mode; strerr_die6sys(111,FATAL,"unable to chown ",home,"/",subdir,": "); if (chmod(subdir,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",subdir,": "); + alloc_free(dh.s); } void p(home,fifo,uid,gid,mode) @@ -51,6 +103,9 @@ int uid; int gid; int mode; { + stralloc dh = { 0 }; + ddhome(&dh, home); + home=dh.s; if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); if (fifo_make(fifo,0700) == -1) @@ -60,6 +115,7 @@ int mode; strerr_die6sys(111,FATAL,"unable to chown ",home,"/",fifo,": "); if (chmod(fifo,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",fifo,": "); + alloc_free(dh.s); } char inbuf[SUBSTDIO_INSIZE]; @@ -77,7 +133,10 @@ int mode; { int fdin; int fdout; + stralloc dh = { 0 }; + ddhome(&dh, home); + home=dh.s; if (fchdir(fdsourcedir) == -1) strerr_die2sys(111,FATAL,"unable to switch back to source directory: "); @@ -115,6 +174,7 @@ int mode; strerr_die6sys(111,FATAL,"unable to chown .../",subdir,"/",file,": "); if (chmod(file,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod .../",subdir,"/",file,": "); + alloc_free(dh.s); } void z(home,file,len,uid,gid,mode) @@ -126,7 +186,10 @@ int gid; int mode; { int fdout; + stralloc dh = { 0 }; + ddhome(&dh, home); + home=dh.s; if (chdir(home) == -1) strerr_die4sys(111,FATAL,"unable to switch to ",home,": "); @@ -150,6 +213,7 @@ int mode; strerr_die6sys(111,FATAL,"unable to chown ",home,"/",file,": "); if (chmod(file,mode) == -1) strerr_die6sys(111,FATAL,"unable to chmod ",home,"/",file,": "); + alloc_free(dh.s); } void main()