Hi Anders,

Please see my comments inline

Thanks
Minh
> Ack with minor comments, marked AndersW> below.
>
> regards,
>
> Anders Widell
>
>
> On 03/19/2018 04:36 AM, Minh Chau wrote:
>> ---
>>   src/base/os_defs.c | 32 +++++++++++++++++++++++++++-----
>>   1 file changed, 27 insertions(+), 5 deletions(-)
>>
>> diff --git a/src/base/os_defs.c b/src/base/os_defs.c
>> index 6f9ec52..79d8631 100644
>> --- a/src/base/os_defs.c
>> +++ b/src/base/os_defs.c
>> @@ -1052,14 +1052,36 @@ uint32_t
>> ncs_os_process_execute_timed(NCS_OS_PROC_EXECUTE_TIMED_INFO *req)
>>               * child */
>>              if (getenv("OPENSAF_KEEP_FD_OPEN_AFTER_FORK") == NULL) {
>>                      /* Close all inherited file descriptors */
>> -                    int i = sysconf(_SC_OPEN_MAX);
>> -                    if (i == -1) {
>> +                    long fd_max = sysconf(_SC_OPEN_MAX);
>> +
>> +                    if (fd_max == -1) {
>>                              syslog(LOG_ERR, "%s: sysconf failed - %s",
>> -                                   __FUNCTION__, strerror(errno));
>> +                                    __FUNCTION__, strerror(errno));
>>                              exit(EXIT_FAILURE);
>>                      }
>> -                    for (i--; i >= 0; --i)
>> -                            (void)close(i); /* close all descriptors */
>> +                    struct dirent *dir_entry = NULL;
>> +                    DIR *dir = opendir("/proc/self/fd");
>> +
>> +                    if (dir != NULL) {
>> +                            while ((dir_entry = readdir(dir)) != NULL) {
>> +                                    if (dir_entry->d_name[0] != '\0') {
>> +                                            char *end_ptr = NULL;
>> +                                            long int fd = 
>> strtol(dir_entry->d_name, &end_ptr, 10);
>
> AndersW> Remove "int".
>
>> +
>> +                                            if (end_ptr != NULL && 
>> end_ptr[0] == '\0' &&
>
> AndersW> I don't think end_ptr can be NULL, so you can simplify the
> expression by removing this check.
[Minh]: yes, the @end_ptr should just point to any elements of @d_name
>
>> +                                                    0 <= fd && fd <= 
>> fd_max) {
>
> AndersW> "fd <= fd_max" should be "fd < fd_max"
>
>> +                                                    close((int)fd);
>
> AndersW> Is the cast to int really needed (to avoid compiler warnings)?
> If not, remove it. If it is needed, add a space after (int).
[Minh]: no, just to make right casting to pass to close()
>
>> +                                            }
>> +                                    }
>> +                            }
>> +                            closedir(dir);
>> +                    } else {
>> +                            /* fall back, close all possible descriptors */
>> +                            syslog(LOG_ERR, "%s: opendir failed - %s",
>> +                                    __FUNCTION__, strerror(errno));
>> +                            for (fd_max--; fd_max >= 0; --fd_max)
>> +                                    close((int)fd_max);
> AndersW> Same comment as above.
>> +                    }
>>
>>                      /* Redirect standard files to /dev/null */
>>                      if (freopen("/dev/null", "r", stdin) == NULL)
>
>



------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to