10000 Connection refused when connect /dev/socket/logdr socket · Issue #308 · termux/proot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
8000

Connection refused when connect /dev/socket/logdr socket #308

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

Open
chairwa opened this issue Feb 27, 2025 · 3 comments
Open

Connection refused when connect /dev/socket/logdr socket #308

chairwa opened this issue Feb 27, 2025 · 3 comments

Comments

@chairwa
Copy link
chairwa commented Feb 27, 2025

Problem description
From within proot-distro login ubuntu-oldlts, I failed to connect /dev/socket/logdr socket.

Steps to reproduce
the test program:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <errno.h>

int main() {
    int sock;
    struct sockaddr_un addr;
    
    // create UNIX domain socket
    sock = socket(AF_UNIX, SOCK_SEQPACKET, 0);
    if (sock < 0) {
        printf("socket() failed: %s\n", strerror(errno));
        return 1;
    }
    
    // set socket addr
    memset(&addr, 0, sizeof(addr));
    addr.sun_family = AF_UNIX;
    strncpy(addr.sun_path, "/dev/socket/logdr", sizeof(addr.sun_path) - 1);
    
    // connect socket
    printf("try connect /dev/socket/logdr...\n");
    if (connect(sock, (struct sockaddr*)&addr, sizeof(addr)) < 0) {
        printf("conn failed: %s (errno: %d)\n", strerror(errno), errno);
        close(sock);
        return 1;
    }
    
    printf("conn OK!\n");
    
    // close socket
    close(sock);
    return 0;
}

Expected behavior
connection OK

Additional information
the above code is OK in termux.

@twaik
Copy link
Member
twaik commented Feb 27, 2025

Why exactly do you need connecting logd socket and why can not you use logwrapper?

@chairwa
Copy link
Author
chairwa commented Feb 27, 2025

https://github.com/twoyi/twoyi
As what Twoyi did, I'm trying to run Android rootfs in termux proot environment.

Twoyi's logcat is OK, but my AOSP logcat failed to connect logdr socket. At first, I thought this was permission problem; but I found the above test program is OK in termux.
So the problem might lie in proot.

@chairwa
Copy link
Author
chairwa commented Feb 28, 2025

It seems to be caused by my modifications to proot.
I cannot bind entire /dev to the proot guest,
and -b /dev/socket/logdr will also fail.
proot warning: can't sanitize binding "/dev/socket/logdr": Permission denied

I have to modify the proot code, hoping to achieve direct access to the host's /dev/socket/logdr, without binding and translation, from within the guest.
In the path.c translate_path function, I made the following modification.
Because ECONNREFUSED (Connection refused) occurred, the modification seems not right.

status = canonicalize(tracee, guest_path, deref_final, result, 0);
changed to

    const char *excluded_paths[] = {
        "/dev/socket/logd",
        "/dev/socket/logdr",
        "/dev/socket/logdw"
    };
    const int num_excluded_paths = sizeof(excluded_paths) / sizeof(excluded_paths[0]);

    // Flag variable, used to determine whether to call canonicalize
    int should_canonicalize = 1;
    // Traverse the exclusion path list and check if it matches
    for (int i = 0; i < num_excluded_paths; i++) {
        if (strcmp(guest_path, excluded_paths[i]) == 0) {
            // If matched, set the flag to 0 and exit the loop
            should_canonicalize = 0;
            break;
        }
    }

	if (should_canonicalize) {
		/* Canonicalize regarding the new root. */
		status = canonicalize(tracee, guest_path, deref_final, result, 0);
		if (status < 0)
			return status;
	}

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

No branches or pull requests

2 participants
0