Implement --socket-path option for dinitctl.
authorDavin McCall <davmac@davmac.org>
Sat, 6 Jul 2019 02:45:07 +0000 (03:45 +0100)
committerDavin McCall <davmac@davmac.org>
Sat, 6 Jul 2019 04:06:17 +0000 (14:06 +1000)
doc/manpages/dinitctl.8
src/dinitctl.cc

index f151a072a62ac2f1c45147d58a958fd8425f0065..02d57a52d420944af026c453982057929d8703ed 100644 (file)
@@ -5,40 +5,40 @@ dinitctl \- control services supervised by Dinit
 .SH SYNOPSIS
 .\"
 .B dinitctl
 .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
 .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
 .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
 .br
 .B dinitctl
-[\fB\-s\fR] [\fB\-\-quiet\fR] \fBrelease\fR \fIservice-name\fR
+[\fIoptions\fR] \fBrelease\fR \fIservice-name\fR
 .br
 .B dinitctl
 .br
 .B dinitctl
-[\fB\-s\fR] [\fB\-\-quiet\fR] \fBunpin\fR \fIservice-name\fR
+[\fIoptions\fR] \fBunpin\fR \fIservice-name\fR
 .br
 .B dinitctl
 .br
 .B dinitctl
-[\fB\-s\fR] \fBunload\fR \fIservice-name\fR
+[\fIoptions\fR] \fBunload\fR \fIservice-name\fR
 .br
 .B dinitctl
 .br
 .B dinitctl
-[\fB\-s\fR] \fBlist\fR
+[\fIoptions\fR] \fBlist\fR
 .br
 .B dinitctl
 .br
 .B dinitctl
-[\fB\-s\fR] \fBshutdown\fR
+[\fIoptions\fR] \fBshutdown\fR
 .br
 .B dinitctl
 .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
 .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
 .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
 .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
 .\"
 .\"
 .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. 
 .\"
 \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
 .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
 \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
 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
 \fIservice-name\fR
 Specifies the name of the service to which the command applies.
 .TP
index dd7ecaa1d3ff2b50712f1e14b153683d3821d32b..8d8b8d5c55078c1068f1df1dc714f74dff6886cc 100644 (file)
@@ -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], "--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;
             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"
           "General options:\n"
           "  -s, --system     : control system daemon instead of user daemon\n"
           "  --quiet          : suppress output (except errors)\n"
+          "  --socket-path <path>, -p <path>\n"
+          "                   : specify socket for communication with daemon\n"
           "\n"
           "Command options:\n"
           "  --help           : show this help\n"
           "\n"
           "Command options:\n"
           "  --help           : show this help\n"
@@ -268,26 +278,30 @@ int main(int argc, char **argv)
     
     signal(SIGPIPE, SIG_IGN);
     
     
     signal(SIGPIPE, SIG_IGN);
     
-    control_socket_path = SYSCONTROLSOCKET;
-    
     // Locate control socket
     // 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;
         }
     }
     
         }
     }