pespin has uploaded this change for review. ( 
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(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/20/33920/1

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;
        }
 }

--
To view, visit https://gerrit.osmocom.org/c/libosmocore/+/33920
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I9b971dda389fe958627d41fa5ba6f45ee588bf99
Gerrit-Change-Number: 33920
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>
Gerrit-MessageType: newchange

Reply via email to