mirror of
https://github.com/pygos/init.git
synced 2024-11-22 03:09:46 +01:00
Centralize/unify version string printing
Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
parent
3b8764b9d2
commit
42fba964c9
9 changed files with 49 additions and 51 deletions
|
@ -2,6 +2,7 @@ shutdown_SOURCES = cmd/shutdown.c
|
|||
shutdown_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
shutdown_CFLAGS = $(AM_CFLAGS)
|
||||
shutdown_LDFLAGS = $(AM_LDFLAGS)
|
||||
shutdown_LDADD = libinit.a
|
||||
|
||||
runsvc_SOURCES = cmd/runsvc/runsvc.c cmd/runsvc/env.c cmd/runsvc/runsvc.h
|
||||
runsvc_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
|
|
|
@ -63,19 +63,6 @@ static NORETURN void usage(const char *progname, int status)
|
|||
exit(status);
|
||||
}
|
||||
|
||||
static NORETURN void version(const char *progname)
|
||||
{
|
||||
fprintf(stdout,
|
||||
"%s (Pygos init) %s\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n",
|
||||
progname, PACKAGE_VERSION);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c, ret, flags = 0;
|
||||
|
@ -108,7 +95,7 @@ int main(int argc, char **argv)
|
|||
defact = RB_AUTOBOOT;
|
||||
break;
|
||||
case 'V':
|
||||
version(ptr);
|
||||
print_version(ptr);
|
||||
case 'h':
|
||||
usage(ptr, EXIT_SUCCESS);
|
||||
default:
|
||||
|
|
15
cmd/syslog.c
15
cmd/syslog.c
|
@ -72,13 +72,6 @@ static const struct option options[] = {
|
|||
|
||||
static const char *shortopt = "hVcf:l:i:";
|
||||
|
||||
static const char *versiontext =
|
||||
"syslog (Pygos init) "PACKAGE_VERSION"\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
static const char *helptext =
|
||||
"Usage: syslog [OPTION]... [STRING]...\n\n"
|
||||
"Concatenate the given STRINGs and send a log message to the syslog daemon.\n"
|
||||
|
@ -125,12 +118,6 @@ static NORETURN void usage(int status)
|
|||
exit(status);
|
||||
}
|
||||
|
||||
static NORETURN void version(void)
|
||||
{
|
||||
fputs(versiontext, stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
static int readint(const char *str)
|
||||
{
|
||||
int x = 0;
|
||||
|
@ -188,7 +175,7 @@ static void process_options(int argc, char **argv)
|
|||
case 'h':
|
||||
usage(EXIT_SUCCESS);
|
||||
case 'V':
|
||||
version();
|
||||
print_version("syslog");
|
||||
default:
|
||||
usage(EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ HEADRS = lib/include/util.h lib/include/service.h lib/include/telinit.h
|
|||
libinit_a_SOURCES = lib/util/delsvc.c lib/util/svcmap.c lib/util/enum_by_name.c
|
||||
libinit_a_SOURCES += lib/util/rdsvc.c lib/util/svcscan.c lib/util/mksock.c
|
||||
libinit_a_SOURCES += lib/util/del_svc_list.c lib/util/svc_tsort.c
|
||||
libinit_a_SOURCES += lib/util/opensock.c lib/util/enum_to_name.c $(HEADRS)
|
||||
libinit_a_SOURCES += lib/util/opensock.c lib/util/enum_to_name.c
|
||||
libinit_a_SOURCES += lib/util/print_version.c $(HEADRS)
|
||||
libinit_a_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
libinit_a_CFLAGS = $(AM_CFLAGS)
|
||||
|
||||
|
|
|
@ -70,5 +70,8 @@ const char *enum_to_name(const enum_map_t *map, int value);
|
|||
*/
|
||||
int mksock(const char *path, int flags);
|
||||
|
||||
/* print a default version info and license string */
|
||||
NORETURN void print_version(const char *program);
|
||||
|
||||
#endif /* UTIL_H */
|
||||
|
||||
|
|
37
lib/util/print_version.c
Normal file
37
lib/util/print_version.c
Normal file
|
@ -0,0 +1,37 @@
|
|||
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
||||
/*
|
||||
* Copyright (C) 2018 - David Oberhollenzer
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
#define GPL_URL "https://gnu.org/licenses/gpl.html"
|
||||
|
||||
static const char *version_string =
|
||||
"%s (pygos init) " PACKAGE_VERSION "\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <" GPL_URL ">.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
void print_version(const char *program)
|
||||
{
|
||||
fprintf(stdout, version_string, program);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
|
@ -14,6 +14,7 @@ klogd_SOURCES = syslogd/klogd.c
|
|||
klogd_CPPFLAGS = $(AM_CPPFLAGS)
|
||||
klogd_CFLAGS = $(AM_CFLAGS)
|
||||
klogd_LDFLAGS = $(AM_LDFLAGS)
|
||||
klogd_LDADD = libinit.a
|
||||
|
||||
sbin_PROGRAMS += klogd
|
||||
endif
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <errno.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "util.h"
|
||||
|
||||
enum {
|
||||
KLOG_CLOSE = 0,
|
||||
|
@ -48,13 +49,6 @@ static const struct option options[] = {
|
|||
|
||||
static const char *shortopt = "hVl:";
|
||||
|
||||
static const char *versiontext =
|
||||
"klogd (Pygos init) "PACKAGE_VERSION"\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
static const char *helptext =
|
||||
"Usage: klogd [OPTION]... \n\n"
|
||||
"Collect printk() messages from the kernel and forward them to syslogd.\n"
|
||||
|
@ -82,8 +76,7 @@ static void process_options(int argc, char **argv)
|
|||
fputs(helptext, stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'V':
|
||||
fputs(versiontext, stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
print_version("klogd");
|
||||
default:
|
||||
fputs("Try `klogd --help' for more information\n",
|
||||
stderr);
|
||||
|
|
|
@ -32,10 +32,6 @@
|
|||
#include "syslogd.h"
|
||||
#include "util.h"
|
||||
|
||||
|
||||
#define GPL_URL "https://gnu.org/licenses/gpl.html"
|
||||
|
||||
|
||||
static const struct option long_opts[] = {
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "version", no_argument, NULL, 'V' },
|
||||
|
@ -49,13 +45,6 @@ static const struct option long_opts[] = {
|
|||
|
||||
static const char *short_opts = "hVcrm:u:g:";
|
||||
|
||||
const char *version_string =
|
||||
"usyslogd (pygos init) " PACKAGE_VERSION "\n"
|
||||
"Copyright (C) 2018 David Oberhollenzer\n\n"
|
||||
"License GPLv3+: GNU GPL version 3 or later <" GPL_URL ">.\n"
|
||||
"This is free software: you are free to change and redistribute it.\n"
|
||||
"There is NO WARRANTY, to the extent permitted by law.\n";
|
||||
|
||||
const char *usage_string =
|
||||
"Usage: usyslogd [OPTIONS..]\n\n"
|
||||
"The following options are supported:\n"
|
||||
|
@ -183,8 +172,7 @@ static void process_options(int argc, char **argv)
|
|||
fputs(usage_string, stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
case 'V':
|
||||
fputs(version_string, stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
print_version("usyslogd");
|
||||
default:
|
||||
goto fail;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue