Browse Source

Formatting: tabs to spaces

Davin McCall 10 months ago
parent
commit
3770e1ca45
8 changed files with 392 additions and 392 deletions
  1. 192 192
      src/baseproc-service.cc
  2. 15 15
      src/dinitcheck.cc
  3. 34 34
      src/dinitctl.cc
  4. 17 17
      src/includes/dinit-util.h
  5. 2 2
      src/includes/load-service.h
  6. 81 81
      src/load-service.cc
  7. 49 49
      src/proc-service.cc
  8. 2 2
      src/service.cc

+ 192 - 192
src/baseproc-service.cc

@@ -107,194 +107,194 @@ bool base_process_service::start_ps_process(const std::vector<const char *> &cmd
 
     const char * logfile = this->logfile.c_str();
     if (this->log_type == log_type_id::LOGFILE || this->log_type == log_type_id::NONE) {
-    	// Note: if log_type == NONE, logfile should be empty.
-    	if (*logfile == 0) {
-    		logfile = "/dev/null";
-    	}
+        // Note: if log_type == NONE, logfile should be empty.
+        if (*logfile == 0) {
+            logfile = "/dev/null";
+        }
     }
     else /* log_type_id::BUFFER */ {
-    	if (this->log_output_fd == -1) {
-    		int logfd[2];
-    		// Note: we set CLOEXEC on the file descriptors here; when the output file descriptor is dup'd
-    		// to stdout, this will be effectively removed for the output end
-    	    if (bp_sys::pipe2(logfd, O_CLOEXEC)) {
-    	        log(loglevel_t::ERROR, get_name(), ": can't create output pipe: ", strerror(errno));
-    	        goto out_p;
-    	    }
-    	    this->log_input_fd = logfd[0];
-    	    this->log_output_fd = logfd[1];
-    	    try {
-    	    	this->log_output_listener.add_watch(event_loop, logfd[0], dasynq::IN_EVENTS,
-    	    			false /* not enabled */);
-    	    }
-    	    catch (...) {
-    	    	log(loglevel_t::ERROR, get_name(), ": can't add output watch (insufficient resources)");
-    	    	bp_sys::close(this->log_input_fd);
-    	    	bp_sys::close(this->log_output_fd);
-    	    	this->log_input_fd = -1;
-    	    	this->log_output_fd = -1;
-    	    	goto out_p;
-    	    }
-    	}
-    	// (More is done below, after we have performed additional setup)
+        if (this->log_output_fd == -1) {
+            int logfd[2];
+            // Note: we set CLOEXEC on the file descriptors here; when the output file descriptor is dup'd
+            // to stdout, this will be effectively removed for the output end
+            if (bp_sys::pipe2(logfd, O_CLOEXEC)) {
+                log(loglevel_t::ERROR, get_name(), ": can't create output pipe: ", strerror(errno));
+                goto out_p;
+            }
+            this->log_input_fd = logfd[0];
+            this->log_output_fd = logfd[1];
+            try {
+                this->log_output_listener.add_watch(event_loop, logfd[0], dasynq::IN_EVENTS,
+                        false /* not enabled */);
+            }
+            catch (...) {
+                log(loglevel_t::ERROR, get_name(), ": can't add output watch (insufficient resources)");
+                bp_sys::close(this->log_input_fd);
+                bp_sys::close(this->log_output_fd);
+                this->log_input_fd = -1;
+                this->log_output_fd = -1;
+                goto out_p;
+            }
+        }
+        // (More is done below, after we have performed additional setup)
     }
 
     {
-		bool child_status_registered = false;
-		control_conn_t *control_conn = nullptr;
-
-		int control_socket[2] = {-1, -1};
-		int notify_pipe[2] = {-1, -1};
-		bool have_notify = !notification_var.empty() || force_notification_fd != -1;
-		ready_notify_watcher * rwatcher = have_notify ? get_ready_watcher() : nullptr;
-		bool ready_watcher_registered = false;
-
-		if (onstart_flags.pass_cs_fd) {
-			if (dinit_socketpair(AF_UNIX, SOCK_STREAM, /* protocol */ 0, control_socket, SOCK_NONBLOCK)) {
-				log(loglevel_t::ERROR, get_name(), ": can't create control socket: ", strerror(errno));
-				goto out_lfd;
-			}
-
-			// Make the server side socket close-on-exec:
-			int fdflags = bp_sys::fcntl(control_socket[0], F_GETFD);
-			bp_sys::fcntl(control_socket[0], F_SETFD, fdflags | FD_CLOEXEC);
-
-			try {
-				control_conn = new control_conn_t(event_loop, services, control_socket[0]);
-			}
-			catch (std::exception &exc) {
-				log(loglevel_t::ERROR, get_name(), ": can't launch process; out of memory");
-				goto out_cs;
-			}
-		}
-
-		if (have_notify) {
-			// Create a notification pipe:
-			if (bp_sys::pipe2(notify_pipe, 0) != 0) {
-				log(loglevel_t::ERROR, get_name(), ": can't create notification pipe: ", strerror(errno));
-				goto out_cs_h;
-			}
-
-			// Set the read side as close-on-exec:
-			int fdflags = bp_sys::fcntl(notify_pipe[0], F_GETFD);
-			bp_sys::fcntl(notify_pipe[0], F_SETFD, fdflags | FD_CLOEXEC);
-
-			// add, but don't yet enable, readiness watcher:
-			try {
-				rwatcher->add_watch(event_loop, notify_pipe[0], dasynq::IN_EVENTS, false);
-				ready_watcher_registered = true;
-			}
-			catch (std::exception &exc) {
-				log(loglevel_t::ERROR, get_name(), ": can't add notification watch: ", exc.what());
-				goto out_cs_h;
-			}
-		}
-
-		if (log_type == log_type_id::BUFFER) {
-	    	// Set watcher enabled if space in buffer
-			if (log_buf_size > 0) {
-				// Append a "restarted" message to buffer contents
-				const char *restarting_msg = "\n(dinit: note: service restarted)\n";
-				unsigned restarting_msg_len = strlen(restarting_msg);
-				bool trailing_nl = log_buffer[log_buf_size - 1] == '\n';
-				if (trailing_nl) {
-					++restarting_msg; // trim leading newline
-					--restarting_msg_len;
-				}
-				if (log_buf_size + restarting_msg_len >= log_buf_max) {
-					goto skip_enable_log_watch;
-				}
-				if (!ensure_log_buffer_backing(log_buf_size + restarting_msg_len)) {
-					goto skip_enable_log_watch;
-				}
-				memcpy(log_buffer.data() + log_buf_size, restarting_msg, restarting_msg_len);
-				log_buf_size += restarting_msg_len;
-			}
-			log_output_listener.set_enabled(event_loop, true);
-		}
-		skip_enable_log_watch: ;
-
-		// Set up complete, now fork and exec:
-
-		pid_t forkpid;
-
-		try {
-			child_status_listener.add_watch(event_loop, pipefd[0], dasynq::IN_EVENTS);
-			child_status_registered = true;
-
-			// We specify a high priority (i.e. low priority value) so that process termination is
-			// handled early. This means we have always recorded that the process is terminated by the
-			// time that we handle events that might otherwise cause us to signal the process, so we
-			// avoid sending a signal to an invalid (and possibly recycled) process ID.
-			forkpid = child_listener.fork(event_loop, reserved_child_watch, dasynq::DEFAULT_PRIORITY - 10);
-			reserved_child_watch = true;
-		}
-		catch (std::exception &e) {
-			log(loglevel_t::ERROR, get_name(), ": could not fork: ", e.what());
-			goto out_cs_h;
-		}
-
-		if (forkpid == 0) {
-			const char * working_dir_c = nullptr;
-			if (! working_dir.empty()) working_dir_c = working_dir.c_str();
-			after_fork(getpid());
-			run_proc_params run_params{cmd.data(), working_dir_c, logfile, pipefd[1], run_as_uid, run_as_gid, rlimits};
-			run_params.on_console = on_console;
-			run_params.in_foreground = !onstart_flags.shares_console;
-			run_params.csfd = control_socket[1];
-			run_params.socket_fd = socket_fd;
-			run_params.notify_fd = notify_pipe[1];
-			run_params.force_notify_fd = force_notification_fd;
-			run_params.notify_var = notification_var.c_str();
-			run_params.env_file = env_file.c_str();
-			run_params.output_fd = log_output_fd;
-			#if SUPPORT_CGROUPS
-			run_params.run_in_cgroup = run_in_cgroup.c_str();
-			#endif
-			run_child_proc(run_params);
-		}
-		else {
-			// Parent process
-			pid = forkpid;
-
-			bp_sys::close(pipefd[1]); // close the 'other end' fd
-			if (control_socket[1] != -1) bp_sys::close(control_socket[1]);
-			if (notify_pipe[1] != -1) bp_sys::close(notify_pipe[1]);
-			notification_fd = notify_pipe[0];
-			waiting_for_execstat = true;
-			return true;
-		}
-
-		// Failure exit:
-
-		out_cs_h:
-		if (child_status_registered) {
-			child_status_listener.deregister(event_loop);
-		}
-
-		if (notify_pipe[0] != -1) bp_sys::close(notify_pipe[0]);
-		if (notify_pipe[1] != -1) bp_sys::close(notify_pipe[1]);
-		if (ready_watcher_registered) {
-			rwatcher->deregister(event_loop);
-		}
-
-		if (onstart_flags.pass_cs_fd) {
-			delete control_conn;
-
-			out_cs:
-			bp_sys::close(control_socket[0]);
-			bp_sys::close(control_socket[1]);
-		}
+        bool child_status_registered = false;
+        control_conn_t *control_conn = nullptr;
+
+        int control_socket[2] = {-1, -1};
+        int notify_pipe[2] = {-1, -1};
+        bool have_notify = !notification_var.empty() || force_notification_fd != -1;
+        ready_notify_watcher * rwatcher = have_notify ? get_ready_watcher() : nullptr;
+        bool ready_watcher_registered = false;
+
+        if (onstart_flags.pass_cs_fd) {
+            if (dinit_socketpair(AF_UNIX, SOCK_STREAM, /* protocol */ 0, control_socket, SOCK_NONBLOCK)) {
+                log(loglevel_t::ERROR, get_name(), ": can't create control socket: ", strerror(errno));
+                goto out_lfd;
+            }
+
+            // Make the server side socket close-on-exec:
+            int fdflags = bp_sys::fcntl(control_socket[0], F_GETFD);
+            bp_sys::fcntl(control_socket[0], F_SETFD, fdflags | FD_CLOEXEC);
+
+            try {
+                control_conn = new control_conn_t(event_loop, services, control_socket[0]);
+            }
+            catch (std::exception &exc) {
+                log(loglevel_t::ERROR, get_name(), ": can't launch process; out of memory");
+                goto out_cs;
+            }
+        }
+
+        if (have_notify) {
+            // Create a notification pipe:
+            if (bp_sys::pipe2(notify_pipe, 0) != 0) {
+                log(loglevel_t::ERROR, get_name(), ": can't create notification pipe: ", strerror(errno));
+                goto out_cs_h;
+            }
+
+            // Set the read side as close-on-exec:
+            int fdflags = bp_sys::fcntl(notify_pipe[0], F_GETFD);
+            bp_sys::fcntl(notify_pipe[0], F_SETFD, fdflags | FD_CLOEXEC);
+
+            // add, but don't yet enable, readiness watcher:
+            try {
+                rwatcher->add_watch(event_loop, notify_pipe[0], dasynq::IN_EVENTS, false);
+                ready_watcher_registered = true;
+            }
+            catch (std::exception &exc) {
+                log(loglevel_t::ERROR, get_name(), ": can't add notification watch: ", exc.what());
+                goto out_cs_h;
+            }
+        }
+
+        if (log_type == log_type_id::BUFFER) {
+            // Set watcher enabled if space in buffer
+            if (log_buf_size > 0) {
+                // Append a "restarted" message to buffer contents
+                const char *restarting_msg = "\n(dinit: note: service restarted)\n";
+                unsigned restarting_msg_len = strlen(restarting_msg);
+                bool trailing_nl = log_buffer[log_buf_size - 1] == '\n';
+                if (trailing_nl) {
+                    ++restarting_msg; // trim leading newline
+                    --restarting_msg_len;
+                }
+                if (log_buf_size + restarting_msg_len >= log_buf_max) {
+                    goto skip_enable_log_watch;
+                }
+                if (!ensure_log_buffer_backing(log_buf_size + restarting_msg_len)) {
+                    goto skip_enable_log_watch;
+                }
+                memcpy(log_buffer.data() + log_buf_size, restarting_msg, restarting_msg_len);
+                log_buf_size += restarting_msg_len;
+            }
+            log_output_listener.set_enabled(event_loop, true);
+        }
+        skip_enable_log_watch: ;
+
+        // Set up complete, now fork and exec:
+
+        pid_t forkpid;
+
+        try {
+            child_status_listener.add_watch(event_loop, pipefd[0], dasynq::IN_EVENTS);
+            child_status_registered = true;
+
+            // We specify a high priority (i.e. low priority value) so that process termination is
+            // handled early. This means we have always recorded that the process is terminated by the
+            // time that we handle events that might otherwise cause us to signal the process, so we
+            // avoid sending a signal to an invalid (and possibly recycled) process ID.
+            forkpid = child_listener.fork(event_loop, reserved_child_watch, dasynq::DEFAULT_PRIORITY - 10);
+            reserved_child_watch = true;
+        }
+        catch (std::exception &e) {
+            log(loglevel_t::ERROR, get_name(), ": could not fork: ", e.what());
+            goto out_cs_h;
+        }
+
+        if (forkpid == 0) {
+            const char * working_dir_c = nullptr;
+            if (! working_dir.empty()) working_dir_c = working_dir.c_str();
+            after_fork(getpid());
+            run_proc_params run_params{cmd.data(), working_dir_c, logfile, pipefd[1], run_as_uid, run_as_gid, rlimits};
+            run_params.on_console = on_console;
+            run_params.in_foreground = !onstart_flags.shares_console;
+            run_params.csfd = control_socket[1];
+            run_params.socket_fd = socket_fd;
+            run_params.notify_fd = notify_pipe[1];
+            run_params.force_notify_fd = force_notification_fd;
+            run_params.notify_var = notification_var.c_str();
+            run_params.env_file = env_file.c_str();
+            run_params.output_fd = log_output_fd;
+            #if SUPPORT_CGROUPS
+            run_params.run_in_cgroup = run_in_cgroup.c_str();
+            #endif
+            run_child_proc(run_params);
+        }
+        else {
+            // Parent process
+            pid = forkpid;
+
+            bp_sys::close(pipefd[1]); // close the 'other end' fd
+            if (control_socket[1] != -1) bp_sys::close(control_socket[1]);
+            if (notify_pipe[1] != -1) bp_sys::close(notify_pipe[1]);
+            notification_fd = notify_pipe[0];
+            waiting_for_execstat = true;
+            return true;
+        }
+
+        // Failure exit:
+
+        out_cs_h:
+        if (child_status_registered) {
+            child_status_listener.deregister(event_loop);
+        }
+
+        if (notify_pipe[0] != -1) bp_sys::close(notify_pipe[0]);
+        if (notify_pipe[1] != -1) bp_sys::close(notify_pipe[1]);
+        if (ready_watcher_registered) {
+            rwatcher->deregister(event_loop);
+        }
+
+        if (onstart_flags.pass_cs_fd) {
+            delete control_conn;
+
+            out_cs:
+            bp_sys::close(control_socket[0]);
+            bp_sys::close(control_socket[1]);
+        }
     }
 
     out_lfd:
-	if (log_input_fd != -1) {
-		log_output_listener.deregister(event_loop);
-		bp_sys::close(log_input_fd);
-		bp_sys::close(log_output_fd);
-		log_input_fd = -1;
-		log_output_fd = -1;
-	}
+    if (log_input_fd != -1) {
+        log_output_listener.deregister(event_loop);
+        bp_sys::close(log_input_fd);
+        bp_sys::close(log_output_fd);
+        log_input_fd = -1;
+        log_output_fd = -1;
+    }
 
     out_p:
     bp_sys::close(pipefd[0]);
@@ -545,22 +545,22 @@ bool base_process_service::open_socket() noexcept
 
 bool base_process_service::ensure_log_buffer_backing(unsigned new_size) noexcept
 {
-	//  Note: we manage capacity manually to avoid it exceeding maximum
+    //  Note: we manage capacity manually to avoid it exceeding maximum
     if (log_buffer.size() < new_size) {
         if (log_buffer.capacity() < new_size) {
-        	try {
-				unsigned new_capacity = std::max((unsigned)log_buffer.capacity() * 2, new_size);
-				new_capacity = std::min(new_capacity, log_buf_max);
-				log_buffer.reserve(new_capacity);
-				log_buffer.resize(new_capacity);
-        	}
-        	catch (std::bad_alloc &badalloc) {
-        		log(loglevel_t::WARN, get_name(), ": cannot increase log buffer; out-of-memory");
-        		return false;
-        	}
+            try {
+                unsigned new_capacity = std::max((unsigned)log_buffer.capacity() * 2, new_size);
+                new_capacity = std::min(new_capacity, log_buf_max);
+                log_buffer.reserve(new_capacity);
+                log_buffer.resize(new_capacity);
+            }
+            catch (std::bad_alloc &badalloc) {
+                log(loglevel_t::WARN, get_name(), ": cannot increase log buffer; out-of-memory");
+                return false;
+            }
         }
         else {
-        	log_buffer.resize(new_size);
+            log_buffer.resize(new_size);
         }
     }
     return true;

+ 15 - 15
src/dinitcheck.cc

@@ -140,15 +140,15 @@ int main(int argc, char **argv)
             }
             // add chain_to to services_to_check
             if (!sr->chain_to.empty() && !contains(services_to_check, sr->chain_to)) {
-            	if (!contains(services_to_check, sr->chain_to)) {
-            		services_to_check.push_back(sr->chain_to);
-            	}
+                if (!contains(services_to_check, sr->chain_to)) {
+                    services_to_check.push_back(sr->chain_to);
+                }
             }
             // add before_svcs to services_to_check
             for (const std::string &before_name : sr->before_svcs) {
-            	if (!contains(services_to_check, before_name)) {
-            		services_to_check.push_back(before_name);
-            	}
+                if (!contains(services_to_check, before_name)) {
+                    services_to_check.push_back(before_name);
+                }
             }
         }
         catch (service_load_exc &exc) {
@@ -159,13 +159,13 @@ int main(int argc, char **argv)
 
     // For "before" reverse-dependencies, set up dependencies in the forwards direction (from the dependent)
     for (const auto &svc_name_record : service_set) {
-    	for (const std::string &before_name : svc_name_record.second->before_svcs) {
-    		auto before_svc_it = service_set.find(before_name);
-    		if (before_svc_it != service_set.end()) {
-    			before_svc_it->second->dependencies.emplace_back(svc_name_record.first,
-    					dependency_type::BEFORE);
-    		}
-    	}
+        for (const std::string &before_name : svc_name_record.second->before_svcs) {
+            auto before_svc_it = service_set.find(before_name);
+            if (before_svc_it != service_set.end()) {
+                before_svc_it->second->dependencies.emplace_back(svc_name_record.first,
+                        dependency_type::BEFORE);
+            }
+        }
     }
 
     // Check for circular dependencies
@@ -227,12 +227,12 @@ int main(int argc, char **argv)
         errors_found = true;
         std::cerr << "Found dependency cycle:\n";
         for (auto chain_link : service_chain) {
-        	service_record *svc = std::get<0>(chain_link);
+            service_record *svc = std::get<0>(chain_link);
             size_t dep_index = std::get<1>(chain_link);
             std::cerr << "    " << svc->name << " ->";
             auto dep_it = std::next(svc->dependencies.begin(), dep_index);
             if (dep_it->dep_type == dependency_type::BEFORE) {
-            	std::cerr << " (via 'before')";
+                std::cerr << " (via 'before')";
             }
             std::cerr << "\n";
         }

+ 34 - 34
src/dinitctl.cc

@@ -239,7 +239,7 @@ int dinitctl_main(int argc, char **argv)
                 command = command_t::UNSET_TRIGGER;
             }
             else if (strcmp(argv[i], "catlog") == 0) {
-            	command = command_t::CAT_LOG;
+                command = command_t::CAT_LOG;
             }
             else {
                 cerr << "dinitctl: unrecognized command: " << argv[i] << " (use --help for help)\n";
@@ -251,17 +251,17 @@ int dinitctl_main(int argc, char **argv)
             if (command == command_t::ADD_DEPENDENCY || command == command_t::RM_DEPENDENCY) {
                 if (! dep_type_set) {
                     if (strcmp(argv[i], "regular") == 0) {
-                    	dep_type = dependency_type::REGULAR;
+                        dep_type = dependency_type::REGULAR;
                     }
                     else if (strcmp(argv[i], "milestone") == 0) {
-                    	dep_type = dependency_type::MILESTONE;
+                        dep_type = dependency_type::MILESTONE;
                     }
                     else if (strcmp(argv[i], "waits-for") == 0) {
-                    	dep_type = dependency_type::WAITS_FOR;
+                        dep_type = dependency_type::WAITS_FOR;
                     }
                     else {
-                    	show_help = true;
-                    	break;
+                        show_help = true;
+                        break;
                     }
                     dep_type_set = true;
                 }
@@ -1100,7 +1100,7 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
             rbuffer.extract((char *)&service_pid, 8, sizeof(service_pid));
         }
         else {
-        	rbuffer.extract((char *)&exit_status, 8, sizeof(exit_status));
+            rbuffer.extract((char *)&exit_status, 8, sizeof(exit_status));
         }
 
         fill_buffer_to(rbuffer, socknum, name_len + hdrsize);
@@ -1149,14 +1149,14 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
             cout << (did_fail ? 'X' : '-');
         }
         else {
-        	cout << ' ';
+            cout << ' ';
         }
         cout << (target == service_state_t::STOPPED ? '}' : ' ');
 
         cout << "] " << name;
 
         if (current != service_state_t::STOPPED && has_pid) {
-        	cout << " (pid: " << service_pid << ")";
+            cout << " (pid: " << service_pid << ")";
         }
         
         if (current == service_state_t::STOPPED && stop_reason == stopped_reason_t::TERMINATED) {
@@ -1169,10 +1169,10 @@ static int list_services(int socknum, cpbuffer_t &rbuffer)
         }
 
         if (has_console) {
-        	cout << " (has console)";
+            cout << " (has console)";
         }
         else if (waiting_console) {
-        	cout << " (waiting for console)";
+            cout << " (waiting for console)";
         }
 
         cout << endl;
