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

rpc-sys packagelist lists 'not-installed' packages #6

Open
efahl opened this issue Jul 10, 2024 · 3 comments · May be fixed by #8
Open

rpc-sys packagelist lists 'not-installed' packages #6

efahl opened this issue Jul 10, 2024 · 3 comments · May be fixed by #8

Comments

@efahl
Copy link
Contributor

efahl commented Jul 10, 2024

@jck112 @dangowrt

Running x86/64 SNAPSHOT r26829.

Expecting to get libustream-mbedtls only, but get the openssl version:

$ ubus call rpc-sys packagelist '{"all":false}' | grep libustream
                "libustream-openssl": "2024.04.19~524a76e5-r1",

$ ubus call rpc-sys packagelist '{"all":true}' | grep libustream
                "libustream-openssl": "2024.04.19~524a76e5-r1",
                "libustream-mbedtls": "2024.04.19~524a76e5-r1",

Looking in the package status we see both packages, but openssl version is not-installed and mbedtls version is installed. (I have no idea how this came to be in this state, I install/remove packages on this test machine constantly.)

$ grep 'Package: libustream' /usr/lib/opkg/status -A7
Package: libustream-openssl20201210
ABIVersion: 20201210
Version: 2024.04.19~524a76e5-r1
Depends: libc, libubox20240329, libopenssl3
Provides: libustream-openssl
Status: install user not-installed    <<<<<<<<<<<<<<<<<<<<<<<<<<< here
Architecture: x86_64

--
Package: libustream-mbedtls20201210
ABIVersion: 20201210
Version: 2024.04.19~524a76e5-r1
Depends: libc, libubox20240329, libmbedtls21
Provides: libustream-mbedtls
Conflicts: libustream-openssl, libustream-wolfssl
Status: install ok installed    <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< here
Architecture: x86_64
Installed-Time: 1719864281
Auto-Installed: yes

Seems like something is not right around https://github.com/openwrt/rpcd/blob/master/sys.c#L241. installed seems like it should be false for the ssl package...

The opkg status file is well-formed; if I manually edit out the whole not-installed package entry, then everything works as expected.

@efahl
Copy link
Contributor Author

efahl commented Jul 10, 2024

Aha, sscanf doesn't match on the tail.

#include <stdio.h>

void check(char *line)
{
    char tmp[128];
    int result = sscanf(line, "Status: install %63s installed", tmp);
    printf("%d >%s< %s\n", result, tmp, line);
}

int main()
{
    check("Hello");
    check("Status: install ok installed\n");
    check("Status: install ok installed");
    check("Status: install user not-installed\n");
    check("Status: install user not-installed");
    check("Status: install any old junk");
}

gives

0 >< Hello
1 >ok< Status: install ok installed

1 >ok< Status: install ok installed
1 >user< Status: install user not-installed

1 >user< Status: install user not-installed
1 >any< Status: install any old junk

@jck112
Copy link
Contributor

jck112 commented Jul 10, 2024

Good catch on the sscanf behavior.

The wanted state is install because an install was requested for libustream-openssl20201210, but it has the current state not-installed because of the conflict with libustream-mbedtls20201210.

We can change the sscanf line to parse the current state into a variable then compare that to "installed".

@efahl
Copy link
Contributor Author

efahl commented Jul 10, 2024

I didn't read through opkg source, which is probably the "specification", but digging through a bunch of status files makes me think that a simple one-liner would work.

    installed = strstr(line, " installed") != NULL;  // Note: leading blank is significant.

dangowrt added a commit to dangowrt/rpcd that referenced this issue Oct 23, 2024
Don't rely on sscanf() doesn't care about unused suffixes of the status
string. Use strstr() instead to make sure only actually installed
packages are returned.

Suggested-by: Eric Fahlgren <ericfahlgren@gmail.com>
Reported-by: Eric Fahlgren <ericfahlgren@gmail.com>
Fixes: openwrt#6
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
@dangowrt dangowrt linked a pull request Oct 23, 2024 that will close this issue
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 a pull request may close this issue.

2 participants