3

The prototype of prctl is

int prctl(int option, unsigned long arg2, unsigned long arg3,
          unsigned long arg4, unsigned long arg5);

in the man page whereas in the header it is declared as a variadic function:

extern int prctl (int __option, ...) __THROW;

  1. Do I have to call it with 5 arguments when I only need 2?
  2. Do I need to cast args to unsigned long?
sigsegv
  • 73
  • 3

1 Answers1

3

Just pass what you have to pass and write 0 casted to unsigned long in the rest of arguments or skip them entirely. As prctl is declared as variadic function it will handle this situation accordingly.

const char* name = "The user";
if (prctl(PR_SET_NAME, (unsigned long) name,
         (unsigned long)0, (unsigned long)0, (unsigned long)0) == -1)
{
    // handle error
    perror("prctl failed");
    return -1;
}

or

const char* name = "The user";
if (prctl(PR_SET_NAME, (unsigned long) name) == -1)
{
    // handle error
    perror("prctl failed");
    return -1;
}
4pie0
  • 29,204
  • 9
  • 82
  • 118