From b7e9accbaaa6bebe278bf76ec60106201a3ddf03 Mon Sep 17 00:00:00 2001 From: Poul-Henning Kamp Date: Thu, 22 Sep 1994 02:49:24 +0000 Subject: [PATCH] Various cleanup and fixes. --- usr.sbin/ctm/ctm/Makefile | 5 ++- usr.sbin/ctm/ctm/ctm.c | 57 ++++++++++++++++++++++------------ usr.sbin/ctm/ctm/ctm.h | 15 ++++++--- usr.sbin/ctm/ctm/ctm_pass2.c | 23 +++++++++----- usr.sbin/ctm/ctm/ctm_pass3.c | 3 +- usr.sbin/ctm/ctm/ctm_syntax.c | 10 ++++-- usr.sbin/ctm/ctm_scan/Makefile | 3 +- usr.sbin/ctm/mkCTM/mkCTM | 4 +-- 8 files changed, 77 insertions(+), 43 deletions(-) diff --git a/usr.sbin/ctm/ctm/Makefile b/usr.sbin/ctm/ctm/Makefile index dff14eba8690..690636621f73 100644 --- a/usr.sbin/ctm/ctm/Makefile +++ b/usr.sbin/ctm/ctm/Makefile @@ -6,7 +6,7 @@ # this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp # ---------------------------------------------------------------------------- # -# $Id: Makefile,v 1.3 1994/09/21 04:38:26 phk Exp $ +# $Id$ # PROG= ctm @@ -15,6 +15,5 @@ SRCS= ctm.c ctm_input.c ctm_pass1.c ctm_pass2.c ctm_pass3.c \ ctm_syntax.c ctm_ed.c LDADD+= -lmd NOMAN= 1 -CFLAGS+= -Wall -BINDIR= /usr/sbin +CFLAGS+= -Wall -g .include diff --git a/usr.sbin/ctm/ctm/ctm.c b/usr.sbin/ctm/ctm/ctm.c index db449b21abe9..d4af9a6c025e 100644 --- a/usr.sbin/ctm/ctm/ctm.c +++ b/usr.sbin/ctm/ctm/ctm.c @@ -16,17 +16,19 @@ * -a Attempt best effort. * -b Base-dir * -B Backup to tar-file. - * -c Check it out, "ma non troppo" * -d Debug TBD. - * -F Force * -m Email me instead. - * -p Less paranoid. - * -P Paranoid. - * -q Be quiet. * -r Reconstruct file. * -R Read list of files to reconstruct. + * + * Options we have: + * -c Check it out, don't do anything. + * -F Force + * -p Less paranoid. + * -P Paranoid. + * -q Tell us less. * -T . Temporary files. - * -v Tell about each file. + * -v Tell us more. * */ @@ -73,7 +75,7 @@ main(int argc, char **argv) if(stat) { fprintf(stderr,"%d errors during option processing\n",stat); - exit(2); + return Exit_Pilot; } stat = 0; argc -= optind; @@ -82,9 +84,15 @@ main(int argc, char **argv) if(!argc) stat |= Proc("-"); - while(argc-- && !stat) + while(argc-- && !stat) { stat |= Proc(*argv++); + } + if(stat == Exit_Done) + stat = Exit_OK; + + if(Verbose) + fprintf(stderr,"Exit(%d)\n",stat); return stat; } @@ -103,13 +111,14 @@ Proc(char *filename) strcpy(p,"gunzip < "); strcat(p,filename); f = popen(p,"r"); + if(!f) { perror(p); return Exit_Garbage; } } else { p = 0; f = fopen(filename,"r"); } if(!f) { perror(filename); - return 1; + return Exit_Garbage; } if(Verbose > 1) @@ -127,12 +136,15 @@ Proc(char *filename) if(!f2) { perror(fn); fclose(f); - return 4; + return Exit_Broke; } unlink(fn); fprintf(stderr,"Writing tmp-file \"%s\"\n",fn); while(EOF != (i=getc(f))) - putc(i,f2); + if(EOF == putc(i,f2)) { + fclose(f2); + return Exit_Broke; + } fclose(f); f = f2; } @@ -148,25 +160,30 @@ Proc(char *filename) } else { pclose(f); f = popen(p,"r"); + if(!f) { perror(p); return Exit_Broke; } } - if((i=Pass2(f))) - return i; + i=Pass2(f); if(!p) { rewind(f); } else { pclose(f); f = popen(p,"r"); + if(!f) { perror(p); return Exit_Broke; } + } + + if(i) { + if((!Force) || (i & ~Exit_Forcible)) + return i; } if(CheckIt) { - fprintf(stderr,"All ok\n"); - return 0; + fprintf(stderr,"All checks out ok.\n"); + return Exit_Done; } - if((i=Pass3(f))) - return i; + i=Pass3(f); if(!p) { fclose(f); @@ -174,7 +191,9 @@ Proc(char *filename) pclose(f); Free(p); } + if(i) + return i; - fprintf(stderr,"All ok\n"); - return 0; + fprintf(stderr,"All done ok\n"); + return Exit_Done; } diff --git a/usr.sbin/ctm/ctm/ctm.h b/usr.sbin/ctm/ctm/ctm.h index 7260e01148d4..93d1f9f00a92 100644 --- a/usr.sbin/ctm/ctm/ctm.h +++ b/usr.sbin/ctm/ctm/ctm.h @@ -22,10 +22,6 @@ #include #include -/* - * We redefine the names to make it look nice... - */ - #define VERSION "2.0" #define MAXSIZE (1024*1024*10) @@ -47,6 +43,7 @@ #define CTM_Q_MD5_After 0x0100 #define CTM_Q_MD5_Before 0x0200 #define CTM_Q_MD5_Chunk 0x0400 +#define CTM_Q_MD5_Force 0x0800 struct CTM_Syntax { char *Key; @@ -102,12 +99,20 @@ EXTERN int Exit; EXTERN int Force; EXTERN int CheckIt; +#define Exit_OK 0 +#define Exit_Garbage 1 +#define Exit_Pilot 2 +#define Exit_Broke 4 +#define Exit_NotOK 8 +#define Exit_Forcible 16 +#define Exit_Mess 32 +#define Exit_Done 64 char * String(char *s); void Fatal_(int ln, char *fn, char *kind); #define Fatal(foo) Fatal_(__LINE__,__FILE__,foo) #define Assert() Fatal_(__LINE__,__FILE__,"Assert failed.") -#define WRONG {Assert(); return 32;} +#define WRONG {Assert(); return Exit_Mess;} u_char * Ffield(FILE *fd, MD5_CTX *ctx,u_char term); diff --git a/usr.sbin/ctm/ctm/ctm_pass2.c b/usr.sbin/ctm/ctm/ctm_pass2.c index 599f4da21f2c..bf98e72ec046 100644 --- a/usr.sbin/ctm/ctm/ctm_pass2.c +++ b/usr.sbin/ctm/ctm/ctm_pass2.c @@ -75,14 +75,14 @@ Pass2(FILE *fd) if(-1 != stat(name,&st)) { fprintf(stderr," %s: %s exists.\n", sp->Key,name); - ret |= 8; + ret |= Exit_Forcible; } break; } if(-1 == stat(name,&st)) { fprintf(stderr," %s: %s doesn't exists.\n", sp->Key,name); - ret |= 8; + ret |= Exit_NotOK; break; } if (j & CTM_Q_Name_Dir) { @@ -90,7 +90,7 @@ Pass2(FILE *fd) fprintf(stderr, " %s: %s exist, but isn't dir.\n", sp->Key,name); - ret |= 8; + ret |= Exit_NotOK; } break; } @@ -99,7 +99,7 @@ Pass2(FILE *fd) fprintf(stderr, " %s: %s exist, but isn't file.\n", sp->Key,name); - ret |= 8; + ret |= Exit_NotOK; } break; } @@ -117,8 +117,15 @@ Pass2(FILE *fd) strcmp(MD5File(name),p)) { fprintf(stderr," %s: %s md5 mismatch.\n", sp->Key,name); - ret |= 8; - + if(j & CTM_Q_MD5_Force) { + if(Force) + fprintf(stderr," Can and will force.\n"); + else + fprintf(stderr," Could have forced.n"); + ret |= Exit_Forcible; + } else { + ret |= Exit_NotOK; + } } break; } @@ -127,7 +134,7 @@ Pass2(FILE *fd) break; } /* Unqualified MD5 */ - ret = 32; + WRONG break; case CTM_F_Count: GETBYTECNT(cnt,sep); @@ -146,7 +153,7 @@ Pass2(FILE *fd) } else if(strcmp(md5,MD5File(p))) { fprintf(stderr," %s: %s edit fails.\n", sp->Key,name); - ret |= 32; + ret |= Exit_Mess; return ret; } unlink(p); diff --git a/usr.sbin/ctm/ctm/ctm_pass3.c b/usr.sbin/ctm/ctm/ctm_pass3.c index fb39a719f9b3..d6508be9e148 100644 --- a/usr.sbin/ctm/ctm/ctm_pass3.c +++ b/usr.sbin/ctm/ctm/ctm_pass3.c @@ -107,10 +107,11 @@ Pass3(FILE *fd) continue; } if(!strcmp(sp->Key,"FE")) { - ed = popen("ed -s","w"); + ed = popen("ed","w"); if(!ed) { WRONG } + fprintf(ed,"e %s\n",name); if(cnt != fwrite(trash,1,cnt,ed)) { perror(name); pclose(ed); diff --git a/usr.sbin/ctm/ctm/ctm_syntax.c b/usr.sbin/ctm/ctm/ctm_syntax.c index ac5039ad3e20..a2da70a03199 100644 --- a/usr.sbin/ctm/ctm/ctm_syntax.c +++ b/usr.sbin/ctm/ctm/ctm_syntax.c @@ -28,15 +28,19 @@ #define After CTM_Q_MD5_After #define Before CTM_Q_MD5_Before #define Chunk CTM_Q_MD5_Chunk +#define Force CTM_Q_MD5_Force static int ctmFM[] = /* File Make */ - { Name|File|New, Uid, Gid, Mode, MD5|After|Chunk, Count, Bytes,0 }; + { Name|File|New, Uid, Gid, Mode, + MD5|After|Chunk, Count, Bytes,0 }; static int ctmFS[] = /* File Substitute */ - { Name|File, Uid, Gid, Mode, MD5|Before, MD5|After|Chunk, Count, Bytes,0 }; + { Name|File, Uid, Gid, Mode, + MD5|Before|Force, MD5|After|Chunk, Count, Bytes,0 }; static int ctmFE[] = /* File Edit */ - { Name|File, Uid, Gid, Mode, MD5|Before, MD5|After, Count, Bytes,0 }; + { Name|File, Uid, Gid, Mode, + MD5|Before, MD5|After, Count, Bytes,0 }; static int ctmFR[] = /* File Remove */ { Name|File, MD5|Before, 0 }; diff --git a/usr.sbin/ctm/ctm_scan/Makefile b/usr.sbin/ctm/ctm_scan/Makefile index aedbc347b60d..6230e6d678e1 100644 --- a/usr.sbin/ctm/ctm_scan/Makefile +++ b/usr.sbin/ctm/ctm_scan/Makefile @@ -6,11 +6,10 @@ # this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp # ---------------------------------------------------------------------------- # -# $Id: Makefile,v 1.3 1994/09/21 04:38:46 phk Exp $ +# $Id$ # PROG= ctm_scan LDADD+= -lmd NOMAN= 1 CFLAGS+= -Wall -BINDIR= /usr/sbin .include diff --git a/usr.sbin/ctm/mkCTM/mkCTM b/usr.sbin/ctm/mkCTM/mkCTM index a29bd76b53b2..047fa0e06981 100644 --- a/usr.sbin/ctm/mkCTM/mkCTM +++ b/usr.sbin/ctm/mkCTM/mkCTM @@ -84,10 +84,10 @@ proc CTMchg {t1 n1 m1 u1 g1 b1 s1 h1 t2 n2 m2 u2 g2 b2 s2 h2} { } if {$b1 == "0" && $b2 == "0"} { puts stderr "E $b1$b2 $t1$t2 $n1" - set i [catch "exec diff -e $d1/$n1 $d2/$n2 > tmp" j] + set i [catch "exec diff -n $d1/$n1 $d2/$n2 > tmp" j] set s [file size tmp] if {$s < $s2} { - puts $fo_files "CTMFE $n1 $u2 $g2 $m2 $h1 $h2 $s" + puts $fo_files "CTMFN $n1 $u2 $g2 $m2 $h1 $h2 $s" flush $fo_files exec cat tmp >@ $fo_files puts $fo_files ""