lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

December 2023

  • 1 participants
  • 1601 discussions
[M] Change in libosmocore[master]: util: add osmo_strbuf macros to manipulate the strbuf tail
by osmith 04 Dec '23

04 Dec '23
Attention is currently required from: neels. osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35207?usp=email ) Change subject: util: add osmo_strbuf macros to manipulate the strbuf tail ...................................................................... Patch Set 1: Code-Review+1 (1 comment) File include/osmocom/core/utils.h: https://gerrit.osmocom.org/c/libosmocore/+/35207/comment/c3dba968_29edcd21 PS1, Line 329: } while (0) What is the advantage of having these long macros instead of turning them into (probably more readable) functions? -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35207?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I997707c328eab3ffa00a78fdb9a0a2cbe18404b4 Gerrit-Change-Number: 35207 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Comment-Date: Mon, 04 Dec 2023 08:23:53 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[S] Change in libosmocore[master]: util: add OSMO_STRBUF_REMAIN()
by osmith 04 Dec '23

04 Dec '23
Attention is currently required from: neels. osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35206?usp=email ) Change subject: util: add OSMO_STRBUF_REMAIN() ...................................................................... Patch Set 1: Code-Review+1 -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35206?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I6f2991125882bff948708bbb4ae218f9f3d1e50c Gerrit-Change-Number: 35206 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Comment-Date: Mon, 04 Dec 2023 08:11:51 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes Gerrit-MessageType: comment
1 0
0 0
[M] Change in osmo-ci[master]: jobs: fix undefined parameter log warnings
by osmith 04 Dec '23

