Пример #1
0
gboolean
affile_open_file(gchar *name, FileOpenOptions *open_opts, FilePermOptions *perm_opts, gint *fd)
{
  cap_t saved_caps;

  if (_path_is_spurious(name, spurious_paths))
    {
      msg_error("Spurious path, logfile not created",
                evt_tag_str("path", name),
                NULL);
      return FALSE;
    }

  saved_caps = g_process_cap_save();

  if (!_obtain_capabilities(name, open_opts, perm_opts, &saved_caps))
    {
      g_process_cap_restore(saved_caps);
      return FALSE;
    }

  _validate_file_type(name, open_opts);

  *fd = _open_fd(name, open_opts, perm_opts);

  if (!is_file_device(name))
    _set_fd_permission(perm_opts, *fd);

  g_process_cap_restore(saved_caps);

  msg_trace("affile_open_file",
            evt_tag_str("path", name),
            evt_tag_int("fd", *fd),
            NULL);

  return (*fd != -1);
}
Пример #2
0
/*
 * event_notify - Notify Moab of some event
 * event_code IN - message code to send Moab
 *          1234 - job state change
 *          1235  - partition state change
 * desc IN - event description
 * RET 0 on success, -1 on failure
 */
extern int	event_notify(int event_code, char *desc)
{
	time_t now = time(NULL);
	int rc = 0, retry = 2;
	char *event_msg;
	DEF_TIMERS;

	START_TIMER;
	if (e_port == 0) {
		/* Event notification disabled */
		return 0;
	}

	if (event_code == 1234) {		/* job change */
		if (job_aggregation_time
		&&  (difftime(now, last_notify_time) < job_aggregation_time)) {
			debug("wiki event notification already sent recently");
			return 0;
		}
		event_msg = "1234";
	} else if (event_code == 1235) {	/* configuration change */
		event_msg = "1235";
	} else {
		error("event_notify: invalid event code: %d", event_code);
		return -1;
	}

	slurm_mutex_lock(&event_mutex);
	while (retry) {
		if ((event_fd == -1) && ((rc = _open_fd(now)) == -1)) {
			/* Can't even open socket.
			 * Don't retry again for a while (2 mins)
			 * to avoid long delays from ETIMEDOUT */
			last_notify_time = now + 120;
			break;
		}

		if (write(event_fd, event_msg, (strlen(event_msg) + 1)) > 0) {
			verbose("wiki event_notification sent: %s", desc);
			last_notify_time = now;
			rc = 0;
			/* Dave Jackson says to leave the connection
			 * open, but Moab isn't. Without the _close_fd()
			 * here, the next write() generates a broken pipe
			 * error. Just remove the _close_fd() and this
			 * comment when Moab maintains the connection. */
			_close_fd();
			break;	/* success */
		}

		error("wiki event notification failure: %m");
		rc = -1;
		retry--;
		if ((errno == EAGAIN) || (errno == EINTR))
			continue;

		_close_fd();
		if (errno == EPIPE) {
			/* If Moab closed the socket we get an EPIPE,
			 * retry once */
			continue;
		} else {
			break;
		}
	}
	slurm_mutex_unlock(&event_mutex);
	END_TIMER2("event_notify");

	return rc;
}