[LTP] connect01: Convert to new API
Wei Gao
wegao@suse.com
Thu May 28 06:43:05 CEST 2026
On Mon, May 25, 2026 at 10:12:54AM +0000, linuxtestproject.agent@gmail.com wrote:
> Hi Wei,
>
> On Mon, 25 May 2026, Wei Gao wrote:
> > connect01: Convert to new API
>
> > +// SPDX-License-Identifier: GPL-2.0-or-later
> > /*
> > - *
> > - * Copyright (c) International Business Machines Corp., 2001
> > + * Copyright (c) International Business Machines Corp., 2001
> > + * Copyright (c) Linux Test Project, 2006-2024
>
> The patch is from 2026; the LTP copyright year should be updated to 2006-2026.
>
> > +static int sys_connect(int sockfd, const struct sockaddr *addr,
> > + socklen_t addrlen)
>
> Indentation regressed from two tabs to one. The continuation parameter should
> be aligned with the opening parenthesis (or at minimum two tabs to match the
> original), per kernel coding style.
>
> > + pid = SAFE_FORK();
> > +
> > + if (!pid) {
> > + int nfd = SAFE_ACCEPT(fd_server, NULL, NULL);
> > +
> > + SAFE_CLOSE(nfd);
> > + exit(0);
> > + }
> > + close(fd_server);
>
> Use SAFE_CLOSE() here for consistency.
>
> [...]
>
> --- [PATCH 2/2] connect01: Add negative tests ---
>
> > + fd_unix_server = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0);
> > + SAFE_BIND(fd_unix_server, (struct sockaddr *)&sock4, sizeof(sock4));
> > + SAFE_LISTEN(fd_unix_server, 5);
> > +
> > + fd_unix_dgram = SAFE_SOCKET(AF_UNIX, SOCK_DGRAM, 0);
> > + fd_unix_stream = SAFE_SOCKET(AF_UNIX, SOCK_STREAM, 0);
> > +
> > + pw = SAFE_GETPWNAM("nobody");
>
> The EACCES test relies on "nobody" not having write permission to SOCK_FILE.
> The socket file's permissions are umask-dependent; with umask 0000 the file
> gets mode 0777 and the test would fail spuriously. Add an explicit
> `SAFE_CHMOD(SOCK_FILE, 0700)` after the SAFE_BIND() to make this reliable.
>
> > + if (tc->exp_errno == EACCES) {
> > + if (!SAFE_FORK()) {
> > + SAFE_SETUID(pw->pw_uid);
> > + TST_EXP_FAIL(sys_connect(*tc->fd, addr, tc->salen),
> > + tc->exp_errno, "%s", tc->desc);
> > + exit(0);
> > + }
>
> Result propagation via shared memory with .forks_child = 1 is correct, but
> the exit code is always 0 even on failure. Use `tst_exit()` or exit with the
> appropriate code so that unexpected crashes are also caught by the parent.
> Alternatively this is a style nit if tst_exit() is not the expected pattern
> here.
I think TST_EXP_FAIL already report failure so exit(0) is acceptable.
>
> ---
> Note:
>
> Our agent completed the review of the patch. The full review can be
> found at: https://github.com/linux-test-project/ltp-agent/actions/runs/26394925194
>
> The agent can sometimes produce false positives although often its
> findings are genuine. If you find issues with the review, please
> comment this email or ignore the suggestions.
>
> Regards,
> LTP AI Reviewer
More information about the ltp
mailing list