04 Dec '23
osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-ci/+/35211?usp=email ) Change subject: jobs: fix undefined parameter log warnings ...................................................................... jobs: fix undefined parameter log warnings Adjust all jobs in the gerrit verifications pipeline to use the same parameters from a new include file, to prevent undefined parameter warnings in the log. Fixes: OS#6261 Change-Id: Iadc5cd8996eb4ed86634ceb35829a3e9239e598d --- M jobs/gerrit-binpkgs.yml M jobs/gerrit-lint.yml M jobs/gerrit-verifications-comment.yml A jobs/gerrit-verifications-parameters.yaml.inc M jobs/gerrit-verifications.yml 5 files changed, 74 insertions(+), 96 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-ci refs/changes/11/35211/1 diff --git a/jobs/gerrit-binpkgs.yml b/jobs/gerrit-binpkgs.yml index ecfbd52..7cf2230 100644 --- a/jobs/gerrit-binpkgs.yml +++ b/jobs/gerrit-binpkgs.yml @@ -24,26 +24,7 @@ Related issue: <a href="https://osmocom.org/issues/2385">OS#2385</a> parameters: - - string: - name: BRANCH_CI - description: | - osmo-ci.git branch - default: 'master' - - string: - name: GERRIT_REPO_URL - description: set by gerrit verification pipeline job - - string: - name: GERRIT_BRANCH - description: set by gerrit verification pipeline job - - string: - name: GERRIT_REFSPEC - description: set by gerrit verification pipeline job - - string: - name: PROJECT_NAME - description: project to test, e.g. 'libosmocore' (set by pipeline) - - string: - name: DISTRO - description: distribution to build for, e.g. 'debian:12' (set by pipeline) + !include: gerrit-verifications-parameters.yaml.inc scm: - git: diff --git a/jobs/gerrit-lint.yml b/jobs/gerrit-lint.yml index 16377cd..3039829 100644 --- a/jobs/gerrit-lint.yml +++ b/jobs/gerrit-lint.yml @@ -23,38 +23,7 @@ Related issue: <a href="https://osmocom.org/issues/5087">OS#5087</a> parameters: - - string: - name: BRANCH_CI - description: | - osmo-ci.git branch - default: 'master' - - string: - name: GERRIT_PROJECT - description: set by gerrit verification pipeline job - - string: - name: GERRIT_CHANGE_NUMBER - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PATCHSET_NUMBER - description: set by gerrit verification pipeline job - - string: - name: GERRIT_BRANCH - description: set by gerrit verification pipeline job - - string: - name: GERRIT_HOST - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PATCHSET_REVISION - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PORT - description: set by gerrit verification pipeline job - - string: - name: GERRIT_REFSPEC - description: set by gerrit verification pipeline job - - string: - name: GERRIT_REPO_URL - description: set by gerrit verification pipeline job + !include: gerrit-verifications-parameters.yaml.inc scm: - git: diff --git a/jobs/gerrit-verifications-comment.yml b/jobs/gerrit-verifications-comment.yml index 6c8d90d..3ed54ad 100644 --- a/jobs/gerrit-verifications-comment.yml +++ b/jobs/gerrit-verifications-comment.yml @@ -22,44 +22,7 @@ Related issue: <a href="https://osmocom.org/issues/2385">OS#2385</a> parameters: - - string: - name: BRANCH_CI - description: | - osmo-ci.git branch - default: 'master' - - string: - name: COMMENT_TYPE - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PROJECT - description: set by gerrit verification pipeline job - - string: - name: GERRIT_CHANGE_NUMBER - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PATCHSET_NUMBER - description: set by gerrit verification pipeline job - - string: - name: GERRIT_BRANCH - description: set by gerrit verification pipeline job - - string: - name: GERRIT_HOST - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PATCHSET_REVISION - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PATCHSET_UPLOADER_NAME - description: set by gerrit verification pipeline job - - string: - name: GERRIT_PORT - description: set by gerrit verification pipeline job - - string: - name: GERRIT_REFSPEC - description: set by gerrit verification pipeline job - - string: - name: PIPELINE_BUILD_URL - description: set by gerrit verification pipeline job + !include: gerrit-verifications-parameters.yaml.inc scm: - git: diff --git a/jobs/gerrit-verifications-parameters.yaml.inc b/jobs/gerrit-verifications-parameters.yaml.inc new file mode 100644 index 0000000..32df1b6 --- /dev/null +++ b/jobs/gerrit-verifications-parameters.yaml.inc @@ -0,0 +1,53 @@ +# This file gets included as parameters element of various jobs in the +# gerrit-verifications pipeline. All of these jobs have the same parameters +# and can be called from one run_job() function, without creating log entries +# about undefined parameters (OS#6261). See gerrit-verifications.yml for more +# information. + +- string: + name: BRANCH_CI + description: | + osmo-ci.git branch + default: 'master' +- string: + name: COMMENT_TYPE + description: set by gerrit verification pipeline job +- string: + name: DISTRO + description: set by gerrit verification pipeline job +- string: + name: GERRIT_BRANCH + description: set by gerrit verification pipeline job +- string: + name: GERRIT_CHANGE_NUMBER + description: set by gerrit verification pipeline job +- string: + name: GERRIT_HOST + description: set by gerrit verification pipeline job +- string: + name: GERRIT_PATCHSET_NUMBER + description: set by gerrit verification pipeline job +- string: + name: GERRIT_PATCHSET_REVISION + description: set by gerrit verification pipeline job +- string: + name: GERRIT_PATCHSET_UPLOADER_NAME + description: set by gerrit verification pipeline job +- string: + name: GERRIT_PORT + description: set by gerrit verification pipeline job +- string: + name: GERRIT_PROJECT + description: set by gerrit verification pipeline job +- string: + name: GERRIT_REFSPEC + description: set by gerrit verification pipeline job +- string: + name: GERRIT_REPO_URL + description: set by gerrit verification pipeline job +- string: + name: PIPELINE_BUILD_URL + description: set by gerrit verification pipeline job +- string: + name: PROJECT_NAME + description: set by gerrit verification pipeline job diff --git a/jobs/gerrit-verifications.yml b/jobs/gerrit-verifications.yml index 07f07f4..90c5fb5 100644 --- a/jobs/gerrit-verifications.yml +++ b/jobs/gerrit-verifications.yml @@ -473,6 +473,9 @@ try {{ echo "pipeline_${{display_name}}: running job ${{job_name}}" + // IMPORTANT: Keep gerrit-verifications-parameters.yaml.inc in sync + // with the list of parameters here, and make sure all jobs passed + // to run_job() include the .yaml.inc file. (OS#6261) build job: job_name, parameters: [ string(name: "COMMENT_TYPE", value: comment_type), string(name: "DISTRO", value: distro), @@ -691,12 +694,7 @@ recursive: true parameters: - - string: - name: GERRIT_BRANCH - description: set by gerrit-{repos} job - - string: - name: GERRIT_REFSPEC - description: set by gerrit-{repos} job + !include: gerrit-verifications-parameters.yaml.inc builders: - shell: '{obj:cmd}' -- To view, visit https://gerrit.osmocom.org/c/osmo-ci/+/35211?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-ci Gerrit-Branch: master Gerrit-Change-Id: Iadc5cd8996eb4ed86634ceb35829a3e9239e598d Gerrit-Change-Number: 35211 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[XS] Change in osmo-mgw[master]: [do not merge] test gerrit verifications
by osmith 04 Dec '23

