Commit 3a02d6c0 authored by Paolo 'Blaisorblade' Giarrusso's avatar Paolo 'Blaisorblade' Giarrusso Committed by Linus Torvalds

[PATCH] uml: don't remove umid files in conflict case

Only remove the UML pidfile and management socket if we created them.
Currently in case two UMLs are started with the same umid, the second will
remove the first's ones.

Probably we should also panic() at that point, not sure however.
Signed-off-by: default avatarPaolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 8686bcd0
...@@ -31,6 +31,8 @@ static char *uml_dir = UML_DIR; ...@@ -31,6 +31,8 @@ static char *uml_dir = UML_DIR;
/* Changed by set_umid */ /* Changed by set_umid */
static int umid_is_random = 1; static int umid_is_random = 1;
static int umid_inited = 0; static int umid_inited = 0;
/* Have we created the files? Should we remove them? */
static int umid_owned = 0;
static int make_umid(int (*printer)(const char *fmt, ...)); static int make_umid(int (*printer)(const char *fmt, ...));
...@@ -82,20 +84,21 @@ int __init umid_file_name(char *name, char *buf, int len) ...@@ -82,20 +84,21 @@ int __init umid_file_name(char *name, char *buf, int len)
extern int tracing_pid; extern int tracing_pid;
static int __init create_pid_file(void) static void __init create_pid_file(void)
{ {
char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")];
char pid[sizeof("nnnnn\0")]; char pid[sizeof("nnnnn\0")];
int fd, n; int fd, n;
if(umid_file_name("pid", file, sizeof(file))) return 0; if(umid_file_name("pid", file, sizeof(file)))
return;
fd = os_open_file(file, of_create(of_excl(of_rdwr(OPENFLAGS()))), fd = os_open_file(file, of_create(of_excl(of_rdwr(OPENFLAGS()))),
0644); 0644);
if(fd < 0){ if(fd < 0){
printf("Open of machine pid file \"%s\" failed: %s\n", printf("Open of machine pid file \"%s\" failed: %s\n",
file, strerror(-fd)); file, strerror(-fd));
return 0; return;
} }
sprintf(pid, "%d\n", os_getpid()); sprintf(pid, "%d\n", os_getpid());
...@@ -103,7 +106,6 @@ static int __init create_pid_file(void) ...@@ -103,7 +106,6 @@ static int __init create_pid_file(void)
if(n != strlen(pid)) if(n != strlen(pid))
printf("Write of pid file failed - err = %d\n", -n); printf("Write of pid file failed - err = %d\n", -n);
os_close_file(fd); os_close_file(fd);
return 0;
} }
static int actually_do_remove(char *dir) static int actually_do_remove(char *dir)
...@@ -147,7 +149,8 @@ static int actually_do_remove(char *dir) ...@@ -147,7 +149,8 @@ static int actually_do_remove(char *dir)
void remove_umid_dir(void) void remove_umid_dir(void)
{ {
char dir[strlen(uml_dir) + UMID_LEN + 1]; char dir[strlen(uml_dir) + UMID_LEN + 1];
if(!umid_inited) return; if (!umid_owned)
return;
sprintf(dir, "%s%s", uml_dir, umid); sprintf(dir, "%s%s", uml_dir, umid);
actually_do_remove(dir); actually_do_remove(dir);
...@@ -155,11 +158,12 @@ void remove_umid_dir(void) ...@@ -155,11 +158,12 @@ void remove_umid_dir(void)
char *get_umid(int only_if_set) char *get_umid(int only_if_set)
{ {
if(only_if_set && umid_is_random) return(NULL); if(only_if_set && umid_is_random)
return(umid); return NULL;
return umid;
} }
int not_dead_yet(char *dir) static int not_dead_yet(char *dir)
{ {
char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")];
char pid[sizeof("nnnnn\0")], *end; char pid[sizeof("nnnnn\0")], *end;
...@@ -193,7 +197,8 @@ int not_dead_yet(char *dir) ...@@ -193,7 +197,8 @@ int not_dead_yet(char *dir)
(p == CHOOSE_MODE(tracing_pid, os_getpid()))) (p == CHOOSE_MODE(tracing_pid, os_getpid())))
dead = 1; dead = 1;
} }
if(!dead) return(1); if(!dead)
return(1);
return(actually_do_remove(dir)); return(actually_do_remove(dir));
} }
...@@ -286,6 +291,7 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) ...@@ -286,6 +291,7 @@ static int __init make_umid(int (*printer)(const char *fmt, ...))
if(errno == EEXIST){ if(errno == EEXIST){
if(not_dead_yet(tmp)){ if(not_dead_yet(tmp)){
(*printer)("umid '%s' is in use\n", umid); (*printer)("umid '%s' is in use\n", umid);
umid_owned = 0;
return(-1); return(-1);
} }
err = mkdir(tmp, 0777); err = mkdir(tmp, 0777);
...@@ -296,7 +302,8 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) ...@@ -296,7 +302,8 @@ static int __init make_umid(int (*printer)(const char *fmt, ...))
return(-1); return(-1);
} }
return(0); umid_owned = 1;
return 0;
} }
__uml_setup("uml_dir=", set_uml_dir, __uml_setup("uml_dir=", set_uml_dir,
...@@ -309,7 +316,8 @@ static int __init make_umid_setup(void) ...@@ -309,7 +316,8 @@ static int __init make_umid_setup(void)
/* one function with the ordering we need ... */ /* one function with the ordering we need ... */
make_uml_dir(); make_uml_dir();
make_umid(printf); make_umid(printf);
return create_pid_file(); create_pid_file();
return 0;
} }
__uml_postsetup(make_umid_setup); __uml_postsetup(make_umid_setup);
......
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