53
54
/* accept and add to our lists */
54
55
cli_fd = ud_accept(fd, &creds);
56
acpid_log(LOG_ERR, "can't accept client: %s\n",
57
acpid_log(LOG_ERR, "can't accept client: %s",
59
60
if (accept_errors >= 5) {
60
acpid_log(LOG_ERR, "giving up\n");
61
acpid_log(LOG_ERR, "giving up");
61
62
clean_exit_with_status(EXIT_FAILURE);
66
/* This check against clientmax is from the non-netlink 1.0.10. */
68
/* don't allow too many non-root clients */
67
69
if (creds.uid != 0 && non_root_clients >= clientmax) {
70
"too many non-root clients\n");
71
acpid_log(LOG_ERR, "too many non-root clients");
73
74
if (creds.uid != 0) {
74
75
non_root_clients++;
76
fcntl(cli_fd, F_SETFD, FD_CLOEXEC);
77
snprintf(buf, sizeof(buf)-1, "%d[%d:%d]",
78
/* don't leak fds when execing */
79
if (fcntl(cli_fd, F_SETFD, FD_CLOEXEC) < 0) {
81
acpid_log(LOG_ERR, "fcntl() on client for FD_CLOEXEC: %s",
86
/* don't allow clients to block this */
87
if (fcntl(cli_fd, F_SETFL, O_NONBLOCK) < 0) {
89
acpid_log(LOG_ERR, "fcntl() on client for O_NONBLOCK: %s",
94
snprintf(buf, sizeof(buf)-1, "%d[%d:%d]",
78
95
creds.pid, creds.uid, creds.gid);
79
96
acpid_add_client(cli_fd, buf);
99
/* set up the socket for client connections */
88
106
fd = ud_create_socket(socketfile);
90
acpid_log(LOG_ERR, "can't open socket %s: %s\n",
108
acpid_log(LOG_ERR, "can't open socket %s: %s",
91
109
socketfile, strerror(errno));
92
110
exit(EXIT_FAILURE);
94
fcntl(fd, F_SETFD, FD_CLOEXEC);
95
chmod(socketfile, socketmode);
113
/* don't leak fds when execing */
114
if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
116
acpid_log(LOG_ERR, "fcntl() on socket %s for FD_CLOEXEC: %s",
117
socketfile, strerror(errno));
121
/* avoid a potential hang */
122
if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
124
acpid_log(LOG_ERR, "fcntl() on socket %s for O_NONBLOCK: %s",
125
socketfile, strerror(errno));
129
if (chmod(socketfile, socketmode) < 0) {
131
acpid_log(LOG_ERR, "chmod() on socket %s: %s",
132
socketfile, strerror(errno));
136
/* if we need to change the socket's group, do so */
96
137
if (socketgroup) {
99
gr = getgrnam(socketgroup);
141
gr = getgrnam(socketgroup);
101
acpid_log(LOG_ERR, "group %s does not exist\n", socketgroup);
143
acpid_log(LOG_ERR, "group %s does not exist", socketgroup);
102
144
exit(EXIT_FAILURE);
104
146
if (stat(socketfile, &buf) < 0) {
105
acpid_log(LOG_ERR, "can't stat %s\n", socketfile);
147
acpid_log(LOG_ERR, "can't stat %s: %s",
148
socketfile, strerror(errno));
106
149
exit(EXIT_FAILURE);
108
151
if (chown(socketfile, buf.st_uid, gr->gr_gid) < 0) {
109
acpid_log(LOG_ERR, "can't chown: %s\n", strerror(errno));
152
acpid_log(LOG_ERR, "can't chown %s: %s",
153
socketfile, strerror(errno));
110
154
exit(EXIT_FAILURE);