| 68 | |
| 69 | |
| 70 | int socketAccept(int fd) { |
| 71 | struct sockaddr_un un; |
| 72 | socklen_t len = sizeof(un); |
| 73 | int acceptFd = accept(fd, (struct sockaddr *) &un, &len); |
| 74 | if (acceptFd < 0) { |
| 75 | perr("accept error, fd:%d, ret:%d", fd, acceptFd); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | if (0 > setSocketNonBlock(acceptFd)) { |
| 80 | perr("setSocketNonBlock error, acceptFd:%d", acceptFd); |
| 81 | close(acceptFd); |
| 82 | return -2; |
| 83 | } |
| 84 | |
| 85 | len -= offsetof(struct sockaddr_un, sun_path); |
| 86 | un.sun_path[len] = 0; |
| 87 | char *path = un.sun_path + 1; // pos 0 is \0 |
| 88 | struct ucred ucred; |
| 89 | len = sizeof(struct ucred); |
| 90 | getsockopt(acceptFd, SOL_SOCKET, SO_PEERCRED, &ucred, &len); |
| 91 | pdbg("socketAccept getsockopt pid:%d, uid:%d, gid:%d, len:%d", ucred.pid, ucred.uid, ucred.gid, len); |
| 92 | |
| 93 | uid_t uid = ucred.uid; |
| 94 | pwrn("socketAccept fd:%d, acceptFd:%d, uid:%d, path:%s", m_fd, acceptFd, uid, path); |
| 95 | |
| 96 | if (0 > recvEvent(EVENT_CONNECT, acceptFd, ucred.pid, uid, path, NULL, 0)) { |
| 97 | perr("recvEvent NotAccept, fd:%d, pid:%d, uid:%d, path:%s", acceptFd, ucred.pid, uid, un.sun_path); |
| 98 | close(acceptFd); |
| 99 | return -4; |
| 100 | } |
| 101 | |
| 102 | std::pair<uid_t, std::string> p; |
| 103 | p.first = uid; |
| 104 | p.second = un.sun_path; |
| 105 | mapUid[acceptFd] = p; |
| 106 | return acceptFd; |
| 107 | } |
| 108 | |
| 109 | void notifyError(int recvFd) { |
| 110 | if (recvFd == m_fd) { //client |
nothing calls this directly
no outgoing calls
no test coverage detected