- 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;