summaryrefslogtreecommitdiffstats
path: root/docs
AgeCommit message (Collapse)AuthorFilesLines
2021-11-04Prepare master for new framework integrationJan-Simon Moeller1-1/+0
During the last workshop the transition to the new framework was presented. This change essentially deprecates the SMACK-based application framework. To prepare the integration of it, we remove the deprecated components: - meta-agl-core: remove Smack kernel patches - meta-app-framework - meta-pipewire/dynamic-layers/meta-app-framework/ v2: rebased Bug-AGL: SPEC-4121 Signed-off-by: Jan-Simon Moeller <jsmoeller@linuxfoundation.org> Change-Id: Icdaeadfb5d2193f3a4c535168c88da6073423e67 Reviewed-on: https://gerrit.automotivelinux.org/gerrit/c/AGL/meta-agl/+/26752
2019-05-28Updated topic title for AGL layers intro "master"Scott Rifenbark1-1/+1
The title for the overview of the AGL Layers topic was badly named. It was called "AGL Overview", which indicates an overview of AGL itself. The topis really an introduction to the layers that AGL uses. I changed it to "Overview", which also matches how the topics are named for "guppy" and "flounder". Signed-off-by: Scott Rifenbark <srifenbark@gmail.com> Change-Id: I230e3e4ffae47e550f25723823dae6c8456beafb
2019-04-04Meta-agl: Added new layer files and updated book file.Scott Rifenbark1-4/+4
Change-Id: I9bfe46ef1776c78e4d9230bfae1228b17c81d91e Signed-off-by: Scott Rifenbark <srifenbark@gmail.com>
2018-12-20docs: add yaml bookFrederic Marec1-0/+15
Bug-AGL: SPEC-1988 Change-Id: Ia8fed93a05cef7a018900199b2527e04aa6e8cf5 Signed-off-by: Frederic Marec <frederic.marec@iot.bzh>
2018-08-01Remove porter reference from meta-aglRonan Le Martret1-29/+42
* Remove, from recipes, reference to porter, gen2, krogoth. * cleanup mardown from reference to porter. * cleanup markdown (markdownlint score 0). Change-Id: I70b9880fc52ef3c848da588d3a256fa8eee48606 Signed-off-by: Ronan Le Martret <ronan.lemartret@iot.bzh>
2018-05-313rd part of the layer/profile rework [1/2]Jan-Simon Möller1-0/+134
This is the last larger commit in this series and deals with the graphical part. We introduce the graphical profiles: - meta-agl-profile-graphical -- meta-agl-profile-graphical-html5 -- meta-agl-profile-graphical-qt5 Notable changes: - weston-ini-conf moved to the meta-agl-bsp layer. Most BSPs have bbappends, so we need to have the recipes present (but unused) even in the console images. - new image: agl-image-boot = terminal-only + network + package-manaager. Ready for using package-feeds - new image/sdk: agl-image-minimal-crosssdk - agl-service-mediaplayer has a dependency on weston, thus it cannot be in the 'core'. Moved it to profile-graphical. - The wayland-ivi-extension moved to the agl-demo-platform. - The app-framework layer included and pulled 'web-runtime' as dependency. This broke console-only images. This has been moved to be in meta-agl-demo only for now. - added and massaged the agl-features. - found and added a useful script 'oe-depends-dot' that helps to work with the dot files (produced with bitbake -g) Todo: - we'll need another pass through the packagegroups. The dependencies for the layers/profiles are now sorted-out but we might have to add/shuffle a few packages. For further details, see meta-agl/docs/profiles.md. v2: fix meta-agl/meta-security/conf/layer.conf - the immediate expansion previously used in there caused some recipes not being added to BBFILES. v3: fix packagegroup renaming (packagegroup-agl-devel -> packagegroup-agl-core-devel) v4: fix missing packagegroup inclusion (tnx Jose, Scott, Stephane) v5: fix missing packagegroup inclusion v6: explicitely put profile-graphical-qt5 on-top of profile-graphical v7: re-add 'procps' when agl-devel feature is on Bug-AGL: SPEC-145 Change-Id: I24cdcd1118932758d0c55d333338238f2a770877 Signed-off-by: Jan-Simon Möller <jsmoeller@linuxfoundation.org>
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
/*
 * Copyright (C) 2018 "IoT.bzh"
 * Author José Bollo <jose.bollo@iot.bzh>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define _GNU_SOURCE

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <endian.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>

#if defined(WITH_SYSTEMD_ACTIVATION)
#include <systemd/sd-daemon.h>
#endif

#include "socket.h"

#define BACKLOG  30

/******************************************************************************/

/**
 * known types
 */
enum type {
	/** type internet */
	Type_Inet,

	/** type systemd */
	Type_Systemd,

	/** type Unix */
	Type_Unix
};

/**
 * Structure for known entries
 */
struct entry
{
	/** the known prefix */
	const char *prefix;

	/** the type of the entry */
	unsigned type: 2;

	/** should not set SO_REUSEADDR for servers */
	unsigned noreuseaddr: 1;

	/** should not call listen for servers */
	unsigned nolisten: 1;
};

/**
 * The known entries with the default one at the first place
 */
static struct entry entries[] = {
	{
		.prefix = "tcp:",
		.type = Type_Inet
	},
	{
		.prefix = "sd:",
		.type = Type_Systemd,
		.noreuseaddr = 1,
		.nolisten = 1
	},
	{
		.prefix = "unix:",
		.type = Type_Unix
	}
};

/******************************************************************************/

