2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
14 #include "choose-mode.h"
23 static void pre_exec(void *d
)
25 struct dog_data
*data
= d
;
28 dup2(data
->stdout
, 1);
29 dup2(data
->stdout
, 2);
30 os_close_file(data
->stdin
);
31 os_close_file(data
->stdout
);
32 os_close_file(data
->close_me
[0]);
33 os_close_file(data
->close_me
[1]);
36 int start_watchdog(int *in_fd_ret
, int *out_fd_ret
, char *sock
)
39 int in_fds
[2], out_fds
[2], pid
, n
, err
;
40 char pid_buf
[sizeof("nnnnn\0")], c
;
41 char *pid_args
[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf
, NULL
};
42 char *mconsole_args
[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL
,
46 err
= os_pipe(in_fds
, 1, 0);
48 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
52 err
= os_pipe(out_fds
, 1, 0);
54 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
58 data
.stdin
= out_fds
[0];
59 data
.stdout
= in_fds
[1];
60 data
.close_me
[0] = out_fds
[1];
61 data
.close_me
[1] = in_fds
[0];
64 mconsole_args
[2] = sock
;
68 /* XXX The os_getpid() is not SMP correct */
69 sprintf(pid_buf
, "%d", CHOOSE_MODE(tracing_pid
, os_getpid()));
73 pid
= run_helper(pre_exec
, &data
, args
, NULL
);
75 os_close_file(out_fds
[0]);
76 os_close_file(in_fds
[1]);
80 printk("harddog_open - run_helper failed, errno = %d\n", -err
);
84 n
= os_read_file(in_fds
[0], &c
, sizeof(c
));
86 printk("harddog_open - EOF on watchdog pipe\n");
92 printk("harddog_open - read of watchdog pipe failed, "
98 *in_fd_ret
= in_fds
[0];
99 *out_fd_ret
= out_fds
[1];
103 os_close_file(in_fds
[0]);
104 os_close_file(in_fds
[1]);
106 os_close_file(out_fds
[0]);
107 os_close_file(out_fds
[1]);
112 void stop_watchdog(int in_fd
, int out_fd
)
114 os_close_file(in_fd
);
115 os_close_file(out_fd
);
118 int ping_watchdog(int fd
)
123 n
= os_write_file(fd
, &c
, sizeof(c
));
125 printk("ping_watchdog - write failed, err = %d\n", -n
);
135 * Overrides for Emacs so that we follow Linus's tabbing style.
136 * Emacs will notice this stuff at the end of the file and automatically
137 * adjust the settings for this buffer only. This must remain at the end
139 * ---------------------------------------------------------------------------
141 * c-file-style: "linux"