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