Skip to content
This repository has been archived by the owner on Oct 6, 2023. It is now read-only.

Commit

Permalink
fix(process): Deadlocks removed in process/process_manager (#67)
Browse files Browse the repository at this point in the history
    * enh(cmake): new possibility to compile with clang and with libc++
    * fix(process): With clang, this file did not compile
    * enh(process): new tests
    * fix(process): wait on condition variable protected now.
    * fix(process_manager): attempt to join add() and update_list()
    * fix(process_manager): mutexes management modified.
    * cleanup(process_manager): Dead code removed and comments added.
    * fix(test): unit tests re enabled for some of them.
    * fix(process): wait() could badly wait.
    * fix(process): warnings removed.
    * fix(process_manager): orphans management was broken
    * cleanup(gitignore): new files to ignore
    * doc(process_manager): Improvement of the doc
    * cleanup(various): coding style
    * fix(process_manager): a process can be stopped very early, before being stored in the manager

    REFS: MON-11027
  • Loading branch information
bouda1 committed Oct 7, 2021
1 parent 27d20ca commit 4434a8c
Show file tree
Hide file tree
Showing 179 changed files with 1,326 additions and 1,027 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
.*.swp
.vscode
CMakeLists.txt.user
build/*
deps.png
inc/com/centreon/clib/version.hh
script/centreon-clib.pc
tags
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ informations.
This one is in the process class. When the process is stopping and we write to
its stdin, we could arrive to a deadlock.

Another one in the process\_manager class is also fixed.

*Fast processes*

If process fastly writes to stdout and then exits, process\_manager could miss
the output.

## 20.10.3

### Bug fixes
Expand Down
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
cmake_minimum_required(VERSION 2.8)
project("Centreon Clib" C CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -stdlib=libc++")
#set(CMAKE_CXX_COMPILER "clang++")
add_definitions("-D_GLIBCXX_USE_CXX11_ABI=1")

# Set directories.
Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/exceptions/basic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class basic : public std::exception {

misc::stringifier _buffer;
};
}
} // namespace exceptions

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/exceptions/interruption.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class interruption : public basic {
return (*this);
}
};
}
} // namespace exceptions

CC_END()

Expand Down
4 changes: 2 additions & 2 deletions inc/com/centreon/io/directory_entry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <list>
#include <string>
#include "com/centreon/io/file_entry.hh"
#include "com/centreon/handle.hh"
#include "com/centreon/io/file_entry.hh"
#include "com/centreon/namespace.hh"

CC_BEGIN()
Expand Down Expand Up @@ -55,7 +55,7 @@ class directory_entry {
file_entry _entry;
std::list<file_entry> _entry_lst;
};
}
} // namespace io

CC_END()

Expand Down
6 changes: 3 additions & 3 deletions inc/com/centreon/io/file_entry.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
#ifndef CC_IO_FILE_ENTRY_HH
#define CC_IO_FILE_ENTRY_HH

#include <string>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <string>
#include "com/centreon/handle.hh"
#include "com/centreon/namespace.hh"

Expand Down Expand Up @@ -65,7 +65,7 @@ class file_entry {
std::string _path;
struct stat _sbuf;
};
}
} // namespace io

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/io/file_stream.hh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class file_stream : public handle {
bool _auto_close;
FILE* _stream;
};
}
} // namespace io

CC_END()

Expand Down
9 changes: 2 additions & 7 deletions inc/com/centreon/logging/backend.hh
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,7 @@ class stringifier;
}

namespace logging {
enum time_precision {
none = 0,
microsecond = 1,
millisecond = 2,
second = 3
};
enum time_precision { none = 0, microsecond = 1, millisecond = 2, second = 3 };

/**
* @class backend backend.hh "com/centreon/logging/backend.hh"
Expand Down Expand Up @@ -81,7 +76,7 @@ class backend {
protected:
void _internal_copy(backend const& right);
};
}
} // namespace logging

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/logging/engine.hh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class engine {
unsigned long long _list_types[sizeof(unsigned int) * CHAR_BIT];
mutable std::mutex _mtx;
};
}
} // namespace logging

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/logging/file.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class file : public backend {
FILE* _out;
uint64_t _size;
};
}
} // namespace logging

CC_END()

Expand Down
20 changes: 8 additions & 12 deletions inc/com/centreon/logging/logger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,16 @@ enum type_value {
type_error = (1ull << 63)
};

enum verbosity_level {
low = 0,
medium = 1,
high = 2
};
}
enum verbosity_level { low = 0, medium = 1, high = 2 };
} // namespace logging

CC_END()

#define log_info(verbose) \
for (unsigned int __com_centreon_logging_define_ui(0); \
!__com_centreon_logging_define_ui && \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_info, verbose); \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_info, verbose); \
++__com_centreon_logging_define_ui) \
com::centreon::logging::temp_logger(com::centreon::logging::type_info, \
verbose) \
Expand All @@ -52,8 +48,8 @@ CC_END()
#define log_debug(verbose) \
for (unsigned int __com_centreon_logging_define_ui(0); \
!__com_centreon_logging_define_ui && \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_debug, verbose); \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_debug, verbose); \
++__com_centreon_logging_define_ui) \
com::centreon::logging::temp_logger(com::centreon::logging::type_debug, \
verbose) \
Expand All @@ -62,8 +58,8 @@ CC_END()
#define log_error(verbose) \
for (unsigned int __com_centreon_logging_define_ui(0); \
!__com_centreon_logging_define_ui && \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_error, verbose); \
com::centreon::logging::engine::instance().is_log( \
com::centreon::logging::type_error, verbose); \
++__com_centreon_logging_define_ui) \
com::centreon::logging::temp_logger(com::centreon::logging::type_error, \
verbose) \
Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/logging/syslogger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class syslogger : public backend {
int _facility;
std::string _id;
};
}
} // namespace logging

CC_END()

Expand Down
4 changes: 2 additions & 2 deletions inc/com/centreon/logging/temp_logger.hh
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

#include <string>
#include "com/centreon/logging/engine.hh"
#include "com/centreon/namespace.hh"
#include "com/centreon/misc/stringifier.hh"
#include "com/centreon/namespace.hh"

CC_BEGIN()

Expand Down Expand Up @@ -59,7 +59,7 @@ class temp_logger {
unsigned long long _type;
unsigned int _verbose;
};
}
} // namespace logging

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/misc/argument.hh
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class argument {
char _name;
std::string _value;
};
}
} // namespace misc

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/misc/command_line.hh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class command_line {
char** _argv;
size_t _size;
};
}
} // namespace misc

CC_END()

Expand Down
4 changes: 2 additions & 2 deletions inc/com/centreon/misc/get_options.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <map>
#include <string>
#include <vector>
#include "com/centreon/namespace.hh"
#include "com/centreon/misc/argument.hh"
#include "com/centreon/namespace.hh"

CC_BEGIN()

Expand Down Expand Up @@ -74,7 +74,7 @@ class get_options {
std::string& key,
std::string& value);
};
}
} // namespace misc

CC_END()

Expand Down
2 changes: 1 addition & 1 deletion inc/com/centreon/misc/stringifier.hh
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class stringifier {
static unsigned int const _static_buffer_size = 1024;
char _static_buffer[_static_buffer_size];
};
}
} // namespace misc

CC_END()

Expand Down
34 changes: 24 additions & 10 deletions inc/com/centreon/process.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
#define CC_PROCESS_POSIX_HH

#include <sys/types.h>
#include <array>
#include <atomic>
#include <condition_variable>
#include <csignal>
#include <mutex>
#include <string>
#include "com/centreon/timestamp.hh"
Expand All @@ -39,6 +42,24 @@ class process_manager;
class process {
friend class process_manager;

/* Constants */
const std::array<bool, 3> _enable_stream;
process_listener* const _listener;

/* Constants except during exec() call */
uint32_t _timeout;

/* Constants except when they are initialized at exec() and closed when
* process is over. */
std::atomic_bool _is_timeout;
std::atomic_int _status;
std::array<int, 3> _stream;
pid_t _process;

/* Almost never changed, we have two such functions, one with pgid and the
* other without. */
pid_t (*_create_process)(char**, char**);

public:
enum status { normal = 0, crash = 1, timeout = 2 };
enum stream { in = 0, out = 1, err = 2 };
Expand All @@ -59,20 +80,12 @@ class process {
* method is called by the process manager in its main loop when needed.
*/
std::string _buffer_out;
pid_t (*_create_process)(char**, char**);
mutable std::condition_variable _cv_buffer_err;
mutable std::condition_variable _cv_buffer_out;
mutable std::condition_variable _cv_process_running;
const std::array<bool, 3> _enable_stream;
std::array<int, 3> _stream;
timestamp _end_time;
bool _is_timeout;
process_listener* _listener;
mutable std::mutex _lock_process;
pid_t _process;
timestamp _start_time;
int _status;
uint32_t _timeout;

static void _close(int& fd) noexcept;
static pid_t _create_process_with_setpgid(char** args, char** env);
Expand Down Expand Up @@ -101,7 +114,7 @@ class process {
void exec(std::string const& cmd, uint32_t timeout = 0);
int exit_code() const noexcept;
status exit_status() const noexcept;
void kill();
void kill(int sig = SIGKILL);
void read(std::string& data);
void read_err(std::string& data);
void setpgid_on_exec(bool enable) noexcept;
Expand All @@ -110,9 +123,10 @@ class process {
void terminate();
void wait() const;
bool wait(uint32_t timeout) const;
void update_ending_process(int status);
uint32_t write(std::string const& data);
uint32_t write(void const* data, uint32_t size);
void update_ending_process(int status);
void set_timeout(bool timeout);
};

CC_END()
Expand Down
Loading

0 comments on commit 4434a8c

Please sign in to comment.