예제 #1
0
파일: coredump.c 프로젝트: jananive/gencore
/* Services requests */
int service_request(void)
{
	int ret;
	char core_file[CORE_FILE_NAME_SZ];
	struct ucred client_info;

	/* Handles stopping of the servicing process */
	signal(SIGTERM, sig_handler_service_proc);
	signal(SIGSEGV, sig_handler_service_proc);
	signal(SIGPIPE, sig_handler_service_proc);

	/* Receive the message */
	ret = receive_core_filename(core_file);
	if (ret)
		goto cleanup;

	/* Fetch client PID */
	ret = get_client_pid(&client_info);
	if (ret)
		goto cleanup;

	/* Dump process */
	ret = dump_task(&client_info, core_file);
	if (ret)
		goto cleanup;

cleanup:
	close(new_sock);
	if (ret == -1)
		exit(EXIT_FAILURE);

	exit(EXIT_SUCCESS);
}
예제 #2
0
파일: coredump.c 프로젝트: jananive/gencore
/* Systemd socket for self dump */
int socket_dump(void)
{
	int n, ret;
	char core_file[CORE_FILE_NAME_SZ];
	struct ucred client_info;

	/* Fetching the Socket ID from systemd */
	n = sd_listen_fds(0);
	if (n > 1) {
		gencore_log("Too many file descriptors received.\n");
		return -1;
	} else if (n == 1)
		new_sock = SD_LISTEN_FDS_START + 0;
	else
		return -1;

	/* Receive the message */
	ret = receive_core_filename(core_file);
	if (ret)
		return -1;

	/* Fetch client PID */
	ret = get_client_pid(&client_info);
	if (ret)
		return -1;

	/* Dump process */
	ret = dump_task(&client_info, core_file);
	if (ret)
		return -1;

	return 0;
}
예제 #3
0
파일: ipc-server.c 프로젝트: SirCmpwn/sway
int ipc_handle_connection(int fd, uint32_t mask, void *data) {
	(void) fd; (void) data;
	sway_log(L_DEBUG, "Event on IPC listening socket");
	assert(mask == WLC_EVENT_READABLE);

	int client_fd = accept(ipc_socket, NULL, NULL);
	if (client_fd == -1) {
		sway_log_errno(L_INFO, "Unable to accept IPC client connection");
		return 0;
	}

	int flags;
	if ((flags=fcntl(client_fd, F_GETFD)) == -1 || fcntl(client_fd, F_SETFD, flags|FD_CLOEXEC) == -1) {
		sway_log_errno(L_INFO, "Unable to set CLOEXEC on IPC client socket");
		close(client_fd);
		return 0;
	}

	pid_t pid = get_client_pid(client_fd);
	if (!(get_feature_policy(pid) & FEATURE_IPC)) {
		sway_log(L_INFO, "Permission to connect to IPC socket denied to %d", pid);
		const char *error = "{\"success\": false, \"message\": \"Permission denied\"}";
		if (write(client_fd, &error, sizeof(error)) < (int)sizeof(error)) {
			sway_log(L_DEBUG, "Failed to write entire error");
		}
		close(client_fd);
		return 0;
	}

	struct ipc_client* client = malloc(sizeof(struct ipc_client));
	client->payload_length = 0;
	client->fd = client_fd;
	client->subscribed_events = 0;
	client->event_source = wlc_event_loop_add_fd(client_fd, WLC_EVENT_READABLE, ipc_client_handle_readable, client);

	list_add(ipc_client_list, client);

	return 0;
}