* [PATCH 1/3] logger: avoid explicit fclose(stdout)
@ 2012-05-23 20:35 Dave Reisner
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Dave Reisner @ 2012-05-23 20:35 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
This is done for us via an atexit hook since c05a80ca6385b8. Avoids a
useless 'Write error' on exit whenever invoking the tool.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/logger.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 067272a..19b4c47 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -248,8 +248,6 @@ main(int argc, char **argv) {
else
LogSock = myopenlog(usock);
- (void) fclose(stdout);
-
/* log input line if appropriate */
if (argc > 0) {
register char *p, *endp;
--
1.7.10.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/3] logger: use memcpy instead of bcopy
2012-05-23 20:35 [PATCH 1/3] logger: avoid explicit fclose(stdout) Dave Reisner
@ 2012-05-23 20:35 ` Dave Reisner
2012-05-23 22:43 ` Mike Frysinger
2012-05-27 23:23 ` Guillem Jover
2012-05-23 20:36 ` [PATCH 3/3] logger: mark decode/pencode as static Dave Reisner
2012-05-29 7:58 ` [PATCH 1/3] logger: avoid explicit fclose(stdout) Karel Zak
2 siblings, 2 replies; 9+ messages in thread
From: Dave Reisner @ 2012-05-23 20:35 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
bcopy is marked legacy in POSIX.1-2001 and should not be used.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/logger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 19b4c47..a187227 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -96,7 +96,7 @@ udpopenlog(const char *servername, uint16_t port) {
if ((fd = socket(AF_INET, SOCK_DGRAM , 0)) == -1)
err(EXIT_FAILURE, _("socket"));
- bcopy(serverhost->h_addr,&s_addr.sin_addr,serverhost->h_length);
+ memcpy(serverhost->h_addr,&s_addr.sin_addr,serverhost->h_length);
s_addr.sin_family=AF_INET;
s_addr.sin_port=htons(port);
--
1.7.10.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/3] logger: mark decode/pencode as static
2012-05-23 20:35 [PATCH 1/3] logger: avoid explicit fclose(stdout) Dave Reisner
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
@ 2012-05-23 20:36 ` Dave Reisner
2012-05-29 7:59 ` Karel Zak
2012-05-29 7:58 ` [PATCH 1/3] logger: avoid explicit fclose(stdout) Karel Zak
2 siblings, 1 reply; 9+ messages in thread
From: Dave Reisner @ 2012-05-23 20:36 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
Move these functions to the top of the file where they can be marked
static and the prototypes can be removed.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/logger.c | 84 +++++++++++++++++++++++----------------------------
1 file changed, 37 insertions(+), 47 deletions(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index a187227..fda22d8 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -58,12 +58,46 @@
#define SYSLOG_NAMES
#include <syslog.h>
-int decode (char *, CODE *);
-int pencode (char *);
-
static int optd = 0;
static uint16_t udpport = 514;
+static int decode(char *name, CODE *codetab)
+{
+ register CODE *c;
+
+ if (isdigit(*name))
+ return (atoi(name));
+
+ for (c = codetab; c->c_name; c++)
+ if (!strcasecmp(name, c->c_name))
+ return (c->c_val);
+
+ return -1;
+}
+
+static int pencode(char *s)
+{
+ char *save;
+ int fac, lev;
+
+ for (save = s; *s && *s != '.'; ++s);
+ if (*s) {
+ *s = '\0';
+ fac = decode(save, facilitynames);
+ if (fac < 0)
+ errx(EXIT_FAILURE, _("unknown facility name: %s."), save);
+ *s++ = '.';
+ }
+ else {
+ fac = LOG_USER;
+ s = save;
+ }
+ lev = decode(s, prioritynames);
+ if (lev < 0)
+ errx(EXIT_FAILURE, _("unknown priority name: %s."), save);
+ return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
+}
+
static int
myopenlog(const char *sock) {
int fd;
@@ -302,47 +336,3 @@ main(int argc, char **argv) {
return EXIT_SUCCESS;
}
-
-/*
- * Decode a symbolic name to a numeric value
- */
-int
-pencode(char *s)
-{
- char *save;
- int fac, lev;
-
- for (save = s; *s && *s != '.'; ++s);
- if (*s) {
- *s = '\0';
- fac = decode(save, facilitynames);
- if (fac < 0)
- errx(EXIT_FAILURE,
- _("unknown facility name: %s."), save);
- *s++ = '.';
- }
- else {
- fac = LOG_USER;
- s = save;
- }
- lev = decode(s, prioritynames);
- if (lev < 0)
- errx(EXIT_FAILURE,
- _("unknown priority name: %s."), save);
- return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
-}
-
-int
-decode(char *name, CODE *codetab)
-{
- register CODE *c;
-
- if (isdigit(*name))
- return (atoi(name));
-
- for (c = codetab; c->c_name; c++)
- if (!strcasecmp(name, c->c_name))
- return (c->c_val);
-
- return (-1);
-}
--
1.7.10.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] logger: use memcpy instead of bcopy
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
@ 2012-05-23 22:43 ` Mike Frysinger
2012-05-27 23:23 ` Guillem Jover
1 sibling, 0 replies; 9+ messages in thread
From: Mike Frysinger @ 2012-05-23 22:43 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
[-- Attachment #1: Type: Text/Plain, Size: 255 bytes --]
On Wednesday 23 May 2012 16:35:59 Dave Reisner wrote:
> bcopy is marked legacy in POSIX.1-2001 and should not be used.
wonder if it'd be useful to add local defines for bcopy() & friends that result
in an error if people try to use them ...
-mike
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/3] logger: use memcpy instead of bcopy
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
2012-05-23 22:43 ` Mike Frysinger
@ 2012-05-27 23:23 ` Guillem Jover
2012-05-28 18:02 ` [PATCH] " Dave Reisner
1 sibling, 1 reply; 9+ messages in thread
From: Guillem Jover @ 2012-05-27 23:23 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Wed, 2012-05-23 at 16:35:59 -0400, Dave Reisner wrote:
> bcopy is marked legacy in POSIX.1-2001 and should not be used.
>
> Signed-off-by: Dave Reisner <dreisner@archlinux.org>
> ---
> misc-utils/logger.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/misc-utils/logger.c b/misc-utils/logger.c
> index 19b4c47..a187227 100644
> --- a/misc-utils/logger.c
> +++ b/misc-utils/logger.c
> @@ -96,7 +96,7 @@ udpopenlog(const char *servername, uint16_t port) {
> if ((fd = socket(AF_INET, SOCK_DGRAM , 0)) == -1)
> err(EXIT_FAILURE, _("socket"));
>
> - bcopy(serverhost->h_addr,&s_addr.sin_addr,serverhost->h_length);
> + memcpy(serverhost->h_addr,&s_addr.sin_addr,serverhost->h_length);
The src/dst arguments to memcpy() should get swapped.
thanks,
guillem
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] logger: use memcpy instead of bcopy
2012-05-27 23:23 ` Guillem Jover
@ 2012-05-28 18:02 ` Dave Reisner
2012-05-29 7:59 ` Karel Zak
0 siblings, 1 reply; 9+ messages in thread
From: Dave Reisner @ 2012-05-28 18:02 UTC (permalink / raw)
To: util-linux; +Cc: Dave Reisner
bcopy is marked legacy in POSIX.1-2001 and should not be used.
Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
misc-utils/logger.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/misc-utils/logger.c b/misc-utils/logger.c
index 19b4c47..0a935f6 100644
--- a/misc-utils/logger.c
+++ b/misc-utils/logger.c
@@ -96,7 +96,7 @@ udpopenlog(const char *servername, uint16_t port) {
if ((fd = socket(AF_INET, SOCK_DGRAM , 0)) == -1)
err(EXIT_FAILURE, _("socket"));
- bcopy(serverhost->h_addr,&s_addr.sin_addr,serverhost->h_length);
+ memcpy(&s_addr.sin_addr, serverhost->h_addr, serverhost->h_length);
s_addr.sin_family=AF_INET;
s_addr.sin_port=htons(port);
--
1.7.10.2
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 1/3] logger: avoid explicit fclose(stdout)
2012-05-23 20:35 [PATCH 1/3] logger: avoid explicit fclose(stdout) Dave Reisner
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
2012-05-23 20:36 ` [PATCH 3/3] logger: mark decode/pencode as static Dave Reisner
@ 2012-05-29 7:58 ` Karel Zak
2 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-29 7:58 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Wed, May 23, 2012 at 04:35:58PM -0400, Dave Reisner wrote:
> misc-utils/logger.c | 2 --
> 1 file changed, 2 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] logger: use memcpy instead of bcopy
2012-05-28 18:02 ` [PATCH] " Dave Reisner
@ 2012-05-29 7:59 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-29 7:59 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Mon, May 28, 2012 at 02:02:59PM -0400, Dave Reisner wrote:
> misc-utils/logger.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/3] logger: mark decode/pencode as static
2012-05-23 20:36 ` [PATCH 3/3] logger: mark decode/pencode as static Dave Reisner
@ 2012-05-29 7:59 ` Karel Zak
0 siblings, 0 replies; 9+ messages in thread
From: Karel Zak @ 2012-05-29 7:59 UTC (permalink / raw)
To: Dave Reisner; +Cc: util-linux
On Wed, May 23, 2012 at 04:36:00PM -0400, Dave Reisner wrote:
> misc-utils/logger.c | 84 +++++++++++++++++++++++----------------------------
> 1 file changed, 37 insertions(+), 47 deletions(-)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2012-05-29 7:59 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-23 20:35 [PATCH 1/3] logger: avoid explicit fclose(stdout) Dave Reisner
2012-05-23 20:35 ` [PATCH 2/3] logger: use memcpy instead of bcopy Dave Reisner
2012-05-23 22:43 ` Mike Frysinger
2012-05-27 23:23 ` Guillem Jover
2012-05-28 18:02 ` [PATCH] " Dave Reisner
2012-05-29 7:59 ` Karel Zak
2012-05-23 20:36 ` [PATCH 3/3] logger: mark decode/pencode as static Dave Reisner
2012-05-29 7:59 ` Karel Zak
2012-05-29 7:58 ` [PATCH 1/3] logger: avoid explicit fclose(stdout) Karel Zak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).