Changeset 17731


Ignore:
Timestamp:
10/10/11 10:21:26 (20 months ago)
Author:
eko
Message:

ttraff: automatic remove of old date if nvram space runs low

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/router/rc/ttraff.c

    r15334 r17731  
    88#include <stdio.h> 
    99#include <time.h> 
     10#include <string.h> 
    1011#include <stdlib.h> 
    1112#include <unistd.h> 
     
    1617#include <syslog.h> 
    1718#include <utils.h> 
     19 
     20 
     21void 
     22remove_oldest_entry(int cur_month, int cur_year) 
     23{ 
     24        char old[32]; 
     25        int month, year; 
     26        int len = 0; 
     27 
     28        for (year = 2008; year <= cur_year; year++) { 
     29                for (month = 1; month <= 12; month++) { 
     30                        if (month == cur_month && year == cur_year) { 
     31                                return; 
     32                        } 
     33                        sprintf(old, "traff-%02u-%u", month, year); 
     34                        len = strlen(nvram_safe_get(old)); 
     35                        if (len > 0) { 
     36                                dd_syslog(LOG_DEBUG,  
     37                                        "ttraff: old data for %d-%d removed, freeing %d bytes of nvram\n", month, year, len + 15); 
     38                                nvram_unset(old); 
     39                                return; 
     40                        }                
     41                } 
     42        } 
     43 
     44        return; 
     45} 
    1846 
    1947void 
     
    3765        memset(buffer, 0, 2048); 
    3866        sprintf(tq, "traff-%02u-%u", month, year); 
     67 
     68        /* keep some nvram free by removing oldest traf data */          
     69        int space = 0; 
     70        int used = nvram_used(&space); 
     71        if ((space - used) < 2048) { /* 2048 bytes to be on a safe side */ 
     72                remove_oldest_entry(month, year); 
     73        } 
     74         
    3975        tdata = nvram_safe_get(tq); 
    4076         
     
    89125        return; 
    90126} 
     127 
    91128 
    92129int main(int argc, char **argv) 
Note: See TracChangeset for help on using the changeset viewer.