diff options
| author | Mel <einebeere@gmail.com> | 2024-02-17 02:09:26 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-02-17 02:09:26 +0100 |
| commit | c1cab90dbcd0f1fc743cb733114064f602766db6 (patch) | |
| tree | f63817122163eb7ef99b7e329279a6225f2df440 /service.c | |
| download | single-container-example-c1cab90dbcd0f1fc743cb733114064f602766db6.tar.zst single-container-example-c1cab90dbcd0f1fc743cb733114064f602766db6.zip | |
Single container with a service and Postgres main
Diffstat (limited to 'service.c')
| -rw-r--r-- | service.c | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/service.c b/service.c new file mode 100644 index 0000000..edc6fd0 --- /dev/null +++ b/service.c @@ -0,0 +1,22 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <libpq-fe.h> + +int main() { + PGconn *conn; + for (int i = 0; i < 100; i++) { + printf("trying to connect...\n"); + conn = PQconnectdb("host=localhost dbname=postgres user=postgres password="); + if (PQstatus(conn) == CONNECTION_OK) { + printf("connected :)\n"); + break; + } else { + fprintf(stderr, "connection failed: %s", PQerrorMessage(conn)); + sleep(2); + } + } + + PQfinish(conn); +} + |
