commit 18a6052120d40a8c583180d3e9f321732cbe2b10
parent badb8db957aed6bd24adc2bfe9a68d09be953385
Author: Friedel Schön <[email protected]>
Date: Fri, 30 Jun 2023 01:12:28 +0200
removing ./env and ./user-support as chpst should do it
Diffstat:
M | docs/index.txt | 36 | ------------------------------------ |
M | src/parse.c | 56 | -------------------------------------------------------- |
M | src/start.c | 49 | ++----------------------------------------------- |
3 files changed, 2 insertions(+), 139 deletions(-)
diff --git a/docs/index.txt b/docs/index.txt
@@ -293,42 +293,6 @@ exec myservice $ARGS
This example sources conf in the service-directory if present and executes
myservice with _$ARGS_.
-_./params_~
-run often needs parameters, these can be defined inside params. Your
-arguments must be newline-demilitered. Usually the 0th argument is not
-included and defaults to './run', but if you want to define the 0th argument
-you can prefix the first line with '%' and the argument counting starts at 0.
-No shell-substitution will be done.
-@code
-%fiss-service
--L
--p 8000
-@endcode
-In this example, run would be executed with 'fiss-service' as 0th argument and
-'-L' '-p 8000'
-
-_./env_~
-This file describes environment-variables for run. This is as params a
-newline-demilitered file with key=value pairs. As for params, there is no
-shell-substitution done.
-@code
-HOME=/home/foo
-XDG_CONFIG_DIRS=/etc/
-PATH=/bin:/sbin:/usr/bin:/usr/sbin
-@endcode
-
-_./user_~
-If this file is present, run will be executes as defined user and group(s).
-You can define your user as 'user' and the group will be the user group or you
-explicitly define 'user:group'. You can add multiple groups with
-'user:group:group2:group3', if user is prefixed with a colon (':'), users and
-groups will be parsed as numeric thus ':1000:1000:1001'.
-@code
-foo:foo:mysql
-@endcode
-In this example, run would be executed as 'foo' and als 'foo' as group with
-'mysql' as additional group.
-
_./start_~
If your services cannot be run in the foreground, you should execute link it
to start, start is a short-running executable, if start exits it is considered
diff --git a/src/parse.c b/src/parse.c
@@ -10,62 +10,6 @@
#include <unistd.h>
-void parse_param_file(service_t* s, char* args[]) {
- int param_file;
- int args_size = 0;
- int line_size = 0;
- char c;
- bool start = true;
-
- strcpy(args[args_size++], "./run");
-
- if ((param_file = openat(s->dir, "params", O_RDONLY)) != -1) {
- while (read(param_file, &c, 1) > 0) {
- if (start && c == '%') {
- args_size--;
- continue;
- }
- if (c == '\n') {
- args[args_size++][line_size] = '\0';
-
- line_size = 0;
- } else {
- args[args_size][line_size++] = c;
- }
- start = false;
- }
- if (line_size > 0)
- args[args_size++][line_size] = '\0';
- close(param_file);
- }
-
- args[args_size] = NULL;
-}
-
-void parse_env_file(char** env) {
- int env_file;
- int env_size = 0;
- int line_size = 0;
- char c;
-
- if ((env_file = open("env", O_RDONLY)) != -1) {
- while (read(env_file, &c, 1) > 0) {
- if (c == '\n') {
- env[env_size++][line_size] = '\0';
-
- line_size = 0;
- } else {
- env[env_size][line_size++] = c;
- }
- }
- if (line_size > 0)
- env[env_size++][line_size] = '\0';
- close(env_file);
- }
-
- env[env_size] = NULL;
-}
-
/* uid:gid[:gid[:gid]...] */
static int parse_ugid_num(char* str, uid_t* uid, gid_t* gids) {
int i;
diff --git a/src/start.c b/src/start.c
@@ -52,36 +52,6 @@ static void set_pipes(service_t* s) {
}
}
-static void set_user(void) {
- char buffer[SV_USER_BUFFER];
- int user_file;
- ssize_t n;
- uid_t uid;
- gid_t gids[SV_USER_GROUP_MAX];
-
- if ((user_file = open("user", O_RDONLY)) == -1)
- return;
-
- if ((n = read(user_file, buffer, sizeof(buffer))) == -1) {
- print_error("error: failed reading ./user: %s\n");
- close(user_file);
- return;
- }
- buffer[n] = '\0';
-
- if ((n = parse_ugid(buffer, &uid, gids)) <= 0) {
- fprintf(stderr, "warn: malformatted user file\n");
- close(user_file);
- return;
- }
-
- setgroups(n, gids);
- setgid(gids[0]);
- setuid(uid);
-
- close(user_file);
-}
-
void service_run(service_t* s) {
struct stat st;
@@ -107,25 +77,10 @@ void service_run(service_t* s) {
fchdir(s->dir);
set_pipes(s);
- char args[SV_ARGUMENTS_MAX][SV_PARAM_FILE_LINE_MAX];
- char* argv[SV_ARGUMENTS_MAX];
- for (int i = 0; i < SV_ARGUMENTS_MAX; i++)
- argv[i] = args[i];
-
- char envs[SV_ENV_MAX][SV_ENV_FILE_LINE_MAX];
- char* envv[SV_ENV_MAX];
- for (int i = 0; i < SV_ENV_MAX; i++)
- envv[i] = envs[i];
-
- parse_param_file(s, argv);
- parse_env_file(envv);
-
- set_user();
-
if (s->state == STATE_STARTING) {
- execve("./start", argv, envv);
+ execl("./start", "./start", NULL);
} else {
- execve("./run", argv, envv);
+ execl("./run", "./run", NULL);
}
print_error("error: cannot execute service: %s\n");
_exit(1);