04 Dec '23
osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-mgw/+/35210?usp=email ) Change subject: [do not merge] test gerrit verifications ...................................................................... [do not merge] test gerrit verifications Change-Id: I6a491a9b36299443be72b41bc13cac7242b088f4 --- A test 1 file changed, 9 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/10/35210/1 diff --git a/test b/test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/35210?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I6a491a9b36299443be72b41bc13cac7242b088f4 Gerrit-Change-Number: 35210 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[XS] Change in osmo-dev[master]: [do not merge] test gerrit verifications
by osmith 04 Dec '23

04 Dec '23
osmith has abandoned this change. ( https://gerrit.osmocom.org/c/osmo-dev/+/35209?usp=email ) Change subject: [do not merge] test gerrit verifications ...................................................................... Abandoned -- To view, visit https://gerrit.osmocom.org/c/osmo-dev/+/35209?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-dev Gerrit-Branch: master Gerrit-Change-Id: Ia506922e0c47b0a0329048dba5ac433c17b6b484 Gerrit-Change-Number: 35209 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: abandon
1 0
0 0
[XS] Change in osmo-dev[master]: [do not merge] test gerrit verifications
by osmith 04 Dec '23

04 Dec '23
osmith has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-dev/+/35209?usp=email ) Change subject: [do not merge] test gerrit verifications ...................................................................... [do not merge] test gerrit verifications Change-Id: Ia506922e0c47b0a0329048dba5ac433c17b6b484 --- A test 1 file changed, 9 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-dev refs/changes/09/35209/1 diff --git a/test b/test new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/test -- To view, visit https://gerrit.osmocom.org/c/osmo-dev/+/35209?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: osmo-dev Gerrit-Branch: master Gerrit-Change-Id: Ia506922e0c47b0a0329048dba5ac433c17b6b484 Gerrit-Change-Number: 35209 Gerrit-PatchSet: 1 Gerrit-Owner: osmith <osmith(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[S] Change in libosmocore[master]: util: add OSMO_STRBUF_REMAIN()
by neels 04 Dec '23

04 Dec '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35206?usp=email ) Change subject: util: add OSMO_STRBUF_REMAIN() ...................................................................... util: add OSMO_STRBUF_REMAIN() This code already exists twice, and upcoming patch will need this as well in logging.c. Add a macro to remove the code dup. Related: OS#6284 Related: Ib577a5e0d7450ce93ff21f37ba3262704cbf4752 Change-Id: I6f2991125882bff948708bbb4ae218f9f3d1e50c --- M include/osmocom/core/utils.h 1 file changed, 19 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/06/35206/1 diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index ee7cfa4..2a3670b 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -249,7 +249,7 @@ #define OSMO_STRBUF_APPEND(STRBUF, func, args...) do { \ if (!(STRBUF).pos) \ (STRBUF).pos = (STRBUF).buf; \ - size_t _sb_remain = (STRBUF).buf ? (STRBUF).len - ((STRBUF).pos - (STRBUF).buf) : 0; \ + size_t _sb_remain = OSMO_STRBUF_REMAIN(STRBUF); \ int _sb_l = func((STRBUF).pos, _sb_remain, ##args); \ if (_sb_l < 0 || (size_t)_sb_l > _sb_remain) \ (STRBUF).pos = (STRBUF).buf + (STRBUF).len; \ @@ -281,6 +281,9 @@ #define OSMO_STRBUF_PRINTF(STRBUF, fmt, args...) \ OSMO_STRBUF_APPEND(STRBUF, snprintf, fmt, ##args) +/*! Return remaining space for characters and terminating nul in the given struct osmo_strbuf. */ +#define OSMO_STRBUF_REMAIN(STRBUF) ((STRBUF).buf ? (STRBUF).len - ((STRBUF).pos - (STRBUF).buf) : 0) + /*! Like OSMO_STRBUF_APPEND(), but for function signatures that return the char* buffer instead of a length. * When using this function, the final STRBUF.chars_needed may not reflect the actual number of characters needed, since * that number cannot be obtained from this kind of function signature. @@ -292,7 +295,7 @@ #define OSMO_STRBUF_APPEND_NOLEN(STRBUF, func, args...) do { \ if (!(STRBUF).pos) \ (STRBUF).pos = (STRBUF).buf; \ - size_t _sb_remain = (STRBUF).buf ? (STRBUF).len - ((STRBUF).pos - (STRBUF).buf) : 0; \ + size_t _sb_remain = OSMO_STRBUF_REMAIN(STRBUF); \ if (_sb_remain) { \ func((STRBUF).pos, _sb_remain, ##args); \ } \ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35206?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I6f2991125882bff948708bbb4ae218f9f3d1e50c Gerrit-Change-Number: 35206 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in libosmocore[master]: util: add osmo_strbuf macros to manipulate the strbuf tail
by neels 04 Dec '23

