added HAWK_SKAD_TO_OOCSTR_UNIXAT. this changes the behaivor of skad to string conversion.

updated string to skad converter to handle a unix socket starting with a slash
This commit is contained in:
hyung-hwan 2023-06-29 17:51:14 +09:00
parent 05509d8e96
commit b6e6e96578
3 changed files with 75 additions and 61 deletions

View File

@ -31,10 +31,13 @@
#define HAWK_SKAD_TO_OOCSTR_ADDR (1 << 0)
#define HAWK_SKAD_TO_OOCSTR_PORT (1 << 1)
#define HAWK_SKAD_TO_OOCSTR_UNIXAT (1 << 2) /* prefix the unix address string with @ */
#define HAWK_SKAD_TO_UCSTR_ADDR HAWK_SKAD_TO_OOCSTR_ADDR
#define HAWK_SKAD_TO_UCSTR_PORT HAWK_SKAD_TO_OOCSTR_PORT
#define HAWK_SKAD_TO_UCSTR_UNIXAT HAWK_SKAD_TO_OOCSTR_UNIXAT
#define HAWK_SKAD_TO_BCSTR_ADDR HAWK_SKAD_TO_OOCSTR_ADDR
#define HAWK_SKAD_TO_BCSTR_PORT HAWK_SKAD_TO_OOCSTR_PORT
#define HAWK_SKAD_TO_BCSTR_UNIXAT HAWK_SKAD_TO_OOCSTR_UNIXAT
typedef struct hawk_ifcfg_t hawk_ifcfg_t;

View File

@ -4502,8 +4502,9 @@ local://xxx opens the local syslog using the openlog() call in the libc library.
openlog() affects the entire process.
to open /dev/log on the local system for the current running context,
you can specify the remote:// with /dev/log.
you can specify the remote:// with /dev/log or @/dev/log.
sys::openlog("remote:///dev/log/xxx", sys::LOG_OPT_PID | sys::LOG_OPT_NDELAY, sys::LOG_FAC_LOCAL0);
sys::openlog("remote://@/dev/log/xxx", sys::LOG_OPT_PID | sys::LOG_OPT_NDELAY, sys::LOG_FAC_LOCAL0);
*/
static void open_remote_log_socket (hawk_rtx_t* rtx, rtx_data_t* rdp)
{
@ -4726,7 +4727,6 @@ static int fnc_closelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
return 0;
}
static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
{
hawk_int_t rx = ERRNUM_TO_RC(HAWK_EOTHER);
@ -4780,14 +4780,20 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
};
if (rdp->log.sck <= -1) open_remote_log_socket (rtx, rdp);
if (rdp->log.sck >= 0)
{
hawk_ntime_t now;
struct tm tm, * tmx;
time_t t;
if (rdp->log.sck <= -1)
{
open_remote_log_socket (rtx, rdp);
if (rdp->log.sck <= -1)
{
rx = set_error_on_sys_list_with_errno(rtx, sys_list, HAWK_T("unable to open log socket"));
goto done;
}
}
if (!rdp->log.dmsgbuf)
{
rdp->log.dmsgbuf = hawk_becs_open(hawk_rtx_getgem(rtx), 0, 0);
@ -4834,8 +4840,13 @@ static int fnc_writelog (hawk_rtx_t* rtx, const hawk_fnc_info_t* fi)
#endif
/* don't care about output failure */
sendto (rdp->log.sck, HAWK_BECS_PTR(rdp->log.dmsgbuf), HAWK_BECS_LEN(rdp->log.dmsgbuf),
0, (struct sockaddr*)&rdp->log.skad, hawk_skad_get_size(&rdp->log.skad));
if (sendto(rdp->log.sck, HAWK_BECS_PTR(rdp->log.dmsgbuf), HAWK_BECS_LEN(rdp->log.dmsgbuf),
0, (struct sockaddr*)&rdp->log.skad, hawk_skad_get_size(&rdp->log.skad)) <= -1)
{
hawk_ooch_t msg[256] = HAWK_T("unable to write to log socket ");
hawk_gem_skadtooocstr(hawk_rtx_getgem(rtx), &rdp->log.skad, &msg[30], HAWK_COUNTOF(msg) - 30, HAWK_SKAD_TO_OOCSTR_ADDR | HAWK_SKAD_TO_OOCSTR_PORT);
rx = set_error_on_sys_list_with_errno(rtx, sys_list, msg);
goto done;
}
#endif
}

View File

@ -344,14 +344,14 @@ int hawk_gem_ucharstoskad (hawk_gem_t* gem, const hawk_uch_t* str, hawk_oow_t le
/* use HAWK_SIZEOF(*_skad) instead of HAWK_SIZEOF(*skad) in case they are different */
HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*_skad));
if (*p == '@')
if (*p == '@' || *p == '/')
{
#if defined(AF_UNIX) && (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
/* @aaa, @/tmp/aaa ... */
hawk_oow_t srclen, dstlen;
dstlen = HAWK_COUNTOF(skad->un.sun_path) - 1;
srclen = len - 1;
if (hawk_gem_convutobchars(gem, p + 1, &srclen, skad->un.sun_path, &dstlen) <= -1) return -1;
srclen = len - (*p == '@');
if (hawk_gem_convutobchars(gem, p + (*p == '@'), &srclen, skad->un.sun_path, &dstlen) <= -1) return -1;
skad->un.sun_path[dstlen] = '\0';
skad->un.sun_family = AF_UNIX;
return 0;
@ -564,11 +564,11 @@ int hawk_gem_bcharstoskad (hawk_gem_t* gem, const hawk_bch_t* str, hawk_oow_t le
/* use HAWK_SIZEOF(*_skad) instead of HAWK_SIZEOF(*skad) in case they are different */
HAWK_MEMSET (skad, 0, HAWK_SIZEOF(*_skad));
if (*p == '@')
if (*p == '@' || *p == '/')
{
#if defined(AF_UNIX) && (HAWK_SIZEOF_STRUCT_SOCKADDR_UN > 0)
/* @aaa, @/tmp/aaa ... */
hawk_copy_bchars_to_bcstr (skad->un.sun_path, HAWK_COUNTOF(skad->un.sun_path), str + 1, len - 1);
/* @aaa, @/tmp/aaa /tmp/aaa ... */
hawk_copy_bchars_to_bcstr (skad->un.sun_path, HAWK_COUNTOF(skad->un.sun_path), str + (*p == '@'), len - (*p == '@'));
skad->un.sun_family = AF_UNIX;
return 0;
#else
@ -1015,7 +1015,7 @@ hawk_oow_t hawk_gem_skadtoucstr (hawk_gem_t* gem, const hawk_skad_t* _skad, hawk
if (flags & HAWK_SKAD_TO_BCSTR_ADDR)
{
if (xlen + 1 >= len) goto done;
buf[xlen++] = '@';
if (flags & HAWK_SKAD_TO_BCSTR_UNIXAT) buf[xlen++] = '@';
if (xlen + 1 >= len) goto done;
else
@ -1265,7 +1265,7 @@ hawk_oow_t hawk_gem_skadtobcstr (hawk_gem_t* gem, const hawk_skad_t* _skad, hawk
if (flags & HAWK_SKAD_TO_BCSTR_ADDR)
{
if (xlen + 1 >= len) goto done;
buf[xlen++] = '@';
if (flags & HAWK_SKAD_TO_BCSTR_UNIXAT) buf[xlen++] = '@';
if (xlen + 1 >= len) goto done;
xlen += hawk_copy_bcstr(&buf[xlen], len - xlen, skad->un.sun_path);