console-dbus.c (e258e51fd256c275cd58a104a6bcb379ff1534f9) | console-dbus.c (b14ca19cf380efbf7a96a348cc6fc81e75bf0591) |
---|---|
1/** 2 * Copyright © 2023 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 8 unchanged lines hidden (view full) --- 17#include <errno.h> 18#include <err.h> 19 20#include "console-server.h" 21 22/* size of the dbus object path length */ 23const size_t dbus_obj_path_len = 1024; 24 | 1/** 2 * Copyright © 2023 IBM Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 --- 8 unchanged lines hidden (view full) --- 17#include <errno.h> 18#include <err.h> 19 20#include "console-server.h" 21 22/* size of the dbus object path length */ 23const size_t dbus_obj_path_len = 1024; 24 |
25#define DBUS_ERR "org.openbmc.error" 26#define INTF_NAME "xyz.openbmc_project.Console" 27#define DBUS_NAME "xyz.openbmc_project.Console.%s" 28#define OBJ_NAME "/xyz/openbmc_project/console/%s" | 25#define DBUS_ERR "org.openbmc.error" 26#define DBUS_NAME "xyz.openbmc_project.Console.%s" 27#define OBJ_NAME "/xyz/openbmc_project/console/%s" 28#define TTY_INTF "xyz.openbmc_project.console" 29#define ACCESS_INTF "xyz.openbmc_project.Console.Access" |
29 30static void tty_change_baudrate(struct console *console) 31{ 32 struct handler *handler; 33 int i; 34 int rc; 35 36 tty_init_termios(console); --- 59 unchanged lines hidden (view full) --- 96 warnx("Invalid baud rate: '%d'", console->tty_baud); 97 } 98 99 r = sd_bus_message_append(reply, "u", baudrate); 100 101 return r; 102} 103 | 30 31static void tty_change_baudrate(struct console *console) 32{ 33 struct handler *handler; 34 int i; 35 int rc; 36 37 tty_init_termios(console); --- 59 unchanged lines hidden (view full) --- 97 warnx("Invalid baud rate: '%d'", console->tty_baud); 98 } 99 100 r = sd_bus_message_append(reply, "u", baudrate); 101 102 return r; 103} 104 |
104static const sd_bus_vtable console_vtable[] = { | 105static int get_socket_name(sd_bus *bus __attribute__((unused)), 106 const char *path __attribute__((unused)), 107 const char *interface __attribute__((unused)), 108 const char *property __attribute__((unused)), 109 sd_bus_message *reply, void *userdata, 110 sd_bus_error *error __attribute__((unused))) 111{ 112 struct console *console = userdata; 113 114 /* The abstract socket name starts with null character hence we need to 115 * send it as a byte stream instead of regular string. 116 */ 117 return sd_bus_message_append_array(reply, 'y', console->socket_name, 118 console->socket_name_len); 119} 120 121static const sd_bus_vtable console_tty_vtable[] = { |
105 SD_BUS_VTABLE_START(0), 106 SD_BUS_METHOD("setBaudRate", "u", "x", method_set_baud_rate, 107 SD_BUS_VTABLE_UNPRIVILEGED), 108 SD_BUS_PROPERTY("baudrate", "u", get_handler, 0, 0), 109 SD_BUS_VTABLE_END, 110}; 111 | 122 SD_BUS_VTABLE_START(0), 123 SD_BUS_METHOD("setBaudRate", "u", "x", method_set_baud_rate, 124 SD_BUS_VTABLE_UNPRIVILEGED), 125 SD_BUS_PROPERTY("baudrate", "u", get_handler, 0, 0), 126 SD_BUS_VTABLE_END, 127}; 128 |
129static const sd_bus_vtable console_access_vtable[] = { 130 SD_BUS_VTABLE_START(0), 131 SD_BUS_PROPERTY("SocketName", "ay", get_socket_name, 0, 0), 132 SD_BUS_VTABLE_END, 133}; 134 |
|
112void dbus_init(struct console *console, 113 struct config *config __attribute__((unused))) 114{ 115 char obj_name[dbus_obj_path_len]; 116 char dbus_name[dbus_obj_path_len]; 117 int dbus_poller = 0; 118 int fd; 119 int r; --- 14 unchanged lines hidden (view full) --- 134 bytes = snprintf(obj_name, dbus_obj_path_len, OBJ_NAME, 135 console->console_id); 136 if (bytes >= dbus_obj_path_len) { 137 warnx("Console id '%s' is too long. There is no enough space in the buffer.", 138 console->console_id); 139 return; 140 } 141 | 135void dbus_init(struct console *console, 136 struct config *config __attribute__((unused))) 137{ 138 char obj_name[dbus_obj_path_len]; 139 char dbus_name[dbus_obj_path_len]; 140 int dbus_poller = 0; 141 int fd; 142 int r; --- 14 unchanged lines hidden (view full) --- 157 bytes = snprintf(obj_name, dbus_obj_path_len, OBJ_NAME, 158 console->console_id); 159 if (bytes >= dbus_obj_path_len) { 160 warnx("Console id '%s' is too long. There is no enough space in the buffer.", 161 console->console_id); 162 return; 163 } 164 |
142 r = sd_bus_add_object_vtable(console->bus, NULL, obj_name, INTF_NAME, 143 console_vtable, console); | 165 /* Register tty interface */ 166 r = sd_bus_add_object_vtable(console->bus, NULL, obj_name, TTY_INTF, 167 console_tty_vtable, console); |
144 if (r < 0) { 145 warnx("Failed to issue method call: %s", strerror(-r)); 146 return; 147 } 148 | 168 if (r < 0) { 169 warnx("Failed to issue method call: %s", strerror(-r)); 170 return; 171 } 172 |
173 /* Register access interface */ 174 r = sd_bus_add_object_vtable(console->bus, NULL, obj_name, ACCESS_INTF, 175 console_access_vtable, console); 176 if (r < 0) { 177 warnx("Failed to issue method call: %s", strerror(-r)); 178 return; 179 } 180 |
|
149 bytes = snprintf(dbus_name, dbus_obj_path_len, DBUS_NAME, 150 console->console_id); 151 if (bytes >= dbus_obj_path_len) { 152 warnx("Console id '%s' is too long. There is no enough space in the buffer.", 153 console->console_id); 154 return; 155 } 156 | 181 bytes = snprintf(dbus_name, dbus_obj_path_len, DBUS_NAME, 182 console->console_id); 183 if (bytes >= dbus_obj_path_len) { 184 warnx("Console id '%s' is too long. There is no enough space in the buffer.", 185 console->console_id); 186 return; 187 } 188 |
189 /* Finally register the bus name */ |
|
157 r = sd_bus_request_name(console->bus, dbus_name, 158 SD_BUS_NAME_ALLOW_REPLACEMENT | 159 SD_BUS_NAME_REPLACE_EXISTING); 160 if (r < 0) { 161 warnx("Failed to acquire service name: %s", strerror(-r)); 162 return; 163 } 164 165 fd = sd_bus_get_fd(console->bus); 166 if (fd < 0) { 167 warnx("Couldn't get the bus file descriptor"); 168 return; 169 } 170 171 dbus_poller = POLLFD_DBUS; 172 173 console->pollfds[dbus_poller].fd = fd; 174 console->pollfds[dbus_poller].events = POLLIN; 175} | 190 r = sd_bus_request_name(console->bus, dbus_name, 191 SD_BUS_NAME_ALLOW_REPLACEMENT | 192 SD_BUS_NAME_REPLACE_EXISTING); 193 if (r < 0) { 194 warnx("Failed to acquire service name: %s", strerror(-r)); 195 return; 196 } 197 198 fd = sd_bus_get_fd(console->bus); 199 if (fd < 0) { 200 warnx("Couldn't get the bus file descriptor"); 201 return; 202 } 203 204 dbus_poller = POLLFD_DBUS; 205 206 console->pollfds[dbus_poller].fd = fd; 207 console->pollfds[dbus_poller].events = POLLIN; 208} |