04 Dec '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35207?usp=email ) Change subject: util: add osmo_strbuf macros to manipulate the strbuf tail ...................................................................... util: add osmo_strbuf macros to manipulate the strbuf tail Upcoming patch adopts osmo_strbuf in logging.c, which sometimes needs to steal and re-add trailing newline characters, and also needs to let ctime_r() write to the buffer before updating the osmo_strbuf state. Related: OS#6284 Related: Ib577a5e0d7450ce93ff21f37ba3262704cbf4752 Change-Id: I997707c328eab3ffa00a78fdb9a0a2cbe18404b4 --- M include/osmocom/core/utils.h M tests/utils/utils_test.c M tests/utils/utils_test.ok 3 files changed, 154 insertions(+), 0 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/07/35207/1 diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 2a3670b..d90bf6f 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -284,6 +284,10 @@ /*! Return remaining space for characters and terminating nul in the given struct osmo_strbuf. */ #define OSMO_STRBUF_REMAIN(STRBUF) ((STRBUF).buf ? (STRBUF).len - ((STRBUF).pos - (STRBUF).buf) : 0) +/*! Return number of actual characters contained in struct osmo_strbuf (without terminating nul). */ +#define OSMO_STRBUF_CHAR_COUNT(STRBUF) ((STRBUF).buf && (STRBUF).pos > (STRBUF).buf ? \ + OSMO_MIN((STRBUF).pos - (STRBUF).buf, (STRBUF).len - 1) : 0) + /*! Like OSMO_STRBUF_APPEND(), but for function signatures that return the char* buffer instead of a length. * When using this function, the final STRBUF.chars_needed may not reflect the actual number of characters needed, since * that number cannot be obtained from this kind of function signature. @@ -307,6 +311,41 @@ (STRBUF).chars_needed += _sb_l; \ } while(0) +/*! Remove up to N chars from the end of an osmo_strbuf. + * |--char-count---| - - chars_needed - - | + * |<---------drop----------| + */ +#define OSMO_STRBUF_DROP_TAIL(STRBUF, N_CHARS) do { \ + if ((STRBUF).pos > (STRBUF).buf) { \ + size_t _sb_drop_n = (STRBUF).chars_needed; \ + _sb_drop_n = OSMO_MIN(_sb_drop_n, N_CHARS); \ + (STRBUF).chars_needed -= _sb_drop_n; \ + \ + if ((STRBUF).chars_needed < OSMO_STRBUF_CHAR_COUNT(STRBUF)) { \ + (STRBUF).pos = (STRBUF).buf + (STRBUF).chars_needed; \ + *(STRBUF).pos = '\0'; \ + } \ + } \ + } while (0) + +/* Let osmo_strbuf know that N_CHARS characters (excluding nul) were written to STRBUF.pos. + * Advance STRBUF.pos and STRBUF.chars_needed by at most N_CHARS, or up to STRBUF.len - 1. + * Ensure nul termination. */ +#define OSMO_STRBUF_ADDED_TAIL(STRBUF, N_CHARS) \ + do { \ + if (!(STRBUF).pos) \ + (STRBUF).pos = (STRBUF).buf; \ + (STRBUF).chars_needed += N_CHARS; \ + size_t _sb_added = OSMO_STRBUF_REMAIN(STRBUF); \ + if (_sb_added) \ + _sb_added--; \ + _sb_added = OSMO_MIN(_sb_added, N_CHARS); \ + if (_sb_added) \ + (STRBUF).pos += _sb_added; \ + if ((STRBUF).pos < (STRBUF).buf + (STRBUF).len) \ + *(STRBUF).pos = '\0'; \ + } while (0) + bool osmo_str_startswith(const char *str, const char *startswith_str); int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision); diff --git a/tests/utils/utils_test.c b/tests/utils/utils_test.c index 0b7bfe4..bdeedb5 100644 --- a/tests/utils/utils_test.c +++ b/tests/utils/utils_test.c @@ -31,6 +31,7 @@ #include <errno.h> #include <limits.h> #include <inttypes.h> +#include <string.h> static void hexdump_test(void) { @@ -1306,6 +1307,50 @@ printf("%zu: %s (need=%zu)\n", sb.len, buf, sb.chars_needed); } +void strbuf_test_tail_for_buflen(size_t buflen) +{ + char buf[buflen]; + struct osmo_strbuf sb = { .buf = buf, .len = buflen }; + printf("\n%s(%zu)\n", __func__, buflen); + +#define SHOW(N) \ + printf(#N ": %s sb.chars_needed=%zu sb.pos=&sb.buf[%d]\n", \ + osmo_quote_str(buf, -1), sb.chars_needed, (int)(sb.pos - sb.buf)) + + /* shorten in steps using OSMO_STRBUF_DROP_TAIL(), removing and re-adding a trailing newline. */ + OSMO_STRBUF_PRINTF(sb, "banananana\n"); + SHOW(1); + OSMO_STRBUF_DROP_TAIL(sb, 3); + SHOW(2); + OSMO_STRBUF_PRINTF(sb, "\n"); + SHOW(3); + OSMO_STRBUF_DROP_TAIL(sb, 3); + SHOW(4); + OSMO_STRBUF_PRINTF(sb, "\n"); + SHOW(5); + + /* drop trailing newline */ + OSMO_STRBUF_DROP_TAIL(sb, 1); + SHOW(6); + + /* test writing something to the end and letting OSMO_STRBUF_ADDED_TAIL() know later */ + int n = OSMO_MIN(6, OSMO_STRBUF_REMAIN(sb)); + if (n) + memcpy(sb.pos, "bread\n", n); + OSMO_STRBUF_ADDED_TAIL(sb, 6); + SHOW(7); +} + +void strbuf_test_tail(void) +{ + strbuf_test_tail_for_buflen(64); + strbuf_test_tail_for_buflen(32); + strbuf_test_tail_for_buflen(16); + strbuf_test_tail_for_buflen(8); + strbuf_test_tail_for_buflen(4); + strbuf_test_tail_for_buflen(1); +} + static void startswith_test_str(const char *str, const char *startswith_str, bool expect_rc) { bool rc = osmo_str_startswith(str, startswith_str); @@ -2152,6 +2197,7 @@ osmo_str_tolowupper_test(); strbuf_test(); strbuf_test_nolen(); + strbuf_test_tail(); startswith_test(); name_c_impl_test(); osmo_print_n_test(); diff --git a/tests/utils/utils_test.ok b/tests/utils/utils_test.ok index 3f453e9..6f5d46b 100644 --- a/tests/utils/utils_test.ok +++ b/tests/utils/utils_test.ok @@ -470,6 +470,60 @@ more: 0001011100101010000 (need=19) 10: 000101110 (need=9) +strbuf_test_tail_for_buflen(64) +1: "banananana\n" sb.chars_needed=11 sb.pos=&sb.buf[11] +2: "bananana" sb.chars_needed=8 sb.pos=&sb.buf[8] +3: "bananana\n" sb.chars_needed=9 sb.pos=&sb.buf[9] +4: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +5: "banana\n" sb.chars_needed=7 sb.pos=&sb.buf[7] +6: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +7: "bananabread\n" sb.chars_needed=12 sb.pos=&sb.buf[12] + +strbuf_test_tail_for_buflen(32) +1: "banananana\n" sb.chars_needed=11 sb.pos=&sb.buf[11] +2: "bananana" sb.chars_needed=8 sb.pos=&sb.buf[8] +3: "bananana\n" sb.chars_needed=9 sb.pos=&sb.buf[9] +4: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +5: "banana\n" sb.chars_needed=7 sb.pos=&sb.buf[7] +6: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +7: "bananabread\n" sb.chars_needed=12 sb.pos=&sb.buf[12] + +strbuf_test_tail_for_buflen(16) +1: "banananana\n" sb.chars_needed=11 sb.pos=&sb.buf[11] +2: "bananana" sb.chars_needed=8 sb.pos=&sb.buf[8] +3: "bananana\n" sb.chars_needed=9 sb.pos=&sb.buf[9] +4: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +5: "banana\n" sb.chars_needed=7 sb.pos=&sb.buf[7] +6: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +7: "bananabread\n" sb.chars_needed=12 sb.pos=&sb.buf[12] + +strbuf_test_tail_for_buflen(8) +1: "bananan" sb.chars_needed=11 sb.pos=&sb.buf[8] +2: "bananan" sb.chars_needed=8 sb.pos=&sb.buf[8] +3: "bananan" sb.chars_needed=9 sb.pos=&sb.buf[8] +4: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +5: "banana\n" sb.chars_needed=7 sb.pos=&sb.buf[7] +6: "banana" sb.chars_needed=6 sb.pos=&sb.buf[6] +7: "bananab" sb.chars_needed=12 sb.pos=&sb.buf[7] + +strbuf_test_tail_for_buflen(4) +1: "ban" sb.chars_needed=11 sb.pos=&sb.buf[4] +2: "ban" sb.chars_needed=8 sb.pos=&sb.buf[4] +3: "ban" sb.chars_needed=9 sb.pos=&sb.buf[4] +4: "ban" sb.chars_needed=6 sb.pos=&sb.buf[4] +5: "ban" sb.chars_needed=7 sb.pos=&sb.buf[4] +6: "ban" sb.chars_needed=6 sb.pos=&sb.buf[4] +7: "ban" sb.chars_needed=12 sb.pos=&sb.buf[4] + +strbuf_test_tail_for_buflen(1) +1: "" sb.chars_needed=11 sb.pos=&sb.buf[1] +2: "" sb.chars_needed=8 sb.pos=&sb.buf[1] +3: "" sb.chars_needed=9 sb.pos=&sb.buf[1] +4: "" sb.chars_needed=6 sb.pos=&sb.buf[1] +5: "" sb.chars_needed=7 sb.pos=&sb.buf[1] +6: "" sb.chars_needed=6 sb.pos=&sb.buf[1] +7: "" sb.chars_needed=12 sb.pos=&sb.buf[1] + startswith_test() osmo_str_startswith(NULL, NULL) == true osmo_str_startswith("", NULL) == true -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35207?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I997707c328eab3ffa00a78fdb9a0a2cbe18404b4 Gerrit-Change-Number: 35207 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[M] Change in libosmocore[master]: logging: fix nul octets in log output / use osmo_strbuf
by neels 04 Dec '23