@@ -1797,9 +1797,9 @@ static int cat_service_log(int socknum, cpbuffer_t &rbuffer, const char *service
 
     // Issue CATLOG
     auto m = membuf()
-    		 .append<char>(DINIT_CP_CATLOG)
-			 .append<char>(0)
-			 .append(handle);
+             .append<char>(DINIT_CP_CATLOG)
+             .append<char>(0)
+             .append(handle);
     write_all_x(socknum, m);
 
     wait_for_reply(rbuffer, socknum);
@@ -1819,26 +1819,26 @@ static int cat_service_log(int socknum, cpbuffer_t &rbuffer, const char *service
 
     // output the log
     if (bufsize > 0) {
-		cout << flush;
-
-		bool trailing_nl = false;
-		char output_buf[rbuffer.get_size()];
-		while (bufsize > 0) {
-			unsigned l = rbuffer.get_length();
-			if (l == 0) {
-				fill_buffer_to(rbuffer, socknum, 1);
-			}
-			l = std::min(rbuffer.get_length(), bufsize);
-			rbuffer.extract(output_buf, 0, l);
-			write(STDOUT_FILENO, output_buf, l);
-			rbuffer.consume(l);
-			bufsize -= l;
-			trailing_nl = (output_buf[l - 1] == '\n');
-		}
-
-		if (!trailing_nl) {
-			cout << "\n(last line is truncated or incomplete)\n";
-		}
+        cout << flush;
+
+        bool trailing_nl = false;
+        char output_buf[rbuffer.get_size()];
+        while (bufsize > 0) {
+            unsigned l = rbuffer.get_length();
+            if (l == 0) {
+                fill_buffer_to(rbuffer, socknum, 1);
+            }
+            l = std::min(rbuffer.get_length(), bufsize);
+            rbuffer.extract(output_buf, 0, l);
+            write(STDOUT_FILENO, output_buf, l);
+            rbuffer.consume(l);
+            bufsize -= l;
+            trailing_nl = (output_buf[l - 1] == '\n');
+        }
+
+        if (!trailing_nl) {
+            cout << "\n(last line is truncated or incomplete)\n";
+        }
     }
 
     return 0;

+ 17 - 17
src/includes/dinit-util.h

@@ -21,28 +21,28 @@
 // Use like:     value(x).is_in(1,2,3)
 template <typename T>
 class value_cls {
-	const T &v;
+    const T &v;
 public:
-	value_cls(const T &v) : v(v) {}
-
-	template <typename U>
-	bool is_in(U&& val)
-	{
-		return v == val;
-	}
-
-	template <typename U, typename ...V>
-	bool is_in(U&&val, V&&... vals) {
-		if (v == val)
-			return true;
-		return is_in(vals...);
-	}
+    value_cls(const T &v) : v(v) {}
+
+    template <typename U>
+    bool is_in(U&& val)
+    {
+        return v == val;
+    }
+
+    template <typename U, typename ...V>
+    bool is_in(U&&val, V&&... vals) {
+        if (v == val)
+            return true;
+        return is_in(vals...);
+    }
 };
 
 template <typename T>
 value_cls<T> value(const T &v)
 {
-	return value_cls<T>(v);
+    return value_cls<T>(v);
 }
 
 // Complete read - read the specified size until end-of-file or error; continue read if
@@ -138,7 +138,7 @@ public:
     template <typename U = std::enable_if<std::is_default_constructible<T>::value>>
     void construct(T *obj)
     {
-    	// avoid value-initialisation:
+        // avoid value-initialisation:
         ::new(obj) T;
     }
 

+ 2 - 2
src/includes/load-service.h

@@ -726,7 +726,7 @@ static void value_var_subst(const char *setting_name, std::string &line,
             }
             else {
                 // variable
-            	auto token_end = std::next(line.begin(), i->second);
+                auto token_end = std::next(line.begin(), i->second);
                 bool brace = line[dindx + 1] == '{';
                 auto i = std::next(line.begin(), dindx + 1 + int(brace));
                 // read environment variable name
@@ -993,7 +993,7 @@ class service_settings_wrapper
 #endif
 
         if (log_type != log_type_id::LOGFILE) {
-        	logfile.clear();
+            logfile.clear();
         }
     }
 };

+ 81 - 81
src/load-service.cc

@@ -124,7 +124,7 @@ static void check_cycle(service_dep_list &deps, service_record *orig, const std:
 // Check for dependency cycles in "before" dependencies, _orig_ is where cycles will be identified.
 static void check_cycle(service_dep_list &deps, service_record *orig)
 {
-	check_cycle(deps, orig, orig->get_name());
+    check_cycle(deps, orig, orig->get_name());
 }
 
 // Update the dependencies of the specified service atomically.
@@ -313,7 +313,7 @@ static bool check_settings_for_reload(service_record *service,
 service_record * dirload_service_set::load_reload_service(const char *name, service_record *reload_svc,
         const service_record *avoid_circular)
 {
-	// Load a new service, or reload an already-loaded service.
+    // Load a new service, or reload an already-loaded service.
 
     // For reload, we have the following problems:
     // - ideally want to allow changing service type, at least for stopped services. That implies creating
@@ -327,26 +327,26 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
     //   (which we can only do if the type doesn't change).
 
     // Approach:
-	// - determine whether we need a new service record or can alter the existing one
-	//   (loading a new service always creates a new record; reload only creates a new record if the service
-	//   type changes, and otherwise just changes the existing record in-place).
-	// - if loading a new service, a dummy record is created to enable easy cyclic dependency detection.
-	//   (In other cases cycles must be checked by walking the service graph).
-	//   The dummy is replaced with the real service once loading is complete (or is removed if it fails).
-	// - process settings from the service file (into a service_settings_wrapper).
+    // - determine whether we need a new service record or can alter the existing one
+    //   (loading a new service always creates a new record; reload only creates a new record if the service
+    //   type changes, and otherwise just changes the existing record in-place).
+    // - if loading a new service, a dummy record is created to enable easy cyclic dependency detection.
+    //   (In other cases cycles must be checked by walking the service graph).
+    //   The dummy is replaced with the real service once loading is complete (or is removed if it fails).
+    // - process settings from the service file (into a service_settings_wrapper).
     // - check that the new settings are valid (for reload, if the service is running, check if the settings
-	//   can be altered).
-	// - create the new record and install the new settings in it (or the existing record if not creating a
-	//   new record). If doing a reload, check for cycles at this point (there is no dummy record in this
-	//   case, so the quick cycle detection is not active).
-	// - (if doing a reload, with a new record) move the dependents on the original record to the new record.
-	//
-	// "Before" dependencies require special handling, as a "before = " specified in a service actually creates
-	// a dependency in the specified service on this service. Hence they always require explicit cycle checks
-	// (the quick cycle detection method using a dummy service cannot be used). For reloads this is done early,
-	// for new services it is done late (after the dummy has been removed).
-	//
-	// This is all an intricate dance. If failure occurs at any stage, we must restore the previous state.
+    //   can be altered).
+    // - create the new record and install the new settings in it (or the existing record if not creating a
+    //   new record). If doing a reload, check for cycles at this point (there is no dummy record in this
+    //   case, so the quick cycle detection is not active).
+    // - (if doing a reload, with a new record) move the dependents on the original record to the new record.
+    //
+    // "Before" dependencies require special handling, as a "before = " specified in a service actually creates
+    // a dependency in the specified service on this service. Hence they always require explicit cycle checks
+    // (the quick cycle detection method using a dummy service cannot be used). For reloads this is done early,
+    // for new services it is done late (after the dummy has been removed).
+    //
+    // This is all an intricate dance. If failure occurs at any stage, we must restore the previous state.
 
     // Limitations:
     // - caller must check there are no handles (or only a single requesting handle) to the service before
@@ -373,7 +373,7 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
                 throw service_cyclic_dependency(name);
             }
             if (existing->get_type() != service_type_t::PLACEHOLDER) {
-            	return existing;
+                return existing;
             }
 
             // If we found a placeholder, we proceed as for a reload:
@@ -435,8 +435,8 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
             delete dummy;
         }
         if (create_new_record && rval != nullptr) {
-        	rval->prepare_for_unload();
-        	delete rval;
+            rval->prepare_for_unload();
+            delete rval;
         }
         for (service_dep &before_dep : before_deps) {
             service_record *before_svc = before_dep.get_from();
@@ -457,21 +457,21 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
         }
     };
 
-	if (reload_svc == nullptr) {
-		// Add a placeholder record now to prevent infinite recursion in case of cyclic dependency.
-		// We replace this with the real service later (or remove it if we find a configuration error).
-		try {
-			dummy = new service_record(this, string(name), service_record::LOADING_TAG);
-			add_service(dummy);
-		}
-		catch (...) {
-			delete dummy; // (no effect if dummy is null)
-			dummy = nullptr;
-			throw;
-		}
-	}
-
-	try {
+    if (reload_svc == nullptr) {
+        // Add a placeholder record now to prevent infinite recursion in case of cyclic dependency.
+        // We replace this with the real service later (or remove it if we find a configuration error).
+        try {
+            dummy = new service_record(this, string(name), service_record::LOADING_TAG);
+            add_service(dummy);
+        }
+        catch (...) {
+            delete dummy; // (no effect if dummy is null)
+            dummy = nullptr;
+            throw;
+        }
+    }
+
+    try {
         process_service_file(name, service_file,
                 [&](string &line, unsigned line_num, string &setting,
                         string_iterator &i, string_iterator &end) -> void {
@@ -611,8 +611,8 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
                 before_deps.emplace_back(before_svc, reload_svc, dependency_type::BEFORE);
                 // (note, we may need to adjust the to-service if we create a new service record object
                 // - this will be done later)
-			}
-		}
+            }
+        }
 
         if (service_type == service_type_t::PROCESS) {
             do_env_subst("command", settings.command, settings.command_offsets, srv_envmap);
@@ -762,7 +762,7 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
         if (create_new_record) {
             // switch dependencies on old record so that they refer to the new record
 
-        	// first link in all the (new) "before" dependents (one way at this stage):
+            // first link in all the (new) "before" dependents (one way at this stage):
             auto &dept_list = rval->get_dependents();
             unsigned added_dependents = 0;
             try {
@@ -796,52 +796,52 @@ service_record * dirload_service_set::load_reload_service(const char *name, serv
             if (reload_svc != nullptr) {
                 // Complete dependency/dependent transfers.
 
-            	// Remove all "before" dependents from the original service (these were created by the
+                // Remove all "before" dependents from the original service (these were created by the
                 // original service itself)
-				auto &reload_depts = reload_svc->get_dependents();
-				for (auto i = reload_depts.begin(); i != reload_depts.end(); ) {
-					auto next_i = std::next(i);
-					if ((*i)->dep_type == dependency_type::BEFORE) {
-					    service_record *before_svc = (*i)->get_from();
-						before_svc->rm_dep(**i);
-						if (before_svc->get_type() == service_type_t::PLACEHOLDER && before_svc->is_unrefd()) {
-						    remove_service(before_svc);
-						    delete before_svc;
-						}
-					}
-					i = next_i;
-				}
-
-				// Transfer dependents from the original service record to the new record;
-				// set links in all dependents on the original to point to the new service:
-				auto first_new_before = dept_list.begin();
-				dept_list.splice(first_new_before, reload_depts);
-				for (auto &dept : dept_list) {
-					dept->set_to(rval);
-				}
-
-				// Transfer all "before" dependencies (which are actually created by other services) to the
-				// new service
-				auto &dep_list_prev = reload_svc->get_dependencies();
-				auto &dep_list = rval->get_dependencies();
-				for (auto i = dep_list_prev.begin(); i != dep_list_prev.end(); ++i) {
-				    if (i->dep_type == dependency_type::BEFORE) {
-				        i->set_from(rval);
-				        dep_list.splice(dep_list.end(), dep_list_prev, i++);
-				        continue;
-				    }
-				}
-
-				// Remove dependent-link for all dependencies from the original:
-				reload_svc->prepare_for_unload();
+                auto &reload_depts = reload_svc->get_dependents();
+                for (auto i = reload_depts.begin(); i != reload_depts.end(); ) {
+                    auto next_i = std::next(i);
+                    if ((*i)->dep_type == dependency_type::BEFORE) {
+                        service_record *before_svc = (*i)->get_from();
+                        before_svc->rm_dep(**i);
+                        if (before_svc->get_type() == service_type_t::PLACEHOLDER && before_svc->is_unrefd()) {
+                            remove_service(before_svc);
+                            delete before_svc;
+                        }
+                    }
+                    i = next_i;
+                }
+
+                // Transfer dependents from the original service record to the new record;
+                // set links in all dependents on the original to point to the new service:
+                auto first_new_before = dept_list.begin();
+                dept_list.splice(first_new_before, reload_depts);
+                for (auto &dept : dept_list) {
+                    dept->set_to(rval);
+                }
+
+                // Transfer all "before" dependencies (which are actually created by other services) to the
+                // new service
+                auto &dep_list_prev = reload_svc->get_dependencies();
+                auto &dep_list = rval->get_dependencies();
+                for (auto i = dep_list_prev.begin(); i != dep_list_prev.end(); ++i) {
+                    if (i->dep_type == dependency_type::BEFORE) {
+                        i->set_from(rval);
+                        dep_list.splice(dep_list.end(), dep_list_prev, i++);
+                        continue;
+                    }
+                }
+
+                // Remove dependent-link for all dependencies from the original:
+                reload_svc->prepare_for_unload();
             }
 
             // Finally, replace the old service with the new one:
             service_record *old_service = (reload_svc != nullptr) ? reload_svc : dummy;
 
             auto iter = std::find(records.begin(), records.end(), old_service);
-			*iter = rval;
-			delete old_service;
+            *iter = rval;
+            delete old_service;
         }
 
         return rval;

+ 49 - 49
src/proc-service.cc

@@ -85,8 +85,8 @@ void process_service::exec_succeeded() noexcept
 
 void scripted_service::exec_succeeded() noexcept
 {
-	// For a scripted service, this means nothing other than that the start/stop
-	// script will now begin.
+    // For a scripted service, this means nothing other than that the start/stop
+    // script will now begin.
 }
 
 rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) noexcept
@@ -259,54 +259,54 @@ dasynq::rearm stop_child_watcher::status_change(eventloop_t &loop, pid_t child,
 
 rearm log_output_watcher::fd_event(eventloop_t &eloop, int fd, int flags) noexcept
 {
-	// In case buffer size has been decreased, check if we are already at the limit:
-	if (service->log_buf_size >= service->log_buf_max) {
-		// If so, read and discard.
-		char buf[1024];
-		int r = bp_sys::read(fd, buf, 1024);
-		if (r == -1) {
-	    	if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
-	    		return rearm::REARM;
-	    	}
-	    	goto bad_read;
-		}
-		if (r == 0) goto eof_read;
-		return rearm::REARM;
-	}
-
-	{
-		size_t max_read = std::max(service->log_buf_max / 8, 256u);
-		max_read = std::min((unsigned)max_read, service->log_buf_max - service->log_buf_size);
-
-		// ensure vector has size sufficient to read
-		unsigned new_size = service->log_buf_size + max_read;
-		if (!service->ensure_log_buffer_backing(new_size)) {
-			return rearm::DISARM;
-		}
-
-		max_read = service->log_buffer.size() - service->log_buf_size;
-
-		int r = bp_sys::read(fd, service->log_buffer.data() + service->log_buf_size, max_read);
-		if (r == -1) {
-			if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
-				return rearm::REARM;
-			}
-			goto bad_read;
-		}
-
-		if (r == 0) goto eof_read;
-
-		service->log_buf_size += r;
-		return rearm::REARM;
-	}
+    // In case buffer size has been decreased, check if we are already at the limit:
+    if (service->log_buf_size >= service->log_buf_max) {
+        // If so, read and discard.
+        char buf[1024];
+        int r = bp_sys::read(fd, buf, 1024);
+        if (r == -1) {
+            if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
+                return rearm::REARM;
+            }
+            goto bad_read;
+        }
+        if (r == 0) goto eof_read;
+        return rearm::REARM;
+    }
+
+    {
+        size_t max_read = std::max(service->log_buf_max / 8, 256u);
+        max_read = std::min((unsigned)max_read, service->log_buf_max - service->log_buf_size);
+
+        // ensure vector has size sufficient to read
+        unsigned new_size = service->log_buf_size + max_read;
+        if (!service->ensure_log_buffer_backing(new_size)) {
+            return rearm::DISARM;
+        }
+
+        max_read = service->log_buffer.size() - service->log_buf_size;
+
+        int r = bp_sys::read(fd, service->log_buffer.data() + service->log_buf_size, max_read);
+        if (r == -1) {
+            if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
+                return rearm::REARM;
+            }
+            goto bad_read;
+        }
+
+        if (r == 0) goto eof_read;
+
+        service->log_buf_size += r;
+        return rearm::REARM;
+    }
 
     // error/end-of-stream handling:
 
     bad_read:
-	log(loglevel_t::WARN, "Service ", service->get_name(), " output not readable: ", strerror(errno));
+    log(loglevel_t::WARN, "Service ", service->get_name(), " output not readable: ", strerror(errno));
 
-	eof_read:
-	deregister(eloop);
+    eof_read:
+    deregister(eloop);
     close(fd);
     close(service->log_output_fd);
     service->log_input_fd = -1;
@@ -846,10 +846,10 @@ void process_service::kill_with_fire() noexcept
 
 void scripted_service::bring_down() noexcept
 {
-	if (pid != -1) {
-		// We're already running the stop script; nothing to do.
-		return;
-	}
+    if (pid != -1) {
+        // We're already running the stop script; nothing to do.
+        return;
+    }
 
     if (stop_command.length() == 0) {
         stopped();

+ 2 - 2
src/service.cc

@@ -199,7 +199,7 @@ void service_record::release(bool issue_stop) noexcept
 
         if (service_state != service_state_t::STOPPED && service_state != service_state_t::STOPPING
                 && issue_stop) {
-        	stop_reason = stopped_reason_t::NORMAL;
+            stop_reason = stopped_reason_t::NORMAL;
             do_stop();
         }
     }
@@ -618,7 +618,7 @@ void service_record::stop(bool bring_down) noexcept
     if (bring_down && service_state != service_state_t::STOPPED) {
         // Note even if we are already STOPPING we should call do_stop for the case where we need
         // to interrupt any currently ongoing restart of dependents.
-    	stop_reason = stopped_reason_t::NORMAL;
+        stop_reason = stopped_reason_t::NORMAL;
         do_stop();
     }
 }