1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
17 static void pre_exec(void *d
)
19 struct dog_data
*data
= d
;
21 dup2(data
->stdin_fd
, 0);
22 dup2(data
->stdout_fd
, 1);
23 dup2(data
->stdout_fd
, 2);
24 close(data
->stdin_fd
);
25 close(data
->stdout_fd
);
26 close(data
->close_me
[0]);
27 close(data
->close_me
[1]);
30 int start_watchdog(int *in_fd_ret
, int *out_fd_ret
, char *sock
)
33 int in_fds
[2], out_fds
[2], pid
, n
, err
;
34 char pid_buf
[sizeof("nnnnnnn\0")], c
;
35 char *pid_args
[] = { "/usr/bin/uml_watchdog", "-pid", pid_buf
, NULL
};
36 char *mconsole_args
[] = { "/usr/bin/uml_watchdog", "-mconsole", NULL
,
40 err
= os_pipe(in_fds
, 1, 0);
42 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
46 err
= os_pipe(out_fds
, 1, 0);
48 printk("harddog_open - os_pipe failed, err = %d\n", -err
);
52 data
.stdin_fd
= out_fds
[0];
53 data
.stdout_fd
= in_fds
[1];
54 data
.close_me
[0] = out_fds
[1];
55 data
.close_me
[1] = in_fds
[0];
58 mconsole_args
[2] = sock
;
62 /* XXX The os_getpid() is not SMP correct */
63 sprintf(pid_buf
, "%d", os_getpid());
67 pid
= run_helper(pre_exec
, &data
, args
);
74 printk("harddog_open - run_helper failed, errno = %d\n", -err
);
78 n
= read(in_fds
[0], &c
, sizeof(c
));
80 printk("harddog_open - EOF on watchdog pipe\n");
86 printk("harddog_open - read of watchdog pipe failed, "
92 *in_fd_ret
= in_fds
[0];
93 *out_fd_ret
= out_fds
[1];
106 void stop_watchdog(int in_fd
, int out_fd
)
112 int ping_watchdog(int fd
)
117 n
= write(fd
, &c
, sizeof(c
));
118 if (n
!= sizeof(c
)) {
119 printk("ping_watchdog - write failed, ret = %d, err = %d\n",