#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>
return full_path;
}
+#ifndef PETITBOOT_TEST
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 load_url_result *load_url_async(void *ctx, struct pb_url *url,
- load_url_complete async_cb, void *async_data)
+ load_url_complete async_cb, void *async_data,
+ waiter_cb stdout_cb, void *stdout_data)
{
struct load_url_result *result;
struct load_task *task;
task->async = async_cb != NULL;
task->result = talloc_zero(ctx, struct load_url_result);
task->result->task = task;
+ task->result->url = url;
task->process = process_create(task);
if (task->async) {
task->async_cb = async_cb;
task->async_data = async_data;
task->process->exit_cb = load_url_process_exit;
task->process->data = task;
+ task->process->stdout_cb = stdout_cb;
+ task->process->stdout_data = stdout_data;
+ }
+
+ /* Make sure we save output for any task that has a custom handler */
+ if (task->process->stdout_cb) {
+ task->process->add_stderr = true;
+ task->process->keep_stdout = true;
}
switch (url->scheme) {
struct load_url_result *load_url(void *ctx, struct pb_url *url)
{
- return load_url_async(ctx, url, NULL, NULL);
+ return load_url_async(ctx, url, NULL, NULL, NULL, NULL);
}
void load_url_async_cancel(struct load_url_result *res)
res->status = LOAD_CANCELLED;
process_stop_async(task->process);
}
+
+#else
+
+static void __attribute__((unused)) load_local(
+ struct load_task *task __attribute__((unused)))
+{
+}
+static void __attribute__((unused)) load_wget(
+ struct load_task *task __attribute__((unused)),
+ int flags __attribute__((unused)))
+{
+}
+static void __attribute__((unused)) load_tftp(
+ struct load_task *task __attribute__((unused)))
+{
+}
+static void __attribute__((unused)) load_sftp(
+ struct load_task *task __attribute__((unused)))
+{
+}
+static void __attribute__((unused)) load_nfs(
+ struct load_task *task __attribute__((unused)))
+{
+}
+static void __attribute__((unused)) load_url_process_exit(
+ struct process *process __attribute__((unused)))
+{
+}
+
+#endif