Signed-off-by: Ferry Huberts <ferry.huberts@pelagic.nl>
static size_t line_length = 256;
/* forward declaration */
static size_t line_length = 256;
/* forward declaration */
-static bool readEgressFile(char * fileName);
+static bool readEgressFile(const char * fileName);
* @param fileName the filename
* @return true to indicate changes (any egress_if->bwChanged is true)
*/
* @param fileName the filename
* @return true to indicate changes (any egress_if->bwChanged is true)
*/
-static bool readEgressFile(char * fileName) {
+static bool readEgressFile(const char * fileName) {
FILE * fp = NULL;
struct stat statBuf;
unsigned int lineNumber = 0;
ssize_t length = -1;
bool reportedErrorsLocal = false;
FILE * fp = NULL;
struct stat statBuf;
unsigned int lineNumber = 0;
ssize_t length = -1;
bool reportedErrorsLocal = false;
+ const char * filepath = !fileName ? DEF_GW_EGRESS_FILE : fileName;
- fd = open(!fileName ? DEF_GW_EGRESS_FILE : fileName, O_RDONLY);
- if (fd < 0) {
- /* could not access the file */
- cachedStat.timeStamp = 0;
- readEgressFileClear();
- goto outerror;
- }
+ if (cachedStat.timeStamp != 0) {
+ /* read the file before */
- if (fstat(fd, &statBuf)) {
- /* could not stat the file */
- cachedStat.timeStamp = 0;
- readEgressFileClear();
- goto outerror;
- }
+ if (stat(filepath, &statBuf)) {
+ /* could not stat the file */
+ cachedStat.timeStamp = 0;
+ readEgressFileClear();
+ goto outerror;
+ }
- if (!memcmp(&cachedStat.timeStamp, &statBuf.st_mtime, sizeof(cachedStat.timeStamp))) {
- /* file did not change since last read */
- goto out;
+ if (!memcmp(&cachedStat.timeStamp, &statBuf.st_mtime, sizeof(cachedStat.timeStamp))) {
+ /* file did not change since last read */
+ return false;
+ }
+ fp = fopen(filepath, "r");
if (!fp) {
/* could not open the file */
cachedStat.timeStamp = 0;
if (!fp) {
/* could not open the file */
cachedStat.timeStamp = 0;
reportedErrors = reportedErrorsLocal;
reportedErrors = reportedErrorsLocal;
- outerror: if (fd >= 0) {
- close(fd);
- fd = -1;
- }
/* clear absent egress interfaces and setup 'changed' status */
{
/* clear absent egress interfaces and setup 'changed' status */
{
- out: if (fd >= 0) {
- close(fd);
- fd = -1;
- }
-