16 #include <sys/types.h> 
   19 #include <sys/utsname.h> 
   31 #include <qb/qbdefs.h> 
   42 #include <libxml2/libxml/relaxng.h> 
   47 #  define PW_BUFFER_LEN     500 
   93             score_f = (int) score_ll;
 
  111         snprintf(buf, len, 
"%d", score);
 
  125     return pcmk__itoa(score);
 
  134     struct passwd *pwentry = NULL;
 
  137     if (buffer == NULL) {
 
  141     rc = getpwnam_r(name, &pwd, buffer, 
PW_BUFFER_LEN, &pwentry);
 
  144             *uid = pwentry->pw_uid;
 
  147             *gid = pwentry->pw_gid;
 
  149         crm_trace(
"User %s has uid=%d gid=%d", name, pwentry->pw_uid, pwentry->pw_gid);
 
  152         rc = rc? -rc : -EINVAL;
 
  171     static uid_t daemon_uid;
 
  172     static gid_t daemon_gid;
 
  173     static bool found = 
false;
 
  201 version_helper(
const char *text, 
const char **end_text)
 
  203     int atoi_result = -1;
 
  209     if (text != NULL && text[0] != 0) {
 
  216         atoi_result = (int) strtol(text, (
char **) end_text, 10);
 
  218         if (errno == EINVAL) {
 
  219             crm_err(
"Conversion of '%s' %c failed", text, text[0]);
 
  236     const char *ver1_iter, *ver2_iter;
 
  238     if (version1 == NULL && version2 == NULL) {
 
  240     } 
else if (version1 == NULL) {
 
  242     } 
else if (version2 == NULL) {
 
  246     ver1_iter = version1;
 
  247     ver2_iter = version2;
 
  255         if (ver1_iter == ver2_iter) {
 
  259         if (ver1_iter != NULL) {
 
  260             digit1 = version_helper(ver1_iter, &ver1_iter);
 
  263         if (ver2_iter != NULL) {
 
  264             digit2 = version_helper(ver2_iter, &ver2_iter);
 
  267         if (digit1 < digit2) {
 
  271         } 
else if (digit1 > digit2) {
 
  276         if (ver1_iter != NULL && *ver1_iter == 
'.') {
 
  279         if (ver1_iter != NULL && *ver1_iter == 
'\0') {
 
  283         if (ver2_iter != NULL && *ver2_iter == 
'.') {
 
  286         if (ver2_iter != NULL && *ver2_iter == 0) {
 
  292         crm_trace(
"%s == %s (%d)", version1, version2, lpc);
 
  294         crm_trace(
"%s < %s (%d)", version1, version2, lpc);
 
  296         crm_trace(
"%s > %s (%d)", version1, version2, lpc);
 
  322     } 
else if (input[0] == 
'P') {
 
  335         crm_warn(
"Using 0 instead of '%s'", input);
 
  339     return (msec >= G_MAXUINT)? G_MAXUINT : (guint) msec;
 
  352 log_assertion_as(
const char *file, 
const char *
function, 
int line,
 
  353                  const char *assert_condition)
 
  358     crm_err(
"%s: Triggered fatal assertion at %s:%d : %s",
 
  359             function, file, line, assert_condition);
 
  375 abort_as(
const char *file, 
const char *
function, 
int line,
 
  376          const char *assert_condition)
 
  378     log_assertion_as(file, 
function, line, assert_condition);
 
  396 fail_assert_as(
const char *file, 
const char *
function, 
int line,
 
  397                const char *assert_condition)
 
  403         abort_as(file, 
function, line, assert_condition); 
 
  409             crm_warn(
"%s: Cannot dump core for non-fatal assertion at %s:%d " 
  410                      ": %s", 
function, file, line, assert_condition);
 
  418             crm_err(
"%s: Forked child [%d] to record non-fatal assertion at " 
  419                     "%s:%d : %s", 
function, pid, file, line, assert_condition);
 
  422                 if (waitpid(pid, &status, 0) == pid) {
 
  425             } 
while (errno == EINTR);
 
  426             if (errno == ECHILD) {
 
  428                 crm_trace(
"Cannot wait on forked child [%d] " 
  429                           "(SIGCHLD is probably ignored)", pid);
 
  431                 crm_err(
"Cannot wait on forked child [%d]: %s",
 
  440 crm_abort(
const char *file, 
const char *
function, 
int line,
 
  441           const char *assert_condition, gboolean do_core, gboolean do_fork)
 
  444         abort_as(file, 
function, line, assert_condition);
 
  445     } 
else if (do_core) {
 
  446         fail_assert_as(file, 
function, line, assert_condition);
 
  448         log_assertion_as(file, 
function, line, assert_condition);
 
  472         crm_err(
"%s: already running [pid %lld in %s]",
 
  473                 name, (
long long) pid, pidfile);
 
  474         printf(
"%s: already running [pid %lld in %s]\n",
 
  475                name, (
long long) pid, pidfile);
 
  481         fprintf(stderr, 
"%s: could not start daemon\n", name);
 
  485     } 
else if (pid > 0) {
 
  493         printf(
"Could not lock '%s' for %s: %s (%d)\n",
 
  498     umask(S_IWGRP | S_IWOTH | S_IROTH);
 
  501     pcmk__open_devnull(O_RDONLY);   
 
  503     close(STDOUT_FILENO);
 
  504     pcmk__open_devnull(O_WRONLY);   
 
  506     close(STDERR_FILENO);
 
  507     pcmk__open_devnull(O_WRONLY);   
 
  515     char *crm_name = NULL;
 
  521     max = strlen(crm_name);
 
  522     for (; lpc < max; lpc++) {
 
  523         switch (crm_name[lpc]) {
 
  536     const char *value = NULL;
 
  540         value = g_hash_table_lookup(hash, key);
 
  547 #ifdef HAVE_UUID_UUID_H 
  548 #  include <uuid/uuid.h> 
  554     unsigned char uuid[16];
 
  555     char *buffer = malloc(37);  
 
  558     uuid_unparse(uuid, buffer);
 
  562 #ifdef HAVE_GNUTLS_GNUTLS_H 
  564 crm_gnutls_global_init(
void)
 
  566     signal(SIGPIPE, SIG_IGN);
 
  567     gnutls_global_init();
 
  579     struct utsname hostinfo;
 
  581     return (
uname(&hostinfo) < 0)? NULL : strdup(hostinfo.nodename);
 
  618 #if defined(HAVE_NANOSLEEP) 
  621         struct timespec req = { .tv_sec = 0, .tv_nsec = (long) (ms * 1000000) };
 
  623         nanosleep(&req, NULL);
 
  625 #elif defined(HAVE_USLEEP) 
  627     usleep((useconds_t) ms);
 
  631         struct timeval tv = { .tv_sec = 0, .tv_usec = (suseconds_t) ms };
 
  633         select(0, NULL, NULL, NULL, &tv);
 
#define CRM_CHECK(expr, failure_action)
 
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
 
const char * pcmk_strerror(int rc)
 
void crm_enable_stderr(int enable)
 
char * crm_generate_uuid(void)
 
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
 
struct crm_time_s crm_time_t
 
int char2score(const char *score)
 
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent. 
 
char * score2char_stack(int score, char *buf, size_t len)
 
const char * crm_meta_value(GHashTable *hash, const char *field)
 
crm_time_t * crm_time_parse_duration(const char *duration_str)
Parse a time duration from an ISO 8601 duration specification. 
 
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
 
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user. 
 
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code. 
 
#define CRM_SCORE_INFINITY
 
Wrappers for and extensions to glib mainloop. 
 
char * crm_meta_name(const char *field)
 
#define CRM_TRACE_INIT_DATA(name)
 
gboolean crm_config_error
 
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
 
#define crm_warn(fmt, args...)
 
void pcmk__sleep_ms(unsigned int ms)
 
#define crm_trace(fmt, args...)
 
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
 
#define CRM_MINUS_INFINITY_S
 
Wrappers for and extensions to libxml2. 
 
bool pcmk_str_is_infinity(const char *s)
 
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
 
long long int crm_time_get_seconds(crm_time_t *dt)
 
void pcmk__daemonize(const char *name, const char *pidfile)
 
int pcmk__lock_pidfile(const char *filename, const char *name)
 
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr. 
 
#define crm_err(fmt, args...)
 
bool pcmk_str_is_minus_infinity(const char *s)
 
char guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification. 
 
gboolean crm_config_warning
 
int compare_version(const char *version1, const char *version2)
 
int pcmk__pidfile_matches(const char *filename, pid_t expected_pid, const char *expected_name, pid_t *pid)
 
IPC interface to Pacemaker daemons. 
 
#define CRM_PLUS_INFINITY_S
 
char * pcmk_hostname(void)
Get the local hostname. 
 
void crm_abort(const char *file, const char *function, int line, const char *condition, gboolean do_core, gboolean do_fork)
 
#define crm_info(fmt, args...)
 
char * score2char(int score)
 
void crm_time_free(crm_time_t *dt)