From ca3f3fe68ae72fec6f607278bf88d30ab1497627 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 25 Mar 2022 15:43:47 +0100 Subject: change echo to printf and for sfeed_opml_export use a control-character separator echo is unportable in this way and names containing characters like an option (-n) or backslash or escape codes (\e, \n, etc) could be messy. For awk set LC_ALL=C for simple collation. This makes sfeed_opml_export slower in some shells that don't have printf builtin though. For example with about 150 feeds in a config file it is a bit slower on OpenBSD ksh. time ./sfeed_opml_export | wc -l 152 0m00.29s real 0m00.05s user 0m00.20s system time sfeed_opml_export | wc -l 152 0m00.02s real 0m00.00s user 0m00.03s system --- sfeed_opml_export | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'sfeed_opml_export') diff --git a/sfeed_opml_export b/sfeed_opml_export index eb22520..2a9396a 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -18,7 +18,7 @@ loadconfig() { if [ -r "${path}" ]; then . "${path}" else - echo "Configuration file \"${config}\" cannot be read." >&2 + printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 echo "See sfeedrc.example for an example." >&2 exit 1 fi @@ -27,8 +27,8 @@ loadconfig() { # override feed function to output OPML XML. # feed(name, feedurl, [basesiteurl], [encoding]) feed() { - # TABs, newlines and echo options in field values are not checked. - echo "$1 $2" + # uses the characters 0x1f and 0x1e as a separator. + printf '%s\037%s\036' "$1" "$2" } # load config file. @@ -43,7 +43,11 @@ cat < ! -feeds | awk -F '\t' '{ +feeds | LC_ALL=C awk ' +BEGIN { + FS = "\x1f"; RS = "\x1e"; +} +{ gsub("&", "\\&"); gsub("\"", "\\""); gsub("'"'"'", "\\'"); -- cgit v1.2.3 From 9d6dd2a5072c0702cb56cced861ca4539e98c553 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 17 Feb 2023 15:39:29 +0100 Subject: sfeed_update, sfeed_opml_export, README: reference the example sfeedrc man page ... and some small rewording. --- README | 4 ++-- sfeed_opml_export | 2 +- sfeed_update | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'sfeed_opml_export') diff --git a/README b/README index 26de06c..dcff323 100644 --- a/README +++ b/README @@ -251,8 +251,8 @@ output example: - - - -Make sure your sfeedrc config file exists, see sfeedrc.example. To update your -feeds (configfile argument is optional): +Make sure your sfeedrc config file exists, see the sfeedrc.example file. To +update your feeds (configfile argument is optional): sfeed_update "configfile" diff --git a/sfeed_opml_export b/sfeed_opml_export index 2a9396a..3835934 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -19,7 +19,7 @@ loadconfig() { . "${path}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 - echo "See sfeedrc.example for an example." >&2 + echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2 exit 1 fi } diff --git a/sfeed_update b/sfeed_update index 44ce23c..f989be6 100755 --- a/sfeed_update +++ b/sfeed_update @@ -28,7 +28,7 @@ loadconfig() { . "${path}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 - echo "See sfeedrc.example for an example." >&2 + echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2 exit 1 fi } -- cgit v1.2.3 From bf378f4350b0e92efcefd9c0c34f7b5c57c098f4 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Mon, 10 Apr 2023 16:44:13 +0200 Subject: remove sfeed "branding" in outputs Technically for sfeed_atom this violates the RFC standard. There must be an author in the feed or for an item. However sfeed is not the author, it is a generator. All readers will read these feeds anyway. https://www.rfc-editor.org/rfc/rfc4287#section-4.1.1 "atom:feed elements MUST contain one or more atom:author elements, unless all of the atom:feed element's child atom:entry elements contain at least one atom:author element." *shrug* --- sfeed_atom.c | 3 +-- sfeed_mbox.c | 2 +- sfeed_opml_export | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) (limited to 'sfeed_opml_export') diff --git a/sfeed_atom.c b/sfeed_atom.c index cfaeb5b..aeea2de 100644 --- a/sfeed_atom.c +++ b/sfeed_atom.c @@ -132,8 +132,7 @@ main(int argc, char *argv[]) fputs("\n" "\n" - "\tNewsfeed\n" - "\tsfeed\n", stdout); + "\tNewsfeed\n", stdout); printf("\turn:newsfeed:%lld\n" "\t%04d-%02d-%02dT%02d:%02d:%02dZ\n", (long long)now, diff --git a/sfeed_mbox.c b/sfeed_mbox.c index 0cfd836..b5e7e3d 100644 --- a/sfeed_mbox.c +++ b/sfeed_mbox.c @@ -82,7 +82,7 @@ printfeed(FILE *fp, const char *feedname) printf("Date: %s\n", dtimebuf); /* invalid/missing: use current time */ } - printf("From: %s \n", fields[FieldAuthor][0] ? fields[FieldAuthor] : feedname); + printf("From: %s \n", fields[FieldAuthor][0] ? fields[FieldAuthor] : feedname); printf("To: %s <%s@%s>\n", user, user, host); printf("Subject: %s\n", fields[FieldTitle]); printf("Message-ID: <%s%s%llu@%s>\n", diff --git a/sfeed_opml_export b/sfeed_opml_export index 3835934..7c96d5d 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -38,7 +38,7 @@ cat < - OPML export from sfeed + OPML export ! -- cgit v1.2.3 From 63308527f5197ddbcad6b06c5c1bbaf12f997e57 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Sat, 9 Dec 2023 21:51:45 +0100 Subject: improve compatibility with zsh as a non-interactive shell In zsh the variables $path and $status are special. https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-path https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-status (No promises I will keep up with this insanity in the future though) --- README | 6 +++--- sfeed_opml_export | 8 ++++---- sfeed_update | 12 ++++++------ 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'sfeed_opml_export') diff --git a/README b/README index 8098a76..85a3fb9 100644 --- a/README +++ b/README @@ -752,12 +752,12 @@ sfeed_update_xargs shellscript: mkdir -p "${sfeedpath}" # print feeds for parallel processing with xargs. feeds | SFEED_UPDATE_CHILD="1" xargs -r -0 -P "${maxjobs}" -L 6 "$(readlink -f "$0")" - status=$? + statuscode=$? # check error exit status indicator for parallel jobs. - test -f "${sfeedtmpdir}/ok" || status=1 + test -f "${sfeedtmpdir}/ok" || statuscode=1 # cleanup temporary files etc. cleanup - exit ${status} + exit ${statuscode} - - - diff --git a/sfeed_opml_export b/sfeed_opml_export index 7c96d5d..6420d5e 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -7,16 +7,16 @@ loadconfig() { if [ "$1" != "" ]; then # get absolute path of config file required for including. config="$1" - path=$(readlink -f "${config}" 2>/dev/null) + configpath=$(readlink -f "${config}" 2>/dev/null) else # default config location. config="$HOME/.sfeed/sfeedrc" - path="${config}" + configpath="${config}" fi # config is loaded here to be able to override $sfeedpath or functions. - if [ -r "${path}" ]; then - . "${path}" + if [ -r "${configpath}" ]; then + . "${configpath}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2 diff --git a/sfeed_update b/sfeed_update index dadea9b..2b7d89b 100755 --- a/sfeed_update +++ b/sfeed_update @@ -16,16 +16,16 @@ loadconfig() { if [ "$1" != "" ]; then # get absolute path of config file required for including. config="$1" - path=$(readlink -f "${config}" 2>/dev/null) + configpath=$(readlink -f "${config}" 2>/dev/null) else # default config location. config="$HOME/.sfeed/sfeedrc" - path="${config}" + configpath="${config}" fi # config is loaded here to be able to override $sfeedpath or functions. - if [ -r "${path}" ]; then - . "${path}" + if [ -r "${configpath}" ]; then + . "${configpath}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 echo "See the sfeedrc.example file or the sfeedrc(5) man page for an example." >&2 @@ -214,12 +214,12 @@ main() { [ ${signo} -eq 0 ] && wait # check error exit status indicator for parallel jobs. [ -f "${sfeedtmpdir}/ok" ] - status=$? + statuscode=$? # cleanup temporary files etc. cleanup # on signal SIGINT and SIGTERM exit with signal number + 128. [ ${signo} -ne 0 ] && exit $((signo+128)) - exit ${status} + exit ${statuscode} } [ "${SFEED_UPDATE_INCLUDE}" = "1" ] || main "$@" -- cgit v1.2.3 From 03a0a0ddb450f33e59a911a8be1b17d31507fa43 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Thu, 28 Dec 2023 16:48:06 +0100 Subject: sfeed_opml_export: disallow using a directory as a config file Same as the commit 9754fe74f7b5c0600cc41eef8c6f5c8305a74a18 for sfeed_update Tested on NetBSD 5.1: evaluating directories as config files could allow garbage, so disallow it. Devices / fifo, etc are still allowed. --- sfeed_opml_export | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'sfeed_opml_export') diff --git a/sfeed_opml_export b/sfeed_opml_export index 6420d5e..9e769f7 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -15,7 +15,7 @@ loadconfig() { fi # config is loaded here to be able to override $sfeedpath or functions. - if [ -r "${configpath}" ]; then + if [ -r "${configpath}" ] && [ ! -d "${configpath}" ]; then . "${configpath}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 -- cgit v1.2.3 From cbf92f526528fc995e309d2f13b7dcebfd1e5c75 Mon Sep 17 00:00:00 2001 From: Hiltjo Posthuma Date: Fri, 29 Dec 2023 13:50:55 +0100 Subject: sfeed_update/sfeed_opml_export: only allow regular files Be more strict and only allow regular files. It makes no sense to use device files or fifos with sfeed_update and it can cause issues, because sfeed_update expects to read the config file for each (child) invocation also. --- sfeed_opml_export | 2 +- sfeed_update | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'sfeed_opml_export') diff --git a/sfeed_opml_export b/sfeed_opml_export index 9e769f7..f949488 100755 --- a/sfeed_opml_export +++ b/sfeed_opml_export @@ -15,7 +15,7 @@ loadconfig() { fi # config is loaded here to be able to override $sfeedpath or functions. - if [ -r "${configpath}" ] && [ ! -d "${configpath}" ]; then + if [ -r "${configpath}" ] && [ -f "${configpath}" ]; then . "${configpath}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 diff --git a/sfeed_update b/sfeed_update index 607c048..1f797f8 100755 --- a/sfeed_update +++ b/sfeed_update @@ -24,7 +24,7 @@ loadconfig() { fi # config is loaded here to be able to override $sfeedpath or functions. - if [ -r "${configpath}" ] && [ ! -d "${configpath}" ]; then + if [ -r "${configpath}" ] && [ -f "${configpath}" ]; then . "${configpath}" else printf "Configuration file \"%s\" cannot be read.\n" "${config}" >&2 -- cgit v1.2.3