Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dracut-install cleanup #1796

Merged
merged 7 commits into from
Dec 28, 2022
Merged

Conversation

nabijaczleweli
Copy link
Contributor

@nabijaczleweli nabijaczleweli commented Apr 27, 2022

Changes

See individual commit messages; draft because on top of #1794

@nabijaczleweli nabijaczleweli marked this pull request as draft April 27, 2022 18:00
@github-actions github-actions bot added the modules Issue tracker for all modules label Apr 27, 2022
@nabijaczleweli nabijaczleweli force-pushed the clean branch 3 times, most recently from 63c7bf4 to fe30eb0 Compare April 27, 2022 21:52

realpath_p = realpath(target_dir_p, NULL);
if (realpath_p == NULL) {
if (realpath(target_dir_p, relative_from) == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative_from as a temporary buffer to build realfrom and realtarget is fine, but its name is confusing. Maybe rename it to buf or whatever? (comments below will need update in this case)

@stale
Copy link

stale bot commented May 30, 2022

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

@stale stale bot added the stale communication is stuck label May 30, 2022
@nabijaczleweli
Copy link
Contributor Author

bad bot

@stale stale bot removed the stale communication is stuck label May 30, 2022
@nabijaczleweli nabijaczleweli marked this pull request as ready for review June 9, 2022 23:54
@github-actions github-actions bot removed the modules Issue tracker for all modules label Jun 9, 2022
@nabijaczleweli
Copy link
Contributor Author

rebased

if (vfork() == 0) {
dup2(fds[1], 1);
dup2(fds[1], 2);
execlp(ldd, ldd, fullsrcpath, (char *)NULL);
Copy link
Contributor

@marcosfrm marcosfrm Jun 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will break at least the "command not found" case, that will be considered successful (ret = 0). However current popen() code is also broken for non-english locales: sh and ldd output is internationalized and error messages do not match.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this actually depends on the "command not found" bash output? sh -c obviously outputs sh: 1: ldd: not found, like it has for the past 30+ years. Wild. Added a "command not found" write to compensate.

The latter fixed by setting LC_ALL=C.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if checking wstatus could simplify things, like:

        pid_t pid = fork();
        if (pid == 0) {
                dup2(fds[1], 1);
                dup2(fds[1], 2);
                putenv("LC_ALL=C");
                execlp(ldd, ldd, fullsrcpath, (char *)NULL);
                _exit(EXIT_FAILURE);
        }
        close(fds[1]);

        while (waitpid(pid, &ret, 0) < 0) {
                if (errno != EINTR) {
                        ret = 1;
                        break;
                }
        }

        if (ret != 0) {
                log_error("ERROR: failed to run '%s %s'", ldd, fullsrcpath);
                return 1;
        }

        while (getline(&buf, &linesize, fptr) >= 0) {

        ...

(dropped err)

Then clean up strstr() calls below, removing the ones which correspond to unclean exit codes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, there's three strings

"you do not have execution permission"
"unable to find sysroot"
"command not found"

The last one is obviously from bash, but (my) ldd (or ld.so) doesn't contain the other two. Are they all foldable together to $? != 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"you do not have execution permission" is generated by ldd itself:

$ cp -p /usr/bin/true .
$ chmod -x true
$ LANG=C ldd true
ldd: warning: you do not have execution permission for `./true'
        linux-vdso.so.1 (0x00007ffe08fd3000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fe9f8a28000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fe9f8c38000)

The exit code is 0... maybe ignore the warning? Dunno.

"unable to find sysroot" appears to come from https://github.com/crosstool-ng/crosstool-ng/blob/8fa98eeeff9bc53478d97ef722f366fea151ae64/scripts/xldd.in#L170 , so it must stay I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oddly, I don't see it on bullseye:

$ cp /bin/rm .
$ chmod -x rm
$ ldd ./rm
        linux-vdso.so.1 (0x00007ffdef1d4000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f70fc5fb000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f70fc42e000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f70fc2ea000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f70fc125000)
        libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f70fc08d000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f70fc087000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f70fc649000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f70fc06b000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f70fc049000)

And grepping through ldd there's a "you have no read" but no "you have no execute".

Would love a hard opinion on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am on Fedora 36 here btw. "you do not have execution permission" was added in

b4dc22c

hence it must stay too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, if the noexec case makes ldd exit code != 0, then drop it. Needs testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out this is a Debian patch, all/local-ldd.diff:

-    test -x "$file" || echo 'ldd:' $"\
-warning: you do not have execution permission for" "\`$file'" >&2

Applied != 0 => ret += 1; retained all except for "command not found"

@nabijaczleweli nabijaczleweli force-pushed the clean branch 4 times, most recently from 60a6afc to e5d9df8 Compare June 15, 2022 20:21
wait(&err);
while (waitpid(ldd_pid, &err, 0) == -1) {
if (errno != EINTR) {
if (err != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waitpid() returns the terminated pid (> 0) when sucessfull, but its exit status still can be abnormal: non-zero exit code, killed by signal... hence err != 0 check and error message print need to be outside the loop[*]. If waitpid() < 0 and errno != EINTR things are broken and we must assume everything failed: err in this case cannot be trusted (I think most implementations do not change it, not sure). Set it to anything non-zero.

write(2, "command not found", ...) is not needed. Also, to print meaningful exit codes/signals in the error message, it would need WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, macros. Overkill in my opinion.

[*] cp() function (normal_copy label) is buggy in this regard too, because those log_error() will not run in case of normal errors, when waitpid() succeeds (missing cp binary, etc).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was clearly in no state to be writing this last night, because this is an obvious error; I've fixed this and cp.

@nabijaczleweli nabijaczleweli force-pushed the clean branch 4 times, most recently from 7943cd0 to bb96d3d Compare June 16, 2022 16:39
@marcosfrm
Copy link
Contributor

LGTM

@marcosfrm
Copy link
Contributor

Can this go in to get more testing?

@stale
Copy link

stale bot commented Oct 8, 2022

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

@stale stale bot added the stale communication is stuck label Oct 8, 2022
@nabijaczleweli
Copy link
Contributor Author

bad bot

@stale stale bot removed the stale communication is stuck label Oct 8, 2022
@stale
Copy link

stale bot commented Nov 9, 2022

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

@stale stale bot added the stale communication is stuck label Nov 9, 2022
@marcosfrm
Copy link
Contributor

ping

@stale stale bot removed the stale communication is stuck label Nov 11, 2022
@nabijaczleweli
Copy link
Contributor Author

pong. looks fine on my end?

@stale
Copy link

stale bot commented Dec 11, 2022

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.

@stale stale bot added the stale communication is stuck label Dec 11, 2022
@nabijaczleweli
Copy link
Contributor Author

so true, bestie

@stale stale bot removed the stale communication is stuck label Dec 11, 2022
@LaszloGombos
Copy link
Collaborator

Personally, I would prefer having #1987 around to help out for these reviews. Not sure if someone there is a way to do a run just for this PR.

@johannbg
Copy link
Collaborator

unresolved conversation and un-requested re-reviews ( @marcosfrm acked in comment section not in the review process ) has the tendency to get pr ignored from those of us that are quite busy anyways let's not merge this until in 059 milestone

@johannbg johannbg added this to the dracut-059 milestone Dec 21, 2022
aafeijoo-suse added a commit to aafeijoo-suse/dracut that referenced this pull request Dec 28, 2022
Copy link
Member

@aafeijoo-suse aafeijoo-suse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything I was able to check and test went well, so let's merge this.

@aafeijoo-suse aafeijoo-suse merged commit 94dcac7 into dracutdevs:master Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants