diary

Text-based journaling program
git clone https://git.in0rdr.ch/diary.git
Log | Files | Refs | README | LICENSE

commit 7da661b31ac0669a9c0f78dfec51de2466f2d69b
parent bdf2969a557c53ab8291005f6f3955602f099b6c
Author: Andreas Gruhler <agruhl@gmx.ch>
Date:   Sun, 26 Jun 2022 22:24:50 +0200

feat(lttng): Replace remaining stderr debug lines

Diffstat:
Msrc/caldav.c | 43++++++++++++++++++++-----------------------
Msrc/diary-tp.h | 46++++++++++++++++++++++++++++++++++++++++++++--
Msrc/diary.c | 2+-
3 files changed, 65 insertions(+), 26 deletions(-)

diff --git a/src/caldav.c b/src/caldav.c @@ -108,7 +108,7 @@ char* read_tokenfile() { /* Refresh global token variables from input buffer */ void update_global_token_vars(char* input) { char* new_access_token = extract_json_value(input, "access_token", true); - //fprintf(stderr, "Info - New access token: %s\n", new_access_token); + tracepoint(diary, debug_string, "New access token", new_access_token); if (new_access_token != NULL) { strncpy(access_token, new_access_token, 200); free(new_access_token); @@ -218,13 +218,11 @@ void get_access_token(char* code, char* verifier, bool refresh) { // Otherwise, a valid token in the possisbly already existing file would // be overwritten. This happens usually during syncing (s/S) while offline. if (res == CURLE_OK) { - // fputs(token_resp.memory, stderr); - // update global token variables update_global_token_vars(token_resp.memory); update_tokenfile_from_global_vars(); } else { - fprintf(stderr, "Error - curl_easy_perform() failed in get_access_token(): %s\n", curl_easy_strerror(res)); + tracepoint(diary, error_string, "curl_easy_perform() failed in get_access_token()", curl_easy_strerror(res)); return; } } @@ -242,7 +240,7 @@ char* get_oauth_code(const char* verifier, WINDOW* header) { int status; if ((status=getaddrinfo(NULL, MKSTR(GOOGLE_OAUTH_REDIRECT_PORT), &hints, &addr_res)) != 0) { - fprintf(stderr, "Error - getaddrinfo: %s\n", gai_strerror(status)); + tracepoint(diary, error_string, "getaddrinfo() failed in get_oauth_code()", gai_strerror(status)); } void *addr; @@ -343,7 +341,7 @@ char* get_oauth_code(const char* verifier, WINDOW* header) { // Ctrl+c: ^C 0x03 // q : q 0x71 if (ch == 0x03 || ch == 0x71) { - fprintf(stderr, "Warning - hanging up, closing server socket\n"); + tracepoint(diary, debug, "Hanging up, closing server socket"); break; } } @@ -375,13 +373,13 @@ char* get_oauth_code(const char* verifier, WINDOW* header) { close(pfds[1].fd); if (bytes_rec == 0) { - fprintf(stderr, "Error - No OAuth header found.\n"); + tracepoint(diary, error, "No OAuth header found"); return NULL; } char* code = extract_oauth_code(http_header); if (code == NULL) { - fprintf(stderr, "Error - No OAuth code found in http header.\n"); + tracepoint(diary, error, "No OAuth code in http header"); return NULL; } @@ -443,7 +441,7 @@ char* caldav_req(struct tm* date, char* url, char* http_method, char* postfields curl_easy_cleanup(curl); if (res != CURLE_OK) { - fprintf(stderr, "Error - curl_easy_perform() failed in caldav_req(): %s\n", curl_easy_strerror(res)); + tracepoint(diary, error_string, "curl_easy_perform() failed in caldav_req()", curl_easy_strerror(res)); free(caldav_resp.memory); return NULL; } @@ -519,7 +517,7 @@ void put_event(struct tm* date, const char* dir, size_t dir_size, char* calendar fpath(dir, dir_size, date, &ppath, sizeof path); if (ppath == NULL) { - fprintf(stderr, "Error retrieving file path for diary reading"); + tracepoint(diary, error_date, "Cannot get file path for entry", date); return; } @@ -542,7 +540,7 @@ void put_event(struct tm* date, const char* dir, size_t dir_size, char* calendar int items_read = fread(descr + descr_label_size, sizeof(char), descr_bytes, fp); if (items_read != descr_bytes) { - fprintf(stderr, "Error - Read %i items but expected %li, aborting.", items_read, descr_bytes); + tracepoint(diary, error_int_long, "Read n items but expected m items, aborting.", items_read, descr_bytes); return; } @@ -575,7 +573,7 @@ void put_event(struct tm* date, const char* dir, size_t dir_size, char* calendar free(descr); if (response == NULL) { - fprintf(stderr, "Error - PUT event failed.\n"); + tracepoint(diary, error, "PUT request for event failed in put_event()"); } // free memory allocated to store curl response @@ -626,7 +624,7 @@ int caldav_sync(struct tm* date, // fetch new code with verifier char* code = get_oauth_code(challenge, header); if (code == NULL) { - fprintf(stderr, "Error retrieving access code.\n"); + tracepoint(diary, error, "Error retrieving oauth code in caldav_sync()"); return -1; } @@ -648,9 +646,9 @@ int caldav_sync(struct tm* date, char* user_principal = caldav_req(date, GOOGLE_CALDAV_URI, "PROPFIND", principal_postfields, 0); if (user_principal == NULL) { - //fprintf(stderr, "Info - Unable to fetch principal, refreshing API token.\n"); // The principal could not be fetched, // get new acess token with refresh token + tracepoint(diary, debug, "Unable to fetch principal, refreshing API token"); get_access_token(NULL, NULL, true); // Retry request for event with new token user_principal = caldav_req(date, GOOGLE_CALDAV_URI, "PROPFIND", principal_postfields, 0); @@ -771,17 +769,17 @@ int caldav_sync(struct tm* date, remote_date = mktime(remote_datetime); - //fprintf(stderr, "Info - remote last mod: %s\n", ctime(&remote_date)); - //fprintf(stderr, "Info - local last mod: %s\n", ctime(&localfile_date)); + tracepoint(diary, debug_string, "Remote last modified", ctime(&remote_date)); + tracepoint(diary, debug_string, "Local last modified", ctime(&localfile_date)); double timediff = difftime(localfile_date, remote_date); - //fprintf(stderr, "Info - Time diff between local and remote mod time:%e\n", timediff); + tracepoint(diary, debug_double, "Time diff between local and remote mod time", timediff); char* rmt_desc; char dstr[16]; int conf_ch = 0; if (timediff == 0) { - //fprintf(stderr, "Warning - local and remote files have equal timestamp or don't exist, giving up.\n"); + tracepoint(diary, debug, "Local and remote files have equal timestamp or don't exist, giving up."); pthread_cancel(progress_tid); wclear(header); // free memory allocated to store curl response @@ -790,13 +788,12 @@ int caldav_sync(struct tm* date, free(home_set); return 0; } else if (timediff > 0) { - //fputs("Info - Local file is newer. Uploading to remote.\n", stderr); - + tracepoint(diary, debug, "Local file is newer. Uploading to remote."); if (remote_uid) { // purge any existing daily calendar entries on the remote side char event_uri[300]; sprintf(event_uri, "%s%s%s.ics", GOOGLE_API_URI, calendar_href, remote_uid); - //fprintf(stderr, "Info - DELETE Url: %s\n", event_uri); + tracepoint(diary, debug_string, "Event URI for DELETE request", event_uri); char* response = caldav_req(date, event_uri, "DELETE", NULL, 0); free(response); } @@ -810,7 +807,7 @@ int caldav_sync(struct tm* date, rmt_desc = extract_ical_field(event, "DESCRIPTION", &search_pos, true); if (rmt_desc == NULL) { - fprintf(stderr, "Error - Could not fetch description of remote event. Aborting sync.\n"); + tracepoint(diary, error, "Could not fetch description of remote event. Aborting sync."); pthread_cancel(progress_tid); wclear(header); free(event); @@ -833,7 +830,7 @@ int caldav_sync(struct tm* date, } if (conf_ch == 'y' || conf_ch == 'Y' || conf_ch == 'a' || conf_ch == '\n' || !confirm) { - //fprintf(stderr, "Info - Remote file is newer. Extracting description from remote.\n"); + tracepoint(diary, debug, "Remote file is newer. Extracting description from remote."); char* i; // persist downloaded buffer to local file diff --git a/src/diary-tp.h b/src/diary-tp.h @@ -30,6 +30,19 @@ TRACEPOINT_EVENT( TRACEPOINT_EVENT( diary, + error_string, + TP_ARGS( + char*, msg_arg, + const char*, arg1 + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_string(arg1, arg1) + ) +) + +TRACEPOINT_EVENT( + diary, error_date, TP_ARGS( char*, msg_arg, @@ -69,7 +82,33 @@ TRACEPOINT_EVENT( TRACEPOINT_EVENT( diary, - warning_2strings, + debug_string, + TP_ARGS( + char*, msg_arg, + char*, arg1 + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_string(arg1, arg1) + ) +) + +TRACEPOINT_EVENT( + diary, + debug_double, + TP_ARGS( + char*, msg_arg, + double, n_arg + ), + TP_FIELDS( + ctf_string(msg, msg_arg) + ctf_integer(double, n, n_arg) + ) +) + +TRACEPOINT_EVENT( + diary, + warning_string, TP_ARGS( char*, msg_arg, char*, arg1 @@ -86,10 +125,13 @@ TRACEPOINT_EVENT( // TRACE_INFO // TRACE_DEBUG_LINE (default) TRACEPOINT_LOGLEVEL(diary, error, TRACE_ERR) +TRACEPOINT_LOGLEVEL(diary, error_string, TRACE_ERR) TRACEPOINT_LOGLEVEL(diary, error_date, TRACE_ERR) TRACEPOINT_LOGLEVEL(diary, error_int_long, TRACE_ERR) TRACEPOINT_LOGLEVEL(diary, debug, TRACE_DEBUG) -TRACEPOINT_LOGLEVEL(diary, warning_2strings, TRACE_WARNING) +TRACEPOINT_LOGLEVEL(diary, debug_string, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(diary, debug_double, TRACE_DEBUG) +TRACEPOINT_LOGLEVEL(diary, warning_string, TRACE_WARNING) #endif /* _DIARY_TP_H */ diff --git a/src/diary.c b/src/diary.c @@ -298,7 +298,7 @@ bool read_config(const char* file_path) { // check if config file is readable if( access( config_file_path, R_OK ) != 0 ) { - tracepoint(diary, warning_2strings, "Config file missing or not readable, skipping", config_file_path); + tracepoint(diary, warning_string, "Config file missing or not readable, skipping", config_file_path); return false; }