Lines Matching refs:uctrl

71         struct udev_ctrl *uctrl;
76 struct udev_ctrl *uctrl;
80 uctrl = new0(struct udev_ctrl, 1);
81 if (uctrl == NULL)
83 uctrl->refcount = 1;
84 uctrl->udev = udev;
87 uctrl->sock = socket(AF_LOCAL, SOCK_SEQPACKET|SOCK_NONBLOCK|SOCK_CLOEXEC, 0);
88 if (uctrl->sock < 0) {
90 udev_ctrl_unref(uctrl);
94 uctrl->bound = true;
95 uctrl->sock = fd;
102 r = setsockopt(uctrl->sock, SOL_SOCKET, SO_PASSCRED, &on, sizeof(on));
106 uctrl->saddr.un.sun_family = AF_LOCAL;
107 strscpy(uctrl->saddr.un.sun_path, sizeof(uctrl->saddr.un.sun_path), "/run/udev/control");
108 uctrl->addrlen = offsetof(struct sockaddr_un, sun_path) + strlen(uctrl->saddr.un.sun_path);
109 return uctrl;
116 int udev_ctrl_enable_receiving(struct udev_ctrl *uctrl) {
119 if (!uctrl->bound) {
120 err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen);
122 unlink(uctrl->saddr.un.sun_path);
123 err = bind(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen);
129 err = listen(uctrl->sock, 0);
133 uctrl->bound = true;
134 uctrl->cleanup_socket = true;
139 struct udev *udev_ctrl_get_udev(struct udev_ctrl *uctrl) {
140 return uctrl->udev;
143 static struct udev_ctrl *udev_ctrl_ref(struct udev_ctrl *uctrl) {
144 if (uctrl)
145 uctrl->refcount++;
147 return uctrl;
150 struct udev_ctrl *udev_ctrl_unref(struct udev_ctrl *uctrl) {
151 if (uctrl && -- uctrl->refcount == 0) {
152 if (uctrl->sock >= 0)
153 close(uctrl->sock);
154 free(uctrl);
160 int udev_ctrl_cleanup(struct udev_ctrl *uctrl) {
161 if (uctrl == NULL)
163 if (uctrl->cleanup_socket)
164 unlink(uctrl->saddr.un.sun_path);
168 int udev_ctrl_get_fd(struct udev_ctrl *uctrl) {
169 if (uctrl == NULL)
171 return uctrl->sock;
174 struct udev_ctrl_connection *udev_ctrl_get_connection(struct udev_ctrl *uctrl) {
184 conn->uctrl = uctrl;
186 conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
209 udev_ctrl_ref(uctrl);
230 udev_ctrl_unref(conn->uctrl);
238 static int ctrl_send(struct udev_ctrl *uctrl, enum udev_ctrl_msg_type type, int intval, const char *buf, int timeout) {
252 if (!uctrl->connected) {
253 if (connect(uctrl->sock, &uctrl->saddr.sa, uctrl->addrlen) < 0) {
257 uctrl->connected = true;
259 if (send(uctrl->sock, &ctrl_msg_wire, sizeof(ctrl_msg_wire), 0) < 0) {
269 pfd[0].fd = uctrl->sock;
292 int udev_ctrl_send_set_log_level(struct udev_ctrl *uctrl, int priority, int timeout) {
293 return ctrl_send(uctrl, UDEV_CTRL_SET_LOG_LEVEL, priority, NULL, timeout);
296 int udev_ctrl_send_stop_exec_queue(struct udev_ctrl *uctrl, int timeout) {
297 return ctrl_send(uctrl, UDEV_CTRL_STOP_EXEC_QUEUE, 0, NULL, timeout);
300 int udev_ctrl_send_start_exec_queue(struct udev_ctrl *uctrl, int timeout) {
301 return ctrl_send(uctrl, UDEV_CTRL_START_EXEC_QUEUE, 0, NULL, timeout);
304 int udev_ctrl_send_reload(struct udev_ctrl *uctrl, int timeout) {
305 return ctrl_send(uctrl, UDEV_CTRL_RELOAD, 0, NULL, timeout);
308 int udev_ctrl_send_set_env(struct udev_ctrl *uctrl, const char *key, int timeout) {
309 return ctrl_send(uctrl, UDEV_CTRL_SET_ENV, 0, key, timeout);
312 int udev_ctrl_send_set_children_max(struct udev_ctrl *uctrl, int count, int timeout) {
313 return ctrl_send(uctrl, UDEV_CTRL_SET_CHILDREN_MAX, count, NULL, timeout);
316 int udev_ctrl_send_ping(struct udev_ctrl *uctrl, int timeout) {
317 return ctrl_send(uctrl, UDEV_CTRL_PING, 0, NULL, timeout);
320 int udev_ctrl_send_exit(struct udev_ctrl *uctrl, int timeout) {
321 return ctrl_send(uctrl, UDEV_CTRL_EXIT, 0, NULL, timeout);