From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on sa.local.altlinux.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,RP_MATCHES_RCVD autolearn=unavailable autolearn_force=no version=3.4.1 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=cs.msu.ru; s=dkim; h=Subject:In-Reply-To:Content-Type:MIME-Version:References:Message-ID :Cc:To:From:Date:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=V8GA8r4u4LG+eP1IWl3of5kCJujqJu3jakcEp0qPGJk=; b=akkSr44J95UWBCjF7uObSDnEhk ir8VRXgJm53Jr5EfHGD5mqnxpckEOdxBQYnJqKJlvRq5DAIUMw6MEgUmNysuV+LR6+atT3OEymClB DHL/npW7hM8BAwcy3mS65W2YJzWEz0E8c2sQyf4ZTp6rQY2Ibl1w3u/NG+ikgGVZRpjuMq5PpSXB7 uOvyMojislj3YQp/N5FWwejjLKQ30Qrdl9gfc8ZBsWWnEhPleR5gGfiF/AouIgyYnxslLsz126Z0X OLm+2Xb6KYo1sZ+K/3SO2hV/jwHnscjgDxYJ6RKt+WIK1UBxTagK8HtU8KTRtYYaLeO+YW0dU/XQ7 6pr4JJ1A==; Date: Thu, 17 Sep 2020 16:12:21 +0300 From: Arseny Maslennikov To: Alex Gladkov , devel@lists.altlinux.org Message-ID: <20200917131221.GJ286846@cello> References: <9bca7626b593f896de4283cba2d6290ec99eb4f2.1576183643.git.legion@altlinux.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/qIPZgKzMPM+y5U5" Content-Disposition: inline In-Reply-To: <9bca7626b593f896de4283cba2d6290ec99eb4f2.1576183643.git.legion@altlinux.org> OpenPGP: url=http://grep.cs.msu.ru/~ar/pgp-key.asc X-SA-Exim-Connect-IP: 10.7.5.179 X-SA-Exim-Mail-From: ar@cs.msu.ru X-SA-Exim-Version: 4.2.1 X-SA-Exim-Scanned: Yes (on mail.cs.msu.ru) Cc: ldv@altlinux.org Subject: Re: [devel] [PATCH hasher-priv v1 1/3] logging.c X-BeenThere: devel@lists.altlinux.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: ALT Linux Team development discussions List-Id: ALT Linux Team development discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Sep 2020 13:12:24 -0000 Archived-At: List-Archive: List-Post: --/qIPZgKzMPM+y5U5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Dec 13, 2019 at 12:42:03PM +0100, Alex Gladkov wrote: > diff --git a/hasher-priv/logging.c b/hasher-priv/logging.c > new file mode 100644 > index 0000000..9adac47 > --- /dev/null > +++ b/hasher-priv/logging.c > @@ -0,0 +1,64 @@ > + > +/* > + Copyright (C) 2019 Alexey Gladkov > + > + A logging functions for the hasher-privd program. > + > + SPDX-License-Identifier: GPL-2.0-or-later > +*/ > + > +#include > +#include > +#include > +#include > +#include > + > +#include "logging.h" > + > +int log_priority = -1; > + > +int logging_level(const char *name) > +{ > + if (!strcasecmp(name, "debug")) > + return LOG_DEBUG; > + > + if (!strcasecmp(name, "info")) > + return LOG_INFO; > + > + if (!strcasecmp(name, "warning")) > + return LOG_WARNING; > + > + if (!strcasecmp(name, "error")) > + return LOG_ERR; > + > + return 0; > +} > + > +void logging_init(int loglevel, int stderr) > +{ > + int options = LOG_PID; > + if (stderr) > + options |= LOG_PERROR; > + log_priority = loglevel; > + openlog(program_invocation_short_name, options, LOG_DAEMON); > +} > + > +void logging_close(void) > +{ > + closelog(); > +} > + > +void > +message(int priority, const char *fmt, ...) > +{ > + va_list ap; > + > + va_start(ap, fmt); > + if (priority <= log_priority) > + vsyslog(priority, fmt, ap); If the daemon is invoked with `-f', why not log to stderr only, prepending the message priority? That behaviour would fit better with service managers that take care of process daemonization / pid tracking themselves and direct the service's stderr to system log. If log message duplication is desired, we can add a command line argument to enforce that. To produce messages of different priorities, we can prepend "<%d>" to each log message. > + else if (log_priority < 0) { > + vfprintf(stderr, fmt, ap); > + fprintf(stderr, "\n"); > + } > + va_end(ap); > +} > diff --git a/hasher-priv/logging.h b/hasher-priv/logging.h > new file mode 100644 > index 0000000..9d28fc8 > --- /dev/null > +++ b/hasher-priv/logging.h > @@ -0,0 +1,55 @@ > + > +/* > + Copyright (C) 2019 Alexey Gladkov > + > + A logging functions for the hasher-privd program. > + > + SPDX-License-Identifier: GPL-2.0-or-later > +*/ > + > +#ifndef _LOGGING_H_ > +#define _LOGGING_H_ > + > +#include > +#include > + > +void logging_init(int, int); > +void logging_close(void); > +int logging_level(const char *lvl) __attribute__((nonnull(1))); > + > +void message(int priority, const char *fmt, ...) __attribute__((format(printf, 2, 3))); > + > +#define fatal(format, arg...) \ > + do { \ > + message(LOG_CRIT, \ > + "%s(%d): %s: " format, \ > + __FILE__, __LINE__, __FUNCTION__, \ > + ##arg); \ > + exit(EXIT_FAILURE); \ > + } while (0) > + > +#define err(format, arg...) \ > + do { \ > + message(LOG_ERR, \ > + "%s(%d): %s: " format, \ > + __FILE__, __LINE__, __FUNCTION__, \ > + ##arg); \ > + } while (0) > + > +#define info(format, arg...) \ > + do { \ > + message(LOG_INFO, \ > + "%s(%d): %s: " format, \ > + __FILE__, __LINE__, __FUNCTION__, \ > + ##arg); \ > + } while (0) > + > +#define dbg(format, arg...) \ > + do { \ > + message(LOG_DEBUG, \ > + "%s(%d): %s: " format, \ > + __FILE__, __LINE__, __FUNCTION__, \ > + ##arg); \ > + } while (0) > + > +#endif /* _LOGGING_H_ */ --/qIPZgKzMPM+y5U5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEE56JD3UKTLEu/ddrm9dQjyAYL01AFAl9jYLUACgkQ9dQjyAYL 01AI6xAAjGeDS+WT9xIOunZVH9O7geCfAK24bgu27ulbh4R6wafdG3UwjW0ga2KS 0/Mf2s5zsZKFXm04oIQliWUf1WCtHkLDM6Lsro0yBzVr75cBPJE+OyaJesT+Efy0 rlOTNnlC48ygFmbYkF3H/hzSfgfsX0jA0k5MDaRrCHyAQpDUJXA+6cl0oRLgK09K zx/Sm0mq297ihcZ+j4chQtIQJf7ZdGiAryZyf1iTpOx9+Uwwhk8AQknUwM9846IQ 6HovUKV2EKubE0h7griScYsVpjAE5nO2kOXcz5MT+G/f9OSbgUNb49xOTUE688B0 n5f+imNNykiH0FMgF6PHcOzLz5NnkpyD3qmvMf+uamnI6ZKZV9G3/GFm6nAvk3iQ EUTRLdm58xUPUcYUSyHgs4da+JzvLbgoQzN34+3Rez6lKZK1Cf8Yg6J8afzkleoT 8mS7q2ZcmVt5sP4uI0ynxptvQU5HxwJU9cGbE+voq/5M8Q1TSQCqm+PrANLEXoDv fqYImIzxuLkEdZHiwhjijtXKFcpg3JzWlFEypJ91G7xvtwO5LghfOmwvKEPEaD/g A/rmZvebkQ2UDJDe2q7gghKrxcobTW7kf9U1gD+TB68JPAiYy0CoqYEwsyL0yfBA 5kNh6dIzW74f37EQbrVr2pQLst7NUEFKerj0ib4Db5PNSj7oPWs= =1XK+ -----END PGP SIGNATURE----- --/qIPZgKzMPM+y5U5--