]> git.saurik.com Git - apple/xnu.git/blobdiff - libsyscall/wrappers/spawn/posix_spawn.c
xnu-4903.270.47.tar.gz
[apple/xnu.git] / libsyscall / wrappers / spawn / posix_spawn.c
index 20083809a4358086a258c044cef1324f6d0164d2..819863128241b7233fb8f26c0c4c65fe6e6780e6 100644 (file)
@@ -2,14 +2,14 @@
  * Copyright (c) 2006-2012 Apple Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
- * 
+ *
  * This file contains Original Code and/or Modifications of Original Code
  * as defined in and that are subject to the Apple Public Source License
  * Version 2.0 (the 'License'). You may not use this file except in
  * compliance with the License. Please obtain a copy of the License at
  * http://www.opensource.apple.com/apsl/ and read it before using this
  * file.
- * 
+ *
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
@@ -17,7 +17,7 @@
  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  * Please see the License for the specific language governing rights and
  * limitations under the License.
- * 
+ *
  * @APPLE_LICENSE_HEADER_END@
  */
 
@@ -33,7 +33,7 @@
 #include <sys/process_policy.h>
 #include <stdlib.h>
 #include <errno.h>
-#include <limits.h>    /* for OPEN_MAX, PATH_MAX */
+#include <limits.h>     /* for OPEN_MAX, PATH_MAX */
 #include <string.h>
 #include <strings.h>
 #include <mach/port.h>
@@ -70,12 +70,11 @@ int
 posix_spawnattr_init(posix_spawnattr_t *attr)
 {
        _posix_spawnattr_t *psattrp = (_posix_spawnattr_t *)attr;
-       int     err = 0;
+       int     err = 0;
 
        if ((*psattrp = (_posix_spawnattr_t)malloc(sizeof(struct _posix_spawnattr))) == NULL) {
                err = ENOMEM;
        } else {
-
                /*
                 * The default value of this attribute shall be as if no
                 * flags were set
@@ -92,11 +91,11 @@ posix_spawnattr_init(posix_spawnattr_t *attr)
                (*psattrp)->psa_sigmask = 0;
 
                /* The default value of this attribute shall be zero */
-               (*psattrp)->psa_pgroup = 0;     /* doesn't matter */
+               (*psattrp)->psa_pgroup = 0;     /* doesn't matter */
 
                /* Default is no binary preferences, i.e. use normal grading */
-               memset((*psattrp)->psa_binprefs, 0, 
-                               sizeof((*psattrp)->psa_binprefs));
+               memset((*psattrp)->psa_binprefs, 0,
+                   sizeof((*psattrp)->psa_binprefs));
 
                /* Default is no port actions to take */
                (*psattrp)->psa_ports = NULL;
@@ -108,11 +107,11 @@ posix_spawnattr_init(posix_spawnattr_t *attr)
                (*psattrp)->psa_pcontrol = 0;
 
                /*
-                * Initializing the alignment paddings. 
+                * Initializing the alignment paddings.
                 */
 
-                (*psattrp)->short_padding = 0; 
-                (*psattrp)->flags_padding = 0; 
+               (*psattrp)->short_padding = 0;
+               (*psattrp)->flags_padding = 0;
 
                /* Default is no new apptype requested */
                (*psattrp)->psa_apptype = POSIX_SPAWN_PROCESS_TYPE_DEFAULT;
@@ -157,7 +156,7 @@ posix_spawnattr_init(posix_spawnattr_t *attr)
                (*psattrp)->psa_max_addr = 0;
        }
 
-       return (err);
+       return err;
 }
 
 
@@ -190,8 +189,9 @@ posix_spawnattr_destroy(posix_spawnattr_t *attr)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        posix_spawn_destroyportactions_np(attr);
@@ -201,7 +201,7 @@ posix_spawnattr_destroy(posix_spawnattr_t *attr)
        free(psattr);
        *attr = NULL;
 
-       return (0);
+       return 0;
 }
 
 
@@ -226,13 +226,14 @@ posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_flags = flags;
 
-       return (0);
+       return 0;
 }
 
 
@@ -260,17 +261,18 @@ posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags)
  */
 int
 posix_spawnattr_getflags(const posix_spawnattr_t * __restrict attr,
-       short * __restrict flagsp)
+    short * __restrict flagsp)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *flagsp = psattr->psa_flags;
 
-       return (0);
+       return 0;
 }
 
 
@@ -296,17 +298,18 @@ posix_spawnattr_getflags(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict attr,
-               sigset_t * __restrict sigdefault)
+    sigset_t * __restrict sigdefault)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *sigdefault = psattr->psa_sigdefault;
 
-       return (0);
+       return 0;
 }
 
 
@@ -331,17 +334,18 @@ posix_spawnattr_getsigdefault(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict attr,
-               pid_t * __restrict pgroup)
+    pid_t * __restrict pgroup)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *pgroup = psattr->psa_pgroup;
 
-       return (0);
+       return 0;
 }
 
 
@@ -367,24 +371,25 @@ posix_spawnattr_getpgroup(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict attr,
-               sigset_t * __restrict sigmask)
+    sigset_t * __restrict sigmask)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *sigmask = psattr->psa_sigmask;
 
