/* Initialize client. */ static int _init_client(char *dmeventd_path, struct dm_event_fifos *fifos) { /* init fifos */ memset(fifos, 0, sizeof(*fifos)); /* FIXME Make these either configurable or depend directly on dmeventd_path */ fifos->client_path = DM_EVENT_FIFO_CLIENT; fifos->server_path = DM_EVENT_FIFO_SERVER; if (!_start_daemon(dmeventd_path, fifos)) return_0; return init_fifos(fifos); }
/* Initialize client. */ static int _init_client(struct dm_event_fifos *fifos) { /* FIXME? Is fifo the most suitable method? Why not share comms/daemon code with something else e.g. multipath? */ /* init fifos */ memset(fifos, 0, sizeof(*fifos)); fifos->client_path = DM_EVENT_FIFO_CLIENT; fifos->server_path = DM_EVENT_FIFO_SERVER; if (!_start_daemon(fifos)) { stack; return 0; } /* Open the fifo used to read from the daemon. */ if ((fifos->server = open(fifos->server_path, O_RDWR)) < 0) { log_error("%s: open server fifo %s", __func__, fifos->server_path); stack; return 0; } /* Lock out anyone else trying to do communication with the daemon. */ if (flock(fifos->server, LOCK_EX) < 0) { log_error("%s: flock %s", __func__, fifos->server_path); close(fifos->server); return 0; } /* if ((fifos->client = open(fifos->client_path, O_WRONLY | O_NONBLOCK)) < 0) {*/ if ((fifos->client = open(fifos->client_path, O_RDWR | O_NONBLOCK)) < 0) { log_error("%s: Can't open client fifo %s: %s", __func__, fifos->client_path, strerror(errno)); close(fifos->server); stack; return 0; } return 1; }