From: John Hodge Date: Sat, 11 Jan 2014 12:37:21 +0000 (+0800) Subject: Kernel/PTY - Fix missed lock X-Git-Tag: rel0.15~15 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=d0f611cd4716fa5647ce029a2fe827eadac8dd4b;p=tpg%2Facess2.git Kernel/PTY - Fix missed lock --- diff --git a/KernelLand/Kernel/drv/pty.c b/KernelLand/Kernel/drv/pty.c index 37fc47b4..ebce2085 100644 --- a/KernelLand/Kernel/drv/pty.c +++ b/KernelLand/Kernel/drv/pty.c @@ -126,7 +126,11 @@ tPTY *PTY_Create(const char *Name, void *Handle, tPTY_OutputFcn Output, tPTY_Req tPTY **prev_np = NULL; size_t namelen; int idx = 1; - if( !Name || Name[0] == '\0' ) + + if( !Name ) + Name = ""; + + if( Name[0] == '\0' ) { RWLock_AcquireWrite(&glPTY_NumPTYs); // Get a pty ID if Name==NULL @@ -146,6 +150,7 @@ tPTY *PTY_Create(const char *Name, void *Handle, tPTY_OutputFcn Output, tPTY_Req // whichever is free prev_np = &gpPTY_FirstNamedPTY; + RWLock_AcquireWrite(&glPTY_NamedPTYs); idx = 0; namelen = strlen(Name)-1; for( tPTY *pty = gpPTY_FirstNamedPTY; pty; prev_np = &pty->Next, pty = pty->Next ) @@ -214,10 +219,10 @@ tPTY *PTY_Create(const char *Name, void *Handle, tPTY_OutputFcn Output, tPTY_Req ret->Name = (char*)(ret + 1); if( idx == -1 ) strcpy(ret->Name, Name); - else { - if(!Name) Name = ""; + else if( Name[0] ) sprintf(ret->Name, "%.*s%u", strlen(Name)-1, Name, idx); - } + else + sprintf(ret->Name, "%u", idx); ret->NumericName = idx; // - Output function and handle (same again) ret->OutputHandle = Handle; @@ -235,7 +240,7 @@ tPTY *PTY_Create(const char *Name, void *Handle, tPTY_OutputFcn Output, tPTY_Req ret->OwnerRW.Ent.ID = Threads_GetUID(); ret->OwnerRW.Perm.Perms = -1; - if( Name && Name[0] ) { + if( Name[0] ) { giPTY_NamedCount ++; RWLock_Release(&glPTY_NamedPTYs); }