FreeBSD/usr.sbin/ctm/ctm_rmail/ctm_rmail.c
/*
 * If the next required delta is now present, let ctm lunch on it and any
 * contiguous deltas.
 */
If the next required delta is now present, let ctm lunch on it and any
contiguous deltas.
If the next required delta is now present let ctm lunch on it and any contiguous deltas .
void
apply_complete()
    {
    int i, dn;
    int lfd;
    FILE *fp, *ctm;
    struct stat sb;
    char class[20];
    char delta[30];
    char junk[2];
    char fname[PATH_MAX];
    char here[PATH_MAX];
    char buf[PATH_MAX*2];
    strcpy(fname, delta_dir);
    strcat(fname, "/.mutex_apply");
    if ((lfd = lock_file(fname)) < 0)
	return;
    sprintf(fname, "%s/%s", base_dir, CTM_STATUS);
    if ((fp = fopen(fname, "r")) == NULL)
	{
	close(lfd);
	return;
	}
    i = fscanf(fp, "%19s %d %c", class, &dn, junk);
    fclose(fp);
    if (i != 2)
	{
	close(lfd);
	return;
	}
    here[0] = '\0';
    if (delta_dir[0] != '/')
	{
	getcwd(here, sizeof(here)-1);
	i = strlen(here) - 1;
	if (i >= 0 && here[i] != '/')
	    {
	    here[++i] = '/';
	    here[++i] = '\0';
	    }
	}
    for (;;)
	{
	sprintf(delta, "%s.%04d.gz", class, ++dn);
	mk_delta_name(fname, delta);
	if (stat(fname, &sb) < 0)
	    break;
	sprintf(buf, "(cd %s && ctm %s%s%s%s) 2>&1", base_dir,
				set_time ? "-u " : "",
				apply_verbose ? "-v " : "", here, fname);
	if ((ctm = popen(buf, "r")) == NULL)
	    {
	    err("ctm failed to apply %s", delta);
	    break;
	    }
	while (fgets(buf, sizeof(buf), ctm) != NULL)
	    {
	    i = strlen(buf) - 1;
	    if (i >= 0 && buf[i] == '\n')
		buf[i] = '\0';
	    err("ctm: %s", buf);
	    }
	if (pclose(ctm) != 0)
	    {
	    err("ctm failed to apply %s", delta);
	    break;
	    }
	if (delete_after)
	    unlink(fname);
	err("%s applied%s", delta, delete_after ? " and deleted" : "");
	}
    close(lfd);
    }
void apply_complete ( ) { int i , dn ; int lfd ; FILE * fp , * ctm ; struct stat sb ; char class [ 20 ] ; char delta [ 30 ] ; char junk [ 2 ] ; char fname [ PATH_MAX ] ; char here [ PATH_MAX ] ; char buf [ PATH_MAX * 2 ] ; strcpy ( fname , delta_dir ) ; strcat ( fname , " " ) ; if ( ( lfd = lock_file ( fname ) ) < 0 ) return ; sprintf ( fname , " " , base_dir , CTM_STATUS ) ; if ( ( fp = fopen ( fname , " " ) ) == NULL ) { close ( lfd ) ; return ; } i = fscanf ( fp , " " , class , & dn , junk ) ; fclose ( fp ) ; if ( i != 2 ) { close ( lfd ) ; return ; } here [ 0 ] = ' \0 ' ; if ( delta_dir [ 0 ] != ' ' ) { getcwd ( here , sizeof ( here ) - 1 ) ; i = strlen ( here ) - 1 ; if ( i >= 0 && here [ i ] != ' ' ) { here [ ++ i ] = ' ' ; here [ ++ i ] = ' \0 ' ; } } for ( ; ; ) { sprintf ( delta , " " , class , ++ dn ) ; mk_delta_name ( fname , delta ) ; if ( stat ( fname , & sb ) < 0 ) break ; sprintf ( buf , " " , base_dir , set_time ? " " : " " , apply_verbose ? " " : " " , here , fname ) ; if ( ( ctm = popen ( buf , " " ) ) == NULL ) { err ( " " , delta ) ; break ; } while ( fgets ( buf , sizeof ( buf ) , ctm ) != NULL ) { i = strlen ( buf ) - 1 ; if ( i >= 0 && buf [ i ] == ' \n ' ) buf [ i ] = ' \0 ' ; err ( " " , buf ) ; } if ( pclose ( ctm ) != 0 ) { err ( " " , delta ) ; break ; } if ( delete_after ) unlink ( fname ) ; err ( " " , delta , delete_after ? " " : " " ) ; } close ( lfd ) ; }
If the next required delta is now present, let ctm lunch on it and any
 contiguous deltas.
If the next required delta is now present let ctm lunch on it and any contiguous deltas .
/*
     * Grab a lock on the ctm mutex file so that we can be sure we are
     * working alone, not fighting another ctm_rmail!
     */ /*
     * Find out which delta ctm needs next.
     */ /*
     * We might need to convert the delta filename to an absolute pathname.
     */ /*
     * Keep applying deltas until we run out or something bad happens.
     */ /*
     * Closing the lock file clears the lock.
     */