17 #include <sys/utsname.h> 30 #include <qb/qbdefs.h> 40 #include <libxml2/libxml/relaxng.h> 56 if (user == NULL || group == NULL) {
61 while ((grent = getgrent()) != NULL) {
62 if (grent->gr_mem == NULL) {
66 if(strcmp(group, grent->gr_name) != 0) {
70 gr_mem = grent->gr_mem;
71 while (*gr_mem != NULL) {
72 if (!strcmp(user, *gr_mem++)) {
88 struct passwd *pwentry = NULL;
98 *uid = pwentry->pw_uid;
101 *gid = pwentry->pw_gid;
103 crm_trace(
"User %s has uid=%d gid=%d",
name, pwentry->pw_uid, pwentry->pw_gid);
106 rc = rc? -rc : -EINVAL;
125 static uid_t daemon_uid;
126 static gid_t daemon_gid;
127 static bool found =
false;
155 version_helper(
const char *text,
const char **end_text)
157 int atoi_result = -1;
163 if (text != NULL && text[0] != 0) {
170 atoi_result = (int) strtol(text, (
char **) end_text, 10);
172 if (errno == EINVAL) {
173 crm_err(
"Conversion of '%s' %c failed", text, text[0]);
190 const char *ver1_iter, *ver2_iter;
192 if (version1 == NULL && version2 == NULL) {
194 }
else if (version1 == NULL) {
196 }
else if (version2 == NULL) {
200 ver1_iter = version1;
201 ver2_iter = version2;
209 if (ver1_iter == ver2_iter) {
213 if (ver1_iter != NULL) {
214 digit1 = version_helper(ver1_iter, &ver1_iter);
217 if (ver2_iter != NULL) {
218 digit2 = version_helper(ver2_iter, &ver2_iter);
221 if (digit1 < digit2) {
225 }
else if (digit1 > digit2) {
230 if (ver1_iter != NULL && *ver1_iter ==
'.') {
233 if (ver1_iter != NULL && *ver1_iter ==
'\0') {
237 if (ver2_iter != NULL && *ver2_iter ==
'.') {
240 if (ver2_iter != NULL && *ver2_iter == 0) {
246 crm_trace(
"%s == %s (%d)", version1, version2, lpc);
248 crm_trace(
"%s < %s (%d)", version1, version2, lpc);
250 crm_trace(
"%s > %s (%d)", version1, version2, lpc);
276 crm_err(
"%s: already running [pid %lld in %s]",
277 name, (
long long)
pid, pidfile);
278 printf(
"%s: already running [pid %lld in %s]\n",
279 name, (
long long)
pid, pidfile);
285 fprintf(stderr,
"%s: could not start daemon\n",
name);
289 }
else if (
pid > 0) {
297 printf(
"Could not lock '%s' for %s: %s (%d)\n",
302 umask(S_IWGRP | S_IWOTH | S_IROTH);
305 pcmk__open_devnull(O_RDONLY);
307 close(STDOUT_FILENO);
308 pcmk__open_devnull(O_WRONLY);
310 close(STDERR_FILENO);
311 pcmk__open_devnull(O_WRONLY);
314 #ifdef HAVE_UUID_UUID_H 315 # include <uuid/uuid.h> 321 unsigned char uuid[16];
322 char *buffer = malloc(37);
326 uuid_unparse(uuid, buffer);
330 #ifdef HAVE_GNUTLS_GNUTLS_H 332 crm_gnutls_global_init(
void)
334 signal(SIGPIPE, SIG_IGN);
335 gnutls_global_init();
374 #if defined(HAVE_NANOSLEEP) 377 struct timespec req = { .tv_sec = 0, .tv_nsec = (long) (ms * 1000000) };
379 nanosleep(&req, NULL);
381 #elif defined(HAVE_USLEEP) 383 usleep((useconds_t) ms);
387 struct timeval tv = { .tv_sec = 0, .tv_usec = (suseconds_t) ms };
389 select(0, NULL, NULL, NULL, &tv);
408 }
else if (
input[0] ==
'P') {
425 return (msec >= G_MAXUINT)? G_MAXUINT : (guint) msec;
431 struct utsname hostinfo;
433 return (
uname(&hostinfo) < 0)? NULL : strdup(hostinfo.nodename);
int crm_user_lookup(const char *name, uid_t *uid, gid_t *gid)
const char * pcmk_strerror(int rc)
_Noreturn crm_exit_t crm_exit(crm_exit_t rc)
#define PCMK_VALUE_MINUS_INFINITY
#define PCMK_VALUE_INFINITY
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.
#define PCMK_VALUE_PLUS_INFINITY
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.
#define crm_warn(fmt, args...)
guint crm_parse_interval_spec(const char *input)
void pcmk__sleep_ms(unsigned int ms)
External (OS/environmental) problem.
#define crm_trace(fmt, args...)
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)
int compare_version(const char *version1, const char *version2)
#define pcmk__assert(expr)
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...)
Deprecated Pacemaker utilities.
#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.
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)