Message ID | 20210820163946.21341-1-zajec5@gmail.com |
---|---|
State | Accepted |
Delegated to: | Rafał Miłecki |
Headers | show |
Series | [ubus] ubusd: log ACL init errors | expand |
On 20.08.2021 18:39, Rafał Miłecki wrote: > From: Rafał Miłecki <rafal@milecki.pl> > > This makes it easier to notice ubusd (and so often a system) failing to > start properly. Some users reported procd failing to initialize fully > without a clear error with faulty /etc/passwd. > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Search for "procd: Connection to ubus failed" to find users reporting this problem. https://forum.openwrt.org/t/master-nginx-boot-hangs-at-loading-kernel-after-sysupgrade/78151 https://forum.openwrt.org/t/uap-ac-pro-not-reachable-after-first-bootup/78132 https://www.mail-archive.com/openwrt-devel@lists.openwrt.org/msg55382.html https://freenode.irclog.whitequark.org/openwrt-devel/2021-03-04
On 20.08.21 18:39, Rafał Miłecki wrote: > From: Rafał Miłecki <rafal@milecki.pl> > > This makes it easier to notice ubusd (and so often a system) failing to > start properly. Some users reported procd failing to initialize fully > without a clear error with faulty /etc/passwd. > > Signed-off-by: Rafał Miłecki <rafal@milecki.pl> Acked-by: John Crispin <john@phrozen.org> > --- > ubusd_acl.c | 13 ++++++++++--- > ubusd_main.c | 3 +++ > 2 files changed, 13 insertions(+), 3 deletions(-) > > diff --git a/ubusd_acl.c b/ubusd_acl.c > index e050e2c..352c581 100644 > --- a/ubusd_acl.c > +++ b/ubusd_acl.c > @@ -26,6 +26,7 @@ > #include <libubox/vlist.h> > #include <libubox/blobmsg_json.h> > #include <libubox/avl-cmp.h> > +#include <libubox/ulog.h> > > #include "ubusd.h" > > @@ -175,19 +176,25 @@ ubusd_acl_init_client(struct ubus_client *cl, int fd) > #ifdef SO_PEERCRED > unsigned int len = sizeof(struct ucred); > > - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) > + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) { > + ULOG_ERR("Failed getsockopt(): %m\n"); > return -1; > + } > #else > memset(&cred, 0, sizeof(cred)); > #endif > > pwd = getpwuid(cred.uid); > - if (!pwd) > + if (!pwd) { > + ULOG_ERR("Failed getpwuid(): %m\n"); > return -1; > + } > > group = getgrgid(cred.gid); > - if (!group) > + if (!group) { > + ULOG_ERR("Failed getgrgid(): %m\n"); > return -1; > + } > > cl->uid = cred.uid; > cl->gid = cred.gid; > diff --git a/ubusd_main.c b/ubusd_main.c > index d454b1a..6b132ce 100644 > --- a/ubusd_main.c > +++ b/ubusd_main.c > @@ -233,6 +233,8 @@ static void mkdir_sockdir() > free(ubus_sock_dir); > } > > +#include <libubox/ulog.h> > + > int main(int argc, char **argv) > { > const char *ubus_socket = UBUS_UNIX_SOCKET; > @@ -242,6 +244,7 @@ int main(int argc, char **argv) > signal(SIGPIPE, SIG_IGN); > signal(SIGHUP, sighup_handler); > > + ulog_open(ULOG_KMSG | ULOG_SYSLOG, LOG_DAEMON, "ubusd"); > openlog("ubusd", LOG_PID, LOG_DAEMON); > uloop_init(); >
diff --git a/ubusd_acl.c b/ubusd_acl.c index e050e2c..352c581 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -26,6 +26,7 @@ #include <libubox/vlist.h> #include <libubox/blobmsg_json.h> #include <libubox/avl-cmp.h> +#include <libubox/ulog.h> #include "ubusd.h" @@ -175,19 +176,25 @@ ubusd_acl_init_client(struct ubus_client *cl, int fd) #ifdef SO_PEERCRED unsigned int len = sizeof(struct ucred); - if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) == -1) { + ULOG_ERR("Failed getsockopt(): %m\n"); return -1; + } #else memset(&cred, 0, sizeof(cred)); #endif pwd = getpwuid(cred.uid); - if (!pwd) + if (!pwd) { + ULOG_ERR("Failed getpwuid(): %m\n"); return -1; + } group = getgrgid(cred.gid); - if (!group) + if (!group) { + ULOG_ERR("Failed getgrgid(): %m\n"); return -1; + } cl->uid = cred.uid; cl->gid = cred.gid; diff --git a/ubusd_main.c b/ubusd_main.c index d454b1a..6b132ce 100644 --- a/ubusd_main.c +++ b/ubusd_main.c @@ -233,6 +233,8 @@ static void mkdir_sockdir() free(ubus_sock_dir); } +#include <libubox/ulog.h> + int main(int argc, char **argv) { const char *ubus_socket = UBUS_UNIX_SOCKET; @@ -242,6 +244,7 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); signal(SIGHUP, sighup_handler); + ulog_open(ULOG_KMSG | ULOG_SYSLOG, LOG_DAEMON, "ubusd"); openlog("ubusd", LOG_PID, LOG_DAEMON); uloop_init();