Lines Matching refs:fd

40 #include "fd-util.h"
86 int fd[2];
90 if (pipe(fd) < 0)
98 safe_close_pair(fd);
108 r = dup2(fd[1], STDOUT_FILENO);
114 safe_close_pair(fd);
130 r = close(fd[1]);
134 return fd[0];
291 int fd,
299 int fd,
303 int fd,
308 int fd, char *name, RemoteSource **source) {
314 assert(fd >= 0);
317 if (!GREEDY_REALLOC0(s->sources, s->sources_size, fd + 1))
325 if (s->sources[fd] == NULL) {
326 s->sources[fd] = source_new(fd, false, name, writer);
327 if (!s->sources[fd]) {
335 *source = s->sources[fd];
339 static int remove_source(RemoteServer *s, int fd) {
343 assert(fd >= 0 && fd < (ssize_t) s->sources_size);
345 source = s->sources[fd];
347 /* this closes fd too */
349 s->sources[fd] = NULL;
356 static int add_source(RemoteServer *s, int fd, char* name, bool own_name) {
364 assert(fd >= 0);
373 r = get_source_for_fd(s, fd, name, &source);
375 log_error_errno(r, "Failed to create source for fd:%d (%s): %m",
376 fd, name);
382 fd, EPOLLIN|EPOLLRDHUP|EPOLLPRI,
392 log_debug("Falling back to sd_event_add_defer for fd:%d (%s)", fd, name);
399 log_error_errno(r, "Failed to register event source for fd:%d: %m",
400 fd);
406 log_error_errno(r, "Failed to set source name for fd:%d: %m", fd);
413 remove_source(s, fd);
417 static int add_raw_socket(RemoteServer *s, int fd) {
419 _cleanup_close_ int fd_ = fd;
422 assert(fd >= 0);
425 fd, EPOLLIN,
430 xsprintf(name, "raw-socket-%d", fd);
442 int fd;
444 fd = make_socket_fd(LOG_INFO, address, SOCK_STREAM, SOCK_CLOEXEC);
445 if (fd < 0)
446 return fd;
448 return add_raw_socket(s, fd);
455 static int request_meta(void **connection_cls, int fd, char *hostname) {
469 source = source_new(fd, true, hostname, writer);
568 int r, code, fd;
604 log_error("MHD_get_connection_info failed: cannot get remote fd");
609 fd = ci->connect_fd;
610 assert(fd >= 0);
618 r = getpeername_pretty(fd, false, &hostname);
626 r = request_meta(connection_cls, fd, hostname);
638 int fd,
645 { MHD_OPTION_LISTEN_SOCKET, fd},
663 assert(fd >= 0);
665 r = fd_nonblock(fd, true);
667 return log_error_errno(r, "Failed to make fd:%d nonblocking: %m", fd);
688 d->fd = (uint64_t) fd;
701 log_debug("Started MHD %s daemon on fd:%d (wrapper @ %p)",
702 key ? "HTTPS" : "HTTP", fd, d);
714 log_error("µhttp epoll fd is invalid");
727 r = sd_event_source_set_description(d->event, "epoll-fd");
739 r = hashmap_put(s->daemons, &d->fd, d);
760 int fd;
762 fd = make_socket_fd(LOG_DEBUG, address, SOCK_STREAM, SOCK_CLOEXEC);
763 if (fd < 0)
764 return fd;
766 return setup_microhttpd_server(s, fd, key, cert, trust);
770 int fd,
813 int fd, r;
815 r = safe_atoi(spec, &fd);
819 if (fd > 0)
822 return -fd;
829 int r, n, fd;
863 for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
864 if (sd_is_socket(fd, AF_UNSPEC, 0, true)) {
865 log_debug("Received a listening socket (fd:%d)", fd);
867 if (fd == http_socket)
868 r = setup_microhttpd_server(s, fd, NULL, NULL, NULL);
869 else if (fd == https_socket)
870 r = setup_microhttpd_server(s, fd, key, cert, trust);
872 r = add_raw_socket(s, fd);
873 } else if (sd_is_socket(fd, AF_UNSPEC, 0, false)) {
876 r = getpeername_pretty(fd, false, &hostname);
880 log_debug("Received a connection socket (fd:%d) from %s", fd, hostname);
882 r = add_source(s, fd, hostname, true);
884 log_error("Unknown socket passed on fd:%d", fd);
890 return log_error_errno(r, "Failed to register socket (fd:%d): %m",
891 fd);
896 fd = spawn_getter(arg_getter);
897 if (fd < 0)
898 return fd;
900 r = add_source(s, fd, (char*) arg_output, false);
919 fd = spawn_curl(url);
920 if (fd < 0)
921 return fd;
934 r = add_source(s, fd, hostname, false);
964 fd = STDIN_FILENO;
969 fd = open(*file, O_RDONLY|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);
970 if (fd < 0)
975 r = add_source(s, fd, (char*) output_name, false);
1030 int fd,
1041 assert(fd >= 0 && fd < (ssize_t) s->sources_size);
1042 source = s->sources[fd];
1043 assert(source->fd == fd);
1049 log_debug("EOF reached with source fd:%d (%s)",
1050 source->fd, source->name);
1055 remove_source(s, source->fd);
1065 remove_source(server, fd);
1079 r = handle_raw_source(event, source->fd, EPOLLIN, server);
1090 int fd,
1099 r = handle_raw_source(event, fd, EPOLLIN, server);
1112 return handle_raw_source(event, source->fd, EPOLLIN, server);
1115 static int accept_connection(const char* type, int fd,
1119 log_debug("Accepting new %s connection on fd:%d", type, fd);
1120 fd2 = accept4(fd, &addr->sockaddr.sa, &addr->size, SOCK_NONBLOCK|SOCK_CLOEXEC);
1122 return log_error_errno(errno, "accept() on fd:%d failed: %m", fd);
1163 int fd,
1174 fd2 = accept_connection("raw", fd, &addr, &hostname);