2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
18 static void pre_exec(void *d)
20 struct dog_data *data = d;
23 dup2(data->stdout, 1);
24 dup2(data->stdout, 2);
27 close(data->close_me[0]);
28 close(data->close_me[1]);
31 int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock)
34 int in_fds[2], out_fds[2], pid, n, err;
35 char pid_buf[sizeof("nnnnn\0")], c;
36 char *pid_args[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf, NULL };
37 char *mconsole_args[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL,
41 err = os_pipe(in_fds, 1, 0);
43 printk("harddog_open - os_pipe failed, err = %d\n", -err);
47 err = os_pipe(out_fds, 1, 0);
49 printk("harddog_open - os_pipe failed, err = %d\n", -err);
53 data.stdin = out_fds[0];
54 data.stdout = in_fds[1];
55 data.close_me[0] = out_fds[1];
56 data.close_me[1] = in_fds[0];
59 mconsole_args[2] = sock;
63 /* XXX The os_getpid() is not SMP correct */
64 sprintf(pid_buf, "%d", os_getpid());
68 pid = run_helper(pre_exec, &data, args);
75 printk("harddog_open - run_helper failed, errno = %d\n", -err);
79 n = read(in_fds[0], &c, sizeof(c));
81 printk("harddog_open - EOF on watchdog pipe\n");
82 helper_wait(pid, 1, NULL);
87 printk("harddog_open - read of watchdog pipe failed, "
89 helper_wait(pid, 1, NULL);
93 *in_fd_ret = in_fds[0];
94 *out_fd_ret = out_fds[1];
107 void stop_watchdog(int in_fd, int out_fd)
113 int ping_watchdog(int fd)
118 n = write(fd, &c, sizeof(c));
119 if (n != sizeof(c)) {
120 printk("ping_watchdog - write failed, ret = %d, err = %d\n",