Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getpgid not implemented with valgrind

Considering this example :

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

int     main()
{
    int pgid;

    if ((pgid = getpgid(0)) == -1)
        perror("getpgid");
    else
        printf("pgid : %d\n", pgid);
}

When I'm running this program without valgrind, everything is going right, and the pgid is printed. Whenever I'm using valgrind, perror will print getpgid: Function not implemented.

  • Is it normal that getpgid is not available under valgrind ?

  • Is there any alternative to get the pgid of a specific pid (excluding getpgrp) ?

I'm using macOS Sierra 10.12.6 and valgrind-3.15.0.

like image 867
rSim Avatar asked Oct 23 '19 14:10

rSim


2 Answers

It seem that valgrind could have some trouble to perform some syscall.

In the valgrind trace, I'm having :

--17135-- WARNING: unhandled amd64-darwin syscall: unix:151
--17135-- You may be able to write your own handler.
--17135-- Read the file README_MISSING_SYSCALL_OR_IOCTL.
--17135-- Nevertheless we consider this a bug.  Please report
--17135-- it at http://valgrind.org/support/bug_reports.html.

So I need to create a wrapper for the function, and it should work. I will report the bug to the support.

like image 58
rSim Avatar answered Nov 05 '22 19:11

rSim


You shouldn't test via valgrind on Mac OS X because after Sierra, it is not supported. Instead, also it is what I do, install ubuntu via an virtual machine software then run valgrind.

macOS Mojave 10.14.6's unistd.h has the following part,

#if __DARWIN_UNIX03
void     encrypt(char *, int) __DARWIN_ALIAS(encrypt);
#else /* !__DARWIN_UNIX03 */
int  encrypt(char *, int);
#endif /* __DARWIN_UNIX03 */
int  fchdir(int);
long     gethostid(void);
pid_t    getpgid(pid_t);
pid_t    getsid(pid_t);

Rule of thumb, always try to be portable!


Incidentally, as @Andrew Henle mentions, pid_t can be of system-dependent type. But, it shouldn't be unsigned type to preserve portability since it can be returned as -1 in the case of a failure. Moreover, on Mac OS X its type is int, as seen below

typedef int               __int32_t;
typedef __int32_t         __darwin_pid_t;         /* [???] process and group IDs */
typedef __darwin_pid_t    pid_t;
like image 24
snr Avatar answered Nov 05 '22 19:11

snr