2018-03-24 22:31:05 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 - David Oberhollenzer
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
#ifndef SERVICE_H
|
|
|
|
#define SERVICE_H
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
enum {
|
2018-03-24 22:31:05 +01:00
|
|
|
/*
|
|
|
|
Start the service in the background and continue with
|
|
|
|
other services. The service will eventually terminate.
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
SVC_ONCE = 0,
|
2018-03-24 22:31:05 +01:00
|
|
|
SVC_WAIT, /* run service and wait until it finishes */
|
|
|
|
|
|
|
|
/*
|
|
|
|
Similar to SVC_ONCE, but restart the service when
|
|
|
|
it terminates.
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
SVC_RESPAWN,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
2018-03-24 22:31:05 +01:00
|
|
|
TGT_BOOT = 0, /* run service when the system boots */
|
|
|
|
TGT_SHUTDOWN, /* run service when at system shut down */
|
|
|
|
TGT_REBOOT, /* run service when during system reboot */
|
|
|
|
TGT_CAD, /* run service when CTRL+ALT+DEL is pressed */
|
2018-02-25 14:33:19 +01:00
|
|
|
|
|
|
|
TGT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct service_t {
|
|
|
|
int type; /* SVC_* service type */
|
|
|
|
int target; /* TGT_* service target */
|
|
|
|
char *name; /* canonical service name */
|
|
|
|
char *desc; /* description string */
|
|
|
|
char **exec; /* command lines to execute */
|
|
|
|
size_t num_exec; /* number of command lines */
|
|
|
|
char *ctty; /* controlling tty or log file */
|
|
|
|
|
2018-03-26 00:34:00 +02:00
|
|
|
int rspwn_limit; /* maximum respawn count */
|
|
|
|
|
2018-03-24 22:31:05 +01:00
|
|
|
char **before; /* services that must be executed later */
|
2018-02-25 14:33:19 +01:00
|
|
|
size_t num_before;
|
2018-03-24 22:31:05 +01:00
|
|
|
char **after; /* services that must be executed first */
|
2018-02-25 14:33:19 +01:00
|
|
|
size_t num_after;
|
|
|
|
|
|
|
|
pid_t pid;
|
|
|
|
int status; /* process exit status */
|
|
|
|
|
|
|
|
struct service_t *next;
|
|
|
|
} service_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
service_t *targets[TGT_MAX];
|
|
|
|
} service_list_t;
|
|
|
|
|
|
|
|
/*
|
|
|
|
Read a service from a file.
|
|
|
|
*/
|
2018-03-25 12:14:06 +02:00
|
|
|
service_t *rdsvc(int dirfd, const char *filename);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 12:14:06 +02:00
|
|
|
void delsvc(service_t *svc);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-24 22:31:05 +01:00
|
|
|
/*
|
|
|
|
Rebuild a service list by scanning a directory and parsing all
|
|
|
|
service descriptions.
|
|
|
|
|
|
|
|
Returns 0 on success, -1 on failure. The function takes care of
|
|
|
|
printing error messages on failure.
|
|
|
|
*/
|
2018-03-25 12:14:06 +02:00
|
|
|
int svcscan(const char *directory, service_list_t *list);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 12:14:06 +02:00
|
|
|
void del_svc_list(service_list_t *list);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
Sort a list of services by dependencies.
|
|
|
|
*/
|
2018-03-25 12:14:06 +02:00
|
|
|
service_t *svc_tsort(service_t *list);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-25 01:55:08 +01:00
|
|
|
const char *svc_type_to_string(int type);
|
|
|
|
|
|
|
|
int svc_type_from_string(const char *type);
|
|
|
|
|
|
|
|
const char *svc_target_to_string(int target);
|
|
|
|
|
|
|
|
int svc_target_from_string(const char *target);
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
#endif /* SERVICE_H */
|
|
|
|
|