diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-04-17 13:02:25 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-18 09:00:21 -0700 |
commit | f9f4a9c232357c3967394e8f6a64f9aa36430a45 (patch) | |
tree | 5a49489115fa788385daff5d42fe936231f352b7 /core | |
parent | 47506028ca81be864b4cf2f6b87b8e81d18052bc (diff) | |
download | subsurface-f9f4a9c232357c3967394e8f6a64f9aa36430a45.tar.gz |
debug output: ensure our debug output is captured on Android
I would have bet money that Android used to send stderr to the logcat
log, but apparently it doesn't (anymore?). So in order to be able to
have a chance to debug weird cloud storage issues on Android, let's do
some wholesale replacement of fprintf(stderr,...) with our own version
of the INFO macro that we long ago borrowed from libdivecomputer (and
rename it to ensure we don't have a conflict there).
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r-- | core/git-access.c | 80 | ||||
-rw-r--r-- | core/load-git.c | 2 | ||||
-rw-r--r-- | core/profile.c | 4 | ||||
-rw-r--r-- | core/qthelper.h | 9 | ||||
-rw-r--r-- | core/save-git.c | 14 | ||||
-rw-r--r-- | core/trip.c | 3 |
6 files changed, 61 insertions, 51 deletions
diff --git a/core/git-access.c b/core/git-access.c index b9292072d..2fb55a016 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -177,7 +177,7 @@ static int reset_to_remote(git_repository *repo, git_reference *local, const git git_object *target; if (verbose) - fprintf(stderr, "git storage: reset to remote\n"); + SSRF_INFO("git storage: reset to remote\n"); // If it's not checked out (bare or not HEAD), just update the reference */ if (git_repository_is_bare(repo) || git_branch_is_head(local) != 1) { @@ -296,7 +296,7 @@ static int update_remote(git_repository *repo, git_remote *origin, git_reference const char *name = git_reference_name(local); if (verbose) - fprintf(stderr, "git storage: update remote\n"); + SSRF_INFO("git storage: update remote\n"); refspec.count = 1; refspec.strings = (char **)&name; @@ -333,7 +333,7 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r outlocal[40] = outremote[40] = 0; git_oid_fmt(outlocal, local_id); git_oid_fmt(outremote, remote_id); - fprintf(stderr, "trying to merge local SHA %s remote SHA %s\n", outlocal, outremote); + SSRF_INFO("trying to merge local SHA %s remote SHA %s\n", outlocal, outremote); } git_merge_init_options(&merge_options, GIT_MERGE_OPTIONS_VERSION); @@ -341,31 +341,31 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r merge_options.file_favor = GIT_MERGE_FILE_FAVOR_UNION; merge_options.rename_threshold = 100; if (git_commit_lookup(&local_commit, repo, local_id)) { - fprintf(stderr, "Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); goto diverged_error; } if (git_commit_tree(&local_tree, local_commit)) { - fprintf(stderr, "Remote storage and local data diverged. Error: failed local tree lookup (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: failed local tree lookup (%s)", giterr_last()->message); goto diverged_error; } if (git_commit_lookup(&remote_commit, repo, remote_id)) { - fprintf(stderr, "Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); goto diverged_error; } if (git_commit_tree(&remote_tree, remote_commit)) { - fprintf(stderr, "Remote storage and local data diverged. Error: failed local tree lookup (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: failed local tree lookup (%s)", giterr_last()->message); goto diverged_error; } if (git_commit_lookup(&base_commit, repo, base)) { - fprintf(stderr, "Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: can't get commit (%s)", giterr_last()->message); goto diverged_error; } if (git_commit_tree(&base_tree, base_commit)) { - fprintf(stderr, "Remote storage and local data diverged. Error: failed base tree lookup (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: failed base tree lookup (%s)", giterr_last()->message); goto diverged_error; } if (git_merge_trees(&merged_index, repo, base_tree, local_tree, remote_tree, &merge_options)) { - fprintf(stderr, "Remote storage and local data diverged. Error: merge failed (%s)", giterr_last()->message); + SSRF_INFO("Remote storage and local data diverged. Error: merge failed (%s)", giterr_last()->message); // this is the one where I want to report more detail to the user - can't quite explain why return report_error(translate("gettextFromC", "Remote storage and local data diverged. Error: merge failed (%s)"), giterr_last()->message); } @@ -379,20 +379,20 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r while (git_index_conflict_next(&ancestor, &ours, &theirs, iter) != GIT_ITEROVER) { /* Mark this conflict as resolved */ - fprintf(stderr, "conflict in %s / %s / %s -- ", + SSRF_INFO("conflict in %s / %s / %s -- ", ours ? ours->path : "-", theirs ? theirs->path : "-", ancestor ? ancestor->path : "-"); if ((!ours && theirs && ancestor) || (ours && !theirs && ancestor)) { // the file was removed on one side or the other - just remove it - fprintf(stderr, "looks like a delete on one side; removing the file from the index\n"); + SSRF_INFO("looks like a delete on one side; removing the file from the index\n"); error = git_index_remove(merged_index, ours ? ours->path : theirs->path, GIT_INDEX_STAGE_ANY); } else if (ancestor) { error = git_index_conflict_remove(merged_index, ours ? ours->path : theirs ? theirs->path : ancestor->path); } if (error) { - fprintf(stderr, "error at conflict resplution (%s)", giterr_last()->message); + SSRF_INFO("error at conflict resplution (%s)", giterr_last()->message); } } git_index_conflict_cleanup(merged_index); @@ -429,7 +429,7 @@ static int try_to_git_merge(git_repository *repo, git_reference **local_p, git_r set_git_id(&commit_oid); git_signature_free(author); if (verbose) - fprintf(stderr, "Successfully merged repositories"); + SSRF_INFO("Successfully merged repositories"); free_buffer(&msg); return 0; @@ -460,7 +460,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference int ret = 0; if (verbose) - fprintf(stderr, "git storage: try to update\n"); + SSRF_INFO("git storage: try to update\n"); if (!git_reference_cmp(local, remote)) return 0; @@ -502,7 +502,7 @@ static int try_to_update(git_repository *repo, git_remote *origin, git_reference /* Is the local repo the more recent one? See if we can update upstream */ if (git_oid_equal(&base, remote_id)) { if (verbose) - fprintf(stderr, "local is newer than remote, update remote\n"); + SSRF_INFO("local is newer than remote, update remote\n"); git_storage_update_progress(translate("gettextFromC", "Push local changes to cloud storage")); return update_remote(repo, origin, local, remote, rt); } @@ -542,7 +542,7 @@ static int check_remote_status(git_repository *repo, git_remote *origin, const c git_reference *local_ref, *remote_ref; if (verbose) - fprintf(stderr, "git storage: check remote status\n"); + SSRF_INFO("git storage: check remote status\n"); if (git_branch_lookup(&local_ref, repo, branch, GIT_BRANCH_LOCAL)) { if (is_subsurface_cloud) @@ -593,7 +593,7 @@ void delete_remote_branch(git_repository *repo, const char *remote, const char * git_config_delete_entry(conf, "http.proxy"); } if (git_remote_lookup(&origin, repo, "origin")) { - fprintf(stderr, "Repository '%s' origin lookup failed (%s)", remote, giterr_last() ? giterr_last()->message : "(unspecified)"); + SSRF_INFO("Repository '%s' origin lookup failed (%s)", remote, giterr_last() ? giterr_last()->message : "(unspecified)"); return; } /* fetch the remote state */ @@ -602,7 +602,7 @@ void delete_remote_branch(git_repository *repo, const char *remote, const char * f_opts.callbacks.credentials = credential_https_cb; error = git_remote_fetch(origin, NULL, &f_opts, NULL); if (error) { - fprintf(stderr, "remote fetch failed (%s)\n", giterr_last() ? giterr_last()->message : "authentication failed"); + SSRF_INFO("remote fetch failed (%s)\n", giterr_last() ? giterr_last()->message : "authentication failed"); return; } /* delete the remote branch by pushing to ":refs/heads/<branch>" */ @@ -616,8 +616,8 @@ void delete_remote_branch(git_repository *repo, const char *remote, const char * error = git_remote_push(origin, &refspec, &p_opts); free(branch_ref); if (error) { - fprintf(stderr, "Unable to delete branch '%s'", branch); - fprintf(stderr, "error was (%s)\n", giterr_last() ? giterr_last()->message : "(unspecified)"); + SSRF_INFO("Unable to delete branch '%s'", branch); + SSRF_INFO("error was (%s)\n", giterr_last() ? giterr_last()->message : "(unspecified)"); } git_remote_free(origin); return; @@ -632,21 +632,21 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc if (git_local_only) { if (verbose) - fprintf(stderr, "don't sync with remote - read from cache only\n"); + SSRF_INFO("don't sync with remote - read from cache only\n"); return 0; } if (verbose) - fprintf(stderr, "sync with remote %s[%s]\n", remote, branch); + SSRF_INFO("sync with remote %s[%s]\n", remote, branch); git_storage_update_progress(translate("gettextFromC", "Sync with cloud storage")); git_repository_config(&conf, repo); if (rt == RT_HTTPS && getProxyString(&proxy_string)) { if (verbose) - fprintf(stderr, "set proxy to \"%s\"\n", proxy_string); + SSRF_INFO("set proxy to \"%s\"\n", proxy_string); git_config_set_string(conf, "http.proxy", proxy_string); free(proxy_string); } else { if (verbose) - fprintf(stderr, "delete proxy setting\n"); + SSRF_INFO("delete proxy setting\n"); git_config_delete_entry(conf, "http.proxy"); } @@ -668,7 +668,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc return 0; } if (verbose) - fprintf(stderr, "git storage: fetch remote\n"); + SSRF_INFO("git storage: fetch remote\n"); git_fetch_options opts = GIT_FETCH_OPTIONS_INIT; opts.callbacks.transfer_progress = &transfer_progress_cb; auth_attempt = 0; @@ -686,7 +686,7 @@ int sync_with_remote(git_repository *repo, const char *remote, const char *branc report_error("Unable to fetch remote '%s'", remote); if (verbose) // If we returned GIT_EUSER during authentication, giterr_last() returns NULL - fprintf(stderr, "remote fetch failed (%s)\n", + SSRF_INFO("remote fetch failed (%s)\n", giterr_last() ? giterr_last()->message : "authentication failed"); // Since we failed to sync with online repository, enter offline mode git_local_only = true; @@ -706,7 +706,7 @@ static git_repository *update_local_repo(const char *localdir, const char *remot git_reference *head; if (verbose) - fprintf(stderr, "git storage: update local repo\n"); + SSRF_INFO("git storage: update local repo\n"); error = git_repository_open(&repo, localdir); if (error) { @@ -723,7 +723,7 @@ static git_repository *update_local_repo(const char *localdir, const char *remot if (!git_branch_name(&name, head)) { if (strcmp(name, branch)) { char *branchref = format_string("refs/heads/%s", branch); - fprintf(stderr, "Setting cache branch from '%s' to '%s'", name, branch); + SSRF_INFO("Setting cache branch from '%s' to '%s'", name, branch); git_repository_set_head(repo, branchref); free(branchref); } @@ -746,19 +746,19 @@ static int repository_create_cb(git_repository **out, const char *path, int bare int ret = git_repository_init(out, path, bare); if (ret != 0) { if (verbose) - fprintf(stderr, "Initializing git repository failed\n"); + SSRF_INFO("Initializing git repository failed\n"); return ret; } git_repository_config(&conf, *out); if (getProxyString(&proxy_string)) { if (verbose) - fprintf(stderr, "set proxy to \"%s\"\n", proxy_string); + SSRF_INFO("set proxy to \"%s\"\n", proxy_string); git_config_set_string(conf, "http.proxy", proxy_string); free(proxy_string); } else { if (verbose) - fprintf(stderr, "delete proxy setting\n"); + SSRF_INFO("delete proxy setting\n"); git_config_delete_entry(conf, "http.proxy"); } return ret; @@ -773,7 +773,7 @@ static git_repository *create_and_push_remote(const char *localdir, const char * char *variable_name, *head; if (verbose) - fprintf(stderr, "git storage: create and push remote\n"); + SSRF_INFO("git storage: create and push remote\n"); /* first make sure the directory for the local cache exists */ subsurface_mkdir(localdir); @@ -812,7 +812,7 @@ static git_repository *create_local_repo(const char *localdir, const char *remot git_clone_options opts = GIT_CLONE_OPTIONS_INIT; if (verbose) - fprintf(stderr, "git storage: create_local_repo\n"); + SSRF_INFO("git storage: create_local_repo\n"); auth_attempt = 0; opts.fetch_opts.callbacks.transfer_progress = &transfer_progress_cb; @@ -826,15 +826,15 @@ static git_repository *create_local_repo(const char *localdir, const char *remot if (is_subsurface_cloud && !canReachCloudServer()) return 0; if (verbose > 1) - fprintf(stderr, "git storage: calling git_clone()\n"); + SSRF_INFO("git storage: calling git_clone()\n"); error = git_clone(&cloned_repo, remote, localdir, &opts); if (verbose > 1) - fprintf(stderr, "git storage: returned from git_clone() with error %d\n", error); + SSRF_INFO("git storage: returned from git_clone() with error %d\n", error); if (error) { char *msg = ""; if (giterr_last()) { msg = giterr_last()->message; - fprintf(stderr, "error message was %s\n", msg); + SSRF_INFO("error message was %s\n", msg); } char *pattern = format_string("reference 'refs/remotes/origin/%s' not found", branch); // it seems that we sometimes get 'Reference' and sometimes 'reference' @@ -843,7 +843,7 @@ static git_repository *create_local_repo(const char *localdir, const char *remot * to our cloud storage and the branch doesn't exist. * So we need to create the branch and push it to the remote */ if (verbose) - fprintf(stderr, "remote repo didn't include our branch\n"); + SSRF_INFO("remote repo didn't include our branch\n"); cloned_repo = create_and_push_remote(localdir, remote, branch); #if !defined(DEBUG) && !defined(SUBSURFACE_MOBILE) } else if (is_subsurface_cloud) { @@ -874,7 +874,7 @@ static struct git_repository *get_remote_repo(const char *localdir, const char * enum remote_transport rt = url_to_remote_transport(remote); if (verbose > 1) { - fprintf(stderr, "git_remote_repo: accessing %s\n", remote); + SSRF_INFO("git_remote_repo: accessing %s\n", remote); } git_storage_update_progress(translate("gettextFromC", "Synchronising data file")); /* Do we already have a local cache? */ @@ -1057,7 +1057,7 @@ struct git_repository *is_git_repository(const char *filename, const char **bran if (subsurface_stat(loc, &st) < 0 || !S_ISDIR(st.st_mode)) { if (verbose) - fprintf(stderr, "loc %s wasn't found or is not a directory\n", loc); + SSRF_INFO("loc %s wasn't found or is not a directory\n", loc); free(loc); free(branch); return dummy_git_repository; diff --git a/core/load-git.c b/core/load-git.c index 9e5924ea1..b7353763f 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -1630,7 +1630,7 @@ static int walk_tree_file(const char *root, const git_tree_entry *entry, struct dive_trip_t *trip = state->active_trip; const char *name = git_tree_entry_name(entry); if (verbose > 1) - fprintf(stderr, "git load handling file %s\n", name); + SSRF_INFO("git load handling file %s\n", name); switch (*name) { case '-': case '+': if (dive) diff --git a/core/profile.c b/core/profile.c index 6914b8301..109ec4508 100644 --- a/core/profile.c +++ b/core/profile.c @@ -318,7 +318,7 @@ int get_cylinder_index(const struct dive *dive, const struct event *ev) * We now match up gas change events with their cylinders at dive * event fixup time. */ - fprintf(stderr, "Still looking up cylinder based on gas mix in get_cylinder_index()!\n"); + SSRF_INFO("Still looking up cylinder based on gas mix in get_cylinder_index()!\n"); mix = get_gasmix_from_event(dive, ev); best = find_best_gasmix_match(mix, &dive->cylinders); @@ -1056,7 +1056,7 @@ void calculate_deco_information(struct deco_state *ds, const struct deco_state * entry->ambpressure = depth_to_bar(entry->depth, dive); entry->gfline = get_gf(ds, entry->ambpressure, dive) * (100.0 - AMB_PERCENTAGE) + AMB_PERCENTAGE; if (t0 > t1) { - fprintf(stderr, "non-monotonous dive stamps %d %d\n", t0, t1); + SSRF_INFO("non-monotonous dive stamps %d %d\n", t0, t1); int xchg = t1; t1 = t0; t0 = xchg; diff --git a/core/qthelper.h b/core/qthelper.h index 848763138..a074e70cd 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -161,4 +161,13 @@ char *get_changes_made(); } #endif +// 4) SSRF_INFO macro to replace fprintf calls in our code +// (originally based on logging bits from libdivecomputer) +#if !defined(Q_OS_ANDROID) && !defined(__ANDROID__) +#define SSRF_INFO(fmt, ...) fprintf(stderr, "INFO: " fmt "\n", ##__VA_ARGS__) +#else +#include <android/log.h> +#define SSRF_INFO(fmt, ...) __android_log_print(ANDROID_LOG_INFO, "Subsurface", "INFO: " fmt "\n", ##__VA_ARGS__); +#endif + #endif // QTHELPER_H diff --git a/core/save-git.c b/core/save-git.c index 6f1cc4646..5de9c2a63 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -448,7 +448,7 @@ static void create_dive_buffer(struct dive *dive, struct membuffer *b) if (dive->dive_site) put_format(b, "divesiteid %08x\n", dive->dive_site->uuid); if (verbose && dive->dive_site) - fprintf(stderr, "removed reference to non-existant dive site with uuid %08x\n", dive->dive_site->uuid); + SSRF_INFO("removed reference to non-existant dive site with uuid %08x\n", dive->dive_site->uuid); save_overview(b, dive); save_cylinder_info(b, dive); save_weightsystem_info(b, dive); @@ -491,7 +491,7 @@ static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git if (ret) { const git_error *gerr = giterr_last(); if (gerr) { - fprintf(stderr, "tree_insert failed with return %d error %s\n", ret, gerr->message); + SSRF_INFO("tree_insert failed with return %d error %s\n", ret, gerr->message); } } return ret; @@ -1071,7 +1071,7 @@ static void create_commit_message(struct membuffer *msg, bool create_empty) free((void *)user_agent); free(changes_made); if (verbose) - fprintf(stderr, "Commit message:\n\n%s\n", mb_cstring(msg)); + SSRF_INFO("Commit message:\n\n%s\n", mb_cstring(msg)); } static int create_new_commit(git_repository *repo, const char *remote, const char *branch, git_oid *tree_id, bool create_empty) @@ -1100,7 +1100,7 @@ static int create_new_commit(git_repository *repo, const char *remote, const cha if (saved_git_id) { if (existing_filename && verbose) - fprintf(stderr, "existing filename %s\n", existing_filename); + SSRF_INFO("existing filename %s\n", existing_filename); const git_oid *id = git_commit_id((const git_commit *) parent); /* if we are saving to the same git tree we got this from, let's make * sure there is no confusion */ @@ -1199,7 +1199,7 @@ static int write_git_tree(git_repository *repo, struct dir *tree, git_oid *resul if (ret && verbose) { const git_error *gerr = giterr_last(); if (gerr) - fprintf(stderr, "tree_insert failed with return %d error %s\n", ret, gerr->message); + SSRF_INFO("tree_insert failed with return %d error %s\n", ret, gerr->message); } /* .. and free the now useless treebuilder */ @@ -1215,7 +1215,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo bool cached_ok; if (verbose) - fprintf(stderr, "git storage: do git save\n"); + SSRF_INFO("git storage: do git save\n"); if (!create_empty) // so we are actually saving the dives git_storage_update_progress(translate("gettextFromC", "Preparing to save data")); @@ -1238,7 +1238,7 @@ int do_git_save(git_repository *repo, const char *branch, const char *remote, bo return -1; if (verbose) - fprintf(stderr, "git storage, write git tree\n"); + SSRF_INFO("git storage, write git tree\n"); if (write_git_tree(repo, &tree, &id)) return report_error("git tree write failed"); diff --git a/core/trip.c b/core/trip.c index 6e7c4653d..070d05a21 100644 --- a/core/trip.c +++ b/core/trip.c @@ -4,6 +4,7 @@ #include "subsurface-string.h" #include "selection.h" #include "table.h" +#include "core/qthelper.h" struct trip_table trip_table; @@ -87,7 +88,7 @@ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip) if (dive->divetrip == trip) return; if (dive->divetrip) - fprintf(stderr, "Warning: adding dive to trip that has trip set\n"); + SSRF_INFO("Warning: adding dive to trip that has trip set\n"); insert_dive(&trip->dives, dive); dive->divetrip = trip; } |