Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add documentation references to service units and program help #2733

Merged
merged 19 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
56f4f44
configure.ac: derive NUT_WEBSITE_BASE from PACKAGE_URL [#722]
jimklimov Dec 21, 2024
a46ddab
scripts/Solaris/*.xml.in: revise heading comments and documentation l…
jimklimov Dec 21, 2024
1a8c0f2
scripts/systemd/nut* units: add documentation links [#722]
jimklimov Dec 21, 2024
a5dfaf5
scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in: introduce *_setDocL…
jimklimov Dec 22, 2024
0f543e7
drivers/main.c: refer to local man (ifdef WITH_DOCS) and website page…
jimklimov Dec 22, 2024
26a20ba
common/common.c, include/common.h, drivers/main.c: introduce suggest_…
jimklimov Dec 23, 2024
7489dae
server/sockdebug.c, server/pipedebug.c: refer to local man (ifdef WIT…
jimklimov Dec 23, 2024
7eb9645
server/upsd.c: refer to local man (ifdef WITH_DOCS) and website page …
jimklimov Dec 23, 2024
a6c6bff
drivers/main.c: move WIN32 var declarations up in main()
jimklimov Dec 23, 2024
d6112a3
drivers/main.c: main(): avoid notification at exit after just showing…
jimklimov Dec 23, 2024
1648070
tools/nut-scanner/nut-scanner.c, tools/nut-scanner/Makefile.am: refer…
jimklimov Dec 23, 2024
e9afd6a
tools/nutconf/nutconf-cli.cpp: refer to local man (ifdef WITH_DOCS) a…
jimklimov Dec 23, 2024
8c129fa
clients/upsc.c, clients/upscmd.c, clients/upsrw.c, clients/upslog.c, …
jimklimov Dec 23, 2024
32a8462
scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in: refer to local man …
jimklimov Dec 24, 2024
e770866
scripts/upsdrvsvcctl/upsdrvsvcctl.in: refer to local man and website …
jimklimov Dec 24, 2024
ecb20b8
drivers/upsdrvctl.c: refer to local man (ifdef WITH_DOCS) and website…
jimklimov Dec 24, 2024
449a658
common/common.c: suggest_doc_links(): do not preallocate buf2, ensure…
jimklimov Dec 24, 2024
c1e09d4
scripts/upsdrvsvcctl/nut-driver-enumerator.sh.in: smf_setDocLink(): c…
jimklimov Dec 25, 2024
54b3a7c
scripts/Windows/wininit.c: refer to local man (ifdef WITH_DOCS) and w…
jimklimov Dec 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,26 @@ https://github.com/networkupstools/nut/milestone/11
in certain cases against high voltage transfer, we only fixed-up one of
them. [#1245]

- development iterations of NUT should now identify with not only the semantic
version of a preceding release, but with git-derived information about the
amount of iterations that followed (if available): the three-number "semver"
would be seen on release snapshots, while other builds would expose the
added components: one with the amount of commits on the main development
trunk since the preceding release which are ancestors of the built code
base, and in case of feature development branches -- another component
with the amount of commits unique to this branch (which are not part of
the development trunk). This allows to produce more relevant (monotonously
growing) version identifiers for packages and similar artifacts, with more
meaningful upgrades via development snapshots, eventually. A copy of the
current version information would be embedded into "dist" archives as a
`VERSION_DEFAULT` file. [#1949]
- SEMVER, know thyself!
* development iterations of NUT should now identify with not only the
semantic version of a preceding release, but with git-derived information
about the amount of iterations that followed (if available):
the three-number "semver" would be seen on release snapshots, while
other builds would expose the added components: one with the amount
of commits on the main development trunk since the preceding release
which are ancestors of the built code base, and in case of feature
development branches -- another component with the amount of commits
unique to this branch (which are not part of the development trunk yet).
This allows to produce more relevant (monotonously growing) version
identifiers for packages and similar artifacts, with more meaningful
upgrades via development snapshots, eventually. A copy of the current
version information would be embedded into "dist" archives as a
`VERSION_DEFAULT` file, among provisions for packager tuning. [#1949]
* SMF manifests and systemd units now refer to man pages and their online
variants under `NUT_WEBSITE_BASE` dependent on codebase maturity
(development or release snapshot); many programs now display such
references in their command-line usage help, method `suggest_doc_links()`
was introduced for this purpose. [issue #722, PR #2733]

- the `upsnotify()` common code introduced in recent NUT releases (integrating
with service management frameworks, etc.) was a bit cryptic when it reported
Expand Down
2 changes: 2 additions & 0 deletions clients/upsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ static void usage(const char *prog)
printf(" -h - display this help text\n");

nut_report_config_flags();

printf("\n%s", suggest_doc_links(prog, NULL));
}

static void printvar(const char *var)
Expand Down
2 changes: 2 additions & 0 deletions clients/upscmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ static void usage(const char *prog)
printf(" [<value>] Additional data for command - number of seconds, etc.\n");

nut_report_config_flags();

printf("\n%s", suggest_doc_links(prog, "upsd.users"));
}

static void print_cmd(char *cmdname)
Expand Down
5 changes: 2 additions & 3 deletions clients/upslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,10 @@ static void help(const char *prog)
printf("format string defaults to:\n");
printf("%s\n", DEFAULT_LOGFORMAT);

printf("\n");
printf("See the upslog(8) man page for more information.\n");

nut_report_config_flags();

printf("\n%s", suggest_doc_links(prog, NULL));

exit(EXIT_SUCCESS);
}

Expand Down
2 changes: 2 additions & 0 deletions clients/upsmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3021,6 +3021,8 @@ static void help(const char *arg_progname)

nut_report_config_flags();

printf("\n%s", suggest_doc_links(arg_progname, "upsmon.conf"));

exit(EXIT_SUCCESS);
}

Expand Down
2 changes: 2 additions & 0 deletions clients/upsrw.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ static void usage(const char *prog)
printf("Call without -s to show all possible read/write variables (same as -l).\n");

nut_report_config_flags();

printf("\n%s", suggest_doc_links(prog, "upsd.users"));
}

static void clean_exit(void)
Expand Down
2 changes: 2 additions & 0 deletions clients/upssched.c
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,8 @@ static void help(const char *arg_progname)

nut_report_config_flags();

printf("\n%s", suggest_doc_links(arg_progname, "upsmon.conf"));

exit(EXIT_SUCCESS);
}

Expand Down
39 changes: 39 additions & 0 deletions common/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,45 @@ int print_banner_once(const char *prog, int even_if_disabled)
return ret;
}

const char *suggest_doc_links(const char *progname, const char *progconf) {
static char buf[LARGEBUF];

buf[0] = '\0';

if (progname) {
char *s = NULL, *buf2 = xstrdup(xbasename(progname));
size_t i;

for (i = 0; buf2[i]; i++) {
buf2[i] = tolower(buf2[i]);
}

if ((s = strstr(buf2, ".exe")) && strcmp(buf2, "nut.exe"))
*s = '\0';

snprintf(buf, sizeof(buf),
"For more information please ");
#if defined(WITH_DOCS) && WITH_DOCS
snprintfcat(buf, sizeof(buf),
"Read The Fine Manual ('man %s') and/or ",
buf2);
#endif
snprintfcat(buf, sizeof(buf),
"see\n\t%s/docs/man/%s.html\n",
NUT_WEBSITE_BASE, buf2);

free(buf2);
}

if (progconf)
snprintfcat(buf, sizeof(buf),
"%s check documentation and samples of %s\n",
progname ? "Also" : "Please",
progconf);

return buf;
}

/* enable writing upslog_with_errno() and upslogx() type messages to
the syslog */
void syslogbit_set(void)
Expand Down
13 changes: 13 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ AC_INIT([nut],
dnl See docs/maintainer-guide.txt about releases - updating the version
dnl above is a small part of the consistent ritual!

dnl PACKAGE_URL="https://www.networkupstools.org/" for development iterations
dnl or "https://www.networkupstools.org/historic/v1.2.3/index.html" for release
dnl snapshots further set in stone. Either way, there should be a slash and
dnl either a filename, or nothing. Adding a bogus filename and chopping it
dnl off by `dirname` should do the trick.
dnl NOTE: the resulting NUT_WEBSITE_BASE string does not end with a slash!
NUT_WEBSITE_BASE="`dirname "${PACKAGE_URL}index.html"`"
dnl Fallback, no trailing slash!
[ -n "${NUT_WEBSITE_BASE-}" ] || NUT_WEBSITE_BASE='https://www.networkupstools.org'

dnl Note: this refers to GITREV at the time of configure script running
dnl primarily for better messaging in the script itself (also to render
dnl the PDF documentation revision history via docs/docinfo.xml.in).
Expand Down Expand Up @@ -747,6 +757,8 @@ AS_IF([test x"${NUT_SOURCE_GITREV}" = x],
[NUT_REPORT([configured version], [${PACKAGE_VERSION} ${NUT_SOURCE_GITREV_DEVREL}])],
[NUT_REPORT([configured version], [${PACKAGE_VERSION} (${NUT_SOURCE_GITREV}) ${NUT_SOURCE_GITREV_DEVREL}])])
])
NUT_REPORT([Documentation website base URL], [${NUT_WEBSITE_BASE}])
AC_DEFINE_UNQUOTED([NUT_WEBSITE_BASE], "${NUT_WEBSITE_BASE}", [Documentation website base URL, no trailing slash])

