2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
13 #include "choose-mode.h"
22 static void pre_exec(void *d
)
24 struct dog_data
*data
= d
;
27 dup2(data
->stdout
, 1);
28 dup2(data
->stdout
, 2);
29 os_close_file(data
->stdin
);
30 os_close_file(data
->stdout
);
31 os_close_file(data
->close_me
[0]);
32 os_close_file(data
->close_me
[1]);
35 int start_watchdog(int *in_fd_ret
, int *out_fd_ret
, char *sock
)
38 int in_fds
[2], out_fds
[2], pid
, n
, err
;
39 char pid_buf
[sizeof("nnnnn\0")], c
;
40 char *pid_args
[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf
, NULL
};
41 char *mconsole_args
[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL
,
45 err
= os_pipe(in_fds
, 1, 0);
47 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
51 err
= os_pipe(out_fds
, 1, 0);
53 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
57 data
.stdin
= out_fds
[0];
58 data
.stdout
= in_fds
[1];
59 data
.close_me
[0] = out_fds
[1];
60 data
.close_me
[1] = in_fds
[0];
63 mconsole_args
[2] = sock
;
67 /* XXX The os_getpid() is not SMP correct */
68 sprintf(pid_buf
, "%d", CHOOSE_MODE(tracing_pid
, os_getpid()));
72 pid
= run_helper(pre_exec
, &data
, args
, NULL
);
74 os_close_file(out_fds
[0]);
75 os_close_file(in_fds
[1]);
79 printk("harddog_open - run_helper failed, errno = %d\n", -err
);
83 n
= os_read_file(in_fds
[0], &c
, sizeof(c
));
85 printk("harddog_open - EOF on watchdog pipe\n");
91 printk("harddog_open - read of watchdog pipe failed, "
97 *in_fd_ret
= in_fds
[0];
98 *out_fd_ret
= out_fds
[1];
102 os_close_file(in_fds
[0]);
103 os_close_file(in_fds
[1]);
105 os_close_file(out_fds
[0]);
106 os_close_file(out_fds
[1]);
111 void stop_watchdog(int in_fd
, int out_fd
)
113 os_close_file(in_fd
);
114 os_close_file(out_fd
);
117 int ping_watchdog(int fd
)
122 n
= os_write_file(fd
, &c
, sizeof(c
));
124 printk("ping_watchdog - write failed, err = %d\n", -n
);
134 * Overrides for Emacs so that we follow Linus's tabbing style.
135 * Emacs will notice this stuff at the end of the file and automatically
136 * adjust the settings for this buffer only. This must remain at the end
138 * ---------------------------------------------------------------------------
140 * c-file-style: "linux"