mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-01 06:55:30 +00:00
Merge branch 'feature/master/unix-cleanup' into 'main'
Remove few lines in unix socket handling See merge request isc-projects/bind9!2687
This commit is contained in:
@@ -4242,22 +4242,33 @@ isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, bool active) {
|
|||||||
#define S_ISSOCK(mode) 0
|
#define S_ISSOCK(mode) 0
|
||||||
#endif /* ifndef S_ISSOCK */
|
#endif /* ifndef S_ISSOCK */
|
||||||
|
|
||||||
if (active) {
|
if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
|
||||||
if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
|
switch (errno) {
|
||||||
|
case ENOENT:
|
||||||
|
if (active) /* We exited cleanly last time */
|
||||||
|
break;
|
||||||
|
/* intentional falltrough */
|
||||||
|
default:
|
||||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||||
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
||||||
ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
|
ISC_LOGMODULE_SOCKET,
|
||||||
|
active ? ISC_LOG_ERROR : ISC_LOG_WARNING,
|
||||||
"isc_socket_cleanunix: stat(%s): %s",
|
"isc_socket_cleanunix: stat(%s): %s",
|
||||||
sockaddr->type.sunix.sun_path, strbuf);
|
sockaddr->type.sunix.sun_path, strbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
if (!(S_ISSOCK(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
|
if (!(S_ISSOCK(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
|
||||||
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
||||||
ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR,
|
ISC_LOGMODULE_SOCKET,
|
||||||
|
active ? ISC_LOG_ERROR : ISC_LOG_WARNING,
|
||||||
"isc_socket_cleanunix: %s: not a socket",
|
"isc_socket_cleanunix: %s: not a socket",
|
||||||
sockaddr->type.sunix.sun_path);
|
sockaddr->type.sunix.sun_path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (active) {
|
||||||
if (unlink(sockaddr->type.sunix.sun_path) < 0) {
|
if (unlink(sockaddr->type.sunix.sun_path) < 0) {
|
||||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
strerror_r(errno, strbuf, sizeof(strbuf));
|
||||||
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
||||||
@@ -4278,29 +4289,6 @@ isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, bool active) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) {
|
|
||||||
switch (errno) {
|
|
||||||
case ENOENT: /* We exited cleanly last time */
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
strerror_r(errno, strbuf, sizeof(strbuf));
|
|
||||||
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
|
||||||
ISC_LOGMODULE_SOCKET, ISC_LOG_WARNING,
|
|
||||||
"isc_socket_cleanunix: stat(%s): %s",
|
|
||||||
sockaddr->type.sunix.sun_path, strbuf);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(S_ISSOCK(sb.st_mode) || S_ISFIFO(sb.st_mode))) {
|
|
||||||
isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL,
|
|
||||||
ISC_LOGMODULE_SOCKET, ISC_LOG_WARNING,
|
|
||||||
"isc_socket_cleanunix: %s: not a socket",
|
|
||||||
sockaddr->type.sunix.sun_path);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connect(s, (const struct sockaddr *)&sockaddr->type.sunix,
|
if (connect(s, (const struct sockaddr *)&sockaddr->type.sunix,
|
||||||
sizeof(sockaddr->type.sunix)) < 0)
|
sizeof(sockaddr->type.sunix)) < 0)
|
||||||
{
|
{
|
||||||
@@ -4326,7 +4314,6 @@ isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, bool active) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cleanup:
|
|
||||||
close(s);
|
close(s);
|
||||||
#else /* ifndef _WIN32 */
|
#else /* ifndef _WIN32 */
|
||||||
UNUSED(sockaddr);
|
UNUSED(sockaddr);
|
||||||
|
Reference in New Issue
Block a user