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 118 return crm_itoa(score);
127 struct passwd *pwentry = NULL;
130 if (buffer == NULL) {
137 *uid = pwentry->pw_uid;
140 *gid = pwentry->pw_gid;
142 crm_trace(
"User %s has uid=%d gid=%d",
name, pwentry->pw_uid, pwentry->pw_gid);
164 static uid_t daemon_uid;
165 static gid_t daemon_gid;
166 static bool found =
false;
194 version_helper(
const char *text,
const char **end_text)
196 int atoi_result = -1;
202 if (text != NULL && text[0] != 0) {
209 atoi_result = (int) strtol(text, (
char **) end_text, 10);
211 if (errno == EINVAL) {
212 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
229 const char *ver1_iter, *ver2_iter;
231 if (version1 == NULL && version2 == NULL) {
233 }
else if (version1 == NULL) {
235 }
else if (version2 == NULL) {
239 ver1_iter = version1;
240 ver2_iter = version2;
248 if (ver1_iter == ver2_iter) {
252 if (ver1_iter != NULL) {
253 digit1 = version_helper(ver1_iter, &ver1_iter);
256 if (ver2_iter != NULL) {
257 digit2 = version_helper(ver2_iter, &ver2_iter);
260 if (digit1 < digit2) {
264 }
else if (digit1 > digit2) {
269 if (ver1_iter != NULL && *ver1_iter ==
'.') {
272 if (ver1_iter != NULL && *ver1_iter ==
'\0') {
276 if (ver2_iter != NULL && *ver2_iter ==
'.') {
279 if (ver2_iter != NULL && *ver2_iter == 0) {
285 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
287 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
289 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
315 }
else if (input[0] ==
'P') {
328 crm_warn(
"Using 0 instead of '%s'", input);
332 return (msec >= G_MAXUINT)? G_MAXUINT : (guint) msec;
337 crm_abort(
const char *file,
const char *
function,
int line,
338 const char *assert_condition, gboolean do_core, gboolean do_fork)
355 if (do_core == FALSE) {
356 crm_err(
"%s: Triggered assert at %s:%d : %s",
function, file, line, assert_condition);
359 }
else if (do_fork) {
363 crm_err(
"%s: Triggered fatal assert at %s:%d : %s",
function, file, line, assert_condition);
367 crm_crit(
"%s: Cannot create core for non-fatal assert at %s:%d : %s",
368 function, file, line, assert_condition);
371 }
else if(
pid == 0) {
378 crm_err(
"%s: Forked child %d to record non-fatal assert at %s:%d : %s",
379 function,
pid, file, line, assert_condition);
383 rc = waitpid(
pid, &status, 0);
388 }
while(errno == EINTR);
390 if (errno == ECHILD) {
392 crm_trace(
"Cannot wait on forked child %d - SIGCHLD is probably set to SIG_IGN",
pid);
418 crm_err(
"%s: already running [pid %lld in %s]",
419 name, (
long long)
pid, pidfile);
420 printf(
"%s: already running [pid %lld in %s]\n",
421 name, (
long long)
pid, pidfile);
427 fprintf(stderr,
"%s: could not start daemon\n",
name);
431 }
else if (
pid > 0) {
439 printf(
"Could not lock '%s' for %s: %s (%d)\n",
444 umask(S_IWGRP | S_IWOTH | S_IROTH);
447 pcmk__open_devnull(O_RDONLY);
449 close(STDOUT_FILENO);
450 pcmk__open_devnull(O_WRONLY);
452 close(STDERR_FILENO);
453 pcmk__open_devnull(O_WRONLY);
461 char *crm_name = NULL;
467 max = strlen(crm_name);
468 for (; lpc < max; lpc++) {
469 switch (crm_name[lpc]) {
482 const char *value = NULL;
486 value = g_hash_table_lookup(hash, key);
493 #ifdef HAVE_UUID_UUID_H 494 # include <uuid/uuid.h> 500 unsigned char uuid[16];
501 char *buffer = malloc(37);
504 uuid_unparse(uuid, buffer);
508 #ifdef HAVE_GNUTLS_GNUTLS_H 510 crm_gnutls_global_init(
void)
512 signal(SIGPIPE, SIG_IGN);
513 gnutls_global_init();
525 struct utsname hostinfo;
527 return (
uname(&hostinfo) < 0)? NULL : strdup(hostinfo.nodename);
#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)
#define crm_crit(fmt, args...)
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.
int crm_parse_int(const char *text, const char *default_text)
Parse an integer value from a string.
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.
#define CRM_SCORE_INFINITY
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.
char * score2char(int score)
#define crm_trace(fmt, args...)
#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
char * crm_itoa_stack(int an_int, char *buf, size_t len)
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.
G_GNUC_INTERNAL bool pcmk__is_daemon
int char2score(const char *score)
#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
bool pcmk__config_warning
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
#define crm_info(fmt, args...)
char * score2char_stack(int score, char *buf, size_t len)
void crm_time_free(crm_time_t *dt)