-       return (0);
+       return 0;
 }
 
 /*
  * posix_spawnattr_getbinpref_np
  *
- * Description:        Obtain the value of the spawn binary preferences attribute from 
- *             the spawn attributes object referenced by 'attr' and place the
+ * Description:        Obtain the value of the spawn binary preferences attribute from
+ *              the spawn attributes object referenced by 'attr' and place the
  *             result into the memory referenced by 'pref'.
  *
  * Parameters: attr                    The spawn attributes object whose
@@ -394,30 +399,32 @@ posix_spawnattr_getsigmask(const posix_spawnattr_t * __restrict attr,
  *             ocount                  The actual number copied
  *
  * Returns:    0                       No binary preferences found
- *             > 0                     The number of cpu types (less than 
- *                                     count) copied over from 'attr'.
+ *              > 0                    The number of cpu types (less than
+ *                                      count) copied over from 'attr'.
  *
  * Implicit Returns:
- *             *pref (modified)        The binary preferences array 
+ *             *pref (modified)        The binary preferences array
  *                                     from the spawn attributes object
  */
 int
 posix_spawnattr_getbinpref_np(const posix_spawnattr_t * __restrict attr,
-               size_t count, cpu_type_t *pref, size_t * __restrict ocount)
+    size_t count, cpu_type_t *pref, size_t * __restrict ocount)
 {
        _posix_spawnattr_t psattr;
        int i = 0;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        for (i = 0; i < count && i < 4; i++) {
                pref[i] = psattr->psa_binprefs[i];
        }
 
-       if (ocount)
+       if (ocount) {
                *ocount = i;
+       }
        return 0;
 }
 
@@ -444,17 +451,18 @@ posix_spawnattr_getbinpref_np(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_getpcontrol_np(const posix_spawnattr_t * __restrict attr,
-               int * __restrict pcontrol)
+    int * __restrict pcontrol)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *pcontrol = psattr->psa_pcontrol;
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -479,17 +487,18 @@ posix_spawnattr_getpcontrol_np(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_getprocesstype_np(const posix_spawnattr_t * __restrict attr,
-               int * __restrict proctype)
+    int * __restrict proctype)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        *proctype = psattr->psa_apptype;
 
-       return (0);
+       return 0;
 }
 /*
  * posix_spawnattr_setsigdefault
@@ -508,17 +517,18 @@ posix_spawnattr_getprocesstype_np(const posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_setsigdefault(posix_spawnattr_t * __restrict attr,
-               const sigset_t * __restrict sigdefault)
+    const sigset_t * __restrict sigdefault)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_sigdefault = *sigdefault;
 
-       return (0);
+       return 0;
 }
 
 
@@ -541,13 +551,14 @@ posix_spawnattr_setpgroup(posix_spawnattr_t * attr, pid_t pgroup)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_pgroup = pgroup;
 
-       return (0);
+       return 0;
 }
 
 
@@ -568,17 +579,18 @@ posix_spawnattr_setpgroup(posix_spawnattr_t * attr, pid_t pgroup)
  */
 int
 posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict attr,
-               const sigset_t * __restrict sigmask)
+    const sigset_t * __restrict sigmask)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_sigmask = *sigmask;
 
-       return (0);
+       return 0;
 }
 
 
@@ -590,27 +602,28 @@ posix_spawnattr_setsigmask(posix_spawnattr_t * __restrict attr,
  *             cpu_type_t array referenced by 'pref', size of 'count'
  *
  * Parameters: attr                    The spawn attributes object whose
- *                                     binary preferences are to be set
- *             count                   Size of the array pointed to by 'pref'
- *             pref                    cpu_type_t array of binary preferences
+ *                                      binary preferences are to be set
+ *              count                  Size of the array pointed to by 'pref'
+ *              pref                   cpu_type_t array of binary preferences
  *             ocount                  The actual number copied
  *
  * Returns:    0                       No preferences copied
- *             > 0                     Number of preferences copied
+ *              > 0                    Number of preferences copied
  *
- * Note:       The posix_spawnattr_t currently only holds four cpu_type_t's. 
- *             If the caller provides more preferences than this limit, they
- *             will be ignored, as reflected in the return value.
+ * Note:       The posix_spawnattr_t currently only holds four cpu_type_t's.
+ *              If the caller provides more preferences than this limit, they
+ *              will be ignored, as reflected in the return value.
  */
 int
 posix_spawnattr_setbinpref_np(posix_spawnattr_t * __restrict attr,
-               size_t count, cpu_type_t *pref, size_t * __restrict ocount)
+    size_t count, cpu_type_t *pref, size_t * __restrict ocount)
 {
        _posix_spawnattr_t psattr;
        int i = 0;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        for (i = 0; i < count && i < 4; i++) {
@@ -618,8 +631,9 @@ posix_spawnattr_setbinpref_np(posix_spawnattr_t * __restrict attr,
        }
 
        /* return number of binprefs copied over */
-       if (ocount)
+       if (ocount) {
                *ocount = i;
+       }
        return 0;
 }
 
@@ -640,17 +654,18 @@ posix_spawnattr_setbinpref_np(posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_setpcontrol_np(posix_spawnattr_t * __restrict attr,
-               const int pcontrol)
+    const int pcontrol)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_pcontrol = pcontrol;
 
-       return (0);
+       return 0;
 }
 
 
@@ -670,23 +685,24 @@ posix_spawnattr_setpcontrol_np(posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_setprocesstype_np(posix_spawnattr_t * __restrict attr,
-               const int proctype)
+    const int proctype)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_apptype = proctype;
 
-       return (0);
+       return 0;
 }
 
 /*
  * posix_spawn_createportactions_np
  * Description: create a new posix_spawn_port_actions struct and link
- *     it into the posix_spawnattr.
+ *      it into the posix_spawnattr.
  */
 static int
 posix_spawn_createportactions_np(posix_spawnattr_t *attr)
