2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
12 #include "choose-mode.h"
21 static void pre_exec(void *d)
23 struct dog_data *data = d;
26 dup2(data->stdout, 1);
27 dup2(data->stdout, 2);
28 os_close_file(data->stdin);
29 os_close_file(data->stdout);
30 os_close_file(data->close_me[0]);
31 os_close_file(data->close_me[1]);
34 int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
37 int in_fds[2], out_fds[2], pid, n, err;
38 char pid_buf[sizeof("nnnnn\0")], c;
39 char *pid_args[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf, NULL };
40 char *mconsole_args[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL,
44 err = os_pipe(in_fds, 1, 0);
46 printk("harddog_open - os_pipe failed, err = %d\n", -err);
50 err = os_pipe(out_fds, 1, 0);
52 printk("harddog_open - os_pipe failed, err = %d\n", -err);
56 data.stdin = out_fds[0];
57 data.stdout = in_fds[1];
58 data.close_me[0] = out_fds[1];
59 data.close_me[1] = in_fds[0];
62 mconsole_args[2] = sock;
66 /* XXX The os_getpid() is not SMP correct */
67 sprintf(pid_buf, "%d", CHOOSE_MODE(tracing_pid, os_getpid()));
71 pid = run_helper(pre_exec, &data, args);
73 os_close_file(out_fds[0]);
74 os_close_file(in_fds[1]);
78 printk("harddog_open - run_helper failed, errno = %d\n", -err);
82 n = os_read_file(in_fds[0], &c, sizeof(c));
84 printk("harddog_open - EOF on watchdog pipe\n");
90 printk("harddog_open - read of watchdog pipe failed, "
96 *in_fd_ret = in_fds[0];
97 *out_fd_ret = out_fds[1];
101 os_close_file(in_fds[0]);
102 os_close_file(in_fds[1]);
104 os_close_file(out_fds[0]);
105 os_close_file(out_fds[1]);
110 void stop_watchdog(int in_fd, int out_fd)
112 os_close_file(in_fd);
113 os_close_file(out_fd);
116 int ping_watchdog(int fd)
121 n = os_write_file(fd, &c, sizeof(c));
123 printk("ping_watchdog - write failed, err = %d\n", -n);