[Bug other/55070] New: pthread_getname_np returns the name with a terminating newline on Linux.

2012-10-24 Thread chandan.jc at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55070



 Bug #: 55070

   Summary: pthread_getname_np returns the name with a terminating

newline on Linux.

Classification: Unclassified

   Product: gcc

   Version: 4.5.2

Status: UNCONFIRMED

  Severity: normal

  Priority: P3

 Component: other

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: chandan...@gmail.com





pthread_getname_np returns the name with a terminating newline.





Steps to reproduce:



Run the following program on Ubuntu 11.04 (should be reproducible on any

version). 



#include 

#include 

#include 

#include 



void *threadfunc(void *parm)

{

printf("In the thread.\n");

sleep(20); // allow main program to set the thread name

return NULL;

}



int main(int argc, char **argv)

{

pthread_t thread;

int rc=0;

char theName[16];



memset(theName, 0, sizeof(theName));

printf("Creating an unnamed thread\n");

rc = pthread_create(&thread, NULL, threadfunc, NULL);

if(0 == rc)

{

sleep(2);

rc = pthread_setname_np(thread, "THREADFOO");

sleep(2);

if(0 == rc)

{

rc = pthread_getname_np(thread, theName, 16);

if(0 == rc)

{

printf("The thread name is %s.\n", theName);

}

else

{

perror("pthread_getname_np");

}

}

else

{

perror("pthread_setname_np");

}

rc = pthread_join(thread, NULL);

}

if(0 != rc)

{

perror("pthread_create");

}

printf("Done\n");

return(rc);

}





Expected output:

Creating an unnamed thread

In the thread.

The thread name is THREADFOO.

Done



Actual Output:

Creating an unnamed thread

In the thread.

The thread name is THREADFOO

.

Done



As you can see, pthread_getname_np is adding a trailing newline to the returned

string.


[Bug other/55070] pthread_getname_np returns the name with a terminating newline on Linux.

2012-10-24 Thread chandan.jc at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55070



--- Comment #2 from Chandan Apsangi  2012-10-25 
06:32:00 UTC ---

Anyway, Not reproducible on latest version of glibc.