Clean up clang warnings
[oweals/dinit.git] / src / includes / proc-service.h
index 010037a18f83eb14db75fdcbc9d8a79eaa78e505..a3ff05a5f57a47a15a347cd22fddd364649831d2 100644 (file)
@@ -255,6 +255,20 @@ class base_process_service : public service_record
         restart_timer.deregister(event_loop);
     }
 
+    // Set the command to run this service (executable and arguments, nul separated). The command_parts_p
+    // vector must contain pointers to each part.
+    void set_command(std::string &&command_p, std::vector<const char *> &&command_parts_p) noexcept
+    {
+        program_name = std::move(command_p);
+        exec_arg_parts = std::move(command_parts_p);
+    }
+
+    void get_command(std::string &command_p, std::vector<const char *> &command_parts_p)
+    {
+        command_p = program_name;
+        command_parts_p = exec_arg_parts;
+    }
+
     // Set the stop command and arguments (may throw std::bad_alloc)
     void set_stop_command(const std::string &command,
             std::list<std::pair<unsigned,unsigned>> &stop_command_offsets)
@@ -263,11 +277,26 @@ class base_process_service : public service_record
         stop_arg_parts = separate_args(stop_command, stop_command_offsets);
     }
 
+    // Set the stop command as a sequence of nul-terminated parts (arguments).
+    //   command - the command and arguments, each terminated with nul ('\0')
+    //   command_parts - pointers to the beginning of each command part
+    void set_stop_command(std::string &&command,
+            std::vector<const char *> &&command_parts) noexcept
+    {
+        stop_command = std::move(command);
+        stop_arg_parts = std::move(command_parts);
+    }
+
     void set_env_file(const std::string &env_file_p)
     {
         env_file = env_file_p;
     }
 
+    void set_env_file(std::string &&env_file_p) noexcept
+    {
+        env_file = std::move(env_file_p);
+    }
+
     void set_rlimits(std::vector<service_rlimits> &&rlimits_p)
     {
         rlimits = std::move(rlimits_p);
@@ -313,6 +342,11 @@ class base_process_service : public service_record
         working_dir = working_dir_p;
     }
 
+    void set_working_dir(string &&working_dir_p) noexcept
+    {
+        working_dir = std::move(working_dir_p);
+    }
+
     // Set the notification fd number that the service process will use
     void set_notification_fd(int fd)
     {
@@ -400,6 +434,21 @@ class process_service : public base_process_service
         strncpy(inittab_line, line, sizeof(inittab_line));
     }
 
+    // Get the utmp (inittab) id, may not be nul terminated if maximum length!
+    const char *get_utmp_id()
+    {
+        return inittab_id;
+    }
+
+    // Get the utmp (inittab) line, may not be nul terminated if maximum length!
+    const char *get_utmp_line()
+    {
+        return inittab_line;
+    }
+
+    constexpr size_t get_utmp_id_size() const { return sizeof(inittab_id); }
+    constexpr size_t get_utmp_line_size() const { return sizeof(inittab_line); }
+
 #endif
 
     ~process_service() noexcept
@@ -420,7 +469,9 @@ class bgproc_service : public base_process_service
         TERMINATED   // read pid successfully, but the process already terminated
     };
 
-    // Read the pid-file, return false on failure
+    string pid_file;
+
+    // Read the pid-file contents
     pid_result_t read_pid_file(bp_sys::exit_status *exit_status) noexcept;
 
     public:
@@ -435,6 +486,16 @@ class bgproc_service : public base_process_service
     ~bgproc_service() noexcept
     {
     }
+
+    void set_pid_file(string &&pid_file) noexcept
+    {
+        this->pid_file = std::move(pid_file);
+    }
+
+    const std::string &get_pid_file() noexcept
+    {
+        return pid_file;
+    }
 };
 
 // Service which is started and stopped via separate commands