From: Davin McCall Date: Sat, 6 Jul 2019 02:45:07 +0000 (+0100) Subject: Implement --socket-path option for dinitctl. X-Git-Tag: v0.6.0~8 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=1b07e74e873e90e606ad7d7df78571540bffb9bb;p=oweals%2Fdinit.git Implement --socket-path option for dinitctl. --- diff --git a/doc/manpages/dinitctl.8 b/doc/manpages/dinitctl.8 index f151a07..02d57a5 100644 --- a/doc/manpages/dinitctl.8 +++ b/doc/manpages/dinitctl.8 @@ -5,40 +5,40 @@ dinitctl \- control services supervised by Dinit .SH SYNOPSIS .\" .B dinitctl -[\fB\-s\fR] [\fB\-\-quiet\fR] \fBstart\fR [\fB\-\-no\-wait\fR] [\fB\-\-pin\fR] \fIservice-name\fR +[\fIoptions\fR] \fBstart\fR [\fB\-\-no\-wait\fR] [\fB\-\-pin\fR] \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] [\fB\-\-quiet\fR] \fBstop\fR [\fB\-\-no\-wait\fR] [\fB\-\-pin\fR] \fIservice-name\fR +[\fIoptions\fR] \fBstop\fR [\fB\-\-no\-wait\fR] [\fB\-\-pin\fR] \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] [\fB\-\-quiet\fR] \fBwake\fR [\fB\-\-no\-wait\fR] \fIservice-name\fR +[\fIoptions\fR] \fBwake\fR [\fB\-\-no\-wait\fR] \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] [\fB\-\-quiet\fR] \fBrelease\fR \fIservice-name\fR +[\fIoptions\fR] \fBrelease\fR \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] [\fB\-\-quiet\fR] \fBunpin\fR \fIservice-name\fR +[\fIoptions\fR] \fBunpin\fR \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] \fBunload\fR \fIservice-name\fR +[\fIoptions\fR] \fBunload\fR \fIservice-name\fR .br .B dinitctl -[\fB\-s\fR] \fBlist\fR +[\fIoptions\fR] \fBlist\fR .br .B dinitctl -[\fB\-s\fR] \fBshutdown\fR +[\fIoptions\fR] \fBshutdown\fR .br .B dinitctl -[\fB\-s\fR] \fBadd-dep\fR \fIdependency-type\fR \fIfrom-service\fR \fIto-service\fR +[\fIoptions\fR] \fBadd-dep\fR \fIdependency-type\fR \fIfrom-service\fR \fIto-service\fR .br .B dinitctl -[\fB\-s\fR] \fBrm-dep\fR \fIdependency-type\fR \fIfrom-service\fR \fIto-service\fR +[\fIoptions\fR] \fBrm-dep\fR \fIdependency-type\fR \fIfrom-service\fR \fIto-service\fR .br .B dinitctl -[\fB\-s\fR] \fBenable\fR [\fB\-\-from\fR \fIfrom-service\fR] \fIto-service\fR +[\fIoptions\fR] \fBenable\fR [\fB\-\-from\fR \fIfrom-service\fR] \fIto-service\fR .br .B dinitctl -[\fB\-s\fR] \fBdisable\fR [\fB\-\-from\fR \fIfrom-service\fR] \fIto-service\fR +[\fIoptions\fR] \fBdisable\fR [\fB\-\-from\fR \fIfrom-service\fR] \fIto-service\fR .\" .SH DESCRIPTION .\" @@ -46,11 +46,23 @@ dinitctl \- control services supervised by Dinit \fBdinit\fR daemon. It allows starting and stopping services, and listing service status. .\" -.SH OPTIONS +.SH GENERAL OPTIONS .TP \fB\-\-help\fR display this help and exit .TP +\fB\-s\fR, \fB\-\-system\fR +Control the system init process. The default is to control the user process. This option selects +the path to the control socket used to communicate with the \fBdinit\fR daemon process. +.TP +\fB\-\-socket\-path\fR \fIsocket-path\fR, \fB\-p\fR \fIsocket-path\fR +Specify the path to the socket used for communicating with the service manager daemon. +.TP +\fB\-\-quiet\fR +Suppress status output, except for errors. +.\" +.SH COMMAND OPTIONS +.TP \fB\-\-no\-wait\fR Do not wait for issued command to complete; exit immediately. .TP @@ -58,10 +70,6 @@ Do not wait for issued command to complete; exit immediately. Pin the service in the requested state. The service will not leave the state until it is unpinned, although start/stop commands will be "remembered" while the service is pinned. .TP -\fB\-s\fR, \fB\-\-system\fR -Control the system init process. The default is to control the user process. This option selects -the path to the control socket used to communicate with the \fBdinit\fR daemon process. -.TP \fIservice-name\fR Specifies the name of the service to which the command applies. .TP diff --git a/src/dinitctl.cc b/src/dinitctl.cc index dd7ecaa..8d8b8d5 100644 --- a/src/dinitctl.cc +++ b/src/dinitctl.cc @@ -114,6 +114,14 @@ int main(int argc, char **argv) else if (strcmp(argv[i], "--pin") == 0) { do_pin = true; } + else if (strcmp(argv[i], "--socket-path") || strcmp(argv[i], "-p")) { + ++i; + if (i == argc) { + cerr << "dinitctl: --socket-path/-p should be followed by socket path" << std::endl; + return 1; + } + control_socket_str = argv[i]; + } else if ((command == command_t::ENABLE_SERVICE || command == command_t::DISABLE_SERVICE) && strcmp(argv[i], "--from") == 0) { ++i; @@ -258,6 +266,8 @@ int main(int argc, char **argv) "General options:\n" " -s, --system : control system daemon instead of user daemon\n" " --quiet : suppress output (except errors)\n" + " --socket-path , -p \n" + " : specify socket for communication with daemon\n" "\n" "Command options:\n" " --help : show this help\n" @@ -268,26 +278,30 @@ int main(int argc, char **argv) signal(SIGPIPE, SIG_IGN); - control_socket_path = SYSCONTROLSOCKET; - // Locate control socket - if (! sys_dinit) { - char * userhome = getenv("HOME"); - if (userhome == nullptr) { - struct passwd * pwuid_p = getpwuid(getuid()); - if (pwuid_p != nullptr) { - userhome = pwuid_p->pw_dir; + if (! control_socket_str.empty()) { + control_socket_path = control_socket_str.c_str(); + } + else { + control_socket_path = SYSCONTROLSOCKET; // default to system + if (! sys_dinit) { + char * userhome = getenv("HOME"); + if (userhome == nullptr) { + struct passwd * pwuid_p = getpwuid(getuid()); + if (pwuid_p != nullptr) { + userhome = pwuid_p->pw_dir; + } + } + + if (userhome != nullptr) { + control_socket_str = userhome; + control_socket_str += "/.dinitctl"; + control_socket_path = control_socket_str.c_str(); + } + else { + cerr << "Cannot locate user home directory (set HOME or check /etc/passwd file)" << endl; + return 1; } - } - - if (userhome != nullptr) { - control_socket_str = userhome; - control_socket_str += "/.dinitctl"; - control_socket_path = control_socket_str.c_str(); - } - else { - cerr << "Cannot locate user home directory (set HOME or check /etc/passwd file)" << endl; - return 1; } }