| 1 |
/* COVERAGE: gethostname uname sethostname */ |
| 2 |
#define _BSD_SOURCE |
| 3 |
#define _DEFAULT_SOURCE |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
#include <string.h> |
| 7 |
#include <unistd.h> |
| 8 |
#include <sys/utsname.h> |
| 9 |
#include <sys/syscall.h> |
| 10 |
|
| 11 |
#define HLEN 1024 |
| 12 |
|
| 13 |
int main() |
| 14 |
{ |
| 15 |
char orig_hname[HLEN]; |
| 16 |
char *new_hname = "stap_test"; |
| 17 |
int rc; |
| 18 |
struct utsname uts; |
| 19 |
|
| 20 |
/* glibc likes to substitute utsname() for gethostname(). So, |
| 21 |
* let's force gethostname()'s use (assuming the syscall actually |
| 22 |
* exists on this platform). */ |
| 23 |
#ifdef __NR_gethostname |
| 24 |
syscall(__NR_gethostname, orig_hname, sizeof(orig_hname)); |
| 25 |
//staptest// gethostname (XXXX, NNNN) = 0 |
| 26 |
|
| 27 |
syscall(__NR_gethostname, -1, sizeof(orig_hname)); |
| 28 |
//staptest// gethostname (0x[f]+, NNNN) = -NNNN |
| 29 |
|
| 30 |
syscall(__NR_gethostname, orig_hname, -1); |
| 31 |
//staptest// gethostname (XXXX, -1) = -NNNN |
| 32 |
#endif |
| 33 |
|
| 34 |
uname(&uts); |
| 35 |
//staptest// uname (XXXX) = 0 |
| 36 |
|
| 37 |
uname((struct utsname *)-1); |
| 38 |
#ifdef __s390__ |
| 39 |
//staptest// uname (0x[7]?[f]+) = -NNNN |
| 40 |
#else |
| 41 |
//staptest// uname (0x[f]+) = -NNNN |
| 42 |
#endif |
| 43 |
|
| 44 |
sethostname((char *)-1, sizeof(new_hname)); |
| 45 |
#ifdef __s390__ |
| 46 |
//staptest// sethostname (0x[7]?[f]+, NNNN) = -NNNN |
| 47 |
#else |
| 48 |
//staptest// sethostname (0x[f]+, NNNN) = -NNNN |
| 49 |
#endif |
| 50 |
|
| 51 |
sethostname(NULL, -1); |
| 52 |
//staptest// sethostname (0x0, -1) = -NNNN |
| 53 |
|
| 54 |
// Notice we aren't calling sethostname() so that it will |
| 55 |
// succeed. This is on purpose, since we can't guarentee that |
| 56 |
// uname()/gethostname() returns exactly what sethostname() wants |
| 57 |
// (and the machine may have more than one name if it has more |
| 58 |
// than one interface). |
| 59 |
return 0; |
| 60 |
} |