diff options
author | Tony Luck <tony.luck@intel.com> | 2005-10-20 13:41:44 -0400 |
---|---|---|
committer | Tony Luck <tony.luck@intel.com> | 2005-10-20 13:41:44 -0400 |
commit | 9cec58dc138d6fcad9f447a19c8ff69f6540e667 (patch) | |
tree | 4fe1cca94fdba8b705c87615bee06d3346f687ce /arch/um/kernel/umid.c | |
parent | 17e5ad6c0ce5a970e2830d0de8bdd60a2f077d38 (diff) | |
parent | ac9b9c667c2e1194e22ebe0a441ae1c37aaa9b90 (diff) |
Update from upstream with manual merge of Yasunori Goto's
changes to swiotlb.c made in commit 281dd25cdc0d6903929b79183816d151ea626341
since this file has been moved from arch/ia64/lib/swiotlb.c to
lib/swiotlb.c
Signed-off-by: Tony Luck <tony.luck@intel.com>
Diffstat (limited to 'arch/um/kernel/umid.c')
-rw-r--r-- | arch/um/kernel/umid.c | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/arch/um/kernel/umid.c b/arch/um/kernel/umid.c index 186c28885016..0b21d59ba0cd 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 | ||
@@ -232,16 +237,13 @@ static int __init make_uml_dir(void) | |||
232 | strlcpy(dir, home, sizeof(dir)); | 237 | strlcpy(dir, home, sizeof(dir)); |
233 | uml_dir++; | 238 | uml_dir++; |
234 | } | 239 | } |
240 | strlcat(dir, uml_dir, sizeof(dir)); | ||
235 | len = strlen(dir); | 241 | len = strlen(dir); |
236 | strncat(dir, uml_dir, sizeof(dir) - len); | 242 | if (len > 0 && dir[len - 1] != '/') |
237 | len = strlen(dir); | 243 | strlcat(dir, "/", sizeof(dir)); |
238 | if((len > 0) && (len < sizeof(dir) - 1) && (dir[len - 1] != '/')){ | ||
239 | dir[len] = '/'; | ||
240 | dir[len + 1] = '\0'; | ||
241 | } | ||
242 | 244 | ||
243 | uml_dir = malloc(strlen(dir) + 1); | 245 | uml_dir = malloc(strlen(dir) + 1); |
244 | if(uml_dir == NULL){ | 246 | if (uml_dir == NULL) { |
245 | printf("make_uml_dir : malloc failed, errno = %d\n", errno); | 247 | printf("make_uml_dir : malloc failed, errno = %d\n", errno); |
246 | exit(1); | 248 | exit(1); |
247 | } | 249 | } |
@@ -286,6 +288,7 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) | |||
286 | if(errno == EEXIST){ | 288 | if(errno == EEXIST){ |
287 | if(not_dead_yet(tmp)){ | 289 | if(not_dead_yet(tmp)){ |
288 | (*printer)("umid '%s' is in use\n", umid); | 290 | (*printer)("umid '%s' is in use\n", umid); |
291 | umid_owned = 0; | ||
289 | return(-1); | 292 | return(-1); |
290 | } | 293 | } |
291 | err = mkdir(tmp, 0777); | 294 | err = mkdir(tmp, 0777); |
@@ -296,7 +299,8 @@ static int __init make_umid(int (*printer)(const char *fmt, ...)) | |||
296 | return(-1); | 299 | return(-1); |
297 | } | 300 | } |
298 | 301 | ||
299 | return(0); | 302 | umid_owned = 1; |
303 | return 0; | ||
300 | } | 304 | } |
301 | 305 | ||
302 | __uml_setup("uml_dir=", set_uml_dir, | 306 | __uml_setup("uml_dir=", set_uml_dir, |
@@ -309,7 +313,8 @@ static int __init make_umid_setup(void) | |||
309 | /* one function with the ordering we need ... */ | 313 | /* one function with the ordering we need ... */ |
310 | make_uml_dir(); | 314 | make_uml_dir(); |
311 | make_umid(printf); | 315 | make_umid(printf); |
312 | return create_pid_file(); | 316 | create_pid_file(); |
317 | return 0; | ||
313 | } | 318 | } |
314 | __uml_postsetup(make_umid_setup); | 319 | __uml_postsetup(make_umid_setup); |
315 | 320 | ||