logger: avoid explicit fclose(stdout)
PATCH 1/3 logger: avoid explicit fclose(stdout)
This is done for us via an atexit hook since c05a80ca6385b8. Avoids a useless 'Write error' on exit whenever invoking the tool.
--- misc-utils/logger.c | 2 -- 1 file changed, 2 deletions(-)
misc-utils/logger.c +0 -2
@@ -248,8 +248,6 @@ main(int argc, char **argv) {else LogSock =myopenlog (usock); - (void )fclose (stdout); -/* log input line if appropriate */ if (argc >0 ) { registerchar *p, *endp;
Signature · 1 line
1.7.10.2
PATCH 2/3 logger: use memcpy instead of bcopy
bcopy is marked legacy in POSIX.1-2001 and should not be used.
--- misc-utils/logger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
misc-utils/logger.c +1 -1
@@ -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);
Signature · 1 line
1.7.10.2
PATCH 3/3 logger: mark decode/pencode as static
In reply to Dave ReisnerMove these functions to the top of the file where they can be marked static and the prototypes can be removed.
--- misc-utils/logger.c | 84 +++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 47 deletions(-)
misc-utils/logger.c +37 -47
@@ -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) +{ + registerCODE *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) -{ - registerCODE *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 ); -}
Signature · 1 line
1.7.10.2
Re: [PATCH 2/3] logger: use memcpy instead of bcopy
In reply to Dave ReisnerQuoted 1 line · 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
Re: [PATCH 2/3] logger: use memcpy instead of bcopy
In reply to Dave ReisnerQuoted 12 lines · Dave Reisner
bcopy is marked legacy in POSIX.1-2001 and should not be used.
Signed-off-by Dave Reisner <[email protected]>--- misc-utils/logger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)misc-utils/logger.c +0
-0
misc-utils/logger.c udpopenlog(const char *servername, uint16_t port) { · line 99
Quoted 5 lines
misc-utils/logger.c +1
-1@@ -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
PATCH 1/1 logger: use memcpy instead of bcopy
bcopy is marked legacy in POSIX.1-2001 and should not be used.
--- misc-utils/logger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
misc-utils/logger.c +1 -1
@@ -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);
Signature · 1 line
1.7.10.2
Quoted 2 lines · Dave Reisner
misc-utils/logger.c | 2 -- 1 file changed, 2 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH] logger: use memcpy instead of bcopy
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
misc-utils/logger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Re: [PATCH 3/3] logger: mark decode/pencode as static
In reply to Dave ReisnerQuoted 2 lines · Dave Reisner
misc-utils/logger.c | 84 +++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 47 deletions(-)
Applied, thanks.
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com