int sock_connect(const char *sockpath) { struct sockaddr_un addr; size_t len; int fd, ret; if (sockpath == NULL) { D_ERR("Invalid socket path\n"); return -1; } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; len = strlcpy(addr.sun_path, sockpath, sizeof(addr.sun_path)); if (len >= sizeof(addr.sun_path)) { D_ERR("Socket path too long, len=%zu\n", strlen(sockpath)); return -1; } fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) { D_ERR("socket() failed, errno=%d\n", errno); return -1; } ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret == -1) { D_ERR("connect() failed, errno=%d\n", errno); close(fd); return -1; } return fd; }
static int socket_connect(const char *sockpath) { struct sockaddr_un addr; size_t len; int fd, ret; memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; len = strlcpy(addr.sun_path, sockpath, sizeof(addr.sun_path)); if (len >= sizeof(addr.sun_path)) { D_ERR("socket path too long: %s\n", sockpath); return -1; } fd = socket(AF_UNIX, SOCK_STREAM, 0); if (fd == -1) { D_ERR("socket create failed - %s\n", sockpath); return -1; } ret = connect(fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret != 0) { D_ERR("socket connect failed - %s\n", sockpath); close(fd); return -1; } return fd; }
int sock_client_setup(TALLOC_CTX *mem_ctx, struct tevent_context *ev, const char *sockpath, struct sock_client_proto_funcs *funcs, void *private_data, struct sock_client_context **result) { struct sock_client_context *sockc; int ret; if (sockpath == NULL) { return EINVAL; } if (funcs == NULL || funcs->request_push == NULL || funcs->reply_pull == NULL || funcs->reply_reqid == NULL) { return EINVAL; } sockc = talloc_zero(mem_ctx, struct sock_client_context); if (sockc == NULL) { return ENOMEM; } sockc->funcs = funcs; sockc->private_data = private_data; sockc->fd = socket_connect(sockpath); if (sockc->fd == -1) { talloc_free(sockc); return EIO; } ret = comm_setup(sockc, ev, sockc->fd, sock_client_read_handler, sockc, sock_client_dead_handler, sockc, &sockc->comm); if (ret != 0) { D_ERR("comm_setup() failed, ret=%d\n", ret); close(sockc->fd); talloc_free(sockc); return ret; } ret = reqid_init(sockc, INT_MAX-200, &sockc->idr); if (ret != 0) { D_ERR("reqid_init() failed, ret=%d\n", ret); close(sockc->fd); talloc_free(sockc); return ret; } talloc_set_destructor(sockc, sock_client_context_destructor); *result = sockc; return 0; }
static bool database_conf_validate_lock_debug_script(const char *key, const char *old_script, const char *new_script, enum conf_update_mode mode) { char script[PATH_MAX]; char script_path[PATH_MAX]; struct stat st; size_t len; int ret; if (new_script == NULL) { return true; } len = strlcpy(script, new_script, sizeof(script)); if (len >= sizeof(script)) { D_ERR("lock debug script name too long\n"); return false; } ret = snprintf(script_path, sizeof(script_path), "%s/%s", path_etcdir(), basename(script)); if (ret >= sizeof(script_path)) { D_ERR("lock debug script path too long\n"); return false; } ret = stat(script_path, &st); if (ret == -1) { D_ERR("lock debug script %s does not exist\n", script_path); return false; } if (! S_ISREG(st.st_mode)) { D_ERR("lock debug script %s is not a file\n", script_path); return false; } if (! (st.st_mode & S_IXUSR)) { D_ERR("lock debug script %s is not executable\n", script_path); return false; } return true; }
int ctdbd_config_load(TALLOC_CTX *mem_ctx, struct conf_context **result) { struct conf_context *conf = NULL; int ret = 0; char *conf_file = NULL; ret = conf_init(mem_ctx, &conf); if (ret != 0) { return ret; } logging_conf_init(conf, "NOTICE"); cluster_conf_init(conf); database_conf_init(conf); event_conf_init(conf); legacy_conf_init(conf); setup_config_pointers(conf); if (! conf_valid(conf)) { ret = EINVAL; goto fail; } conf_file = path_config(conf); if (conf_file == NULL) { D_ERR("Memory allocation error\n"); ret = ENOMEM; goto fail; } ret = conf_load(conf, conf_file, true); /* Configuration file does not need to exist */ if (ret != 0 && ret != ENOENT) { D_ERR("Failed to load configuration file %s\n", conf_file); goto fail; } talloc_free(conf_file); *result = conf; return 0; fail: talloc_free(conf); return ret; }
static bool database_conf_validate_db_dir(const char *key, const char *old_dir, const char *new_dir, enum conf_update_mode mode) { if (! directory_exist(new_dir)) { D_ERR("%s \"%s\" does not exist\n", key, new_dir); return false; } /* This sometimes warns but always returns true */ return check_static_string_change(key, old_dir, new_dir, mode); }
bool sock_clean(const char *sockpath) { int ret; ret = unlink(sockpath); if (ret == 0) { D_WARNING("Removed stale socket %s\n", sockpath); } else if (errno != ENOENT) { D_ERR("Failed to remove stale socket %s\n", sockpath); return false; } return true; }
static void done(struct rt_ep_struct *rt_ep, struct rt_request *req, int status) { ep_del_request(rt_ep, req); if (likely(req->req.status == -EINPROGRESS)) req->req.status = status; else status = req->req.status; if (status && status != -ESHUTDOWN) D_ERR(rt_ep->rt_usb->dev, "<%s> complete %s req %p stat %d len %u/%u\n", __func__, rt_ep->ep.name, &req->req, status,req->req.actual, req->req.length); req->req.complete(&rt_ep->ep, &req->req); }
void imx_ep_stall(struct imx_ep_struct *imx_ep) { struct imx_udc_struct *imx_usb = imx_ep->imx_usb; int temp, i; D_ERR(imx_usb->dev, "<%s> Forced stall on %s\n", __func__, imx_ep->ep.name); imx_flush(imx_ep); /* */ if (!EP_NO(imx_ep)) { temp = __raw_readl(imx_usb->base + USB_CTRL); __raw_writel(temp | CTRL_CMDOVER | CTRL_CMDERROR, imx_usb->base + USB_CTRL); do { } while (__raw_readl(imx_usb->base + USB_CTRL) & CTRL_CMDOVER); temp = __raw_readl(imx_usb->base + USB_CTRL); __raw_writel(temp & ~CTRL_CMDERROR, imx_usb->base + USB_CTRL); } else { temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); __raw_writel(temp | EPSTAT_STALL, imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); for (i = 0; i < 100; i ++) { temp = __raw_readl(imx_usb->base + USB_EP_STAT(EP_NO(imx_ep))); if (!(temp & EPSTAT_STALL)) break; udelay(20); } if (i == 100) D_ERR(imx_usb->dev, "<%s> Non finished stall on %s\n", __func__, imx_ep->ep.name); } }
static void rx_done_do_tasklet(unsigned long arg) { struct rt_ep_struct *rt_ep; struct rt_request *rt_req; struct usb_request *usb_req; struct usb_ep *ep; int i, rx_count, status = 0; struct rt_udc_struct *rt_usb = &controller; for (i = (IN_EP_NUM+1); i < RT_USB_NB_EP; i++) { rt_ep = &rt_usb->rt_ep[i]; ep = &rt_ep->ep; // shared by irq handler, protect it spin_lock_irqsave(&rx_done_lock, rx_done_lock_flags); rx_count = rt_ep->rx_done_count; //spin_unlock_irqrestore(&rx_done_lock, rx_done_lock_flags); for (;rx_count > 0; rx_count--) { if(unlikely(list_empty(&rt_ep->queue))) FATAL_ERROR("empty queue"); rt_req = list_entry(rt_ep->queue.next, struct rt_request, queue); usb_req = &rt_req->req; ep_del_request(rt_ep, rt_req); rt_ep->rx_done_count--; spin_unlock_irqrestore(&rx_done_lock, rx_done_lock_flags); if (unlikely(rt_req->req.status == -EINPROGRESS)) rt_req->req.status = status; else status = rt_req->req.status; if (unlikely(status && status != -ESHUTDOWN)) D_ERR(rt_ep->rt_usb->dev, "<%s> complete %s req %p stat %d len %u/%u\n", __func__, rt_ep->ep.name, &rt_req->req, status,rt_req->req.actual, rt_req->req.length); // indicate gadget driver. usb_req->complete(ep, usb_req); spin_lock_irqsave(&rx_done_lock, rx_done_lock_flags); } spin_unlock_irqrestore(&rx_done_lock, rx_done_lock_flags); } }