Expect

Check-in [f8e8464f14]
Login
Bounty program for improvements to Tcl and certain Tcl packages.

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:errorfd file descriptors should be closed when forking, otherwize a fd leak occurs. This patch make use of F_DUPFD_CLOEXEC if available or fcntl setting FD_CLOEXEC flag if not. Patch by Clément Chigot.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA1: f8e8464f14c728cf02a7dd51ba91cc25c12859de
User & Date: pyssling 2020-05-31 14:16:14
Context
2020-05-31
14:16
errorfd file descriptors should be closed when forking, otherwize a fd leak occurs. This patch make use of F_DUPFD_CLOEXEC if available or fcntl setting FD_CLOEXEC flag if not. Patch by Clément Chigot. Leaf check-in: f8e8464f14 user: pyssling tags: trunk
2020-05-21
16:55
Replace CONST84 with const. CONST84 is deprecated. Reported by multiple users including Peter da Silva. check-in: 4aa905d5e2 user: pyssling tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to exp_clib.c.

2041
2042
2043
2044
2045
2046
2047



2048


2049
2050
2051
2052
2053
2054
2055
	}
#endif /* TIOCNOTTY */

#endif /* SYSV3 */
#endif /* DO_SETSID */

	/* save error fd while we're setting up new one */



	errorfd = fcntl(2,F_DUPFD,3);


	/* and here is the macro to restore it */
#define restore_error_fd {close(2);fcntl(errorfd,F_DUPFD,2);}

	if (exp_autoallocpty) {

	    close(0);
	    close(1);






>
>
>

>
>







2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
	}
#endif /* TIOCNOTTY */

#endif /* SYSV3 */
#endif /* DO_SETSID */

	/* save error fd while we're setting up new one */
#ifdef F_DUPFD_CLOEXEC
	errorfd = fcntl(2,F_DUPFD_CLOEXEC,3);
#else
	errorfd = fcntl(2,F_DUPFD,3);
	fcntl(errorfd, F_SETFD, FD_CLOEXEC);
#endif /* F_DUPFD_CLOXEC */
	/* and here is the macro to restore it */
#define restore_error_fd {close(2);fcntl(errorfd,F_DUPFD,2);}

	if (exp_autoallocpty) {

	    close(0);
	    close(1);

Changes to exp_command.c.

1157
1158
1159
1160
1161
1162
1163



1164


1165
1166
1167
1168
1169
1170
1171
#endif /* SYSV3 */
#endif /* DO_SETSID */

    /* save stderr elsewhere to avoid BSD4.4 bogosity that warns */
    /* if stty finds dev(stderr) != dev(stdout) */

    /* save error fd while we're setting up new one */



    errorfd = fcntl(2,F_DUPFD,3);


    /* and here is the macro to restore it */
#define restore_error_fd {close(2);fcntl(errorfd,F_DUPFD,2);}

    close(0);
    close(1);
    close(2);







>
>
>

>
>







1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
#endif /* SYSV3 */
#endif /* DO_SETSID */

    /* save stderr elsewhere to avoid BSD4.4 bogosity that warns */
    /* if stty finds dev(stderr) != dev(stdout) */

    /* save error fd while we're setting up new one */
#ifdef F_DUPFD_CLOEXEC
    errorfd = fcntl(2,F_DUPFD_CLOEXEC,3);
#else
    errorfd = fcntl(2,F_DUPFD,3);
    fcntl(errorfd, F_SETFD, FD_CLOEXEC);
#endif /* F_DUPFD_CLOXEC */
    /* and here is the macro to restore it */
#define restore_error_fd {close(2);fcntl(errorfd,F_DUPFD,2);}

    close(0);
    close(1);
    close(2);