13 #include <sys/utsname.h> 26 #include <qb/qbdefs.h> 36 #include <libxml2/libxml/relaxng.h> 72 if (user == NULL || group == NULL) {
77 while ((grent = getgrent()) != NULL) {
78 if (grent->gr_mem == NULL) {
82 if(strcmp(group, grent->gr_name) != 0) {
86 gr_mem = grent->gr_mem;
87 while (*gr_mem != NULL) {
88 if (!strcmp(user, *gr_mem++)) {
104 struct passwd *pwentry = NULL;
107 if (buffer == NULL) {
114 *uid = pwentry->pw_uid;
117 *gid = pwentry->pw_gid;
119 crm_trace(
"User %s has uid=%d gid=%d",
name, pwentry->pw_uid, pwentry->pw_gid);
122 rc = rc? -rc : -EINVAL;
141 static uid_t daemon_uid;
142 static gid_t daemon_gid;
143 static bool found =
false;
171 version_helper(
const char *text,
const char **end_text)
173 int atoi_result = -1;
179 if (text != NULL && text[0] != 0) {
186 atoi_result = (int) strtol(text, (
char **) end_text, 10);
188 if (errno == EINVAL) {
189 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
206 const char *ver1_iter, *ver2_iter;
208 if (version1 == NULL && version2 == NULL) {
210 }
else if (version1 == NULL) {
212 }
else if (version2 == NULL) {
216 ver1_iter = version1;
217 ver2_iter = version2;
225 if (ver1_iter == ver2_iter) {
229 if (ver1_iter != NULL) {
230 digit1 = version_helper(ver1_iter, &ver1_iter);
233 if (ver2_iter != NULL) {
234 digit2 = version_helper(ver2_iter, &ver2_iter);
237 if (digit1 < digit2) {
241 }
else if (digit1 > digit2) {
246 if (ver1_iter != NULL && *ver1_iter ==
'.') {
249 if (ver1_iter != NULL && *ver1_iter ==
'\0') {
253 if (ver2_iter != NULL && *ver2_iter ==
'.') {
256 if (ver2_iter != NULL && *ver2_iter == 0) {
262 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
264 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
266 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
292 crm_err(
"%s: already running [pid %lld in %s]",
293 name, (
long long)
pid, pidfile);
294 printf(
"%s: already running [pid %lld in %s]\n",
295 name, (
long long)
pid, pidfile);
301 fprintf(stderr,
"%s: could not start daemon\n",
name);
305 }
else if (
pid > 0) {
311 crm_err(
"Could not lock '%s' for %s: %s " QB_XS
" rc=%d",
313 printf(
"Could not lock '%s' for %s: %s (%d)\n",
318 umask(S_IWGRP | S_IWOTH | S_IROTH);
321 pcmk__open_devnull(O_RDONLY);
323 close(STDOUT_FILENO);
324 pcmk__open_devnull(O_WRONLY);
326 close(STDERR_FILENO);
327 pcmk__open_devnull(O_WRONLY);
330 #ifdef HAVE_UUID_UUID_H 331 # include <uuid/uuid.h> 337 unsigned char uuid[16];
338 char *buffer = malloc(37);
342 uuid_unparse(uuid, buffer);
370 #if defined(HAVE_NANOSLEEP) 373 struct timespec req = { .tv_sec = 0, .tv_nsec = (long) (ms * 1000000) };
375 nanosleep(&req, NULL);
377 #elif defined(HAVE_USLEEP) 379 usleep((useconds_t) ms);
383 struct timeval tv = { .tv_sec = 0, .tv_usec = (suseconds_t) ms };
385 select(0, NULL, NULL, NULL, &tv);
405 if (interval_ms % 1000 == 0) {
411 return g_timeout_add(interval_ms, fn,
data);
429 if (timeout_ms == 0) {
431 }
else if (timeout_ms < 1000) {
435 quot = timeout_ms / 1000;
436 rem = timeout_ms % 1000;
451 _gnutls_log_func(
int level,
const char *msg)
459 signal(SIGPIPE, SIG_IGN);
460 gnutls_global_init();
461 gnutls_global_set_log_level(8);
462 gnutls_global_set_log_function(_gnutls_log_func);
489 "pacemaker-controld",
493 "pacemaker-schedulerd",
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
const char * pcmk_strerror(int rc)
void crm_gnutls_global_init(void)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
bool crm_is_daemon_name(const char *name)
Check whether string represents a client name used by cluster daemons.
void mainloop_cleanup(void)
void pcmk__daemonize(const char *name, const char *pidfile)
void pcmk_common_cleanup(void)
Free all memory used by libcrmcommon.
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
void pcmk__free_common_logger(void)
Wrappers for and extensions to glib mainloop.
bool pcmk__config_has_error
void pcmk__xml_cleanup(void)
void pcmk__sleep_ms(unsigned int ms)
External (OS/environmental) problem.
#define crm_trace(fmt, args...)
bool pcmk__config_has_warning
#define CRM_SYSTEM_PENGINE
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)
int compare_version(const char *version1, const char *version2)
guint pcmk__timeout_ms2s(guint timeout_ms)
#define pcmk__assert(expr)
int pcmk__lock_pidfile(const char *filename, const char *name)
#define CRM_SYSTEM_TENGINE
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
#define crm_err(fmt, args...)
#define pcmk__mem_assert(ptr)
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.
bool pcmk__is_user_in_group(const char *user, const char *group)
guint pcmk__create_timer(guint interval_ms, GSourceFunc fn, gpointer data)
int pcmk_daemon_user(uid_t *uid, gid_t *gid)
Get user and group IDs of pacemaker daemon user.
Deprecated Pacemaker utilities.
#define crm_info(fmt, args...)