/**
 * open a unix domain socket for client or server
 *
 * @param spec the specification of the path (prefix with @ for abstract)
 * @param server 0 for client, server otherwise
 *
 * @return the file descriptor number of the socket or -1 in case of error
 */
static int open_unix(const char *spec, int server)
{
	int fd, rc, abstract;
	struct sockaddr_un addr;
	size_t length;

	abstract = spec[0] == '@';

	/* check the length */
	length = strlen(spec);
	if (length >= 108) {
		errno = ENAMETOOLONG;
		return -1;
	}

	/* remove the file on need */
	if (server && !abstract)
		unlink(spec);

	/* create a  socket */
	fd = socket(AF_UNIX, SOCK_STREAM, 0);
	if (fd < 0)
		return fd;

	/* prepare address  */
	memset(&addr, 0, sizeof addr);
	addr.sun_family = AF_UNIX;
	strcpy(addr.sun_path, spec);
	if (abstract)
		addr.sun_path[0] = 0; /* implement abstract sockets */

	if (server) {
		rc = bind(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
	} else {
		rc = connect(fd, (struct sockaddr *) &addr, (socklen_t)(sizeof addr));
	}
	if (rc < 0) {
		close(fd);
		return rc;
	}
	return fd;
}

/**
 * open a tcp socket for client or server
 *
 * @param spec the specification of the host:port/...
 * @param server 0 for client, server otherwise
 *
 * @return the file descriptor number of the socket or -1 in case of error
 */
static int open_tcp(const char *spec, int server)
{
	int rc, fd;
	const char *service, *host, *tail;
	struct addrinfo hint, *rai, *iai;

	/* scan the uri */
	tail = strchrnul(spec, '/');
	service = strchr(spec, ':');
	if (service == NULL || tail < service) {
		errno = EINVAL;
		return -1;
	}
	host = strndupa(spec, service++ - spec);
	service = strndupa(service, tail - service);

	/* get addr */
	memset(&hint, 0, sizeof hint);
	hint.ai_family = AF_INET;
	hint.ai_socktype = SOCK_STREAM;
	rc = getaddrinfo(host, service, &hint, &rai);
	if (rc != 0) {
		errno = EINVAL;
		return -1;
	}

	/* get the socket */
	iai = rai;
	while (iai != NULL) {
		fd = socket(iai->ai_family, iai->ai_socktype, iai->ai_protocol);
		if (fd >= 0) {
			if (server) {
				rc = bind(fd, iai->ai_addr, iai->ai_addrlen);
			} else {
				rc = connect(fd, iai->ai_addr, iai->ai_addrlen);
			}
			if (rc == 0) {
				freeaddrinfo(rai);
				return fd;
			}
			close(fd);
		}
		iai = iai->ai_next;
	}
	freeaddrinfo(rai);
	return -1;
}

/**
 * open a systemd socket for server
 *
 * @param spec the specification of the systemd name
 *
 * @return the file descriptor number of the socket or -1 in case of error
 */
static int open_systemd(const char *spec)
{
#if defined(WITH_SYSTEMD_ACTIVATION)
	char **names;
	int fd = -1;
	int c = sd_listen_fds_with_names(0, &names);
	if (c < 0)
		errno = -c;
	else if (names) {
		for (c = 0 ; names[c] ; c++) {
			if (!strcmp(names[c], spec))
				fd = SD_LISTEN_FDS_START + c;
			free(names[c]);
		}
		free(names);
	}
	if (fd < 0 && '0' <= *spec && *spec <= '9')
		fd = SD_LISTEN_FDS_START + atoi(spec);
	return fd;
#else
	errno = EAFNOSUPPORT;
	return -1;
#endif
}

/******************************************************************************/

/**
 * Get the entry of the uri by searching to its prefix
 *
 * @param uri the searched uri
 * @param offset where to store the prefix length
 *
 * @return the found entry or the default one
 */
static struct entry *get_entry(const char *uri, int *offset)
{
	int l, i = (int)(sizeof entries / sizeof * entries);

	for (;;) {
		if (!i) {
			l = 0;
			break;
		}
		i--;
		l = (int)strlen(entries[i].prefix);
		if (!strncmp(uri, entries[i].prefix, l))
			break;
	}

	*offset = l;
	return &entries[i];
}

/**
 * open socket for client or server
 *
 * @param uri the specification of the socket
 * @param server 0 for client, server otherwise
 *
 * @return the file descriptor number of the socket or -1 in case of error
 */
int socket_open(const char *uri, int server)
{
	int fd, rc, offset;
	struct entry *e;

	/* search for the entry */
	e = get_entry(uri, &offset);

	/* get the names */
	uri += offset;

	/* open the socket */
	switch (e->type) {
	case Type_Unix:
		fd = open_unix(uri, server);
		break;
	case Type_Inet:
		fd = open_tcp(uri, server);
		break;
	case Type_Systemd:
		if (server)
			fd = open_systemd(uri);
		else {
			errno = EINVAL;
			fd = -1;
		}
		break;
	default:
		errno = EAFNOSUPPORT;
		fd = -1;
		break;
	}
	if (fd < 0)
		return -1;

	/* set it up */
	fcntl(fd, F_SETFD, FD_CLOEXEC);
	fcntl(fd, F_SETFL, O_NONBLOCK);
	if (server) {
		if (!e->noreuseaddr) {
			rc = 1;
			setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &rc, sizeof rc);
		}
		if (!e->nolisten)
			listen(fd, BACKLOG);
	}
	return fd;
}