chore: migrate src to solutions

This commit is contained in:
Klagarge committed 2026-03-21 16:12:58 +01:00
1 parent eab03b73aa
commit 539e277d04
167 files changed
+17 -17

No files matched your search

+20
View File
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/app",
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerServerAddress": "192.168.53.14:1234",
"miDebuggerPath": "/buildroot/output/host/bin/aarch64-linux-gdb"
}
]
}
+15
View File
@@ -0,0 +1,15 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "gdbserver",
"type": "shell",
"command": [
"ssh -t root@192.168.53.14 '/usr/bin/gdbserver :1234",
"${workspaceFolder}/app'"
]
}
]
}
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.28)
project(daemon)
include(../../nanopi.cmake)
add_executable(daemon daemon.c)
+5
View File
@@ -0,0 +1,5 @@
EXE=app
SRCS=$(wildcard *.c)
# Include the standard application Makefile for the CSEL1 labs
include ../appl.mk
+24
View File
@@ -0,0 +1,24 @@
#!/bin/sh
#
# Daemon application
#
case "$1" in
start)
/usr/local/app_a
;;
stop)
killall app_a
;;
restart|reload)
killall app_a
/usr/local/app_a
;;
*)
echo $"Usage: $0 {start|stop|restart}"
exit 1
esac
echo "Daemon application launched"
exit $?
+152
View File
@@ -0,0 +1,152 @@
/**
* Copyright 2015 University of Applied Sciences Western Switzerland / Fribourg
*
* 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.
*
* Module: MA-CSEL1 - Building Embedded Systems under Linux
*
* Abstract: Introduction to the Embedded Linux Development Environment
*
* Purpose: This module implements a simple daemon to be launched
* from a /etc/init.d/S??_* script
*
* Autĥor: Daniel Gachet
* Date: 28.08.2015
*/
#define _XOPEN_SOURCE 600
#define _DEFAULT_SOURCE
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <grp.h>
#include <pwd.h>
#include <signal.h>
#include <syslog.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#define UNUSED(x) (void)(x)
static int signal_catched = 0;
static void catch_signal (int signal)
{
syslog (LOG_INFO, "signal=%d catched\n", signal);
signal_catched++;
}
static void fork_process()
{
pid_t pid = fork();
switch (pid) {
case 0: break; // child process has been created
case -1: syslog (LOG_ERR, "ERROR while forking"); exit (1); break;
default: exit(0); // exit parent process with success
}
}
int main(int argc, char* argv[])
{
UNUSED(argc); UNUSED(argv);
// 1. fork off the parent process
fork_process();
// 2. create new session
if (setsid() == -1) {
syslog (LOG_ERR, "ERROR while creating new session");
exit (1);
}
// 3. fork again to get rid of session leading process
fork_process();
// 4. capture all required signals
struct sigaction act = {.sa_handler = catch_signal,};
sigaction (SIGHUP, &act, NULL); // 1 - hangup
sigaction (SIGINT, &act, NULL); // 2 - terminal interrupt
sigaction (SIGQUIT, &act, NULL); // 3 - terminal quit
sigaction (SIGABRT, &act, NULL); // 6 - abort
sigaction (SIGTERM, &act, NULL); // 15 - termination
sigaction (SIGTSTP, &act, NULL); // 19 - terminal stop signal
// 5. update file mode creation mask
umask(0027);
// 6. change working directory to appropriate place
if (chdir ("/") == -1) {
syslog (LOG_ERR, "ERROR while changing to working directory");
exit (1);
}
// 7. close all open file descriptors
for (int fd = sysconf(_SC_OPEN_MAX); fd >= 0; fd--) {
close (fd);
}
// 8. redirect stdin, stdout and stderr to /dev/null
if (open ("/dev/null", O_RDWR) != STDIN_FILENO) {
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdin");
exit (1);
}
if (dup2 (STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO) {
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stdout");
exit (1);
}
if (dup2 (STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO) {
syslog (LOG_ERR, "ERROR while opening '/dev/null' for stderr");
exit (1);
}
// 9. option: open syslog for message logging
openlog (NULL, LOG_NDELAY | LOG_PID, LOG_DAEMON);
syslog (LOG_INFO, "Daemon has started...");
// 10. option: get effective user and group id for appropriate's one
struct passwd* pwd = getpwnam ("daemon");
if (pwd == 0) {
syslog (LOG_ERR, "ERROR while reading daemon password file entry");
exit (1);
}
// 11. option: change root directory
if (chroot (".") == -1) {
syslog (LOG_ERR, "ERROR while changing to new root directory");
exit (1);
}
// 12. option: change effective user and group id for appropriate's one
if (setegid (pwd->pw_gid) == -1) {
syslog (LOG_ERR, "ERROR while setting new effective group id");
exit (1);
}
if (seteuid (pwd->pw_uid) == -1) {
syslog (LOG_ERR, "ERROR while setting new effective user id");
exit (1);
}
// 13. implement daemon body...
int t = 30;
do {
t = sleep(t);
} while (t > 0);
syslog (LOG_INFO, "daemon stopped. Number of signals catched=%d\n", signal_catched);
closelog();
return 0;
}
+5
View File
@@ -0,0 +1,5 @@
build:
cmake -S . -B build && cmake --build build
clean:
rm -rf build