示例#1
0
static ret_t
remove_old_socket (const char *path)
{
	int         re;
	struct stat info;

	/* It might not exist
	 */
	re = cherokee_stat (path, &info);
	if (re != 0) {
		return ret_ok;
	}

	/* If exist, it must be a socket
	 */
	if (! S_ISSOCK(info.st_mode)) {
		PRINT_MSG ("ERROR: Something happens; '%s' isn't a socket.\n", path);
		return ret_error;
	}

	/* Remove it
	 */
	re = cherokee_unlink (path);
	if (re != 0) {
		PRINT_MSG ("ERROR: Couldn't remove unix socket '%s'.\n", path);
		return ret_error;
	}

	return ret_ok;
}
示例#2
0
static ret_t
cherokee_bind_local (cherokee_socket_t *sock, cherokee_buffer_t *listen_to)
{
#ifdef HAVE_SOCKADDR_UN
	int         re;
	struct stat buf;

	/* Sanity check
	 */
	if ((listen_to->len <= 0) ||
	    (listen_to->len >= sizeof(SOCKET_SUN_PATH(sock))))
		return ret_error;

	/* Remove the socket if it already exists
	 */
	re = cherokee_stat (listen_to->buf, &buf);
	if (re == 0) {
		if (! S_ISSOCK(buf.st_mode)) {
			LOG_CRITICAL (CHEROKEE_ERROR_SOCKET_NO_SOCKET, listen_to->buf);
			return ret_error;
		}

		re = cherokee_unlink (listen_to->buf);
		if (re != 0) {
			LOG_ERRNO (errno, cherokee_err_error,
				   CHEROKEE_ERROR_SOCKET_REMOVE, listen_to->buf);
			return ret_error;
		}
	}

	/* Create the socket
	 */
	memcpy (SOCKET_SUN_PATH(sock), listen_to->buf, listen_to->len + 1);
	sock->client_addr_len = sizeof(SOCKET_ADDR_UNIX(sock)->sun_family) + listen_to->len;

	re = bind (SOCKET_FD(sock),
	           (const struct sockaddr *)SOCKET_ADDR_UNIX(sock),
	           sock->client_addr_len);
	if (re != 0) return ret_error;

	return ret_ok;
#else
	return ret_no_sys;
#endif
}