@@ -694,14 +710,16 @@ posix_spawn_createportactions_np(posix_spawnattr_t *attr)
        _posix_spawnattr_t psattr;
        _posix_spawn_port_actions_t acts;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        acts = (_posix_spawn_port_actions_t)malloc(PS_PORT_ACTIONS_SIZE(2));
-       if (acts == NULL)
+       if (acts == NULL) {
                return ENOMEM;
-       
+       }
+
        acts->pspa_alloc = 2;
        acts->pspa_count = 0;
 
@@ -711,34 +729,39 @@ posix_spawn_createportactions_np(posix_spawnattr_t *attr)
 
 /*
  * posix_spawn_growportactions_np
- * Description: Enlarge the size of portactions if necessary 
+ * Description: Enlarge the size of portactions if necessary
  */
 static int
 posix_spawn_growportactions_np(posix_spawnattr_t *attr)
 {
        _posix_spawnattr_t psattr;
-       _posix_spawn_port_actions_t acts; 
+       _posix_spawn_port_actions_t acts;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
-       acts = psattr->psa_ports; 
-       if (acts == NULL)
+       acts = psattr->psa_ports;
+       if (acts == NULL) {
                return EINVAL;
-       
+       }
+
        /* Double number of port actions allocated for */
        int newnum = 0;
-       if (os_mul_overflow(acts->pspa_alloc, 2, &newnum))
+       if (os_mul_overflow(acts->pspa_alloc, 2, &newnum)) {
                return ENOMEM;
+       }
        size_t newsize = PS_PORT_ACTIONS_SIZE(newnum);
-       if (newsize == 0)
+       if (newsize == 0) {
                return ENOMEM;
+       }
 
        acts = realloc(acts, newsize);
-       if (acts == NULL)
+       if (acts == NULL) {
                return ENOMEM;
-       
+       }
+
        acts->pspa_alloc = newnum;
        psattr->psa_ports = acts;
        return 0;
@@ -752,16 +775,18 @@ static int
 posix_spawn_destroyportactions_np(posix_spawnattr_t *attr)
 {
        _posix_spawnattr_t psattr;
-       _posix_spawn_port_actions_t acts; 
+       _posix_spawn_port_actions_t acts;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
-       acts = psattr->psa_ports; 
-       if (acts == NULL)
+       acts = psattr->psa_ports;
+       if (acts == NULL) {
                return EINVAL;
-       
+       }
+
        free(acts);
        return 0;
 }
@@ -776,13 +801,15 @@ posix_spawn_destroycoalition_info_np(posix_spawnattr_t *attr)
        _posix_spawnattr_t psattr;
        struct _posix_spawn_coalition_info *coal_info;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        coal_info = psattr->psa_coalition_info;
-       if (coal_info == NULL)
+       if (coal_info == NULL) {
                return EINVAL;
+       }
 
        psattr->psa_coalition_info = NULL;
        free(coal_info);
@@ -799,13 +826,15 @@ posix_spawn_destroypersona_info_np(posix_spawnattr_t *attr)
        _posix_spawnattr_t psattr;
        struct _posix_spawn_persona_info *persona;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        persona = psattr->psa_persona_info;
-       if (persona == NULL)
+       if (persona == NULL) {
                return EINVAL;
+       }
 
        psattr->psa_persona_info = NULL;
        free(persona);
@@ -857,22 +886,22 @@ posix_spawn_appendportaction_np(posix_spawnattr_t *attr, _ps_port_action_t *act)
 /*
  * posix_spawnattr_setspecialport_np
  *
- * Description:        Set a new value for a mach special port in the spawned task. 
+ * Description:        Set a new value for a mach special port in the spawned task.
  *
  * Parameters: attr                    The spawn attributes object for the
- *                                     new process
- *             new_port                The new value for the special port
- *             which                   The particular port to be set
- *                                     (see task_set_special_port for details)
+ *                                      new process
+ *              new_port               The new value for the special port
+ *              which                  The particular port to be set
+ *                                      (see task_set_special_port for details)
  *
  * Returns:    0                       Success
- *             ENOMEM                  Couldn't allocate memory
+ *              ENOMEM                 Couldn't allocate memory
  */
-int    
+int
 posix_spawnattr_setspecialport_np(
-               posix_spawnattr_t *attr,
-               mach_port_t      new_port,
-               int             which)
+       posix_spawnattr_t *attr,
+       mach_port_t      new_port,
+       int             which)
 {
        _ps_port_action_t action = {
                .port_type = PSPA_SPECIAL,
@@ -888,23 +917,23 @@ posix_spawnattr_setspecialport_np(
  * Description:        Set a new port for a set of exception ports in the spawned task.
  *
  * Parameters: attr                    The spawn attributes object for the
- *                                     new process
- *             mask                    A bitfield indicating which exceptions
- *                                     to associate the port with
- *             new_port                The new value for the exception port
- *             behavior                The default behavior for the port
- *             flavor                  The default flavor for the port
- *                                     (see task_set_exception_ports)
+ *                                      new process
+ *              mask                   A bitfield indicating which exceptions
+ *                                      to associate the port with
+ *              new_port               The new value for the exception port
+ *              behavior               The default behavior for the port
+ *              flavor                 The default flavor for the port
+ *                                      (see task_set_exception_ports)
  *
  * Returns:    0                       Success
  */
-int    
+int
 posix_spawnattr_setexceptionports_np(
-               posix_spawnattr_t       *attr,
-               exception_mask_t        mask,
-               mach_port_t              new_port,
-               exception_behavior_t    behavior,
-               thread_state_flavor_t   flavor)
+       posix_spawnattr_t       *attr,
+       exception_mask_t        mask,
+       mach_port_t              new_port,
+       exception_behavior_t    behavior,
+       thread_state_flavor_t   flavor)
 {
        _ps_port_action_t action = {
                .port_type = PSPA_EXCEPTION,
@@ -924,15 +953,15 @@ posix_spawnattr_setexceptionports_np(
  *             the new task.
  *
  * Parameters: attr                    The spawn attributes object for the
- *                                     new process
- *             au_sessionport          The audit session send port right
+ *                                      new process
+ *              au_sessionport         The audit session send port right
  *
  * Returns:    0                       Success
  */
-int    
+int
 posix_spawnattr_setauditsessionport_np(
-               posix_spawnattr_t       *attr,
-               mach_port_t              au_sessionport)
+       posix_spawnattr_t       *attr,
+       mach_port_t              au_sessionport)
 {
        _ps_port_action_t action = {
                .port_type = PSPA_AU_SESSION,
@@ -972,7 +1001,7 @@ int
 posix_spawn_file_actions_init(posix_spawn_file_actions_t *file_actions)
 {
        _posix_spawn_file_actions_t *psactsp = (_posix_spawn_file_actions_t *)file_actions;
-       int     err = 0;
+       int     err = 0;
 
        if ((*psactsp = (_posix_spawn_file_actions_t)malloc(PSF_ACTIONS_SIZE(PSF_ACTIONS_INIT_COUNT))) == NULL) {
                err = ENOMEM;
@@ -981,7 +1010,7 @@ posix_spawn_file_actions_init(posix_spawn_file_actions_t *file_actions)
                (*psactsp)->psfa_act_count = 0;
        }
 
-       return (err);
+       return err;
 }
 
 
@@ -1010,14 +1039,15 @@ posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *file_actions)
 {
        _posix_spawn_file_actions_t psacts;
 
-       if (file_actions == NULL || *file_actions == NULL)
+       if (file_actions == NULL || *file_actions == NULL) {
                return EINVAL;
+       }
 
        psacts = *(_posix_spawn_file_actions_t *)file_actions;
        free(psacts);
        *file_actions = NULL;
 
-       return (0);
+       return 0;
 }
 
 
@@ -1042,12 +1072,14 @@ static int
 _posix_spawn_file_actions_grow(_posix_spawn_file_actions_t *psactsp)
 {
        int newnum = 0;
-       if (os_mul_overflow((*psactsp)->psfa_act_alloc, 2, &newnum))
+       if (os_mul_overflow((*psactsp)->psfa_act_alloc, 2, &newnum)) {
                return ENOMEM;
+       }
 
        size_t newsize = PSF_ACTIONS_SIZE(newnum);
-       if (newsize == 0)
+       if (newsize == 0) {
                return ENOMEM;
+       }
 
        /*
         * XXX may want to impose an administrative limit here; POSIX does
@@ -1092,26 +1124,29 @@ _posix_spawn_file_actions_grow(_posix_spawn_file_actions_t *psactsp)
  */
 int
 posix_spawn_file_actions_addopen(
-               posix_spawn_file_actions_t * __restrict file_actions,
-               int filedes, const char * __restrict path, int oflag,
-               mode_t mode)
+       posix_spawn_file_actions_t * __restrict file_actions,
+       int filedes, const char * __restrict path, int oflag,
+       mode_t mode)
 {
        _posix_spawn_file_actions_t *psactsp;
        _psfa_action_t *psfileact;
 
-       if (file_actions == NULL || *file_actions == NULL)
+       if (file_actions == NULL || *file_actions == NULL) {
                return EINVAL;
+       }
 
        psactsp = (_posix_spawn_file_actions_t *)file_actions;
        /* Range check; required by POSIX */
-       if (filedes < 0 || filedes >= OPEN_MAX)
-               return (EBADF);
+       if (filedes < 0 || filedes >= OPEN_MAX) {
+               return EBADF;
+       }
 
        /* If we do not have enough slots, grow the structure */
        if ((*psactsp)->psfa_act_count == (*psactsp)->psfa_act_alloc) {
                /* need to grow file actions structure */
-               if (_posix_spawn_file_actions_grow(psactsp))
-                       return (ENOMEM);
+               if (_posix_spawn_file_actions_grow(psactsp)) {
+                       return ENOMEM;
+               }
        }
 
        /*
@@ -1125,7 +1160,7 @@ posix_spawn_file_actions_addopen(
        psfileact->psfaa_openargs.psfao_mode = mode;
        strlcpy(psfileact->psfaa_openargs.psfao_path, path, PATH_MAX);
 
-       return (0);
+       return 0;
 }
 
 
@@ -1151,24 +1186,27 @@ posix_spawn_file_actions_addopen(
  */
 int
 posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions,
-               int filedes)
+    int filedes)
 {
        _posix_spawn_file_actions_t *psactsp;
        _psfa_action_t *psfileact;
 
-       if (file_actions == NULL || *file_actions == NULL)
+       if (file_actions == NULL || *file_actions == NULL) {
                return EINVAL;
+       }
 
        psactsp = (_posix_spawn_file_actions_t *)file_actions;
        /* Range check; required by POSIX */
-       if (filedes < 0 || filedes >= OPEN_MAX)
-               return (EBADF);
+       if (filedes < 0 || filedes >= OPEN_MAX) {
+               return EBADF;
+       }
 
        /* If we do not have enough slots, grow the structure */
        if ((*psactsp)->psfa_act_count == (*psactsp)->psfa_act_alloc) {
                /* need to grow file actions structure */
-               if (_posix_spawn_file_actions_grow(psactsp))
-                       return (ENOMEM);
+               if (_posix_spawn_file_actions_grow(psactsp)) {
+                       return ENOMEM;
+               }
        }
 
        /*
@@ -1179,7 +1217,7 @@ posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions,
        psfileact->psfaa_type = PSFA_CLOSE;
        psfileact->psfaa_filedes = filedes;
 
-       return (0);
+       return 0;
 }
 
 
@@ -1207,25 +1245,28 @@ posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *file_actions,
  */
 int
 posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions,
-               int filedes, int newfiledes)
+    int filedes, int newfiledes)
 {
        _posix_spawn_file_actions_t *psactsp;
        _psfa_action_t *psfileact;
 
-       if (file_actions == NULL || *file_actions == NULL)
+       if (file_actions == NULL || *file_actions == NULL) {
                return EINVAL;
+       }
 
        psactsp = (_posix_spawn_file_actions_t *)file_actions;
        /* Range check; required by POSIX */
        if (filedes < 0 || filedes >= OPEN_MAX ||
-           newfiledes < 0 || newfiledes >= OPEN_MAX)
-               return (EBADF);
+           newfiledes < 0 || newfiledes >= OPEN_MAX) {
+               return EBADF;
+       }
 
        /* If we do not have enough slots, grow the structure */
        if ((*psactsp)->psfa_act_count == (*psactsp)->psfa_act_alloc) {
                /* need to grow file actions structure */
-               if (_posix_spawn_file_actions_grow(psactsp))
-                       return (ENOMEM);
+               if (_posix_spawn_file_actions_grow(psactsp)) {
+                       return ENOMEM;
+               }
        }
 
        /*
@@ -1237,7 +1278,7 @@ posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions,
        psfileact->psfaa_filedes = filedes;
        psfileact->psfaa_openargs.psfao_oflag = newfiledes;
 
-       return (0);
+       return 0;
 }
 
 /*
@@ -1275,25 +1316,28 @@ posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *file_actions,
  */
 int
 posix_spawn_file_actions_addinherit_np(posix_spawn_file_actions_t *file_actions,
-               int filedes)
+    int filedes)
 {
        _posix_spawn_file_actions_t *psactsp;
        _psfa_action_t *psfileact;
 
-       if (file_actions == NULL || *file_actions == NULL)
-               return (EINVAL);
+       if (file_actions == NULL || *file_actions == NULL) {
+               return EINVAL;
+       }
 
        psactsp = (_posix_spawn_file_actions_t *)file_actions;
        /* Range check; required by POSIX */
-       if (filedes < 0 || filedes >= OPEN_MAX)
-               return (EBADF);
+       if (filedes < 0 || filedes >= OPEN_MAX) {
+               return EBADF;
+       }
 
-#if defined(POSIX_SPAWN_CLOEXEC_DEFAULT)       // TODO: delete this check
+#if defined(POSIX_SPAWN_CLOEXEC_DEFAULT)        // TODO: delete this check
        /* If we do not have enough slots, grow the structure */
        if ((*psactsp)->psfa_act_count == (*psactsp)->psfa_act_alloc) {
                /* need to grow file actions structure */
-               if (_posix_spawn_file_actions_grow(psactsp))
-                       return (ENOMEM);
+               if (_posix_spawn_file_actions_grow(psactsp)) {
+                       return ENOMEM;
+               }
        }
 
        /*
@@ -1304,47 +1348,49 @@ posix_spawn_file_actions_addinherit_np(posix_spawn_file_actions_t *file_actions,
        psfileact->psfaa_type = PSFA_INHERIT;
        psfileact->psfaa_filedes = filedes;
 #endif
-       return (0);
+       return 0;
 }
 
 int
 posix_spawnattr_setcpumonitor_default(posix_spawnattr_t * __restrict attr)
 {
-       return (posix_spawnattr_setcpumonitor(attr, PROC_POLICY_CPUMON_DEFAULTS, 0));
+       return posix_spawnattr_setcpumonitor(attr, PROC_POLICY_CPUMON_DEFAULTS, 0);
 }
 
 int
 posix_spawnattr_setcpumonitor(posix_spawnattr_t * __restrict attr,
-               uint64_t percent, uint64_t interval)
+    uint64_t percent, uint64_t interval)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
-               return (EINVAL);
+       if (attr == NULL || *attr == NULL) {
+               return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
        psattr->psa_cpumonitor_percent = percent;
        psattr->psa_cpumonitor_interval = interval;
 
-       return (0);                     
+       return 0;
 }
 
 int
 posix_spawnattr_getcpumonitor(posix_spawnattr_t * __restrict attr,
-               uint64_t *percent, uint64_t *interval)
+    uint64_t *percent, uint64_t *interval)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
-               return (EINVAL);
+       if (attr == NULL || *attr == NULL) {
+               return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
        *percent = psattr->psa_cpumonitor_percent;
        *interval = psattr->psa_cpumonitor_interval;
 
-       return (0);
+       return 0;
 }
 
 #if TARGET_OS_EMBEDDED
@@ -1367,19 +1413,19 @@ posix_spawnattr_getcpumonitor(posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_setjetsam(posix_spawnattr_t * __restrict attr,
-               short flags, int priority, int memlimit)
+    short flags, int priority, int memlimit)
 {
        short flags_ext = flags;
 
-        if (flags & POSIX_SPAWN_JETSAM_MEMLIMIT_FATAL) {
-                flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
-                flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
-        } else {
-                flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
-                flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
-        }
+       if (flags & POSIX_SPAWN_JETSAM_MEMLIMIT_FATAL) {
+               flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
+               flags_ext |= POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
+       } else {
+               flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_ACTIVE_FATAL;
+               flags_ext &= ~POSIX_SPAWN_JETSAM_MEMLIMIT_INACTIVE_FATAL;
+       }
 
-       return (posix_spawnattr_setjetsam_ext(attr, flags_ext, priority, memlimit, memlimit));
+       return posix_spawnattr_setjetsam_ext(attr, flags_ext, priority, memlimit, memlimit);
 }
 #endif /* TARGET_OS_EMBEDDED */
 
@@ -1402,12 +1448,13 @@ posix_spawnattr_setjetsam(posix_spawnattr_t * __restrict attr,
  */
 int
 posix_spawnattr_setjetsam_ext(posix_spawnattr_t * __restrict attr,
-       short flags, int priority, int memlimit_active, int memlimit_inactive)
+    short flags, int priority, int memlimit_active, int memlimit_inactive)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
@@ -1417,24 +1464,24 @@ posix_spawnattr_setjetsam_ext(posix_spawnattr_t * __restrict attr,
        psattr->psa_memlimit_active = memlimit_active;
        psattr->psa_memlimit_inactive = memlimit_inactive;
 
-       return (0);
+       return 0;
 }
 
 int
 posix_spawnattr_set_threadlimit_ext(posix_spawnattr_t * __restrict attr,
-       int thread_limit)
+    int thread_limit)
 {
        _posix_spawnattr_t psattr;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
        psattr->psa_thread_limit = thread_limit;
 
-       return (0);
-
+       return 0;
 }
 
 
@@ -1442,12 +1489,12 @@ posix_spawnattr_set_threadlimit_ext(posix_spawnattr_t * __restrict attr,
  * posix_spawnattr_set_importancewatch_port_np
  *
  * Description:        Mark ports referred to by these rights
- *              to boost the new task instead of their current task 
+ *              to boost the new task instead of their current task
  *              for the spawn attribute object referred to by 'attr'.
  *              Ports must be valid at posix_spawn time.  They will NOT be
  *              consumed by the kernel, so they must be deallocated after the spawn returns.
  *              (If you are SETEXEC-ing, they are cleaned up by the exec operation).
- * 
+ *
  *              The maximum number of watch ports allowed is defined by POSIX_SPAWN_IMPORTANCE_PORT_COUNT.
  *
  * Parameters: count           Number of ports in portarray
@@ -1458,9 +1505,9 @@ posix_spawnattr_set_threadlimit_ext(posix_spawnattr_t * __restrict attr,
  *              ENOMEM  Insufficient memory exists to add to
  *                      the spawn port actions object.
  */
-int     
+int
 posix_spawnattr_set_importancewatch_port_np(posix_spawnattr_t * __restrict attr,
-                 int count, mach_port_t portarray[]) 
+    int count, mach_port_t portarray[])
 {
        int err = 0, i;
 
@@ -1489,31 +1536,35 @@ posix_spawnattr_macpolicyinfo_lookup(_posix_spawn_mac_policy_extensions_t psmx,
 {
        int i;
 
-       if (psmx == NULL)
+       if (psmx == NULL) {
                return NULL;
-       
+       }
+
        for (i = 0; i < psmx->psmx_count; i++) {
                _ps_mac_policy_extension_t *extension = &psmx->psmx_extensions[i];
-               if (strcmp(extension->policyname, policyname) == 0)
+               if (strcmp(extension->policyname, policyname) == 0) {
                        return extension;
+               }
        }
        return NULL;
 }
 
 int
 posix_spawnattr_getmacpolicyinfo_np(const posix_spawnattr_t * __restrict attr,
-               const char *policyname, void **datap, size_t *datalenp)
+    const char *policyname, void **datap, size_t *datalenp)
 {
        _posix_spawnattr_t psattr;
        _ps_mac_policy_extension_t *extension;
 
-       if (attr == NULL || *attr == NULL || policyname == NULL || datap == NULL)
+       if (attr == NULL || *attr == NULL || policyname == NULL || datap == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        extension = posix_spawnattr_macpolicyinfo_lookup(psattr->psa_mac_extensions, policyname);
-       if (extension == NULL)
+       if (extension == NULL) {
                return ESRCH;
+       }
        *datap = (void *)(uintptr_t)extension->data;
        if (datalenp != NULL) {
                *datalenp = (size_t)extension->datalen;
@@ -1523,14 +1574,15 @@ posix_spawnattr_getmacpolicyinfo_np(const posix_spawnattr_t * __restrict attr,
 
 int
 posix_spawnattr_setmacpolicyinfo_np(posix_spawnattr_t * __restrict attr,
-               const char *policyname, void *data, size_t datalen)
+    const char *policyname, void *data, size_t datalen)
 {
        _posix_spawnattr_t psattr;
        _posix_spawn_mac_policy_extensions_t psmx;
        _ps_mac_policy_extension_t *extension;
 
-       if (attr == NULL || *attr == NULL || policyname == NULL)
+       if (attr == NULL || *attr == NULL || policyname == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psmx = psattr->psa_mac_extensions;
@@ -1539,24 +1591,26 @@ posix_spawnattr_setmacpolicyinfo_np(posix_spawnattr_t * __restrict attr,
                extension->data = (uintptr_t)data;
                extension->datalen = datalen;
                return 0;
-       }
-       else if (psmx == NULL) {
+       } else if (psmx == NULL) {
                psmx = psattr->psa_mac_extensions = malloc(PS_MAC_EXTENSIONS_SIZE(PS_MAC_EXTENSIONS_INIT_COUNT));
-               if (psmx == NULL)
+               if (psmx == NULL) {
                        return ENOMEM;
+               }
                psmx->psmx_alloc = PS_MAC_EXTENSIONS_INIT_COUNT;
                psmx->psmx_count = 0;
-       }
-       else if (psmx->psmx_count == psmx->psmx_alloc) {
+       } else if (psmx->psmx_count == psmx->psmx_alloc) {
                int newnum = 0;
-               if (os_mul_overflow(psmx->psmx_alloc, 2, &newnum))
+               if (os_mul_overflow(psmx->psmx_alloc, 2, &newnum)) {
                        return ENOMEM;
+               }
                size_t extsize = PS_MAC_EXTENSIONS_SIZE(newnum);
-               if (extsize == 0)
+               if (extsize == 0) {
                        return ENOMEM;
+               }
                psmx = psattr->psa_mac_extensions = reallocf(psmx, extsize);
-               if (psmx == NULL)
+               if (psmx == NULL) {
                        return ENOMEM;
+               }
                psmx->psmx_alloc = newnum;
        }
        extension = &psmx->psmx_extensions[psmx->psmx_count];
@@ -1567,8 +1621,9 @@ posix_spawnattr_setmacpolicyinfo_np(posix_spawnattr_t * __restrict attr,
        return 0;
 }
 
-int posix_spawnattr_setcoalition_np(const posix_spawnattr_t * __restrict attr,
-                                   uint64_t coalitionid, int type, int role)
+int
+posix_spawnattr_setcoalition_np(const posix_spawnattr_t * __restrict attr,
+    uint64_t coalitionid, int type, int role)
 {
        _posix_spawnattr_t psattr;
        struct _posix_spawn_coalition_info *coal_info;
@@ -1576,16 +1631,18 @@ int posix_spawnattr_setcoalition_np(const posix_spawnattr_t * __restrict attr,
        if (attr == NULL || *attr == NULL) {
                return EINVAL;
        }
-       if (type < 0 || type > COALITION_TYPE_MAX)
+       if (type < 0 || type > COALITION_TYPE_MAX) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
        coal_info = psattr->psa_coalition_info;
        if (!coal_info) {
                coal_info = (struct _posix_spawn_coalition_info *)malloc(sizeof(*coal_info));
-               if (!coal_info)
+               if (!coal_info) {
                        return ENOMEM;
+               }
                memset(coal_info, 0, sizeof(*coal_info));
                psattr->psa_coalition_info = coal_info;
        }
@@ -1597,7 +1654,8 @@ int posix_spawnattr_setcoalition_np(const posix_spawnattr_t * __restrict attr,
 }
 
 
-int posix_spawnattr_set_qos_clamp_np(const posix_spawnattr_t * __restrict attr, uint64_t qos_clamp)
+int
+posix_spawnattr_set_qos_clamp_np(const posix_spawnattr_t * __restrict attr, uint64_t qos_clamp)
 {
        _posix_spawnattr_t psattr;
 
@@ -1605,8 +1663,9 @@ int posix_spawnattr_set_qos_clamp_np(const posix_spawnattr_t * __restrict attr,
                return EINVAL;
        }
 
-       if (qos_clamp >= POSIX_SPAWN_PROC_CLAMP_LAST)
+       if (qos_clamp >= POSIX_SPAWN_PROC_CLAMP_LAST) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        psattr->psa_qos_clamp = qos_clamp;
@@ -1626,10 +1685,11 @@ posix_spawnattr_get_qos_clamp_np(const posix_spawnattr_t * __restrict attr, uint
        psattr = *(_posix_spawnattr_t *)attr;
        *qos_clampp = psattr->psa_qos_clamp;
 
-       return (0);
+       return 0;
 }
 
-int posix_spawnattr_set_darwin_role_np(const posix_spawnattr_t * __restrict attr, uint64_t darwin_role)
+int
+posix_spawnattr_set_darwin_role_np(const posix_spawnattr_t * __restrict attr, uint64_t darwin_role)
 {
        _posix_spawnattr_t psattr;
 
@@ -1655,7 +1715,7 @@ posix_spawnattr_get_darwin_role_np(const posix_spawnattr_t * __restrict attr, ui
        psattr = *(_posix_spawnattr_t *)attr;
        *darwin_rolep = psattr->psa_darwin_role;
 
-       return (0);
+       return 0;
 }
 
 
@@ -1665,19 +1725,22 @@ posix_spawnattr_set_persona_np(const posix_spawnattr_t * __restrict attr, uid_t
        _posix_spawnattr_t psattr;
        struct _posix_spawn_persona_info *persona;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
-       if (flags & ~POSIX_SPAWN_PERSONA_ALL_FLAGS)
+       if (flags & ~POSIX_SPAWN_PERSONA_ALL_FLAGS) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
 
        persona = psattr->psa_persona_info;
        if (!persona) {
                persona = (struct _posix_spawn_persona_info *)malloc(sizeof(*persona));
-               if (!persona)
+               if (!persona) {
                        return ENOMEM;
+               }
                persona->pspi_uid = 0;
                persona->pspi_gid = 0;
                persona->pspi_ngroups = 0;
@@ -1698,16 +1761,19 @@ posix_spawnattr_set_persona_uid_np(const posix_spawnattr_t * __restrict attr, ui
        _posix_spawnattr_t psattr;
        struct _posix_spawn_persona_info *persona;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        persona = psattr->psa_persona_info;
-       if (!persona)
+       if (!persona) {
                return EINVAL;
+       }
 
-       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY)))
+       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY))) {
                return EINVAL;
+       }
 
        persona->pspi_uid = uid;
 
@@ -1722,16 +1788,19 @@ posix_spawnattr_set_persona_gid_np(const posix_spawnattr_t * __restrict attr, gi
        _posix_spawnattr_t psattr;
        struct _posix_spawn_persona_info *persona;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        persona = psattr->psa_persona_info;
-       if (!persona)
+       if (!persona) {
                return EINVAL;
+       }
 
-       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY)))
+       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY))) {
                return EINVAL;
+       }
 
        persona->pspi_gid = gid;
 
@@ -1746,26 +1815,32 @@ posix_spawnattr_set_persona_groups_np(const posix_spawnattr_t * __restrict attr,
        _posix_spawnattr_t psattr;
        struct _posix_spawn_persona_info *persona;
 
-       if (attr == NULL || *attr == NULL)
+       if (attr == NULL || *attr == NULL) {
                return EINVAL;
+       }
 
-       if (gidarray == NULL)
+       if (gidarray == NULL) {
                return EINVAL;
+       }
 
-       if (ngroups > NGROUPS || ngroups < 0)
+       if (ngroups > NGROUPS || ngroups < 0) {
                return EINVAL;
+       }
 
        psattr = *(_posix_spawnattr_t *)attr;
        persona = psattr->psa_persona_info;
-       if (!persona)
+       if (!persona) {
                return EINVAL;
+       }
 
-       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY)))
+       if (!(persona->pspi_flags & (POSIX_SPAWN_PERSONA_FLAGS_OVERRIDE | POSIX_SPAWN_PERSONA_FLAGS_VERIFY))) {
                return EINVAL;
+       }
 
        persona->pspi_ngroups = ngroups;
-       for (int i = 0; i < ngroups; i++)
+       for (int i = 0; i < ngroups; i++) {
                persona->pspi_groups[i] = gidarray[i];
+       }
 
        persona->pspi_gmuid = gmuid;
 
@@ -1819,14 +1894,14 @@ posix_spawnattr_set_max_addr_np(const posix_spawnattr_t * __restrict attr, uint6
  *             0 or a -1, with the 'errno' variable being set.
  */
 extern int __posix_spawn(pid_t * __restrict, const char * __restrict,
-               struct _posix_spawn_args_desc *,
-               char *const argv[ __restrict], char *const envp[ __restrict]);
+    struct _posix_spawn_args_desc *,
+    char *const argv[__restrict], char *const envp[__restrict]);
 
 int
 posix_spawn(pid_t * __restrict pid, const char * __restrict path,
-               const posix_spawn_file_actions_t *file_actions,
-               const posix_spawnattr_t * __restrict attrp,
-               char *const argv[ __restrict], char *const envp[ __restrict])
+    const posix_spawn_file_actions_t *file_actions,
+    const posix_spawnattr_t * __restrict attrp,
+    char *const argv[__restrict], char *const envp[__restrict])
 {
        int saveerrno = errno;
        int ret;
@@ -1843,8 +1918,8 @@ posix_spawn(pid_t * __restrict pid, const char * __restrict path,
         *              kernel efficiency, even though it would mean copying
         *              the data in user space.
         */
-       if ((file_actions != NULL && (*file_actions != NULL) && (*(_posix_spawn_file_actions_t *)file_actions)->psfa_act_count > 0) || attrp != NULL) {
-               struct _posix_spawn_args_desc   ad;
+       if ((file_actions != NULL && (*file_actions != NULL) && (*(_posix_spawn_file_actions_t *)file_actions)->psfa_act_count > 0) || attrp != NULL) {
+               struct _posix_spawn_args_desc   ad;
 
                memset(&ad, 0, sizeof(ad));
                if (attrp != NULL && *attrp != NULL) {
@@ -1883,7 +1958,7 @@ posix_spawn(pid_t * __restrict pid, const char * __restrict path,
                }
                if (file_actions != NULL && *file_actions != NULL) {
                        _posix_spawn_file_actions_t psactsp =
-                               *(_posix_spawn_file_actions_t *)file_actions;
+                           *(_posix_spawn_file_actions_t *)file_actions;
 
                        if (psactsp->psfa_act_count > 0) {
                                size_t fa_size = PSF_ACTIONS_SIZE(psactsp->psfa_act_count);
@@ -1898,13 +1973,14 @@ posix_spawn(pid_t * __restrict pid, const char * __restrict path,
                }
 
                ret = __posix_spawn(pid, path, &ad, argv, envp);
-       } else
+       } else {
                ret = __posix_spawn(pid, path, NULL, argv, envp);
+       }
 
 out:
-       if (ret < 0)
+       if (ret < 0) {
                ret = errno;
+       }
        errno = saveerrno;
        return ret;
 }
-