static void warn_wall(usec_t n, struct shutdownd_command *c) { assert(c); assert(c->warn_wall); if (n >= c->elapse) return; if (c->wall_message[0]) utmp_wall(c->wall_message, NULL); else { char date[FORMAT_TIMESTAMP_MAX]; const char* prefix; char *l = NULL; if (c->mode == 'H') prefix = "The system is going down for system halt at "; else if (c->mode == 'P') prefix = "The system is going down for power-off at "; else if (c->mode == 'r') prefix = "The system is going down for reboot at "; else assert_not_reached("Unknown mode!"); if (asprintf(&l, "%s%s!", prefix, format_timestamp(date, sizeof(date), c->elapse)) < 0) log_error("Failed to allocate wall message"); else { utmp_wall(l, NULL); free(l); } } }
static int warn_wall(Manager *m, usec_t n) { char date[FORMAT_TIMESTAMP_MAX] = {}; _cleanup_free_ char *l = NULL; usec_t left; int r; assert(m); if (!m->enable_wall_messages) return 0; left = m->scheduled_shutdown_timeout > n; r = asprintf(&l, "%s%sThe system is going down for %s %s%s!", strempty(m->wall_message), isempty(m->wall_message) ? "" : "\n", m->scheduled_shutdown_type, left ? "at " : "NOW", left ? format_timestamp(date, sizeof(date), m->scheduled_shutdown_timeout) : ""); if (r < 0) { log_oom(); return 0; } utmp_wall(l, uid_to_name(m->scheduled_shutdown_uid), m->scheduled_shutdown_tty, logind_wall_tty_filter, m); return 1; }
void server_forward_wall( Server *s, int priority, const char *identifier, const char *message, const struct ucred *ucred) { _cleanup_free_ char *ident_buf = NULL, *l_buf = NULL; const char *l; int r; assert(s); assert(message); if (LOG_PRI(priority) > s->max_level_wall) return; if (ucred) { if (!identifier) { get_process_comm(ucred->pid, &ident_buf); identifier = ident_buf; } if (asprintf(&l_buf, "%s["PID_FMT"]: %s", strempty(identifier), ucred->pid, message) < 0) { log_oom(); return; } l = l_buf; } else if (identifier) { l = l_buf = strjoin(identifier, ": ", message, NULL); if (!l_buf) { log_oom(); return; } } else l = message; r = utmp_wall(l, "systemd-journald", NULL, NULL, NULL); if (r < 0) log_debug_errno(r, "Failed to send wall message: %m"); }