summaryrefslogtreecommitdiff
path: root/src/install.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/install.c')
-rw-r--r--src/install.c127
1 files changed, 49 insertions, 78 deletions
diff --git a/src/install.c b/src/install.c
index c738fb7..e6f95a9 100644
--- a/src/install.c
+++ b/src/install.c
@@ -1,10 +1,11 @@
-#include <unistd.h>
#include <sys/stat.h>
+#include <unistd.h>
+
#include "buffer.h"
-#include "logmsg.h"
-#include "open.h"
#include "exit.h"
#include "fifo.h"
+#include "logmsg.h"
+#include "open.h"
extern void hier();
@@ -12,41 +13,30 @@ extern void hier();
int fdsourcedir = -1;
-void h(char *home,int uid,int gid,int mode)
+void h(char *home, int uid, int gid, int mode)
{
- if (mkdir(home,0700) == -1)
- if (errno != EEXIST)
- logmsg(WHO,111,FATAL,B("unable to mkdir: ",home));
- if (chown(home,uid,gid) == -1)
- logmsg(WHO,111,FATAL,B("unable to chown: ",home));
- if (chmod(home,mode) == -1)
- logmsg(WHO,111,FATAL,B("unable to chmod: ",home));
+ if (mkdir(home, 0700) == -1)
+ if (errno != EEXIST) logmsg(WHO, 111, FATAL, B("unable to mkdir: ", home));
+ if (chown(home, uid, gid) == -1) logmsg(WHO, 111, FATAL, B("unable to chown: ", home));
+ if (chmod(home, mode) == -1) logmsg(WHO, 111, FATAL, B("unable to chmod: ", home));
}
-void d(char *home,char *subdir,int uid,int gid,int mode)
+void d(char *home, char *subdir, int uid, int gid, int mode)
{
- if (chdir(home) == -1)
- logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
- if (mkdir(subdir,0700) == -1)
- if (errno != EEXIST)
- logmsg(WHO,111,FATAL,B("unable to mkdir: ",home,"/",subdir));
- if (chown(subdir,uid,gid) == -1)
- logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",subdir));
- if (chmod(subdir,mode) == -1)
- logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",subdir));
+ if (chdir(home) == -1) logmsg(WHO, 110, FATAL, B("unable to switch to: ", home));
+ if (mkdir(subdir, 0700) == -1)
+ if (errno != EEXIST) logmsg(WHO, 111, FATAL, B("unable to mkdir: ", home, "/", subdir));
+ if (chown(subdir, uid, gid) == -1) logmsg(WHO, 111, FATAL, B("unable to chown: ", home, "/", subdir));
+ if (chmod(subdir, mode) == -1) logmsg(WHO, 111, FATAL, B("unable to chmod: ", home, "/", subdir));
}
-void p(char *home,char *fifo,int uid,int gid,int mode)
+void p(char *home, char *fifo, int uid, int gid, int mode)
{
- if (chdir(home) == -1)
- logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
- if (fifo_make(fifo,0700) == -1)
- if (errno != EEXIST)
- logmsg(WHO,111,FATAL,B("unable to mkfifo: ",home,"/",fifo));
- if (chown(fifo,uid,gid) == -1)
- logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",fifo));
- if (chmod(fifo,mode) == -1)
- logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",fifo));
+ if (chdir(home) == -1) logmsg(WHO, 110, FATAL, B("unable to switch to: ", home));
+ if (fifo_make(fifo, 0700) == -1)
+ if (errno != EEXIST) logmsg(WHO, 111, FATAL, B("unable to mkfifo: ", home, "/", fifo));
+ if (chown(fifo, uid, gid) == -1) logmsg(WHO, 111, FATAL, B("unable to chown: ", home, "/", fifo));
+ if (chmod(fifo, mode) == -1) logmsg(WHO, 111, FATAL, B("unable to chmod: ", home, "/", fifo));
}
char inbuf[BUFFER_INSIZE];
@@ -54,84 +44,65 @@ buffer bi;
char outbuf[BUFFER_OUTSIZE];
buffer bo;
-void c(char *home,char *subdir,char *file,int uid,int gid,int mode)
+void c(char *home, char *subdir, char *file, int uid, int gid, int mode)
{
int fdin;
int fdout;
- if (fchdir(fdsourcedir) == -1)
- logmsg(WHO,110,FATAL,"unable to switch back to source directory: ");
+ if (fchdir(fdsourcedir) == -1) logmsg(WHO, 110, FATAL, "unable to switch back to source directory: ");
fdin = open_read(file);
- if (fdin == -1)
- logmsg(WHO,111,FATAL,B("unable to read: ",file));
- buffer_init(&bi,read,fdin,inbuf,sizeof(inbuf));
+ if (fdin == -1) logmsg(WHO, 111, FATAL, B("unable to read: ", file));
+ buffer_init(&bi, read, fdin, inbuf, sizeof(inbuf));
- if (chdir(home) == -1)
- logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
- if (chdir(subdir) == -1)
- logmsg(WHO,110,FATAL,B("unable to switch to: ",home,"/",subdir));
+ if (chdir(home) == -1) logmsg(WHO, 110, FATAL, B("unable to switch to: ", home));
+ if (chdir(subdir) == -1) logmsg(WHO, 110, FATAL, B("unable to switch to: ", home, "/", subdir));
fdout = open_trunc(file);
- if (fdout == -1)
- logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
- buffer_init(&bo,write,fdout,outbuf,sizeof(outbuf));
-
- switch (buffer_copy(&bo,&bi)) {
- case -2:
- logmsg(WHO,111,FATAL,B("unable to read: ",file));
- case -3:
- logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
+ if (fdout == -1) logmsg(WHO, 111, FATAL, B("unable to write .../", subdir, "/", file));
+ buffer_init(&bo, write, fdout, outbuf, sizeof(outbuf));
+
+ switch (buffer_copy(&bo, &bi)) {
+ case -2: logmsg(WHO, 111, FATAL, B("unable to read: ", file));
+ case -3: logmsg(WHO, 111, FATAL, B("unable to write .../", subdir, "/", file));
}
close(fdin);
- if (buffer_flush(&bo) == -1)
- logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
- if (fsync(fdout) == -1)
- logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
+ if (buffer_flush(&bo) == -1) logmsg(WHO, 111, FATAL, B("unable to write .../", subdir, "/", file));
+ if (fsync(fdout) == -1) logmsg(WHO, 111, FATAL, B("unable to write .../", subdir, "/", file));
if (close(fdout) == -1) /* NFS silliness */
- logmsg(WHO,111,FATAL,B("unable to write .../",subdir,"/",file));
+ logmsg(WHO, 111, FATAL, B("unable to write .../", subdir, "/", file));
- if (chown(file,uid,gid) == -1)
- logmsg(WHO,111,FATAL,B("unable to chown .../",subdir,"/",file));
- if (chmod(file,mode) == -1)
- logmsg(WHO,111,FATAL,B("unable to chmod .../",subdir,"/",file));
+ if (chown(file, uid, gid) == -1) logmsg(WHO, 111, FATAL, B("unable to chown .../", subdir, "/", file));
+ if (chmod(file, mode) == -1) logmsg(WHO, 111, FATAL, B("unable to chmod .../", subdir, "/", file));
}
-void z(char *home,char *file,int len,int uid,int gid,int mode)
+void z(char *home, char *file, int len, int uid, int gid, int mode)
{
int fdout;
- if (chdir(home) == -1)
- logmsg(WHO,110,FATAL,B("unable to switch to: ",home));
+ if (chdir(home) == -1) logmsg(WHO, 110, FATAL, B("unable to switch to: ", home));
fdout = open_trunc(file);
- if (fdout == -1)
- logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
- buffer_init(&bo,write,fdout,outbuf,sizeof(outbuf));
+ if (fdout == -1) logmsg(WHO, 111, FATAL, B("unable to write: ", home, "/", file));
+ buffer_init(&bo, write, fdout, outbuf, sizeof(outbuf));
while (len-- > 0)
- if (buffer_put(&bo,"",1) == -1)
- logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
+ if (buffer_put(&bo, "", 1) == -1) logmsg(WHO, 111, FATAL, B("unable to write: ", home, "/", file));
- if (buffer_flush(&bo) == -1)
- logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
- if (fsync(fdout) == -1)
- logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
+ if (buffer_flush(&bo) == -1) logmsg(WHO, 111, FATAL, B("unable to write: ", home, "/", file));
+ if (fsync(fdout) == -1) logmsg(WHO, 111, FATAL, B("unable to write: ", home, "/", file));
if (close(fdout) == -1) /* NFS silliness */
- logmsg(WHO,111,FATAL,B("unable to write: ",home,"/",file));
+ logmsg(WHO, 111, FATAL, B("unable to write: ", home, "/", file));
- if (chown(file,uid,gid) == -1)
- logmsg(WHO,111,FATAL,B("unable to chown: ",home,"/",file));
- if (chmod(file,mode) == -1)
- logmsg(WHO,111,FATAL,B("unable to chmod: ",home,"/",file));
+ if (chown(file, uid, gid) == -1) logmsg(WHO, 111, FATAL, B("unable to chown: ", home, "/", file));
+ if (chmod(file, mode) == -1) logmsg(WHO, 111, FATAL, B("unable to chmod: ", home, "/", file));
}
int main()
{
fdsourcedir = open_read(".");
- if (fdsourcedir == -1)
- logmsg(WHO,110,FATAL,"unable to open current directory: ");
+ if (fdsourcedir == -1) logmsg(WHO, 110, FATAL, "unable to open current directory: ");
umask(077);
hier();