04 Dec '23
neels has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/35208?usp=email ) Change subject: logging: fix nul octets in log output / use osmo_strbuf ...................................................................... logging: fix nul octets in log output / use osmo_strbuf Patch [1] merged few weeks ago, for yet unknown reasons, sprinkles nul characters at seemingly randomly chosen log line ends. Trying to figure out why that happens, i got tired of the unreadable cruft, and decided to migrate the _output_buf() implementation to osmo_strbuf first. With osmo_strbuf in use and implementing 1:1 what the previous code did, the odd nul octets have disappeared. So the bug was caused by unreadable code. [1] 11a416827dd9f2da6b7c1db0e1e83adb1e6e5cc8 Ia7de9d88aa5ac48ec0d5c1a931a89d21c02c5433 "logging: ensure ANSI color escape is sent in same line/before newline" Related: OS#6284 Related: Ia7de9d88aa5ac48ec0d5c1a931a89d21c02c5433 Change-Id: Ib577a5e0d7450ce93ff21f37ba3262704cbf4752 --- M src/core/logging.c 1 file changed, 70 insertions(+), 84 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/08/35208/1 diff --git a/src/core/logging.c b/src/core/logging.c index dc19cf3..0d215f4 100644 --- a/src/core/logging.c +++ b/src/core/logging.c @@ -486,18 +486,18 @@ unsigned int level, const char *file, int line, int cont, const char *format, va_list ap) { - int ret, len = 0, offset = 0, rem = buf_len; + int ret; const char *c_subsys = NULL; + struct osmo_strbuf sb = { .buf = buf, .len = buf_len }; + + /* safety net in case of encountering errors and returning nothing */ + buf[0] = '\0'; /* are we using color */ if (target->use_color) { c_subsys = color(subsys); - if (c_subsys) { - ret = snprintf(buf + offset, rem, "%s", c_subsys); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } + if (c_subsys) + OSMO_STRBUF_PRINTF(sb, "%s", c_subsys); } if (!cont) { if (target->print_ext_timestamp) { @@ -506,13 +506,10 @@ struct timeval tv; osmo_gettimeofday(&tv, NULL); localtime_r(&tv.tv_sec, &tm); - ret = snprintf(buf + offset, rem, "%04d%02d%02d%02d%02d%02d%03d ", - tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec, - (int)(tv.tv_usec / 1000)); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_PRINTF(sb, "%04d%02d%02d%02d%02d%02d%03d ", + tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec, + (int)(tv.tv_usec / 1000)); #endif } else if (target->print_timestamp) { time_t tm; @@ -520,97 +517,66 @@ goto err; /* Get human-readable representation of time. man ctime: we need at least 26 bytes in buf */ - if (rem < 26 || !ctime_r(&tm, buf + offset)) + if (OSMO_STRBUF_REMAIN(sb) < 26 || !ctime_r(&tm, sb.pos)) goto err; - ret = strlen(buf + offset); + ret = strnlen(sb.pos, 26); if (ret <= 0) goto err; + OSMO_STRBUF_ADDED_TAIL(sb, ret); /* Get rid of useless final '\n' added by ctime_r. We want a space instead. */ - buf[offset + ret - 1] = ' '; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_DROP_TAIL(sb, 1); + OSMO_STRBUF_PRINTF(sb, " "); } if (target->print_tid) { if (logging_tid == 0) logging_tid = (long int)osmo_gettid(); - ret = snprintf(buf + offset, rem, "%ld ", logging_tid); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_PRINTF(sb, "%ld ", logging_tid); } - if (target->print_category) { - ret = snprintf(buf + offset, rem, "%s%s%s%s ", - target->use_color ? level_color(level) : "", - log_category_name(subsys), - target->use_color ? OSMO_LOGCOLOR_END : "", - c_subsys ? c_subsys : ""); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } - if (target->print_level) { - ret = snprintf(buf + offset, rem, "%s%s%s%s ", - target->use_color ? level_color(level) : "", - log_level_str(level), - target->use_color ? OSMO_LOGCOLOR_END : "", - c_subsys ? c_subsys : ""); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } - if (target->print_category_hex) { - ret = snprintf(buf + offset, rem, "<%4.4x> ", subsys); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); - } + if (target->print_category) + OSMO_STRBUF_PRINTF(sb, "%s%s%s%s ", + target->use_color ? level_color(level) : "", + log_category_name(subsys), + target->use_color ? OSMO_LOGCOLOR_END : "", + c_subsys ? c_subsys : ""); + if (target->print_level) + OSMO_STRBUF_PRINTF(sb, "%s%s%s%s ", + target->use_color ? level_color(level) : "", + log_level_str(level), + target->use_color ? OSMO_LOGCOLOR_END : "", + c_subsys ? c_subsys : ""); + if (target->print_category_hex) + OSMO_STRBUF_PRINTF(sb, "<%4.4x> ", subsys); if (target->print_filename_pos == LOG_FILENAME_POS_HEADER_END) { switch (target->print_filename2) { case LOG_FILENAME_NONE: break; case LOG_FILENAME_PATH: - ret = snprintf(buf + offset, rem, "%s:%d ", file, line); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_PRINTF(sb, "%s:%d ", file, line); break; case LOG_FILENAME_BASENAME: - ret = snprintf(buf + offset, rem, "%s:%d ", const_basename(file), line); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_PRINTF(sb, "%s:%d ", const_basename(file), line); break; } } } - ret = vsnprintf(buf + offset, rem, format, ap); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_APPEND(sb, vsnprintf, format, ap); /* For LOG_FILENAME_POS_LAST, print the source file info only when the caller ended the log * message in '\n'. If so, nip the last '\n' away, insert the source file info and re-append an * '\n'. All this to allow LOGP("start..."); LOGPC("...end\n") constructs. */ if (target->print_filename_pos == LOG_FILENAME_POS_LINE_END - && offset > 0 && buf[offset - 1] == '\n') { + && sb.pos > sb.buf && *(sb.pos - 1) == '\n') { switch (target->print_filename2) { case LOG_FILENAME_NONE: break; case LOG_FILENAME_PATH: - offset--; - len--; - ret = snprintf(buf + offset, rem, " (%s:%d)\n", file, line); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_DROP_TAIL(sb, 1); + OSMO_STRBUF_PRINTF(sb, " (%s:%d)\n", file, line); break; case LOG_FILENAME_BASENAME: - offset--; - len--; - ret = snprintf(buf + offset, rem, " (%s:%d)\n", const_basename(file), line); - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); + OSMO_STRBUF_DROP_TAIL(sb, 1); + OSMO_STRBUF_PRINTF(sb, " (%s:%d)\n", const_basename(file), line); break; } } @@ -618,21 +584,15 @@ if (target->use_color && c_subsys) { /* Ensure the last color escape is sent before the newline * (to not clobber journald, which works on single-lines only) */ - if (offset > 0 && buf[offset - 1] == '\n') { - offset--; rem++; - ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END "\n"); + if (sb.pos > sb.buf && *(sb.pos - 1) == '\n') { + OSMO_STRBUF_DROP_TAIL(sb, 1); + OSMO_STRBUF_PRINTF(sb, OSMO_LOGCOLOR_END "\n"); } else { - ret = snprintf(buf + offset, rem, OSMO_LOGCOLOR_END); + OSMO_STRBUF_PRINTF(sb, OSMO_LOGCOLOR_END); } - - if (ret < 0) - goto err; - OSMO_SNPRINTF_RET(ret, rem, offset, len); } err: - len = OSMO_MIN(buf_len - 1, len); - buf[len] = '\0'; - return len; + return OSMO_STRBUF_CHAR_COUNT(sb); } /* Format the log line for given target; use a stack buffer and call target->output */ -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35208?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: Ib577a5e0d7450ce93ff21f37ba3262704cbf4752 Gerrit-Change-Number: 35208 Gerrit-PatchSet: 1 Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de> Gerrit-MessageType: newchange
1 0
0 0
[L] Change in libosmocore[master]: soft_uart: implement modem status lines and flow control
by osmith 04 Dec '23

