mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
drivers/syslog: syslog internal functions should not set the errno variable: ramlog_putc(), syslog_dev_putc(), syslog_dev_write(), syslog_force().
This commit is contained in:
+7
-11
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* drivers/syslog/ramlog.c
|
* drivers/syslog/ramlog.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -802,7 +802,7 @@ int ramlog_putc(int ch)
|
|||||||
{
|
{
|
||||||
/* The buffer is full and nothing was saved. */
|
/* The buffer is full and nothing was saved. */
|
||||||
|
|
||||||
goto errout;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -810,20 +810,16 @@ int ramlog_putc(int ch)
|
|||||||
/* Add the character to the RAMLOG */
|
/* Add the character to the RAMLOG */
|
||||||
|
|
||||||
ret = ramlog_addchar(priv, ch);
|
ret = ramlog_addchar(priv, ch);
|
||||||
if (ret >= 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* Return the character added on success */
|
/* ramlog_addchar() failed */
|
||||||
|
|
||||||
return ch;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* On a failure, we need to return EOF and set the errno so that
|
/* Return the character added on success */
|
||||||
* work like all other putc-like functions.
|
|
||||||
*/
|
|
||||||
|
|
||||||
errout:
|
return ch;
|
||||||
set_errno(-ret);
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* drivers/syslog/syslog.h
|
* drivers/syslog/syslog.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -303,8 +303,8 @@ ssize_t syslog_default_write(FAR const char *buffer, size_t buflen);
|
|||||||
* ch - The character to add to the SYSLOG (must be positive).
|
* ch - The character to add to the SYSLOG (must be positive).
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, the character is echoed back to the caller. A negated
|
* On success, the character is echoed back to the caller. A negated errno
|
||||||
* errno value is returned on any failure.
|
* value is returned on any failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -322,8 +322,8 @@ int syslog_force(int ch);
|
|||||||
* buflen - The number of bytes in the buffer
|
* buflen - The number of bytes in the buffer
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, the character is echoed back to the caller. Minus one
|
* On success, the character is echoed back to the caller. A negated errno
|
||||||
* is returned on any failure with the errno set correctly.
|
* value is returned on any failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|||||||
@@ -474,8 +474,8 @@ int syslog_dev_uninitialize(void)
|
|||||||
* buflen - The number of bytes in the buffer
|
* buflen - The number of bytes in the buffer
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, the character is echoed back to the caller. Minus one
|
* On success, the character is echoed back to the caller. A negated errno
|
||||||
* is returned on any failure with the errno set correctly.
|
* value is returned on any failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
@@ -485,7 +485,6 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
ssize_t nwritten;
|
ssize_t nwritten;
|
||||||
size_t writelen;
|
size_t writelen;
|
||||||
size_t remaining;
|
size_t remaining;
|
||||||
int errcode;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check if the system is ready to do output operations */
|
/* Check if the system is ready to do output operations */
|
||||||
@@ -493,8 +492,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
ret = syslog_dev_outputready();
|
ret = syslog_dev_outputready();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
return ret;
|
||||||
goto errout_with_errcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The syslog device is ready for writing */
|
/* The syslog device is ready for writing */
|
||||||
@@ -508,8 +506,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
* way, we are outta here.
|
* way, we are outta here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
errcode = -ret;
|
return ret;
|
||||||
goto errout_with_errcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Loop until we have output all characters */
|
/* Loop until we have output all characters */
|
||||||
@@ -548,7 +545,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen);
|
nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen);
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
errcode = -nwritten;
|
ret = (int)nwritten;
|
||||||
goto errout_with_sem;
|
goto errout_with_sem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -562,7 +559,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
nwritten = file_write(&g_syslog_dev.sl_file, g_syscrlf, 2);
|
nwritten = file_write(&g_syslog_dev.sl_file, g_syscrlf, 2);
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
errcode = -nwritten;
|
ret = (int)nwritten;
|
||||||
goto errout_with_sem;
|
goto errout_with_sem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -587,7 +584,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen);
|
nwritten = file_write(&g_syslog_dev.sl_file, buffer, writelen);
|
||||||
if (nwritten < 0)
|
if (nwritten < 0)
|
||||||
{
|
{
|
||||||
errcode = -nwritten;
|
ret = (int)nwritten;
|
||||||
goto errout_with_sem;
|
goto errout_with_sem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -597,9 +594,7 @@ ssize_t syslog_dev_write(FAR const char *buffer, size_t buflen)
|
|||||||
|
|
||||||
errout_with_sem:
|
errout_with_sem:
|
||||||
syslog_dev_givesem();
|
syslog_dev_givesem();
|
||||||
errout_with_errcode:
|
return ret;
|
||||||
set_errno(errcode);
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -622,7 +617,6 @@ int syslog_dev_putc(int ch)
|
|||||||
{
|
{
|
||||||
ssize_t nbytes;
|
ssize_t nbytes;
|
||||||
uint8_t uch;
|
uint8_t uch;
|
||||||
int errcode;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Check if the system is ready to do output operations */
|
/* Check if the system is ready to do output operations */
|
||||||
@@ -630,8 +624,7 @@ int syslog_dev_putc(int ch)
|
|||||||
ret = syslog_dev_outputready();
|
ret = syslog_dev_outputready();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
return ret;
|
||||||
goto errout_with_errcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ignore carriage returns */
|
/* Ignore carriage returns */
|
||||||
@@ -654,8 +647,7 @@ int syslog_dev_putc(int ch)
|
|||||||
* way, we are outta here.
|
* way, we are outta here.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
errcode = -ret;
|
return ret;
|
||||||
goto errout_with_errcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Pre-pend a newline with a carriage return. */
|
/* Pre-pend a newline with a carriage return. */
|
||||||
@@ -693,15 +685,10 @@ int syslog_dev_putc(int ch)
|
|||||||
|
|
||||||
if (nbytes < 0)
|
if (nbytes < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
return (int)nbytes;
|
||||||
goto errout_with_errcode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
|
|
||||||
errout_with_errcode:
|
|
||||||
set_errno(errcode);
|
|
||||||
return EOF;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* drivers/syslog/syslog_force.c
|
* drivers/syslog/syslog_force.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -63,8 +63,8 @@
|
|||||||
* ch - The character to add to the SYSLOG (must be positive).
|
* ch - The character to add to the SYSLOG (must be positive).
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* On success, the character is echoed back to the caller. A negated
|
* On success, the character is echoed back to the caller. A negated errno
|
||||||
* errno value is returned on any failure.
|
* value is returned on any failure.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user