Skip to content

Commit

Permalink
I CANNOT READ
Browse files Browse the repository at this point in the history
  • Loading branch information
FauxFaux committed Mar 15, 2020
0 parents commit b7f9da7
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
*.swp
.idea/
9 changes: 9 additions & 0 deletions Dockerfile
@@ -0,0 +1,9 @@
FROM alpine
WORKDIR /b
RUN apk add --update gcc libc-dev
ADD app.c ./
RUN gcc -O1 -static app.c

FROM scratch
COPY --from=0 /b/a.out /a
CMD ["/a"]
57 changes: 57 additions & 0 deletions app.c
@@ -0,0 +1,57 @@
#define _POSIX_C_SOURCE 200112L

#include <stdio.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>

int main() {

const char *head = "HTTP/1.0 200\r\nContent-type: text/plain\r\n\r\n";
char buf[256] = {};
memcpy(buf, head, strlen(head));
if (0 != gethostname(buf + strlen(buf), sizeof(buf))) {
return 4;
}

strcat(buf, "\n");

int sockfd = socket(AF_INET, SOCK_STREAM, 0);

#ifdef REUSEADDR
int enable = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int)) < 0) {
return 5;
}
#endif

struct sockaddr_in servaddr = {};
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(1337);
if (0 != bind(sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) {
return 1;
}

if (0 != listen(sockfd, 50)) {
return 2;
}

for (;;) {
int conn = accept(sockfd, NULL, NULL);
if (conn < 0) {
return 3;
}

// errors intentionally ignored
write(conn, buf, strlen(buf));

// without shutdown, curl sometimes gets the close before the data
shutdown(conn, SHUT_RDWR);
close(conn);
}
}

41 changes: 41 additions & 0 deletions quebec.yml
@@ -0,0 +1,41 @@
---
kind: Deployment
apiVersion: apps/v1
metadata:
name: hosty
spec:
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
replicas: 3
selector:
matchLabels:
name: hosty
template:
metadata:
labels:
name: hosty
spec:
containers:
- name: app
image: faux/hostname-reply
ports:
- containerPort: 1337
readinessProbe:
httpGet:
path: /
port: 1337
---
apiVersion: v1
kind: Service
metadata:
name: hosty
spec:
type: ClusterIP
ports:
- port: 80
targetPort: 1337
selector:
name: hosty

0 comments on commit b7f9da7

Please sign in to comment.