04 Dec '23
Attention is currently required from: fixeria, jolly, laforge, neels. osmith has posted comments on this change. ( https://gerrit.osmocom.org/c/libosmocore/+/35172?usp=email ) Change subject: soft_uart: implement modem status lines and flow control ...................................................................... Patch Set 4: (1 comment) File src/core/soft_uart.c: https://gerrit.osmocom.org/c/libosmocore/+/35172/comment/95d07b17_78756b83 PS2, Line 398: if (active) /* assert the given line */ > re: if assert and de-assert is terminology from the matching spec, then of course keep using those terms here. (could have one comment in the first occurence to explain the term usage maybe) ack -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/35172?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I26b93ce76f2f6b6fbf017f2684312007db3c6d48 Gerrit-Change-Number: 35172 Gerrit-PatchSet: 4 Gerrit-Owner: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-CC: jolly <andreas(a)eversberg.eu> Gerrit-CC: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: jolly <andreas(a)eversberg.eu> Gerrit-Attention: neels <nhofmeyr(a)sysmocom.de> Gerrit-Attention: laforge <laforge(a)osmocom.org> Gerrit-Attention: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-Comment-Date: Mon, 04 Dec 2023 06:40:59 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No Comment-In-Reply-To: osmith <osmith(a)sysmocom.de> Comment-In-Reply-To: jolly <andreas(a)eversberg.eu> Comment-In-Reply-To: neels <nhofmeyr(a)sysmocom.de> Comment-In-Reply-To: fixeria <vyanitskiy(a)sysmocom.de> Gerrit-MessageType: comment
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • ...
  • 161
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.