16 struct passwd
*pwent
= getpwnam(user
);
18 twarn("getpwnam(\"%s\")", user
);
22 twarnx("getpwnam(\"%s\"): no such user", user
);
26 int r
= setgid(pwent
->pw_gid
);
28 twarn("setgid(%d \"%s\")", pwent
->pw_gid
, user
);
32 r
= setuid(pwent
->pw_uid
);
34 twarn("setuid(%d \"%s\")", pwent
->pw_uid
, user
);
50 sa
.sa_handler
= SIG_IGN
;
52 int r
= sigemptyset(&sa
.sa_mask
);
54 twarn("sigemptyset()");
58 r
= sigaction(SIGPIPE
, &sa
, 0);
60 twarn("sigaction(SIGPIPE)");
64 sa
.sa_handler
= enter_drain_mode
;
65 r
= sigaction(SIGUSR1
, &sa
, 0);
67 twarn("sigaction(SIGUSR1)");
71 // Workaround for running the server with pid=1 in Docker.
72 // Handle SIGTERM so the server is killed immediately and
73 // not after 10 seconds timeout. See issue #527.
75 sa
.sa_handler
= handle_sigterm_pid1
;
76 r
= sigaction(SIGTERM
, &sa
, 0);
78 twarn("sigaction(SIGTERM)");
85 main(int argc
, char **argv
)
87 UNUSED_PARAMETER(argc
);
91 optparse(&srv
, argv
+1);
94 printf("pid %d\n", getpid());
97 int r
= make_server_socket(srv
.addr
, srv
.port
);
99 twarnx("make_server_socket()");
111 srv_acquire_wal(&srv
);