Skip to content

Commit

Permalink
Merge pull request #191 from pi-hole/release/v2.13.2
Browse files Browse the repository at this point in the history
Pi-hole FTL v2.13.2
  • Loading branch information
dschaper committed Jan 8, 2018
2 parents 1e45569 + 6305b95 commit 1de2b99
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ before_script:
- mkdir -p "${DEST_DIR}"
- make clean
script:
- make pihole-FTL CC="${BUILD_CC}" CFLAGS="${CFLAGS}"
- make CC="${BUILD_CC}" CFLAGS="${CFLAGS}" GIT_BRANCH="${TRAVIS_BRANCH}" GIT_TAG="${TRAVIS_TAG}" GIT_HASH="${TRAVIS_COMMIT}"
- file pihole-FTL
- if [[ "${BIN_NAME}" == "pihole-FTL-linux-x86_64" ]]; then test/run.sh; fi
- mv pihole-FTL "${DEST_DIR}/${BIN_NAME}"
Expand Down
26 changes: 12 additions & 14 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,19 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "version") == 0)
{
const char * version = GIT_VERSION;
// Check if version is of format vX.YY
// '.' can never be part of a commit hash
if(strstr(version, ".") != NULL)
const char * commit = GIT_HASH;
const char * tag = GIT_TAG;
if(strlen(tag) > 1)
{
printf("%s\n",GIT_VERSION);
}
else
printf("vDev-%s\n",GIT_HASH);
{
char hash[8];
// Extract first 7 characters of the hash
strncpy(hash, commit, 7); hash[7] = 0;
printf("vDev-%s\n", hash);
}
exit(EXIT_SUCCESS);
}

Expand All @@ -90,15 +96,7 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-b") == 0 ||
strcmp(argv[i], "branch") == 0)
{
const char * branch = GIT_BRANCH;
const char * version = GIT_VERSION;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";
printf("%s\n",branch);
printf("%s\n",GIT_BRANCH);
exit(EXIT_SUCCESS);
}

Expand Down
14 changes: 11 additions & 3 deletions database.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ void check_database(int rc)

void dbclose(void)
{
sqlite3_close(db);
int rc = sqlite3_close(db);
// Report any error
if( rc )
logg("dbclose() - SQL error (%i): %s", rc, sqlite3_errmsg(db));

// Unlock mutex on the database
pthread_mutex_unlock(&dblock);
}

Expand Down Expand Up @@ -169,6 +174,9 @@ void db_init(void)
}
}

// Close database to prevent having it opened all time
sqlite3_close(db);

if (pthread_mutex_init(&dblock, NULL) != 0)
{
logg("FATAL: DB mutex init failed\n");
Expand Down Expand Up @@ -385,8 +393,8 @@ void save_to_DB(void)

// Finish prepared statement
ret = dbquery("END TRANSACTION");
if(!ret){ dbclose(); return; }
sqlite3_finalize(stmt);
int ret2 = sqlite3_finalize(stmt);
if(!ret || ret2 != SQLITE_OK){ dbclose(); return; }

// Store index for next loop interation round and update last time stamp
// in the database only if all queries have been saved successfully
Expand Down
4 changes: 2 additions & 2 deletions log.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ void log_counter_info(void)
void log_FTL_version(void)
{
logg("FTL branch: %s", GIT_BRANCH);
logg("FTL version: %s", GIT_VERSION);
logg("FTL tag: %s", GIT_TAG);
logg("FTL version: %s", GIT_TAG);
logg("FTL commit: %s", GIT_HASH);
logg("FTL date: %s", GIT_DATE);
logg("FTL user: %s", username);
}
4 changes: 2 additions & 2 deletions parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,6 @@ void process_pihole_log(int file)
// Debug output
if(strlen(hostname) > 0)
{
// Convert hostname to lower case
strtolower(hostname);
logg("New client: %s %s (%i/%i)", client, hostname, clientID, counters.clients_MAX);
}
else
Expand Down Expand Up @@ -793,6 +791,8 @@ char *resolveHostname(const char *addr)
{
// Return hostname copied to new memory location
hostname = strdup(he->h_name);
// Convert hostname to lower case
strtolower(hostname);
}

return hostname;
Expand Down
25 changes: 13 additions & 12 deletions request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,19 +1038,20 @@ void getVersion(int *sock)
{
char server_message[SOCKETBUFFERLEN];

const char * version = GIT_VERSION;
const char * branch = GIT_BRANCH;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";

if(strstr(version, ".") != NULL)
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", version, GIT_TAG, branch, GIT_DATE);
const char * commit = GIT_HASH;
const char * tag = GIT_TAG;
if(strlen(tag) > 1)
{
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", GIT_VERSION, tag, GIT_BRANCH, GIT_DATE);
}
else
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", GIT_HASH, GIT_TAG, branch, GIT_DATE);
{
char hash[8];
// Extract first 7 characters of the hash
strncpy(hash, commit, 7); hash[7] = 0;
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", hash, tag, GIT_BRANCH, GIT_DATE);
}

swrite(server_message, *sock);

if(debugclients)
Expand Down

0 comments on commit 1de2b99

Please sign in to comment.