From acd09007a12e4901aa5d221af18de9c42044d970 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 28 Oct 2018 13:41:35 +0100 Subject: Remove usyslogd/klogd and syslog utility program This is split out to a seperate package. Signed-off-by: David Oberhollenzer --- cmd/Makemodule.am | 11 --- cmd/syslog.1 | 47 ------------ cmd/syslog.c | 223 ------------------------------------------------------ 3 files changed, 281 deletions(-) delete mode 100644 cmd/syslog.1 delete mode 100644 cmd/syslog.c (limited to 'cmd') diff --git a/cmd/Makemodule.am b/cmd/Makemodule.am index 76a0e49..30e9619 100644 --- a/cmd/Makemodule.am +++ b/cmd/Makemodule.am @@ -31,17 +31,6 @@ service_SOURCES += cmd/service/schedule.c service_SOURCES += cmd/service/unschedule.c endif -if USYSLOGD -syslog_SOURCES = cmd/syslog.c -syslog_CPPFLAGS = $(AM_CPPFLAGS) -syslog_CFLAGS = $(AM_CFLAGS) -syslog_LDFLAGS = $(AM_LDFLAGS) -syslog_LDADD = libinit.a - -bin_PROGRAMS += syslog -dist_man1_MANS += cmd/syslog.1 -endif - dist_man8_MANS += cmd/shutdown.8 cmd/service/service.8 EXTRA_DIST += $(SRVHEADERS) diff --git a/cmd/syslog.1 b/cmd/syslog.1 deleted file mode 100644 index 382b568..0000000 --- a/cmd/syslog.1 +++ /dev/null @@ -1,47 +0,0 @@ -.TH syslog 1 "August 2018" "Pygos Init" -.SH NAME -syslog \- send a log message to the syslog daemon -.SH SYNOPSIS -.B syslog -[options] message.. -.SH DESCRIPTION -The syslog command concatenates all non option arguments to a single message -that it sends to the syslog daemon. -.SH OPTIONS -.TP -.BR \-h , " \-\-help" -Display a brief help text, a list of available facilities, log levels, all the -default setting and exit. -.TP -.BR \-V , " \-\-version" -Print version information and exit. -.TP -.BR \-f , " \-\-facility " \fIfacility\fP -Logging facility name or numeric identifier. Use -.B \-\-help -to get a list of all available facility names. -.TP -.BR \-l , " \-\-level " \fIlevel\fP -A log level number from 0 to 8 with 8 being most severe, or a name from -.I debug -to -.I emergency. -Use -.B \-\-help -to get a list of all available log level names. -.TP -.BR \-i , " \-\-ident " \fIname\fP -Program name to specify to syslog. If not set, "(shell)" is used as sensible -default to indicate that the message came from the command line. -.TP -.BR \-c , " \-\-console" -Try to write directly to the console if opening the syslog socket fails. -.SH AVAILABILITY -This program is part of the Pygos init system. -.SH COPYRIGHT -Copyright \(co 2018 David Oberhollenzer -.br -License: GNU GPL version 3 or later . -.br -This is free software: you are free to change and redistribute it. -There is NO WARRANTY, to the extent permitted by law. diff --git a/cmd/syslog.c b/cmd/syslog.c deleted file mode 100644 index 48c9343..0000000 --- a/cmd/syslog.c +++ /dev/null @@ -1,223 +0,0 @@ -/* 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 . - */ -#include -#include -#include -#include -#include -#include -#include "util.h" - -static int facility = LOG_USER; -static int level = LOG_INFO; -static int flags = LOG_NDELAY | LOG_NOWAIT; -static const char *ident = "(shell)"; - -static const enum_map_t facility_map[] = { - { "auth", LOG_AUTH }, - { "cron", LOG_CRON }, - { "daemon", LOG_DAEMON }, - { "ftp", LOG_FTP }, - { "local0", LOG_LOCAL0 }, - { "local1", LOG_LOCAL1 }, - { "local2", LOG_LOCAL2 }, - { "local3", LOG_LOCAL3 }, - { "local4", LOG_LOCAL4 }, - { "local5", LOG_LOCAL5 }, - { "local6", LOG_LOCAL6 }, - { "local7", LOG_LOCAL7 }, - { "lpr", LOG_LPR }, - { "news", LOG_NEWS }, - { "user", LOG_USER }, - { "uucp", LOG_UUCP }, - { NULL, 0 }, -}; - -static const enum_map_t level_map[] = { - { "emergency", LOG_EMERG }, - { "alert", LOG_ALERT }, - { "critical", LOG_CRIT }, - { "error", LOG_ERR }, - { "warning", LOG_WARNING }, - { "notice", LOG_NOTICE }, - { "info", LOG_INFO }, - { "debug", LOG_DEBUG }, - { NULL, 0 }, -}; - -static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, 'V' }, - { "console", required_argument, NULL, 'c' }, - { "facility", required_argument, NULL, 'f' }, - { "level", required_argument, NULL, 'l' }, - { "ident", required_argument, NULL, 'i' }, - { NULL, 0, NULL, 0 }, -}; - -static const char *shortopt = "hVcf:l:i:"; - -static const char *helptext = -"Usage: syslog [OPTION]... [STRING]...\n\n" -"Concatenate the given STRINGs and send a log message to the syslog daemon.\n" -"\n" -"The following OPTIONSs can be used:\n" -" -f, --facility Logging facilty name or numeric identifier.\n" -" -l, --level Log level name or numeric identifier.\n" -" -i, --ident Program name for log syslog message.\n" -" Default is %s.\n\n" -" -c, --console Write to the console if opening the syslog\n" -" socket fails.\n\n" -" -h, --help Print this help text and exit\n" -" -V, --version Print version information and exit\n\n"; - -static void print_map(const enum_map_t *map, int defaultval, - const char *option) -{ - size_t i; - - printf("The following values can be used for %s:\n", option); - - for (i = 0; map[i].name != NULL; ++i) { - if (map[i].value == defaultval) { - printf(" %s (=%d), set as default\n", - map[i].name, map[i].value); - } else { - printf(" %s (=%d)\n", map[i].name, map[i].value); - } - } - - fputc('\n', stdout); -} - -static NORETURN void usage(int status) -{ - if (status != EXIT_SUCCESS) { - fputs("Try `syslog --help' for more information\n", stderr); - } else { - printf(helptext, ident); - print_map(level_map, level, "--level"); - print_map(facility_map, facility, "--facility"); - } - - exit(status); -} - -static int readint(const char *str) -{ - int x = 0; - - if (!isdigit(*str)) - return -1; - - while (isdigit(*str)) - x = x * 10 + (*(str++)) - '0'; - - return (*str == '\0') ? x : -1; -} - -static void process_options(int argc, char **argv) -{ - const enum_map_t *e; - int c; - - for (;;) { - c = getopt_long(argc, argv, shortopt, options, NULL); - if (c == -1) - break; - - switch (c) { - case 'f': - facility = readint(optarg); - if (facility >= 0) - break; - e = enum_by_name(facility_map, optarg); - if (e == NULL) { - fprintf(stderr, "Unknown facility name '%s'\n", - optarg); - usage(EXIT_FAILURE); - } - facility = e->value; - break; - case 'l': - level = readint(optarg); - if (level >= 0) - break; - e = enum_by_name(level_map, optarg); - if (e == NULL) { - fprintf(stderr, "Unknown log level '%s'\n", - optarg); - usage(EXIT_FAILURE); - } - level = e->value; - break; - case 'i': - ident = optarg; - break; - case 'c': - flags |= LOG_CONS; - break; - case 'h': - usage(EXIT_SUCCESS); - case 'V': - print_version("syslog"); - default: - usage(EXIT_FAILURE); - } - } -} - - -int main(int argc, char **argv) -{ - size_t len = 0; - char *str; - int i; - - process_options(argc, argv); - - if (optind >= argc) { - fputs("Error: no log string provided.\n", stderr); - usage(EXIT_FAILURE); - } - - for (i = optind; i < argc; ++i) - len += strlen(argv[i]); - - len += argc - optind - 1; - - str = calloc(1, len + 1); - if (str == NULL) { - fputs("syslog: out of memory\n", stderr); - return EXIT_FAILURE; - } - - for (i = optind; i < argc; ++i) { - if (i > optind) - strcat(str, " "); - strcat(str, argv[i]); - } - - openlog(ident, flags, facility); - syslog(level, "%s", str); - closelog(); - - free(str); - return EXIT_SUCCESS; -} - -- cgit v1.2.3