laforge has submitted this change. ( https://gerrit.osmocom.org/c/libosmocore/+/33920 )
Change subject: exec: osmo_system_nowait2(): Improve logging and error checks ......................................................................
exec: osmo_system_nowait2(): Improve logging and error checks
Change-Id: I9b971dda389fe958627d41fa5ba6f45ee588bf99 --- M src/core/exec.c 1 file changed, 22 insertions(+), 2 deletions(-)
Approvals: laforge: Looks good to me, approved osmith: Looks good to me, but someone else must approve Jenkins Builder: Verified
diff --git a/src/core/exec.c b/src/core/exec.c index 6412270..2e33788 100644 --- a/src/core/exec.c +++ b/src/core/exec.c @@ -213,10 +213,18 @@ int rc;
if (user) { + if (getpw_buflen == -1) /* Value was indeterminate */ + getpw_buflen = 16384; /* Should be more than enough */ char buf[getpw_buflen]; - getpwnam_r(user, &_pw, buf, sizeof(buf), &pw); - if (!pw) + rc = getpwnam_r(user, &_pw, buf, sizeof(buf), &pw); + if (rc < 0) { + LOGP(DLGLOBAL, LOGL_ERROR, "getpwnam_r("%s") failed: %s\n", user, strerror(-rc)); + return rc; + } + if (!pw) { + LOGP(DLGLOBAL, LOGL_ERROR, "getpwnam_r("%s"): user not found!\n", user); return -EINVAL; + } }
rc = fork(); @@ -264,6 +272,9 @@ return -EIO; } else { /* we are in the parent */ + if (rc == -1) + LOGP(DLGLOBAL, LOGL_ERROR, "fork() error executing command '%s': %s\n", + command, strerror(errno)); return rc; } }