void
do_entry(struct conf_entry *ent)
{
	struct stat sb;
	int modtime;
	off_t size;

	if (lstat(ent->log, &sb) != 0)
		return;
	if (!S_ISREG(sb.st_mode) &&
	    (!S_ISLNK(sb.st_mode) || !(ent->flags & CE_FOLLOW))) {
		DPRINTF(("--> not a regular file, skipping\n"));
		return;
	}
	if (S_ISLNK(sb.st_mode) && stat(ent->log, &sb) != 0) {
		DPRINTF(("--> link target does not exist, skipping\n"));
		return;
	}
	if (ent->uid == (uid_t)-1)
		ent->uid = sb.st_uid;
	if (ent->gid == (gid_t)-1)
		ent->gid = sb.st_gid;

	DPRINTF(("%s <%d%s%s%s%s>: ", ent->log, ent->numlogs,
	    (ent->flags & CE_COMPACT) ? "Z" : "",
	    (ent->flags & CE_BINARY) ? "B" : "",
	    (ent->flags & CE_FOLLOW) ? "F" : "",
	    (ent->flags & CE_MONITOR) && monitormode ? "M" : ""));
	size = sizefile(&sb);
	modtime = age_old_log(ent);
	if (ent->flags & CE_TRIMAT && !force) {
		if (timenow < ent->trim_at ||
		    difftime(timenow, ent->trim_at) >= 60 * 60) {
			DPRINTF(("--> will trim at %s",
			    ctime(&ent->trim_at)));
			return;
		} else if (ent->hours <= 0) {
			DPRINTF(("--> time is up\n"));
		}
	}
	if (ent->size > 0)
		DPRINTF(("size (KB): %.2f [%d] ", size / 1024.0,
		    (int)(ent->size / 1024)));
	if (ent->hours > 0)
		DPRINTF(("age (hr): %d [%d] ", modtime, ent->hours));
	if (monitormode && (ent->flags & CE_MONITOR) && domonitor(ent))
		DPRINTF(("--> monitored\n"));
	else if (!monitormode &&
	    (force || (ent->size > 0 && size >= ent->size) ||
	    (ent->hours <= 0 && (ent->flags & CE_TRIMAT)) ||
	    (ent->hours > 0 && (modtime >= ent->hours || modtime < 0)
	    && ((ent->flags & CE_BINARY) || size >= MIN_SIZE)))) {
		DPRINTF(("--> trimming log....\n"));
		if (noaction && !verbose)
			printf("%s <%d%s%s%s>\n", ent->log,
			    ent->numlogs,
			    (ent->flags & CE_COMPACT) ? "Z" : "",
			    (ent->flags & CE_BINARY) ? "B" : "",
			    (ent->flags & CE_FOLLOW) ? "F" : "");
		dotrim(ent);
		ent->flags |= CE_ROTATED;
	} else
		DPRINTF(("--> skipping\n"));
}
Exemple #2
0
// import from dat file
void importfdat(FILE *f,int wop,int boe){
  freelist(root);
  phone *parr;
  // wop = part(2) or whole(1)
  // boe = end(2) or begin(1)

  int e,offset,i;num = sizefile(f)/sizeof(phone);
  if(wop == 1)   {// whole

    parr = (phone *)malloc(sizeof(phone)*num);
    fread(parr,sizeof(phone),num,f);
    //printf("%d\n",z);
    rewind(f);
    importfA(parr);
    free(parr);
  }  else {

    if(boe == 1){ //part begin
      do {
        printf("\t\tInput offset(<%d) : ",num);scanf("%d",&offset);mfflush();
        if(offset < 0 ||  offset > num ) printf("\t\tWrong input value !!\n input again \n");
      } while (offset < 0 ||  offset > num);

      do {
        printf("\t\tInput element want to read (<%d) : ",num-offset);scanf("%d",&e);mfflush();
        if(e < 0 ||  e > num-offset ) printf("\t\tWrong input value !!\n input again \n");
      } while (e < 0 ||  e > num-offset);

      parr = (phone *)malloc(sizeof(phone)*e);

      if(offset != 0)  fseek(f,sizeof(phone)*(offset-1),SEEK_SET);

      fread(parr,sizeof(phone),e,f);
      rewind(f);
      importfA(parr);
      free(parr);
    } else {//part end
      do {
        printf("\t\tInput offset(<%d) : ",num);scanf("%d",&offset);mfflush();
        if(offset < 1 ||  offset > num ) printf("\t\tWrong input value !!\n input again \n");
      } while (offset < 1 ||  offset > num);

      do {
        printf("\t\tInput element want to read (<%d) : ",num-offset);scanf("%d",&e);mfflush();
        if(e < 0 ||  e > num-offset ) printf("\t\tWrong input value !!\n input again \n");
      } while (e < 0 ||  e > num-offset);

      parr = (phone *)malloc(sizeof(phone)*e);

      fseek(f,(long)0,SEEK_END);
      fseek(f,-sizeof(phone)*offset,SEEK_CUR);
      for (i = 0; i < e; i++) {
        fread(&parr[i],sizeof(phone),1,f);
        fseek(f,-sizeof(phone)*2,SEEK_CUR);
        //printf("%-3d %-40s | %-3d gb | %-3.1f '' |%-10d VND\n",i+1,parr[i].model,parr[i].size,parr[i].screen,parr[i].price);
      }
      rewind(f);
      importfA(parr);
      free(parr);
    }
    num = e;
  }
}
Exemple #3
0
Fichier : pk.c Projet : iogf/sample
int main(int argc, char *argv[]) {
	FILE * output;
	FILE * input;

	struct header hde;
	int err;
	int i;

	if(argc % 2) {
		printf("Usage: pkge <output> <file1> <destin2> <file2> <destin2> ...\n");
		exit(0);
	}

	output = fopen(argv[OUTPUT_NAME], "wb+");

	if(output == NULL) {
		printf("fopen() failed !\n");
		exit(1);
	}

	input = fopen("upk", "rb");

	if(input == NULL) {
		printf("fopen() failed !\n");
		exit(1);
	}

	err = fcatfile(output, input);

	if(err < 0) {
		printf("fcatfile() failed!\n");
		exit(1);
	}

	fclose(input);

	for(i = BEGIN_INPUT; i < argc; i += 2) {
		input = fopen(argv[i], "rb");
		
		if(input == NULL) {
			printf("fopen() failed!\n");
			exit(1);
		}		
		
		hde.size = sizefile(input);
		strcpy(hde.destin, argv[i + 1]); 
	
		fwrite(&hde, sizeof(struct header), 1, output);

		if(ferror(output)) {
			printf("fwrite() failed!\n");
			exit(1);
		}

		err = fcatfile(output, input);

		if(err < 0) {
			printf("fcatfile() failed!\n");
			exit(1);
		}

		fclose(input);
	} 

	fclose(output);

	return 0;
}