Commit 6ec67d6a authored by Jeff Dike's avatar Jeff Dike

A bunch of minor changes ported up from 2.4.

All userspace uses of CONFIG_* have been changed to UML_CONFIG_*
to avoid conflicts with the host's config.
os_open_file now has FD_CLOEXEC support.
parent d8afc203
......@@ -541,7 +541,8 @@ static void winch_cleanup(void)
list_for_each(ele, &winch_handlers){
winch = list_entry(ele, struct winch, list);
close(winch->fd);
if(winch->pid != -1) os_kill_process(winch->pid, 0);
if(winch->pid != -1)
os_kill_process(winch->pid, 1);
}
}
......
......@@ -110,7 +110,7 @@ static int port_accept(struct port_list *port)
out_close:
os_close_file(fd);
if(pid != -1)
os_kill_process(pid, 0);
os_kill_process(pid, 1);
out:
return(ret);
}
......@@ -261,7 +261,7 @@ void port_remove_dev(void *d)
if(dev->helper_pid != -1)
os_kill_process(dev->helper_pid, 0);
if(dev->telnetd_pid != -1)
os_kill_process(dev->telnetd_pid, 0);
os_kill_process(dev->telnetd_pid, 1);
dev->helper_pid = -1;
dev->telnetd_pid = -1;
}
......
......@@ -77,9 +77,11 @@ static struct gendisk *ubd_gendisk[MAX_DEV];
static struct gendisk *fake_gendisk[MAX_DEV];
#ifdef CONFIG_BLK_DEV_UBD_SYNC
#define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0 })
#define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
.cl = 1 })
#else
#define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 0, .c = 0 })
#define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 0, .c = 0, \
.cl = 1 })
#endif
/* Not protected - changed only in ubd_setup_common and then only to
......@@ -177,6 +179,8 @@ static void make_ide_entries(char *dev_name)
if(proc_ide_root == NULL) make_proc_ide();
dir = proc_mkdir(dev_name, proc_ide);
if(!dir) return;
ent = create_proc_entry("media", S_IFREG|S_IRUGO, dir);
if(!ent) return;
ent->nlink = 1;
......@@ -405,7 +409,8 @@ static int io_pid = -1;
void kill_io_thread(void)
{
if(io_pid != -1) kill(io_pid, SIGKILL);
if(io_pid != -1)
os_kill_process(io_pid, 1);
}
__uml_exitcall(kill_io_thread);
......
......@@ -137,7 +137,7 @@ int xterm_open(int input, int output, int primary, void *d, char **dev_out)
}
if(new < 0){
printk("xterm_open : os_rcv_fd failed, errno = %d\n", -new);
return(new);
goto out;
}
tcgetattr(new, &data->tt);
......@@ -145,6 +145,8 @@ int xterm_open(int input, int output, int primary, void *d, char **dev_out)
data->pid = pid;
*dev_out = NULL;
out:
unlink(file);
return(new);
}
......@@ -152,9 +154,11 @@ void xterm_close(int fd, void *d)
{
struct xterm_chan *data = d;
if(data->pid != -1) kill(data->pid, SIGKILL);
if(data->pid != -1)
os_kill_process(data->pid, 1);
data->pid = -1;
if(data->helper_pid != -1) kill(data->helper_pid, SIGKILL);
if(data->helper_pid != -1)
os_kill_process(data->helper_pid, 0);
data->helper_pid = -1;
close(fd);
}
......
......@@ -8,13 +8,13 @@
#include "uml-config.h"
#if defined(CONFIG_MODE_TT) && defined(CONFIG_MODE_SKAS)
#if defined(UML_CONFIG_MODE_TT) && defined(UML_CONFIG_MODE_SKAS)
#define CHOOSE_MODE(tt, skas) (mode_tt ? (tt) : (skas))
#elif defined(CONFIG_MODE_SKAS)
#elif defined(UML_CONFIG_MODE_SKAS)
#define CHOOSE_MODE(tt, skas) (skas)
#elif defined(CONFIG_MODE_TT)
#elif defined(UML_CONFIG_MODE_TT)
#define CHOOSE_MODE(tt, skas) (tt)
#endif
......
......@@ -8,11 +8,11 @@
#include "uml-config.h"
#ifdef CONFIG_MODE_TT
#ifdef UML_CONFIG_MODE_TT
#include "../kernel/tt/include/mode.h"
#endif
#ifdef CONFIG_MODE_SKAS
#ifdef UML_CONFIG_MODE_SKAS
#include "../kernel/skas/include/mode.h"
#endif
......
......@@ -25,9 +25,11 @@ struct openflags {
unsigned int t : 1; /* O_TRUNC */
unsigned int a : 1; /* O_APPEND */
unsigned int e : 1; /* O_EXCL */
unsigned int cl : 1; /* FD_CLOEXEC */
};
#define OPENFLAGS() ((struct openflags) { r : 0, w : 0, c : 0, s : 0 })
#define OPENFLAGS() ((struct openflags) { .r = 0, .w = 0, .s = 0, .c = 0, \
.t = 0, .a = 0, .e = 0, .cl = 0 })
static inline struct openflags of_read(struct openflags flags)
{
......@@ -83,9 +85,16 @@ static inline struct openflags of_excl(struct openflags flags)
return(flags);
}
static inline struct openflags of_cloexec(struct openflags flags)
{
flags.cl = 1;
return(flags);
}
extern int os_seek_file(int fd, __u64 offset);
extern int os_open_file(char *file, struct openflags flags, int mode);
extern int os_read_file(int fd, char *buf, int len);
extern int os_read_file(int fd, void *buf, int len);
extern int os_write_file(int fd, void *buf, int count);
extern int os_file_size(char *file, long long *size_out);
extern int os_pipe(int *fd, int stream, int close_on_exec);
extern int os_set_fd_async(int fd, int owner);
......@@ -98,7 +107,6 @@ extern int create_unix_socket(char *file, int len);
extern int os_connect_socket(char *name);
extern int os_file_type(char *file);
extern int os_file_mode(char *file, struct openflags *mode_out);
extern int os_write_file(int fd, char *buf, int count);
extern unsigned long os_process_pc(int pid);
extern int os_process_parent(int pid);
......
......@@ -111,6 +111,7 @@ static void tty_output(int master, int slave)
printk("Checking that host ptys support output SIGIO...");
memset(buf, 0, sizeof(buf));
while(write(master, buf, sizeof(buf)) > 0) ;
if(errno != EAGAIN)
panic("check_sigio : write failed, errno = %d\n", errno);
......@@ -267,7 +268,8 @@ static void update_thread(void)
return;
fail:
sigio_lock();
if(write_sigio_pid != -1) kill(write_sigio_pid, SIGKILL);
if(write_sigio_pid != -1)
os_kill_process(write_sigio_pid, 1);
write_sigio_pid = -1;
close(sigio_private[0]);
close(sigio_private[1]);
......@@ -394,7 +396,7 @@ void write_sigio_workaround(void)
return;
out_kill:
kill(write_sigio_pid, SIGKILL);
os_kill_process(write_sigio_pid, 1);
write_sigio_pid = -1;
out_close2:
close(sigio_private[0]);
......@@ -421,7 +423,7 @@ int read_sigio_fd(int fd)
static void sigio_cleanup(void)
{
if(write_sigio_pid != -1)
kill(write_sigio_pid, SIGKILL);
os_kill_process(write_sigio_pid, 1);
}
__uml_exitcall(sigio_cleanup);
......
......@@ -8,7 +8,7 @@
#include "uml-config.h"
#ifdef CONFIG_MODE_SKAS
#ifdef UML_CONFIG_MODE_SKAS
#include "skas_ptregs.h"
......
......@@ -39,6 +39,7 @@ static void handle_segv(int pid)
if(err)
panic("handle_segv - PTRACE_FAULTINFO failed, errno = %d\n",
errno);
segv(fault.addr, 0, FAULT_WRITE(fault.is_write), 1, NULL);
}
......@@ -79,6 +80,7 @@ static int userspace_tramp(void *arg)
enable_timer();
ptrace(PTRACE_TRACEME, 0, 0, 0);
os_stop_process(os_getpid());
return(0);
}
void start_userspace(void)
......@@ -328,7 +330,7 @@ int new_mm(int from)
copy = ((struct proc_mm_op) { .op = MM_COPY_SEGMENTS,
.u =
{ .copy_segments = from } } );
n = os_write_file(fd, (char *) &copy, sizeof(copy));
n = os_write_file(fd, &copy, sizeof(copy));
if(n != sizeof(copy))
printk("new_mm : /proc/mm copy_segments failed, "
"errno = %d\n", errno);
......
......@@ -44,7 +44,7 @@ int cont(int pid)
return(ptrace(PTRACE_CONT, pid, 0, 0));
}
#ifdef CONFIG_PT_PROXY
#ifdef UML_CONFIG_PT_PROXY
int debugger_signal(int status, pid_t pid)
{
......
......@@ -8,7 +8,7 @@
#include "uml-config.h"
#ifdef CONFIG_MODE_TT
#ifdef UML_CONFIG_MODE_TT
#include "sysdep/sc.h"
#endif
......
......@@ -35,7 +35,7 @@ static int umid_inited = 0;
static int make_umid(void);
static int __init set_umid(char *name, int *add)
static int __init set_umid(char *name, int is_random)
{
if(umid_inited){
printk("Unique machine name can't be set twice\n");
......@@ -48,12 +48,17 @@ static int __init set_umid(char *name, int *add)
strncpy(umid, name, UMID_LEN - 1);
umid[UMID_LEN - 1] = '\0';
umid_is_random = 0;
umid_is_random = is_random;
umid_inited = 1;
return 0;
}
__uml_setup("umid=", set_umid,
static int __init set_umid_arg(char *name, int *add)
{
return(set_umid(name, 0));
}
__uml_setup("umid=", set_umid_arg,
"umid=<name>\n"
" This is used to assign a unique identity to this UML machine and\n"
" is used for naming the pid file and management console socket.\n\n"
......@@ -253,7 +258,7 @@ static int __init make_umid(void)
strcat(tmp, "XXXXXX");
fd = mkstemp(tmp);
if(fd < 0){
printk("set_umid - mkstemp failed, errno = %d\n",
printk("make_umid - mkstemp failed, errno = %d\n",
errno);
return(1);
}
......@@ -264,7 +269,7 @@ static int __init make_umid(void)
* for directories.
*/
unlink(tmp);
strcpy(umid, &tmp[strlen(uml_dir)]);
set_umid(&tmp[strlen(uml_dir)], 1);
}
sprintf(tmp, "%s%s", uml_dir, umid);
......
......@@ -28,8 +28,8 @@ int os_file_type(char *file)
else if(S_ISLNK(buf.st_mode)) return(OS_TYPE_SYMLINK);
else if(S_ISCHR(buf.st_mode)) return(OS_TYPE_CHARDEV);
else if(S_ISBLK(buf.st_mode)) return(OS_TYPE_BLOCKDEV);
else if(S_ISFIFO(buf.st_mode))return(OS_TYPE_FIFO);
else if(S_ISSOCK(buf.st_mode))return(OS_TYPE_SOCK);
else if(S_ISFIFO(buf.st_mode)) return(OS_TYPE_FIFO);
else if(S_ISSOCK(buf.st_mode)) return(OS_TYPE_SOCK);
else return(OS_TYPE_FILE);
}
......@@ -64,6 +64,15 @@ int os_open_file(char *file, struct openflags flags, int mode)
fd = open64(file, f, mode);
if(fd < 0) return(-errno);
if(flags.cl){
if(fcntl(fd, F_SETFD, 1)){
close(fd);
return(-errno);
}
}
return(fd);
return(fd);
}
......@@ -100,7 +109,7 @@ int os_seek_file(int fd, __u64 offset)
return(0);
}
int os_read_file(int fd, char *buf, int len)
int os_read_file(int fd, void *buf, int len)
{
int n;
......@@ -118,7 +127,7 @@ int os_read_file(int fd, char *buf, int len)
return(n);
}
int os_write_file(int fd, char *buf, int count)
int os_write_file(int fd, void *buf, int count)
{
int n;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment