File: hostname.c

package info (click to toggle)
systemtap 4.8-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 39,000 kB
  • sloc: cpp: 78,785; ansic: 62,419; xml: 49,443; exp: 42,735; sh: 11,254; python: 3,062; perl: 2,252; tcl: 1,305; makefile: 1,072; lisp: 105; awk: 101; asm: 91; java: 56; sed: 16
file content (60 lines) | stat: -rw-r--r-- 1,619 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* COVERAGE: gethostname uname sethostname */
#define _BSD_SOURCE
#define _DEFAULT_SOURCE

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/utsname.h>
#include <sys/syscall.h>

#define HLEN 1024

int main()
{
    char orig_hname[HLEN];
    char *new_hname = "stap_test";
    int rc;
    struct utsname uts;

    /* glibc likes to substitute utsname() for gethostname(). So,
     * let's force gethostname()'s use (assuming the syscall actually
     * exists on this platform). */
#ifdef __NR_gethostname
    syscall(__NR_gethostname, orig_hname, sizeof(orig_hname));
    //staptest// gethostname (XXXX, NNNN) = 0

    syscall(__NR_gethostname, -1, sizeof(orig_hname));
    //staptest// gethostname (0x[f]+, NNNN) = -NNNN

    syscall(__NR_gethostname, orig_hname, -1);
    //staptest// gethostname (XXXX, -1) = -NNNN
#endif

    uname(&uts);
    //staptest// uname (XXXX) = 0

    uname((struct utsname *)-1);
#ifdef __s390__
    //staptest// uname (0x[7]?[f]+) = -NNNN
#else
    //staptest// uname (0x[f]+) = -NNNN
#endif

    sethostname((char *)-1, sizeof(new_hname));
#ifdef __s390__
    //staptest// sethostname (0x[7]?[f]+, NNNN) = -NNNN
#else
    //staptest// sethostname (0x[f]+, NNNN) = -NNNN
#endif

    sethostname(NULL, -1);
    //staptest// sethostname (0x0, -1) = -NNNN

    // Notice we aren't calling sethostname() so that it will
    // succeed. This is on purpose, since we can't guarentee that
    // uname()/gethostname() returns exactly what sethostname() wants
    // (and the machine may have more than one name if it has more
    // than one interface).
    return 0;
}