void device_release_write(struct discover_device *dev, bool release)
{
const char *fstype, *device_path;
- int rc = 0;
if (!release)
return;
device_path = get_device_path(dev);
}
- mount(device_path, dev->mount_path, fstype,
+ if (mount(device_path, dev->mount_path, fstype,
MS_RDONLY | MS_SILENT,
- fs_parameters(dev, MS_RDONLY));
- if (rc)
+ fs_parameters(dev, MS_RDONLY)))
pb_log("Failed to remount %s read-only: %s\n",
device_path, strerror(errno));
else
rc = __be32_to_cpu(*(uint32_t *)buf);
out:
+ talloc_free(buf);
free(namelist);
return rc;
}
out:
lock.l_type = F_UNLCK;
- fcntl(ipmi->fd, F_SETLKW, &lock);
+ if (fcntl(ipmi->fd, F_SETLKW, &lock) == -1)
+ pb_log("IPMI: error unlocking IPMI device: %m\n");
return rc ? -1 : 0;
}
path = local_path(ctx, dev, dirname);
rc = stat(path, &statbuf);
+ talloc_free(path);
if (!rc)
return -1;
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
#include <talloc/talloc.h>
#include <system/system.h>
static char *local_name(void *ctx)
{
char *ret, tmp[] = "/tmp/pb-XXXXXX";
+ mode_t oldmask;
int fd;
+ oldmask = umask(0644);
fd = mkstemp(tmp);
+ umask(oldmask);
if (fd < 0)
return NULL;
const char *argv[] = { pb_system_apps.tftp, "-V", NULL };
struct process *process;
enum tftp_type type;
+ int rc;
process = process_create(ctx);
process->path = pb_system_apps.tftp;
process->argv = argv;
process->keep_stdout = true;
process->add_stderr = true;
- process_run_sync(process);
+ rc = process_run_sync(process);
- if (!process->stdout_buf || process->stdout_len == 0) {
+ if (rc || !process->stdout_buf || process->stdout_len == 0) {
pb_log("Can't check TFTP client type!\n");
type = TFTP_TYPE_BROKEN;
struct process *process;
struct param *param;
const char *argv[6];
- int rc;
+ int rc = 0;
argv[0] = "nvram";
argv[1] = "--update-config";
{
struct autoboot_option *opt, *new = NULL;
char *pos, *end, *old_dev = NULL;
- const char delim = ' ';
unsigned int n_new = 0;
const char *val;
bool conflict;
if (read_bootdev(config, &pos, opt)) {
pb_log("bootdev config is in an unknown format "
- "(expected uuid:... or mac:...)");
+ "(expected uuid:... or mac:...)\n");
talloc_free(opt);
- if (strchr(pos, delim))
- continue;
- return;
+ continue;
}
new = talloc_realloc(config, new, struct autoboot_option,
char path[50];
int fd, rc;
- strcpy(path, sysparams_dir);
- assert(strlen(name) < sizeof(path) - strlen(path));
- strcat(path, name);
+ assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+ snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
fd = open(path, O_RDONLY);
if (fd < 0) {
char path[50];
int fd, rc;
- strcpy(path, sysparams_dir);
- assert(strlen(name) < sizeof(path) - strlen(path));
- strcat(path, name);
+ assert(strlen(sysparams_dir) + strlen(name) < sizeof(path));
+ snprintf(path, sizeof(path), "%s%s", sysparams_dir, name);
fd = open(path, O_WRONLY);
if (fd < 0) {
struct udev_device *dev, struct discover_device *ddev)
{
const char *node;
+ bool eject = false;
node = udev_device_get_devnode(dev);
/* handle CDROM eject requests */
if (udev_device_get_property_value(dev, "DISK_EJECT_REQUEST")) {
- bool eject = false;
-
pb_debug("udev: eject request\n");
/* If the device is mounted, cdrom_id's own eject request may
if (ddev) {
eject = ddev->mounted;
udev_handle_dev_remove(udev, dev);
- return false;
}
if (eject)
static int user_event_process(void *arg)
{
struct user_event *uev = arg;
- char buf[PBOOT_USER_EVENT_SIZE];
+ char buf[PBOOT_USER_EVENT_SIZE + 1];
int len;
- len = recvfrom(uev->socket, buf, sizeof(buf), 0, NULL, NULL);
+ len = recvfrom(uev->socket, buf, PBOOT_USER_EVENT_SIZE, 0, NULL, NULL);
if (len < 0) {
pb_log("%s: socket read failed: %s", __func__, strerror(errno));
return 0;
}
+ buf[len] = '\0';
+
pb_debug("%s: %u bytes\n", __func__, len);
user_event_handle_message(uev, buf, len);
talloc_set_name_const(ret, ret);
}
+ va_end(ap2);
return ret;
}
vsnprintf(s+s_len, len+1, fmt, ap2);
talloc_set_name_const(s, s);
+ va_end(ap2);
return s;
}
rc = pb_protocol_deserialise_device(dev, message);
if (rc) {
pb_log("%s: no device?\n", __func__);
- return 0;
+ goto out;
}
device_add(client, dev);
rc = pb_protocol_deserialise_boot_option(opt, message);
if (rc) {
pb_log("%s: no boot_option?\n", __func__);
- return 0;
+ goto out;
}
boot_option_add(client, opt);
dev_id = pb_protocol_deserialise_string(ctx, message);
if (!dev_id) {
pb_log("%s: no device id?\n", __func__);
- return 0;
+ goto out;
}
device_remove(client, dev_id);
break;
rc = pb_protocol_deserialise_boot_status(status, message);
if (rc) {
pb_log("%s: invalid status message?\n", __func__);
- return 0;
+ goto out;
}
update_status(client, status);
break;
rc = pb_protocol_deserialise_system_info(sysinfo, message);
if (rc) {
pb_log("%s: invalid sysinfo message?\n", __func__);
- return 0;
+ goto out;
}
update_sysinfo(client, sysinfo);
break;
rc = pb_protocol_deserialise_config(config, message);
if (rc) {
pb_log("%s: invalid config message?\n", __func__);
- return 0;
+ goto out;
}
update_config(client, config);
break;
pb_log("%s: unknown action %d\n", __func__, message->action);
}
+out:
talloc_free(ctx);
return 0;
{
unsigned int i;
- for (i = 0; i < item->pmenu->item_count; i++)
- if (item->pmenu->items[i] == item->nci)
- return i;
+ if (item)
+ for (i = 0; i < item->pmenu->item_count; i++)
+ if (item->pmenu->items[i] == item->nci)
+ return i;
pb_log("%s: not found: %p %s\n", __func__, item,
(item ? item->nci->name.str : "(null)"));
post_form(set->form);
form_driver(set->form, REQ_END_FIELD);
- if (set->cur_field) {
+ if (set->cur_field)
set_current_field(set->form, set->cur_field);
- field = set->cur_field;
- }
field = current_field(set->form);
widget = field_userptr(field);