Hi Alin,

Thanks for the patch. The patch looks good, I have one comment regarding the 
GetConsoldeMode function.  I’m not sure if it works. 

I have tried with the below snippet, where I create a new file but the windows 
api returns saying it’s a console device.  
int main()
{
    FILE *fp;
    fopen_s(&fp, "c:\\test.txt", "w");
    if (fp) {
        fprintf(fp, "Testing...\n");
        DWORD st;
        HANDLE h = (HANDLE)GetConsoleMode(fp, &st);
        if (!h) {
            cout << "fp is a console device" << endl;
        }
    }
    return 1;
}

Thanks,
Anand Kumar

On 6/20/17, 9:31 AM, "[email protected] on behalf of Alin 
Serdean" <[email protected] on behalf of 
[email protected]> wrote:

    A lot of tests are failing, due to the open flow ports being outputted using
    names instead of numbers.
    i.e.: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__64.119.130.115_ovs_beb75a40fdc295bfd6521b0068b4cd12f6de507c_testsuite.dir_0464_testsuite.log.gz&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=CGuqGiDcmX3tZIwlJ1DfSxGFZkG-ckHEwsA_c_d3yn4&s=Ymd9_o221AghzrFqOgvnze_Rh9LgtMiY__TpM3PbH-k&e=
 
    
    The issues encountered above is because 'monitor' with 'detach' arguments 
are
    specified, that in turn will call 'close_standard_fds'
    
(https://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_openvswitch_ovs_blob_master_lib_daemon-2Dunix.c-23L472&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=CGuqGiDcmX3tZIwlJ1DfSxGFZkG-ckHEwsA_c_d3yn4&s=zg3LX3FU_KPT_oPNRxB2uaOIIKtO3Z-egrYPvbvtzuo&e=
 )
    which will create a duplicate fd over '/dev/null' on Linux and 'nul' on 
Windows.
    
    'isatty' will be called on those FDs.
    What POSIX standard says:
    http://pubs.opengroup.org/onlinepubs/009695399/functions/isatty.html
    'The isatty() function shall test whether fildes, an open file descriptor,
    is associated with a terminal device.'
    What MSDN says:
    
https://urldefense.proofpoint.com/v2/url?u=https-3A__msdn.microsoft.com_en-2Dus_library_f4s0ddew-28VS.80-29.aspx&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=CGuqGiDcmX3tZIwlJ1DfSxGFZkG-ckHEwsA_c_d3yn4&s=za4o0AOFT9niZXeFyVNlJjsnV8ej5fZFSzgWNuLGmAQ&e=
 
    'The _isatty function determines whether fd is associated with a character
    device (a terminal, console, printer, or serial port).'
    
    This patch adds another check using 'GetConsoleMode'
    
https://urldefense.proofpoint.com/v2/url?u=https-3A__msdn.microsoft.com_en-2Dus_library_windows_desktop_ms683167-28v-3Dvs.85-29.aspx&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=CGuqGiDcmX3tZIwlJ1DfSxGFZkG-ckHEwsA_c_d3yn4&s=s4HNhvjdGmxVDt7aA9S1NGvXVJJit8C78EF_z5VKT5g&e=
 
    which will fail if the handle pointing to the file descriptor is not 
associated
    to a console.
    
    Signed-off-by: Alin Gabriel Serdean <[email protected]>
    Co-authroed-by: Ben Pfaff <[email protected]>
    ---
    v2 replace `isatty` in unistd.h
    ---
     include/windows/unistd.h | 16 ++++++++++++++++
     1 file changed, 16 insertions(+)
    
    diff --git a/include/windows/unistd.h b/include/windows/unistd.h
    index 2e9f0ae..21cc56f 100644
    --- a/include/windows/unistd.h
    +++ b/include/windows/unistd.h
    @@ -85,4 +85,20 @@ __inline long sysconf(int type)
         return value;
     }
     
    +/* On Windows, a console is a specialized character device, and isatty() 
only
    + * reports whether a file description is a character device and thus 
reports
    + * that devices such as /dev/null are ttys.  This replacement avoids that
    + * problem. */
    +#undef isatty
    +#define isatty(fd) rpl_isatty(fd)
    +static __inline int
    +rpl_isatty(int fd)
    +{
    +    HANDLE h = (HANDLE) _get_osfhandle(fd);
    +    DWORD st;
    +    return (_isatty(STDOUT_FILENO)
    +            && h != INVALID_HANDLE_VALUE
    +            && GetConsoleMode(h, &st));
    +}
    +
     #endif /* unistd.h  */
    -- 
    2.10.2.windows.1
    _______________________________________________
    dev mailing list
    [email protected]
    
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.openvswitch.org_mailman_listinfo_ovs-2Ddev&d=DwICAg&c=uilaK90D4TOVoH58JNXRgQ&r=Q5z9tBe-nAOpE7LIHSPV8uy5-437agMXvkeHHMkR8Us&m=CGuqGiDcmX3tZIwlJ1DfSxGFZkG-ckHEwsA_c_d3yn4&s=_2HFoplpvftd-f3R70JtUaNLizu9d6CLtQTV2gGMW_c&e=
 
    

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to