dnl Note: the compiler/pragma/attr methods below are custom for NUT codebase:
NUT_COMPILER_FAMILY
Expand Down Expand Up @@ -4832,6 +4844,7 @@ AC_SUBST(NUT_SOURCE_GITREV)
AC_SUBST(NUT_SOURCE_GITREV_IS_RELEASE)
AC_SUBST(NUT_SOURCE_GITREV_SEMVER)
AC_SUBST(NUT_SOURCE_GITREV_NUMERIC)
AC_SUBST(NUT_WEBSITE_BASE)
AC_SUBST(LIBSSL_CFLAGS)
AC_SUBST(LIBSSL_LIBS)
AC_SUBST(LIBSSL_LDFLAGS_RPATH)
Expand Down
1 change: 0 additions & 1 deletion drivers/blazer_ser.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ ssize_t blazer_command(const char *cmd, char *buf, size_t buflen)

void upsdrv_help(void)
{
printf("Read The Fine Manual ('man 8 blazer_ser')\n");
}


Expand Down
2 changes: 0 additions & 2 deletions drivers/blazer_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,8 +579,6 @@ void upsdrv_help(void)
}
printf("\n\n");
#endif /* TESTING */

printf("Read The Fine Manual ('man 8 blazer_usb')\n");
}


Expand Down
23 changes: 16 additions & 7 deletions drivers/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ static int nut_debug_level_protocol = -1;
#ifndef DRIVERS_MAIN_WITHOUT_MAIN
/* everything else */
static char *pidfn = NULL;
static int dump_data = 0; /* Store the update_count requested */
static int help_only = 0,
dump_data = 0; /* Store the update_count requested */
#endif /* DRIVERS_MAIN_WITHOUT_MAIN */

