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 62 struct passwd *pwentry = NULL;
72 *uid = pwentry->pw_uid;
75 *gid = pwentry->pw_gid;
77 crm_trace(
"User %s has uid=%d gid=%d",
name, pwentry->pw_uid, pwentry->pw_gid);
80 rc = rc? -rc : -EINVAL;
99 static uid_t daemon_uid;
100 static gid_t daemon_gid;
101 static bool found =
false;
129 version_helper(
const char *text,
const char **end_text)
131 int atoi_result = -1;
137 if (text != NULL && text[0] != 0) {
144 atoi_result = (int) strtol(text, (
char **) end_text, 10);
146 if (errno == EINVAL) {
147 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
164 const char *ver1_iter, *ver2_iter;
166 if (version1 == NULL && version2 == NULL) {
168 }
else if (version1 == NULL) {
170 }
else if (version2 == NULL) {
174 ver1_iter = version1;
175 ver2_iter = version2;
183 if (ver1_iter == ver2_iter) {
187 if (ver1_iter != NULL) {
188 digit1 = version_helper(ver1_iter, &ver1_iter);
191 if (ver2_iter != NULL) {
192 digit2 = version_helper(ver2_iter, &ver2_iter);
195 if (digit1 < digit2) {
199 }
else if (digit1 > digit2) {
204 if (ver1_iter != NULL && *ver1_iter ==
'.') {
207 if (ver1_iter != NULL && *ver1_iter ==
'\0') {
211 if (ver2_iter != NULL && *ver2_iter ==
'.') {
214 if (ver2_iter != NULL && *ver2_iter == 0) {
220 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
222 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
224 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
250 }
else if (
input[0] ==
'P') {
267 return (msec >= G_MAXUINT)? G_MAXUINT : (guint) msec;
280 log_assertion_as(
const char *file,
const char *
function,
int line,
281 const char *assert_condition)
286 crm_err(
"%s: Triggered fatal assertion at %s:%d : %s",
287 function, file, line, assert_condition);
303 abort_as(
const char *file,
const char *
function,
int line,
304 const char *assert_condition)
306 log_assertion_as(file,
function, line, assert_condition);
324 fail_assert_as(
const char *file,
const char *
function,
int line,
325 const char *assert_condition)
331 abort_as(file,
function, line, assert_condition);
337 crm_warn(
"%s: Cannot dump core for non-fatal assertion at %s:%d " 338 ": %s",
function, file, line, assert_condition);
346 crm_err(
"%s: Forked child [%d] to record non-fatal assertion at " 347 "%s:%d : %s",
function,
pid, file, line, assert_condition);
350 if (waitpid(
pid, &status, 0) ==
pid) {
353 }
while (errno == EINTR);
354 if (errno == ECHILD) {
356 crm_trace(
"Cannot wait on forked child [%d] " 357 "(SIGCHLD is probably ignored)",
pid);
359 crm_err(
"Cannot wait on forked child [%d]: %s",
368 crm_abort(
const char *file,
const char *
function,
int line,
369 const char *assert_condition, gboolean do_core, gboolean do_fork)
372 abort_as(file,
function, line, assert_condition);
373 }
else if (do_core) {
374 fail_assert_as(file,
function, line, assert_condition);
376 log_assertion_as(file,
function, line, assert_condition);
400 crm_err(
"%s: already running [pid %lld in %s]",
401 name, (
long long)
pid, pidfile);
402 printf(
"%s: already running [pid %lld in %s]\n",
403 name, (
long long)
pid, pidfile);
409 fprintf(stderr,
"%s: could not start daemon\n",
name);
413 }
else if (
pid > 0) {
421 printf(
"Could not lock '%s' for %s: %s (%d)\n",
426 umask(S_IWGRP | S_IWOTH | S_IROTH);
429 pcmk__open_devnull(O_RDONLY);
431 close(STDOUT_FILENO);
432 pcmk__open_devnull(O_WRONLY);
434 close(STDERR_FILENO);
435 pcmk__open_devnull(O_WRONLY);
443 char *crm_name = NULL;
449 max = strlen(crm_name);
450 for (; lpc < max; lpc++) {
451 switch (crm_name[lpc]) {
464 const char *value = NULL;
468 value = g_hash_table_lookup(hash, key);
475 #ifdef HAVE_UUID_UUID_H 476 # include <uuid/uuid.h> 482 unsigned char uuid[16];
483 char *buffer = malloc(37);
486 uuid_unparse(uuid, buffer);
490 #ifdef HAVE_GNUTLS_GNUTLS_H 492 crm_gnutls_global_init(
void)
494 signal(SIGPIPE, SIG_IGN);
495 gnutls_global_init();
507 struct utsname hostinfo;
509 return (
uname(&hostinfo) < 0)? NULL : strdup(hostinfo.nodename);
546 #if defined(HAVE_NANOSLEEP) 549 struct timespec req = { .tv_sec = 0, .tv_nsec = (long) (ms * 1000000) };
551 nanosleep(&req, NULL);
553 #elif defined(HAVE_USLEEP) 555 usleep((useconds_t) ms);
559 struct timeval tv = { .tv_sec = 0, .tv_usec = (suseconds_t) ms };
561 select(0, NULL, NULL, NULL, &tv);
#define CRM_CHECK(expr, failure_action)
char * pcmk_hostname()
Get the local hostname.
void crm_write_blackbox(int nsig, struct qb_log_callsite *callsite)
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
CRM_TRACE_INIT_DATA(common)
long long int crm_time_get_seconds(crm_time_t *dt)
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)
IPC interface to Pacemaker daemons.
#define CRM_PLUS_INFINITY_S
gboolean crm_config_error
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)