aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorDavid Oberhollenzer <goliath@infraroot.at>2020-05-07 22:04:42 +0200
committerDavid Oberhollenzer <goliath@infraroot.at>2020-05-07 22:08:37 +0200
commit13aa3840cc94ce37ef1e63c093c0f71ac84e90fd (patch)
treedb60e6ff38fd7477f5b76cdabcd9277357184b6b /cmd
parentef0dd7cbe779b879f61bdbaf23a01bc1fb643243 (diff)
Temporarily remove initsock handling code
Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Makemodule.am3
-rw-r--r--cmd/service/startstop.c104
-rw-r--r--cmd/service/status.c170
3 files changed, 1 insertions, 276 deletions
diff --git a/cmd/Makemodule.am b/cmd/Makemodule.am
index 7b8296f..e1e9964 100644
--- a/cmd/Makemodule.am
+++ b/cmd/Makemodule.am
@@ -18,8 +18,7 @@ SRVHEADERS = cmd/service/servicecmd.h
service_SOURCES = cmd/service/servicecmd.c cmd/service/help.c
service_SOURCES += cmd/service/enable.c cmd/service/disable.c
service_SOURCES += cmd/service/dumpscript.c cmd/service/list.c
-service_SOURCES += cmd/service/status.c cmd/service/loadsvc.c
-service_SOURCES += cmd/service/startstop.c
+service_SOURCES += cmd/service/loadsvc.c
service_SOURCES += $(SRVHEADERS)
service_CPPFLAGS = $(AM_CPPFLAGS)
service_CFLAGS = $(AM_CFLAGS)
diff --git a/cmd/service/startstop.c b/cmd/service/startstop.c
deleted file mode 100644
index 8c30efa..0000000
--- a/cmd/service/startstop.c
+++ /dev/null
@@ -1,104 +0,0 @@
-/* SPDX-License-Identifier: ISC */
-#include "servicecmd.h"
-#include "initsock.h"
-#include "service.h"
-#include "config.h"
-
-#include <fnmatch.h>
-#include <getopt.h>
-#include <unistd.h>
-
-static int cmd_startstop(int argc, char **argv,
- E_SERVICE_STATE filter, E_INIT_REQUEST action)
-{
- int i, fd, ret = EXIT_FAILURE;
- init_status_t resp;
- char tmppath[256];
- bool found;
-
- if (check_arguments(argv[0], argc, 2, 2))
- return EXIT_FAILURE;
-
- sprintf(tmppath, "/tmp/svcstatus.%d.sock", (int)getpid());
- fd = init_socket_open(tmppath);
-
- if (fd < 0) {
- unlink(tmppath);
- return EXIT_FAILURE;
- }
-
- if (init_socket_send_request(fd, EIR_STATUS, filter))
- goto out;
-
- for (;;) {
- memset(&resp, 0, sizeof(resp));
-
- if (init_socket_recv_status(fd, &resp)) {
- perror("reading from initd socket");
- free_init_status(&resp);
- goto out;
- }
-
- if (resp.state == ESS_NONE) {
- free_init_status(&resp);
- break;
- }
-
- found = false;
-
- for (i = optind; i < argc; ++i) {
- if (fnmatch(argv[i], resp.service_name, 0) == 0) {
- found = true;
- break;
- }
- if (fnmatch(argv[i], resp.filename, 0) == 0) {
- found = true;
- break;
- }
- }
-
- if (found) {
- if (init_socket_send_request(fd, action, resp.id))
- goto out;
- }
-
- free_init_status(&resp);
- }
-
- ret = EXIT_SUCCESS;
-out:
- close(fd);
- unlink(tmppath);
- return ret;
-}
-
-static int cmd_start(int argc, char **argv)
-{
- return cmd_startstop(argc, argv, ESS_NONE, EIR_START);
-}
-
-static int cmd_stop(int argc, char **argv)
-{
- return cmd_startstop(argc, argv, ESS_NONE, EIR_STOP);
-}
-
-static command_t start = {
- .cmd = "start",
- .usage = "services...",
- .s_desc = "start a currently not running service",
- .l_desc = "Start one or more service that are currently not running. "
- "Shell style globbing patterns can used for service names.",
- .run_cmd = cmd_start,
-};
-
-static command_t stop = {
- .cmd = "stop",
- .usage = "services...",
- .s_desc = "stop a currently running service",
- .l_desc = "Stop one or more service that are currently running. "
- "Shell style globbing patterns can used for service names.",
- .run_cmd = cmd_stop,
-};
-
-REGISTER_COMMAND(start)
-REGISTER_COMMAND(stop)
diff --git a/cmd/service/status.c b/cmd/service/status.c
deleted file mode 100644
index a13a450..0000000
--- a/cmd/service/status.c
+++ /dev/null
@@ -1,170 +0,0 @@
-/* SPDX-License-Identifier: ISC */
-#include "servicecmd.h"
-#include "initsock.h"
-#include "service.h"
-#include "config.h"
-
-#include <fnmatch.h>
-#include <getopt.h>
-#include <unistd.h>
-
-static const struct option long_opts[] = {
- { "detail", no_argument, NULL, 'd' },
- { NULL, 0, NULL, 0 },
-};
-
-static const char *short_opts = "d";
-
-static int cmd_status(int argc, char **argv)
-{
- bool is_tty, found, show_details = false;
- int i, fd, ret = EXIT_FAILURE;
- init_status_t resp;
- char tmppath[256];
- const char *state;
- service_t *svc;
-
- for (;;) {
- i = getopt_long(argc, argv, short_opts, long_opts, NULL);
- if (i == -1)
- break;
-
- switch (i) {
- case 'd':
- show_details = true;
- break;
- default:
- tell_read_help(argv[0]);
- return EXIT_FAILURE;
- }
- }
-
- sprintf(tmppath, "/tmp/svcstatus.%d.sock", (int)getpid());
- fd = init_socket_open(tmppath);
-
- if (fd < 0) {
- unlink(tmppath);
- return EXIT_FAILURE;
- }
-
- if (init_socket_send_request(fd, EIR_STATUS, ESS_NONE))
- goto out;
-
- is_tty = (isatty(STDOUT_FILENO) == 1);
-
- for (;;) {
- memset(&resp, 0, sizeof(resp));
-
- if (init_socket_recv_status(fd, &resp)) {
- perror("reading from initd socket");
- free_init_status(&resp);
- goto out;
- }
-
- if (resp.state == ESS_NONE) {
- free_init_status(&resp);
- break;
- }
-
- if (optind < argc) {
- found = false;
-
- for (i = optind; i < argc; ++i) {
- if (fnmatch(argv[i],
- resp.service_name, 0) == 0) {
- found = true;
- break;
- }
- if (fnmatch(argv[i], resp.filename, 0) == 0) {
- found = true;
- break;
- }
- }
-
- if (!found) {
- free_init_status(&resp);
- continue;
- }
- }
-
- switch (resp.state) {
- case ESS_RUNNING:
- if (!is_tty) {
- state = "UP";
- break;
- }
- state = "\033[22;32m UP \033[0m";
- break;
- case ESS_ENQUEUED:
- state = "SCHED";
- break;
- case ESS_FAILED:
- if (!is_tty) {
- state = "FAIL";
- break;
- }
- state = "\033[22;31mFAIL\033[0m";
- break;
- case ESS_DONE:
- if (!is_tty) {
- state = "DONE";
- break;
- }
-
- state = "\033[22;33mDONE\033[0m";
- break;
- default:
- if (!is_tty) {
- state = "UNKNOWN";
- break;
- }
- state = "\033[22;31mUNKNOWN\033[0m";
- break;
- }
-
- if (show_details) {
- printf("Service: %s\n", resp.filename);
- printf("\tStatus: %s\n", state);
- printf("\tTemplate name: %s\n", resp.service_name);
- printf("\tExit status: %d\n", resp.exit_status);
-
- svc = loadsvc(SVCDIR, resp.filename);
-
- if (svc == NULL) {
- fputs("\tError loading service file\n", stdout);
- } else {
- printf("\tDescription: %s\n", svc->desc);
- printf("\tType: %s\n",
- svc_type_to_string(svc->type));
- printf("\tTarget: %s\n",
- svc_target_to_string(svc->target));
- delsvc(svc);
- }
- } else {
- printf("[%s] %s\n", state, resp.filename);
- }
-
- free_init_status(&resp);
- }
-
- ret = EXIT_SUCCESS;
-out:
- close(fd);
- unlink(tmppath);
- return ret;
-}
-
-static command_t status = {
- .cmd = "status",
- .usage = "[-d|--detail] [services...]",
- .s_desc = "report the status of the currently enabled services",
- .l_desc = "Gathers a list of all currently running services and the "
- "state that they are in (currently running, done, failed, "
- "wating to get scheduled). A list of services with wildcard "
- "globbing patterns can be specified. If ommitted, produces "
- "a general overview of all services. If the --detail "
- "is given, more details are shown about a service.",
- .run_cmd = cmd_status,
-};
-
-REGISTER_COMMAND(status)