/* pre-declare some private methods used */
Expand Down Expand Up @@ -292,6 +293,8 @@ static void help_msg(void)
}

upsdrv_help();

printf("\n%s", suggest_doc_links(progname, "ups.conf"));
}
#endif /* DRIVERS_MAIN_WITHOUT_MAIN */

Expand Down Expand Up @@ -1812,7 +1815,7 @@ static void exit_cleanup(void)
{
dstate_setinfo("driver.state", "cleanup.exit");

if (!dump_data) {
if (!dump_data && !help_only) {
upsnotify(NOTIFY_STATE_STOPPING, "exit_cleanup()");
}

Expand Down Expand Up @@ -1983,7 +1986,10 @@ int main(int argc, char **argv)
pid_t oldpid = -1;
#else
/* FIXME: *actually* handle WIN32 builds too */
const char * cmd = NULL;
const char *cmd = NULL;

const char *drv_name;
char *dot;
#endif

const char optstring[] = "+a:s:kDFBd:hx:Lqr:u:g:Vi:c:"
Expand All @@ -2006,6 +2012,10 @@ int main(int argc, char **argv)
case 'd':
dump_data = atoi(optarg);
break;
case 'h':
/* Avoid notification at exit */
help_only = 1;
break;
default:
break;
}
Expand Down Expand Up @@ -2062,12 +2072,11 @@ int main(int argc, char **argv)
progname = xbasename(argv[0]);

#ifdef WIN32
const char * drv_name;
drv_name = xbasename(argv[0]);
/* remove trailing .exe */
char * dot = strrchr(drv_name,'.');
if( dot != NULL ) {
if(strcasecmp(dot, ".exe") == 0 ) {
dot = strrchr(drv_name,'.');
if (dot != NULL) {
if (strcasecmp(dot, ".exe") == 0) {
progname = strdup(drv_name);
char * t = strrchr(progname,'.');
*t = 0;
Expand Down
6 changes: 2 additions & 4 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2921,7 +2921,7 @@ void upsdrv_help(void)
printf(", ");
printf("%s", usbsubdriver[i].name);
}
printf("\n\n");
printf("\n");
# endif /* QX_USB*/

/* Protocols are the first token from "name" field in
Expand All @@ -2944,10 +2944,8 @@ void upsdrv_help(void)
printf(", ");
printf("%s", subdrv_name);
}
printf("\n\n");
printf("\n");
#endif /* TESTING */

printf("Read The Fine Manual ('man 8 nutdrv_qx')\n");
}

/* Adding flags/vars */
Expand Down
5 changes: 5 additions & 0 deletions drivers/upsdrvctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,11 @@ static void help(const char *arg_progname)
printf(" Fields: UPSNAME UPSDRV RUNNING PF_PID S_RESPONSIVE S_PID S_STATUS\n");
printf(" (PF_* = according to PID file, if any; S_* = via socket protocol)\n");

printf("\n%s", suggest_doc_links(arg_progname, "ups.conf"));
#if (defined(WITH_SOLARIS_SMF) && WITH_SOLARIS_SMF) || (defined(HAVE_SYSTEMD) && HAVE_SYSTEMD)
printf("NOTE: On this system you should prefer upsdrvsvcctl and nut-driver-enumerator\n");
#endif

exit(EXIT_SUCCESS);
}

Expand Down
4 changes: 1 addition & 3 deletions drivers/usbhid-ups.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,9 +1025,7 @@ void upsdrv_help(void)
printf(", ");
printf("\"%s\"", subdriver_list[i]->name);
}
printf("\n\n");

printf("Read The Fine Manual ('man 8 usbhid-ups')\n");
printf("\n");
}

