• Re: lpthreads and getpwuid=segmentation fault??

    From stryker2k2@21:1/5 to All on Wed Jan 4 07:30:12 2023
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this as well. Even if you code in the proper checks on the return value, you will still get a SEGFAULT. There is something weird with lpthreads and getpwuid (and also getlogin) and I don'
    t quite know what it is. But, yes... the combo of these two will always cause a SEGFAULT before you can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kenny McCormack@21:1/5 to stryker2k2@gmail.com on Wed Jan 4 16:28:18 2023
    In article <e95d3f27-47ad-4ff4-8429-92821ad3e79en@googlegroups.com>,
    stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink >alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this
    as well. Even if you code in the proper checks on the return value, you
    will still get a SEGFAULT. There is something weird with lpthreads and >getpwuid (and also getlogin) and I don't quite know what it is. But,
    yes... the combo of these two will always cause a SEGFAULT before you
    can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    Could you post code & build instructions?

    Then we might at least have a chance at understanding what you're talking about, Willis...

    --
    The randomly chosen signature file that would have appeared here is more than 4 lines long. As such, it violates one or more Usenet RFCs. In order to remain in compliance with said RFCs, the actual sig can be found at the following URL:
    http://user.xmission.com/~gazelle/Sigs/RoyDeLoon

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Paul@21:1/5 to Kenny McCormack on Wed Jan 4 17:37:24 2023
    On 1/4/2023 11:28 AM, Kenny McCormack wrote:
    In article <e95d3f27-47ad-4ff4-8429-92821ad3e79en@googlegroups.com>, stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink >> alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this
    as well. Even if you code in the proper checks on the return value, you
    will still get a SEGFAULT. There is something weird with lpthreads and
    getpwuid (and also getlogin) and I don't quite know what it is. But,
    yes... the combo of these two will always cause a SEGFAULT before you
    can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    Could you post code & build instructions?

    Then we might at least have a chance at understanding what you're talking about, Willis...


    Mar 5, 2003, 11:49:55 AM

    https://groups.google.com/g/comp.unix.programmer/c/hs23vL73-y0

    Paul

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard Kettlewell@21:1/5 to Paul on Wed Jan 4 22:57:39 2023
    Paul <nospam@needed.invalid> writes:
    On 1/4/2023 11:28 AM, Kenny McCormack wrote:
    stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink >>> alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this
    as well. Even if you code in the proper checks on the return value, you
    will still get a SEGFAULT. There is something weird with lpthreads and
    getpwuid (and also getlogin) and I don't quite know what it is. But,
    yes... the combo of these two will always cause a SEGFAULT before you
    can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu
    Could you post code & build instructions?
    Then we might at least have a chance at understanding what you're
    talking
    about, Willis...

    Mar 5, 2003, 11:49:55 AM

    https://groups.google.com/g/comp.unix.programmer/c/hs23vL73-y0

    The program there doesn’t have “the proper checks on the return value”, so it’s presumably not what you’re actually running. Also, -lpthreads
    does not exist; the library is -lpthread. So we don’t yet have the build commands you used, either. Obviously, nobody can debug code that you’ve
    not shared.

    I would suggest using gdb or valgrind to identify where your version
    crashes.

    --
    https://www.greenend.org.uk/rjk/

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Paul on Wed Jan 4 22:59:22 2023
    Paul <nospam@needed.invalid> writes:

    On 1/4/2023 11:28 AM, Kenny McCormack wrote:
    In article <e95d3f27-47ad-4ff4-8429-92821ad3e79en@googlegroups.com>,
    stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink >>> alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this
    as well. Even if you code in the proper checks on the return value, you
    will still get a SEGFAULT. There is something weird with lpthreads and
    getpwuid (and also getlogin) and I don't quite know what it is. But,
    yes... the combo of these two will always cause a SEGFAULT before you
    can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    Could you post code & build instructions?
    Then we might at least have a chance at understanding what you're talking
    about, Willis...

    Mar 5, 2003, 11:49:55 AM

    https://groups.google.com/g/comp.unix.programmer/c/hs23vL73-y0

    That program, with the undefined behaviour removed, but the curious
    verbose style kept, is

    #include <pwd.h>
    #include <unistd.h>
    #include <stdio.h>

    char *a;

    char *getuser(void)
    {
    char *username;
    struct passwd *info;
    info = getpwuid(getuid());
    username = info->pw_name;
    return username;
    }

    int main(void)
    {
    a = getuser();
    printf(a);
    printf("\n");
    }

    which compiles and runs fine on my system, with either the -pthread or -lpthread option. Of course, since threads are not used, the linker may
    simply be omitting the code that caused the problem 19 years ago.

    The old post refers to -lpthreads (with and s) and my Ubuntu and gcc are
    newer.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Scott Lurndal@21:1/5 to Ben Bacarisse on Wed Jan 4 23:24:16 2023
    Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
    Paul <nospam@needed.invalid> writes:

    On 1/4/2023 11:28 AM, Kenny McCormack wrote:
    In article <e95d3f27-47ad-4ff4-8429-92821ad3e79en@googlegroups.com>,
    stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink
    alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this >>>> as well. Even if you code in the proper checks on the return value, you >>>> will still get a SEGFAULT. There is something weird with lpthreads and >>>> getpwuid (and also getlogin) and I don't quite know what it is. But,
    yes... the combo of these two will always cause a SEGFAULT before you
    can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    Could you post code & build instructions?
    Then we might at least have a chance at understanding what you're talking >>> about, Willis...

    Mar 5, 2003, 11:49:55 AM

    https://groups.google.com/g/comp.unix.programmer/c/hs23vL73-y0

    That program, with the undefined behaviour removed, but the curious
    verbose style kept, is

    #include <pwd.h>
    #include <unistd.h>
    #include <stdio.h>

    char *a;

    char *getuser(void)
    {
    char *username;
    struct passwd *info;
    info = getpwuid(getuid());
    username = info->pw_name;
    return username;
    }

    int main(void)
    {
    a = getuser();
    printf(a);
    printf("\n");
    }

    which compiles and runs fine on my system, with either the -pthread or >-lpthread option. Of course, since threads are not used, the linker may >simply be omitting the code that caused the problem 19 years ago.

    The old post refers to -lpthreads (with and s) and my Ubuntu and gcc are >newer.

    The code will fail if there is no password file entry matching
    the current uid.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Ben Bacarisse@21:1/5 to Scott Lurndal on Wed Jan 4 23:36:15 2023
    scott@slp53.sl.home (Scott Lurndal) writes:

    Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
    Paul <nospam@needed.invalid> writes:

    On 1/4/2023 11:28 AM, Kenny McCormack wrote:
    In article <e95d3f27-47ad-4ff4-8429-92821ad3e79en@googlegroups.com>,
    stryker2k2 <stryker2k2@gmail.com> wrote:
    ARISE, OLD DEAD THREAD! Hey, this thread is almost legally allowed to drink
    alcohol in the United States!

    Anyways... Uwe Ludwig stumbled upon this and now I am stumbling on this >>>>> as well. Even if you code in the proper checks on the return value, you >>>>> will still get a SEGFAULT. There is something weird with lpthreads and >>>>> getpwuid (and also getlogin) and I don't quite know what it is. But, >>>>> yes... the combo of these two will always cause a SEGFAULT before you >>>>> can even check the return.

    Stats:
    - Ubuntu 20.04
    - gcc version 9.4.0
    - x86_64-linux-gnu

    Could you post code & build instructions?
    Then we might at least have a chance at understanding what you're talking >>>> about, Willis...

    Mar 5, 2003, 11:49:55 AM

    https://groups.google.com/g/comp.unix.programmer/c/hs23vL73-y0

    That program, with the undefined behaviour removed, but the curious
    verbose style kept, is

    #include <pwd.h>
    #include <unistd.h>
    #include <stdio.h>

    char *a;

    char *getuser(void)
    {
    char *username;
    struct passwd *info;
    info = getpwuid(getuid());
    username = info->pw_name;
    return username;
    }

    int main(void)
    {
    a = getuser();
    printf(a);
    printf("\n");
    }

    which compiles and runs fine on my system, with either the -pthread or >>-lpthread option. Of course, since threads are not used, the linker may >>simply be omitting the code that caused the problem 19 years ago.

    The old post refers to -lpthreads (with and s) and my Ubuntu and gcc are >>newer.

    The code will fail if there is no password file entry matching
    the current uid.

    Sure, but if that's what the OP is observing, then I can't see the
    connection to the pthread library.

    --
    Ben.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)