diff options
author | Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> | 2005-09-23 00:44:12 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-09-23 01:17:36 -0400 |
commit | 3a02d6c051cf3c214aab38e4330b4bcec5f6e3f8 (patch) | |
tree | 6d99dd06a5228ab6ea9a72dd7dfbc43458861825 /arch/um/kernel/umid.c | |
parent | 8686bcd0a5f5e3f599ed9f1028ec9e449e7b87e3 (diff) |
[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: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/um/kernel/umid.c')
-rw-r--r-- | arch/um/kernel/umid.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/arch/um/kernel/umid.c b/arch/um/kernel/umid.c index 186c28885016..251d277fff2a 100644 --- a/arch/um/kernel/umid.c +++ b/arch/um/kernel/umid.c | |||
@@ -31,6 +31,8 @@ static char *uml_dir = UML_DIR; | |||
31 | /* Changed by set_umid */ | 31 | /* Changed by set_umid */ |
32 | static int umid_is_random = 1; | 32 | static int umid_is_random = 1; |
33 | static int umid_inited = 0; | 33 | static int umid_inited = 0; |
34 | /* Have we created the files? Should we remove them? */ | ||
35 | static int umid_owned = 0; | ||
34 | 36 | ||
35 | static int make_umid(int (*printer)(const char *fmt, ...)); | 37 | static int make_umid(int (*printer)(const char *fmt, ...)); |
36 | 38 | ||
@@ -82,20 +84,21 @@ int __init umid_file_name(char *name, char *buf, int len) | |||
82 | 84 | ||
83 | extern int tracing_pid; | 85 | extern int tracing_pid; |
84 | 86 | ||
85 | static int __init create_pid_file(void) | 87 | static void __init create_pid_file(void) |
86 | { | 88 | { |
87 | char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; | 89 | char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; |
88 | char pid[sizeof("nnnnn\0")]; | 90 | char pid[sizeof("nnnnn\0")]; |
89 | int fd, n; | 91 | int fd, n; |
90 | 92 | ||
91 | if(umid_file_name("pid", file, sizeof(file))) return 0; | 93 | if(umid_file_name("pid", file, sizeof(file))) |
94 | return; | ||
92 | 95 | ||
93 | fd = os_open_file(file, of_create(of_excl(of_rdwr(OPENFLAGS()))), | 96 | fd = os_open_file(file, of_create(of_excl(of_rdwr(OPENFLAGS()))), |
94 | 0644); | 97 | 0644); |
95 | if(fd < 0){ | 98 | if(fd < 0){ |
96 | printf("Open of machine pid file \"%s\" failed: %s\n", | 99 | printf("Open of machine pid file \"%s\" failed: %s\n", |
97 | file, strerror(-fd)); | 100 | file, strerror(-fd)); |
98 | return 0; | 101 | return; |
99 | } | 102 | } |
100 | 103 | ||
101 | sprintf(pid, "%d\n", os_getpid()); | 104 | sprintf(pid, "%d\n", os_getpid()); |
@@ -103,7 +106,6 @@ static int __init create_pid_file(void) | |||
103 | if(n != strlen(pid)) | 106 | if(n != strlen(pid)) |
104 | printf("Write of pid file failed - err = %d\n", -n); | 107 | printf("Write of pid file failed - err = %d\n", -n); |
105 | os_close_file(fd); | 108 | os_close_file(fd); |
106 | return 0; | ||
107 | } | 109 | } |
108 | 110 | ||
109 | static int actually_do_remove(char *dir) | 111 | static int actually_do_remove(char *dir) |
@@ -147,7 +149,8 @@ static int actually_do_remove(char *dir) | |||
147 | void remove_umid_dir(void) | 149 | void remove_umid_dir(void) |
148 | { | 150 | { |
149 | char dir[strlen(uml_dir) + UMID_LEN + 1]; | 151 | char dir[strlen(uml_dir) + UMID_LEN + 1]; |
150 | if(!umid_inited) return; | 152 | if (!umid_owned) |
153 | return; | ||
151 | 154 | ||
152 | sprintf(dir, "%s%s", uml_dir, umid); | 155 | sprintf(dir, "%s%s", uml_dir, umid); |
153 | actually_do_remove(dir); | 156 | actually_do_remove(dir); |
@@ -155,11 +158,12 @@ void remove_umid_dir(void) | |||
155 | 158 | ||
156 | char *get_umid(int only_if_set) | 159 | char *get_umid(int only_if_set) |
157 | { | 160 | { |
158 | if(only_if_set && umid_is_random) return(NULL); | 161 | if(only_if_set && umid_is_random) |
159 | return(umid); | 162 | return NULL; |
163 | return umid; | ||
160 | } | 164 | } |
161 | 165 | ||
162 | int not_dead_yet(char *dir) | 166 | static int not_dead_yet(char *dir) |
163 | { | 167 | { |
164 | char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; | 168 | char file[strlen(uml_dir) + UMID_LEN + sizeof("/pid\0")]; |
165 | char pid[sizeof("nnnnn\0")], *end; | 169 | char pid[sizeof("nnnnn\0")], *end; |
@@ -193,7 +197,8 @@ int not_dead_yet(char *dir) | |||
193 | (p == CHOOSE_MODE(tracing_pid, os_getpid()))) | 197 | (p == CHOOSE_MODE(tracing_pid, os_getpid()))) |
194 | dead = 1; | 198 | dead = 1; |
195 | } | 199 | } |
196 | if(!dead) return(1); | 200 | if(!dead) |
201 | return(1); | ||
197 | return(actually_do_remove(dir)); | 202 | return(actually_do_remove(dir)); |
198 | } | 203 | } |
199 | 204 | ||
@@ -286,6 +291,7 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) | |||
286 | if(errno == EEXIST){ | 291 | if(errno == EEXIST){ |
287 | if(not_dead_yet(tmp)){ | 292 | if(not_dead_yet(tmp)){ |
288 | (*printer)("umid '%s' is in use\n", umid); | 293 | (*printer)("umid '%s' is in use\n", umid); |
294 | umid_owned = 0; | ||
289 | return(-1); | 295 | return(-1); |
290 | } | 296 | } |
291 | err = mkdir(tmp, 0777); | 297 | err = mkdir(tmp, 0777); |
@@ -296,7 +302,8 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) | |||
296 | return(-1); | 302 | return(-1); |
297 | } | 303 | } |
298 | 304 | ||
299 | return(0); | 305 | umid_owned = 1; |
306 | return 0; | ||
300 | } | 307 | } |
301 | 308 | ||
302 | __uml_setup("uml_dir=", set_uml_dir, | 309 | __uml_setup("uml_dir=", set_uml_dir, |
@@ -309,7 +316,8 @@ static int __init make_umid_setup(void) | |||
309 | /* one function with the ordering we need ... */ | 316 | /* one function with the ordering we need ... */ |
310 | make_uml_dir(); | 317 | make_uml_dir(); |
311 | make_umid(printf); | 318 | make_umid(printf); |
312 | return create_pid_file(); | 319 | create_pid_file(); |
320 | return 0; | ||
313 | } | 321 | } |
314 | __uml_postsetup(make_umid_setup); | 322 | __uml_postsetup(make_umid_setup); |
315 | 323 | ||