void upsdrv_makevartable(void)
Expand Down
7 changes: 7 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ extern const char *UPS_VERSION;
* have an end-of-line char of its own. */
const char *describe_NUT_VERSION_once(void);

/* Return a buffer with a (possibly multiline) string that can be printed
* as part of program help/usage message. Caller should not free() the buffer.
* Optional "progconf" allows to suggest config file(s) to study as well.
* NOTE: the string in buffer starts with text and ends with one EOL char.
*/
const char *suggest_doc_links(const char *progname, const char *progconf);

/* Based on NUT_QUIET_INIT_BANNER envvar (present and empty or "true")
* hide the NUT tool name+version banners; show them by default */
int banner_is_disabled(void);
Expand Down
16 changes: 9 additions & 7 deletions scripts/Solaris/nut-driver-enumerator.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
#
# Copyright 2016-2018 Jim Klimov
# Template manifest for instantiated NUT drivers
# Copyright 2016-2024 Jim Klimov
# NDE (nut-driver-enumerator) manages definitions of instantiated NUT drivers
#
-->

<service_bundle type='manifest' name='nut-driver-enumerator'>

<service name='system/power/nut-driver-enumerator' type='service' version='1.2'>
<service name='system/power/nut-driver-enumerator' type='service' version='2'>

<!--
Wait for all local and usr filesystem to be mounted - project is
Expand Down Expand Up @@ -162,10 +162,12 @@
</loctext>
</common_name>
<documentation>
<manpage title='upsdrvsvcctl' section='8'
manpath='/usr/share/man' />
<manpage title='ups.conf' section='5'
manpath='/usr/share/man' />
<doc_link name='upsdrvsvcctl online' uri='@NUT_WEBSITE_BASE@/docs/man/upsdrvsvcctl.html' />
<manpage title='upsdrvsvcctl' section='8' manpath='/usr/share/man' />
<doc_link name='ups.conf online' uri='@NUT_WEBSITE_BASE@/docs/man/ups.conf.html' />
<manpage title='ups.conf' section='5' manpath='/usr/share/man' />
<doc_link name='nut.conf online' uri='@NUT_WEBSITE_BASE@/docs/man/nut.conf.html' />
<manpage title='nut.conf' section='5' manpath='/usr/share/man' />
</documentation>
</template>
</instance>
Expand Down
14 changes: 8 additions & 6 deletions scripts/Solaris/nut-driver.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<!--
#
# Copyright 2016 - 2024 Jim Klimov
# Copyright 2016-2024 Jim Klimov
# Template manifest for instantiated NUT drivers
#
-->

<service_bundle type='manifest' name='nut-driver'>

<service name='system/power/nut-driver' type='service' version='4'>
<service name='system/power/nut-driver' type='service' version='5'>

<!--
Wait for all local and usr filesystem to be mounted - project is
Expand Down Expand Up @@ -127,10 +127,12 @@
</loctext>
</common_name>
<documentation>
<manpage title='upsdrvctl' section='8'
manpath='/usr/share/man' />
<manpage title='ups.conf' section='5'
manpath='/usr/share/man' />
<doc_link name='upsdrvsvcctl online' uri='@NUT_WEBSITE_BASE@/docs/man/upsdrvsvcctl.html' />
<manpage title='upsdrvsvcctl' section='8' manpath='/usr/share/man' />
<doc_link name='ups.conf online' uri='@NUT_WEBSITE_BASE@/docs/man/ups.conf.html' />
<manpage title='ups.conf' section='5' manpath='/usr/share/man' />
<doc_link name='nut.conf online' uri='@NUT_WEBSITE_BASE@/docs/man/nut.conf.html' />
<manpage title='nut.conf' section='5' manpath='/usr/share/man' />
</documentation>
</template>
</service>
Expand Down
Loading
Loading