16 #include <sys/types.h> 19 #include <sys/utsname.h> 32 #include <qb/qbdefs.h> 43 #include <libxml2/libxml/relaxng.h> 59 if (user == NULL || group == NULL) {
64 while ((grent = getgrent()) != NULL) {
65 if (grent->gr_mem == NULL) {
69 if(strcmp(group, grent->gr_name) != 0) {
73 gr_mem = grent->gr_mem;
74 while (*gr_mem != NULL) {
75 if (!strcmp(user, *gr_mem++)) {
91 struct passwd *pwentry = NULL;
101 *uid = pwentry->pw_uid;
104 *gid = pwentry->pw_gid;
106 crm_trace(
"User %s has uid=%d gid=%d",
name, pwentry->pw_uid, pwentry->pw_gid);
109 rc = rc? -rc : -EINVAL;
128 static uid_t daemon_uid;
129 static gid_t daemon_gid;
130 static bool found =
false;
158 version_helper(
const char *text,
const char **end_text)
160 int atoi_result = -1;
166 if (text != NULL && text[0] != 0) {
173 atoi_result = (int) strtol(text, (
char **) end_text, 10);
175 if (errno == EINVAL) {
176 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
193 const char *ver1_iter, *ver2_iter;
195 if (version1 == NULL && version2 == NULL) {
197 }
else if (version1 == NULL) {
199 }
else if (version2 == NULL) {
203 ver1_iter = version1;
204 ver2_iter = version2;
212 if (ver1_iter == ver2_iter) {
216 if (ver1_iter != NULL) {
217 digit1 = version_helper(ver1_iter, &ver1_iter);
220 if (ver2_iter != NULL) {
221 digit2 = version_helper(ver2_iter, &ver2_iter);
224 if (digit1 < digit2) {
228 }
else if (digit1 > digit2) {
233 if (ver1_iter != NULL && *ver1_iter ==
'.') {
236 if (ver1_iter != NULL && *ver1_iter ==
'\0') {
240 if (ver2_iter != NULL && *ver2_iter ==
'.') {
243 if (ver2_iter != NULL && *ver2_iter == 0) {
249 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
251 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
253 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
279 }
else if (
input[0] ==
'P') {
296 return (msec >= G_MAXUINT)? G_MAXUINT : (guint) msec;
309 log_assertion_as(
const char *file,
const char *
function,
int line,
310 const char *assert_condition)
315 crm_err(
"%s: Triggered fatal assertion at %s:%d : %s",
316 function, file, line, assert_condition);
332 abort_as(
const char *file,
const char *
function,
int line,
333 const char *assert_condition)
335 log_assertion_as(file,
function, line, assert_condition);
353 fail_assert_as(
const char *file,
const char *
function,
int line,
354 const char *assert_condition)
360 abort_as(file,
function, line, assert_condition);
366 crm_warn(
"%s: Cannot dump core for non-fatal assertion at %s:%d " 367 ": %s",
function, file, line, assert_condition);
375 crm_err(
"%s: Forked child [%d] to record non-fatal assertion at " 376 "%s:%d : %s",
function,
pid, file, line, assert_condition);
379 if (waitpid(
pid, &status, 0) ==
pid) {
382 }
while (errno == EINTR);
383 if (errno == ECHILD) {
385 crm_trace(
"Cannot wait on forked child [%d] " 386 "(SIGCHLD is probably ignored)",
pid);
388 crm_err(
"Cannot wait on forked child [%d]: %s",
397 crm_abort(
const char *file,
const char *
function,
int line,
398 const char *assert_condition, gboolean do_core, gboolean do_fork)
401 abort_as(file,
function, line, assert_condition);
402 }
else if (do_core) {
403 fail_assert_as(file,
function, line, assert_condition);
405 log_assertion_as(file,
function, line, assert_condition);
429 crm_err(
"%s: already running [pid %lld in %s]",
430 name, (
long long)
pid, pidfile);
431 printf(
"%s: already running [pid %lld in %s]\n",
432 name, (
long long)
pid, pidfile);
438 fprintf(stderr,
"%s: could not start daemon\n",
name);
442 }
else if (
pid > 0) {
450 printf(
"Could not lock '%s' for %s: %s (%d)\n",
455 umask(S_IWGRP | S_IWOTH | S_IROTH);
458 pcmk__open_devnull(O_RDONLY);
460 close(STDOUT_FILENO);
461 pcmk__open_devnull(O_WRONLY);
463 close(STDERR_FILENO);
464 pcmk__open_devnull(O_WRONLY);
472 char *crm_name = NULL;
478 max = strlen(crm_name);
479 for (; lpc < max; lpc++) {
480 switch (crm_name[lpc]) {
493 const char *value = NULL;
497 value = g_hash_table_lookup(hash, key);
504 #ifdef HAVE_UUID_UUID_H 505 # include <uuid/uuid.h> 511 unsigned char uuid[16];
512 char *buffer = malloc(37);
516 uuid_unparse(uuid, buffer);
520 #ifdef HAVE_GNUTLS_GNUTLS_H 522 crm_gnutls_global_init(
void)
524 signal(SIGPIPE, SIG_IGN);
525 gnutls_global_init();
537 struct utsname hostinfo;
539 return (
uname(&hostinfo) < 0)? NULL : strdup(hostinfo.nodename);
576 #if defined(HAVE_NANOSLEEP) 579 struct timespec req = { .tv_sec = 0, .tv_nsec = (long) (ms * 1000000) };
581 nanosleep(&req, NULL);
583 #elif defined(HAVE_USLEEP) 585 usleep((useconds_t) ms);
589 struct timeval tv = { .tv_sec = 0, .tv_usec = (suseconds_t) ms };
591 select(0, NULL, NULL, NULL, &tv);
#define CRM_CHECK(expr, failure_action)
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
const char * pcmk_strerror(int rc)
void crm_enable_stderr(int enable)
const char * crm_meta_value(GHashTable *hash, const char *field)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
bool pcmk_str_is_minus_infinity(const char *s)
struct crm_time_s crm_time_t
long long crm_get_msec(const char *input)
Parse a time+units string and return milliseconds equivalent.
gboolean crm_config_warning
bool pcmk_str_is_infinity(const char *s)
crm_time_t * crm_time_parse_duration(const char *duration_str)
Parse a time duration from an ISO 8601 duration specification.
void pcmk__daemonize(const char *name, const char *pidfile)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Wrappers for and extensions to glib mainloop.
char * crm_meta_name(const char *field)
#define crm_warn(fmt, args...)
guint crm_parse_interval_spec(const char *input)
Parse milliseconds from a Pacemaker interval specification.
void pcmk__sleep_ms(unsigned int ms)
External (OS/environmental) problem.
#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.
char * crm_generate_uuid(void)
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
long long crm_time_get_seconds(const crm_time_t *dt)
CRM_TRACE_INIT_DATA(common)
char * pcmk_hostname(void)
Get the local hostname.
void crm_write_blackbox(int nsig, const struct qb_log_callsite *callsite)
int compare_version(const char *version1, const char *version2)
void crm_abort(const char *file, const char *function, int line, const char *assert_condition, gboolean do_core, gboolean do_fork)
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...)
int pcmk__pidfile_matches(const char *filename, pid_t expected_pid, const char *expected_name, pid_t *pid)
#define PCMK__PW_BUFFER_LEN
IPC interface to Pacemaker daemons.
#define CRM_PLUS_INFINITY_S
gboolean crm_config_error
bool pcmk__is_user_in_group(const char *user, const char *group)
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
#define crm_info(fmt, args...)
void crm_time_free(crm_time_t *dt)