Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 9242
b: refs/heads/master
c: 3a02d6c
h: refs/heads/master
v: v3
  • Loading branch information
Paolo 'Blaisorblade' Giarrusso authored and Linus Torvalds committed Sep 23, 2005
1 parent b6a1dfc commit 0411551
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 8686bcd0a5f5e3f599ed9f1028ec9e449e7b87e3
refs/heads/master: 3a02d6c051cf3c214aab38e4330b4bcec5f6e3f8
30 changes: 19 additions & 11 deletions trunk/arch/um/kernel/umid.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ static char *uml_dir = UML_DIR;
/* Changed by set_umid */
static int umid_is_random = 1;
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, ...));

Expand Down Expand Up @@ -82,28 +84,28 @@ int __init umid_file_name(char *name, char *buf, int len)

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 pid[sizeof("nnnnn\0")];
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()))),
0644);
if(fd < 0){
printf("Open of machine pid file \"%s\" failed: %s\n",
file, strerror(-fd));
return 0;
return;
}

sprintf(pid, "%d\n", os_getpid());
n = os_write_file(fd, pid, strlen(pid));
if(n != strlen(pid))
printf("Write of pid file failed - err = %d\n", -n);
os_close_file(fd);
return 0;
}

static int actually_do_remove(char *dir)
Expand Down Expand Up @@ -147,19 +149,21 @@ static int actually_do_remove(char *dir)
void remove_umid_dir(void)
{
char dir[strlen(uml_dir) + UMID_LEN + 1];
if(!umid_inited) return;
if (!umid_owned)
return;

sprintf(dir, "%s%s", uml_dir, umid);
actually_do_remove(dir);
}

char *get_umid(int only_if_set)
{
if(only_if_set && umid_is_random) return(NULL);
return(umid);
if(only_if_set && umid_is_random)
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 pid[sizeof("nnnnn\0")], *end;
Expand Down Expand Up @@ -193,7 +197,8 @@ int not_dead_yet(char *dir)
(p == CHOOSE_MODE(tracing_pid, os_getpid())))
dead = 1;
}
if(!dead) return(1);
if(!dead)
return(1);
return(actually_do_remove(dir));
}

Expand Down Expand Up @@ -286,6 +291,7 @@ static int __init make_umid(int (*printer)(const char *fmt, ...))
if(errno == EEXIST){
if(not_dead_yet(tmp)){
(*printer)("umid '%s' is in use\n", umid);
umid_owned = 0;
return(-1);
}
err = mkdir(tmp, 0777);
Expand All @@ -296,7 +302,8 @@ static int __init make_umid(int (*printer)(const char *fmt, ...))
return(-1);
}

return(0);
umid_owned = 1;
return 0;
}

__uml_setup("uml_dir=", set_uml_dir,
Expand All @@ -309,7 +316,8 @@ static int __init make_umid_setup(void)
/* one function with the ordering we need ... */
make_uml_dir();
make_umid(printf);
return create_pid_file();
create_pid_file();
return 0;
}
__uml_postsetup(make_umid_setup);

Expand Down

0 comments on commit 0411551

Please sign in to comment.