/* Program to compares *.files produced by trli-lxc0 */ #include #include #include #include #include #include #include using namespace std; static int trli_cmp(const string &f1, const string &f2) { int ret = -1; const char *ptf1 = f1.c_str(); const char *ptf2 = f2.c_str(); struct stat64 st1, st2; if (strncmp(ptf1,"/sys/",5)==0 || strncmp(ptf1,"/etc/",5)==0 || strncmp(ptf1,"/var/lib/mysql/",15)==0){ // Do not compare /sys files ret = 0; }else if (stat64(ptf1,&st1)==-1){ tlmp_error ("File %s does not exist\n",ptf1); }else if (stat64(ptf2,&st2)==-1){ tlmp_error ("File %s does not exist\n",ptf2); }else if (st1.st_size != st2.st_size){ tlmp_error ("File %s and %s have different size: %Lu <> %Lu\n",ptf1,ptf2,(long long)st1.st_size,(long long)st2.st_size); }else{ FILE *fin1 = fopen (ptf1,"r"); if (fin1 == NULL){ tlmp_error ("Can't open file %s (%s)\n",ptf1,strerror(errno)); }else{ FILE *fin2 = fopen(ptf2,"r"); if (fin2 == NULL){ tlmp_error ("Can't open file %s (%s)\n",ptf2,strerror(errno)); }else{ while (1){ const unsigned size = 32*1024; char buf1[size],buf2[size]; int n1 = fread(buf1,1,size,fin1); int n2 = fread(buf2,1,size,fin2); if (n1 != n2){ tlmp_error ("Files %s %s: Different read size %d <> %d\n",ptf1,ptf2,n1,n2); break; }else if (n1 == 0){ ret = 0; break; }else if (memcmp(buf1,buf2,n1)!=0){ tlmp_error ("Files %s %s differ\n",ptf1,ptf2); break; } } fclose (fin2); } fclose (fin1); } } return ret; } int main (int argc, char *argv[]) { glocal int ret = -1; glocal const char *name = NULL; glocal.ret = (argc,argv); setproginfo ("trli-cmp",VERSION,"Compares *.files produced by trli-lxc0"); setarg ('n',"name","Name of the container to verify",glocal.name,true); glocal int ret = 0; for (int i=0; i(argv[i],true); vector tb; int n = str_splitline(line,' ',tb); if (n != 2){ tlmp_error ("Invalid line in file %s: %s\n",info.filename,line); exit (-1); }else if (trli_cmp (tb[0],tb[1])==-1){ glocal.ret = -1; } return 0; } if (glocal.ret == -1) tlmp_error ("Container %s needs update\n",glocal.name); return glocal.ret; return glocal.ret; }